Skip to content

Commit

Permalink
Restrict operator ClusterRole*, ServiceAccount permissions
Browse files Browse the repository at this point in the history
These were added for network-plugin syncer removal so retrict the
delete permissions to the networkplugin-syncer resource names.

Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
  • Loading branch information
tpantelis authored and skitt committed May 6, 2024
1 parent 9d5ba43 commit 7c5eb0f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 13 deletions.
3 changes: 3 additions & 0 deletions config/rbac/submariner-operator/cluster_role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,8 @@ rules:
# Temporarily needed for network-plugin syncer removal
- clusterroles
- clusterrolebindings
resourceNames:
- ocp-submariner-networkplugin-syncer
- submariner-networkplugin-syncer
verbs:
- delete
2 changes: 2 additions & 0 deletions config/rbac/submariner-operator/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ rules:
resources:
# Temporarily needed for network-plugin syncer removal
- serviceaccounts
resourceNames:
- submariner-networkplugin-syncer
verbs:
- delete
- apiGroups:
Expand Down
24 changes: 24 additions & 0 deletions controllers/submariner/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,24 @@ var _ = Describe("Migration tests", func() {
Name: submariner.NetworkPluginSyncerComponent,
},
},
&rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
Namespace: t.Namespace,
Name: "ocp-submariner-networkplugin-syncer",
},
},
&rbacv1.ClusterRoleBinding{
ObjectMeta: metav1.ObjectMeta{
Namespace: t.Namespace,
Name: submariner.NetworkPluginSyncerComponent,
},
},
&rbacv1.ClusterRoleBinding{
ObjectMeta: metav1.ObjectMeta{
Namespace: t.Namespace,
Name: "ocp-submariner-networkplugin-syncer",
},
},
&corev1.ServiceAccount{
ObjectMeta: metav1.ObjectMeta{
Namespace: t.Namespace,
Expand All @@ -83,6 +95,18 @@ var _ = Describe("Migration tests", func() {
},
})

t.AssertNoResource(&rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
Name: "ocp-submariner-networkplugin-syncer",
},
})

t.AssertNoResource(&rbacv1.ClusterRoleBinding{
ObjectMeta: metav1.ObjectMeta{
Name: "ocp-submariner-networkplugin-syncer",
},
})

t.AssertNoResource(&corev1.ServiceAccount{
ObjectMeta: metav1.ObjectMeta{
Name: submariner.NetworkPluginSyncerComponent,
Expand Down
19 changes: 6 additions & 13 deletions controllers/submariner/np_syncer_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func (r *Reconciler) removeNetworkPluginSyncerDeployment(ctx context.Context, in

deleteAll := func(objs ...client.Object) error {
for _, obj := range objs {
obj.SetName(NetworkPluginSyncerComponent)
obj.SetNamespace(instance.Namespace)

err := r.config.ScopedClient.Delete(ctx, obj)
Expand All @@ -59,38 +58,32 @@ func (r *Reconciler) removeNetworkPluginSyncerDeployment(ctx context.Context, in
return deleteAll(
&appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Namespace: instance.Namespace,
Name: NetworkPluginSyncerComponent,
Name: NetworkPluginSyncerComponent,
},
},
&rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
Namespace: instance.Namespace,
Name: NetworkPluginSyncerComponent,
Name: NetworkPluginSyncerComponent,
},
},
&rbacv1.ClusterRoleBinding{
ObjectMeta: metav1.ObjectMeta{
Namespace: instance.Namespace,
Name: NetworkPluginSyncerComponent,
Name: NetworkPluginSyncerComponent,
},
},
&rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
Namespace: instance.Namespace,
Name: "ocp-submariner-networkplugin-syncer",
Name: "ocp-submariner-networkplugin-syncer",
},
},
&rbacv1.ClusterRoleBinding{
ObjectMeta: metav1.ObjectMeta{
Namespace: instance.Namespace,
Name: "ocp-submariner-networkplugin-syncer",
Name: "ocp-submariner-networkplugin-syncer",
},
},
&corev1.ServiceAccount{
ObjectMeta: metav1.ObjectMeta{
Namespace: instance.Namespace,
Name: NetworkPluginSyncerComponent,
Name: NetworkPluginSyncerComponent,
},
},
)
Expand Down
5 changes: 5 additions & 0 deletions pkg/embeddedyamls/yamls.go
Original file line number Diff line number Diff line change
Expand Up @@ -2610,6 +2610,8 @@ rules:
resources:
# Temporarily needed for network-plugin syncer removal
- serviceaccounts
resourceNames:
- submariner-networkplugin-syncer
verbs:
- delete
- apiGroups:
Expand Down Expand Up @@ -2757,6 +2759,9 @@ rules:
# Temporarily needed for network-plugin syncer removal
- clusterroles
- clusterrolebindings
resourceNames:
- ocp-submariner-networkplugin-syncer
- submariner-networkplugin-syncer
verbs:
- delete
`
Expand Down

0 comments on commit 7c5eb0f

Please sign in to comment.