Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change import role to cluster role #2645

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/sirupsen/logrus"

"github.com/rancher/fleet/internal/cmd/controller/agentmanagement/controllers/resources"
secretutil "github.com/rancher/fleet/internal/cmd/controller/agentmanagement/secret"
"github.com/rancher/fleet/internal/config"
fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"
Expand Down Expand Up @@ -142,22 +143,6 @@ func (h *handler) OnChange(token *fleet.ClusterRegistrationToken, status fleet.C
},
},
},
&rbacv1.Role{
ObjectMeta: metav1.ObjectMeta{
Name: name.SafeConcatName(saName, "role"),
Namespace: token.Namespace,
Labels: map[string]string{
fleet.ManagedLabel: "true",
},
},
Rules: []rbacv1.PolicyRule{
{
Verbs: []string{"create"},
APIGroups: []string{fleet.SchemeGroupVersion.Group},
Resources: []string{fleet.ClusterRegistrationResourceNamePlural},
},
},
},
&rbacv1.RoleBinding{
ObjectMeta: metav1.ObjectMeta{
Name: name.SafeConcatName(saName, "to", "role"),
Expand All @@ -175,21 +160,8 @@ func (h *handler) OnChange(token *fleet.ClusterRegistrationToken, status fleet.C
},
RoleRef: rbacv1.RoleRef{
APIGroup: rbacv1.GroupName,
Kind: "Role",
Name: name.SafeConcatName(saName, "role"),
},
},
&rbacv1.Role{
ObjectMeta: metav1.ObjectMeta{
Name: name.SafeConcatName(saName, "creds"),
Namespace: h.systemRegistrationNamespace,
},
Rules: []rbacv1.PolicyRule{
{
Verbs: []string{"get"},
APIGroups: []string{""},
Resources: []string{"secrets"},
},
Kind: "ClusterRole",
Name: resources.ImportRegistration,
},
},
&rbacv1.RoleBinding{
Expand All @@ -206,8 +178,8 @@ func (h *handler) OnChange(token *fleet.ClusterRegistrationToken, status fleet.C
},
RoleRef: rbacv1.RoleRef{
APIGroup: rbacv1.GroupName,
Kind: "Role",
Name: name.SafeConcatName(saName, "creds"),
Kind: "ClusterRole",
Name: resources.ImportCredentials,
},
},
}, secrets...), status, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
const (
BundleDeploymentClusterRole = "fleet-bundle-deployment"
ContentClusterRole = "fleet-content"
ImportRegistration = "fleet-import-registration"
ImportCredentials = "fleet-import-creds" // nolint:gosec // this is not a credential
)

// ApplyBootstrapResources creates the cluster roles, system namespace and system registration namespace
Expand Down Expand Up @@ -54,11 +56,39 @@ func ApplyBootstrapResources(systemNamespace, systemRegistrationNamespace string
},
},
},
// used by import- service accounts
&rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
Name: ImportCredentials,
},
Rules: []rbacv1.PolicyRule{
{
Verbs: []string{"get"},
APIGroups: []string{""},
Resources: []string{"secrets"},
},
},
},
// used by import- service accounts
&rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
Name: ImportRegistration,
},
Rules: []rbacv1.PolicyRule{
{
Verbs: []string{"create"},
APIGroups: []string{fleet.SchemeGroupVersion.Group},
Resources: []string{fleet.ClusterRegistrationResourceNamePlural},
},
},
},
// namespace for the controllers (e.g. cattle-fleet-system)
&corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: systemNamespace,
},
},
// namespace for secrets used in the cluster registration process (e.g. cattle-fleet-clusters-system)
&corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: systemRegistrationNamespace,
Expand Down
Loading