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

Release RBAC Cleanup #1194

Merged
merged 3 commits into from
Sep 20, 2024
Merged
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
4 changes: 2 additions & 2 deletions charts/radix-operator/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v2
name: radix-operator
version: 1.39.0
appVersion: 1.59.1
version: 1.39.2
appVersion: 1.59.2
kubeVersion: ">=1.24.0"
description: Radix Operator
keywords:
Expand Down
19 changes: 7 additions & 12 deletions charts/radix-operator/templates/radix-apps-rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,6 @@ rules:
- watch
- patch
- create
# Remove as part of https://equinor.atlassian.net/browse/RA-725
- apiGroups:
- batch
resources:
- jobs
verbs:
- get
- list
- watch
- patch
- create
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
Expand Down Expand Up @@ -133,7 +122,13 @@ rules:
verbs:
- get
- list

- apiGroups:
- apps
resources:
- deployments
verbs:
- get
- update
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
Expand Down
2 changes: 0 additions & 2 deletions pkg/apis/deployment/oauthproxyresourcemanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,6 @@ func (o *oauthProxyResourceManager) createOrUpdateRbac(ctx context.Context, comp

func (o *oauthProxyResourceManager) createOrUpdateAppAdminRbac(ctx context.Context, component v1.RadixCommonDeployComponent) error {
secretName := utils.GetAuxiliaryComponentSecretName(component.GetName(), defaults.OAuthProxyAuxiliaryComponentSuffix)
deploymentName := utils.GetAuxiliaryComponentDeploymentName(component.GetName(), defaults.OAuthProxyAuxiliaryComponentSuffix)
roleName := o.getRoleAndRoleBindingName("radix-app-adm", component.GetName())
namespace := o.rd.Namespace

Expand All @@ -493,7 +492,6 @@ func (o *oauthProxyResourceManager) createOrUpdateAppAdminRbac(ctx context.Conte
roleName,
radixlabels.ForAuxComponent(o.rd.Spec.AppName, component),
kube.ManageSecretsRule([]string{secretName}),
kube.UpdateDeploymentsRule([]string{deploymentName}),
)

err := o.kubeutil.ApplyRole(ctx, namespace, role)
Expand Down
7 changes: 1 addition & 6 deletions pkg/apis/deployment/oauthproxyresourcemanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,22 +410,17 @@ func (s *OAuthProxyResourceManagerTestSuite) Test_Sync_OAuthProxyRbacCreated() {
expectedRoles := []string{fmt.Sprintf("radix-app-adm-%s", utils.GetAuxiliaryComponentDeploymentName(componentName, defaults.OAuthProxyAuxiliaryComponentSuffix)), fmt.Sprintf("radix-app-reader-%s", utils.GetAuxiliaryComponentDeploymentName(componentName, defaults.OAuthProxyAuxiliaryComponentSuffix))}
expectedLabels := map[string]string{kube.RadixAppLabel: appName, kube.RadixAuxiliaryComponentLabel: componentName, kube.RadixAuxiliaryComponentTypeLabel: defaults.OAuthProxyAuxiliaryComponentType}
expectedSecretName := utils.GetAuxiliaryComponentSecretName(componentName, defaults.OAuthProxyAuxiliaryComponentSuffix)
expectedDeploymentName := utils.GetAuxiliaryComponentDeploymentName(componentName, defaults.OAuthProxyAuxiliaryComponentSuffix)

actualRoles, _ := s.kubeClient.RbacV1().Roles(envNs).List(context.Background(), metav1.ListOptions{})
s.ElementsMatch(expectedRoles, getRoleNames(actualRoles))

admRole := getRoleByName(fmt.Sprintf("radix-app-adm-%s", utils.GetAuxiliaryComponentDeploymentName(componentName, defaults.OAuthProxyAuxiliaryComponentSuffix)), actualRoles)
s.Equal(expectedLabels, admRole.Labels)
s.Len(admRole.Rules, 2)
s.Len(admRole.Rules, 1)
s.ElementsMatch([]string{""}, admRole.Rules[0].APIGroups)
s.ElementsMatch([]string{"secrets"}, admRole.Rules[0].Resources)
s.ElementsMatch([]string{expectedSecretName}, admRole.Rules[0].ResourceNames)
s.ElementsMatch([]string{"get", "update", "patch", "list", "watch", "delete"}, admRole.Rules[0].Verbs)
s.ElementsMatch([]string{"apps"}, admRole.Rules[1].APIGroups)
s.ElementsMatch([]string{"deployments"}, admRole.Rules[1].Resources)
s.ElementsMatch([]string{expectedDeploymentName}, admRole.Rules[1].ResourceNames)
s.ElementsMatch([]string{"update"}, admRole.Rules[1].Verbs)

readerRole := getRoleByName(fmt.Sprintf("radix-app-reader-%s", utils.GetAuxiliaryComponentDeploymentName(componentName, defaults.OAuthProxyAuxiliaryComponentSuffix)), actualRoles)
s.Equal(expectedLabels, readerRole.Labels)
Expand Down
11 changes: 0 additions & 11 deletions pkg/apis/kube/roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,6 @@ func ReadSecretsRule(secretNames []string) RuleBuilder {
}
}

func UpdateDeploymentsRule(deployments []string) RuleBuilder {
return func() rbacv1.PolicyRule {
return rbacv1.PolicyRule{
APIGroups: []string{"apps"},
Resources: []string{"deployments"},
ResourceNames: deployments,
Verbs: []string{"update"},
}
}
}

func CreateAppRole(appName, roleName string, customLabels map[string]string, ruleBuilders ...RuleBuilder) *rbacv1.Role {
role := &rbacv1.Role{
TypeMeta: metav1.TypeMeta{
Expand Down