Skip to content

Restrict consumer permissions - #1474

Merged
devdattakulkarni merged 3 commits into
cloud-ark:masterfrom
marshall867:consumer-permissions
Jul 15, 2026
Merged

Restrict consumer permissions#1474
devdattakulkarni merged 3 commits into
cloud-ark:masterfrom
marshall867:consumer-permissions

Conversation

@marshall867

Copy link
Copy Markdown
Contributor

Addresses #1472

Hello! This is my first contribution to the project - I’m happy to make adjustments based on review and feedback.

Problem

Consumer permissions were granted through a ClusterRoleBinding, which made otherwise namespaced permissions available across the cluster.

For example, a consumer associated with namespace1 could create a Deployment in namespace2.

Changes

This PR changes consumer RBAC bindings from ClusterRoleBinding to namespaced RoleBinding objects. The RoleBinding continues to reference the existing ClusterRole, but limits applicable permissions to the consumer’s namespace.

Providers continue to use ClusterRoleBinding objects because they require cluster-scoped access.

The update, revoke, and delete paths previously shared binding-management logic between providers and consumers. I added entity-specific handling so that:

  • Consumers use RoleBinding.
  • Providers use ClusterRoleBinding.
  • Consumer deletion also cleans up legacy ClusterRoleBinding objects.

I also added a regression test that reproduces the original issue by creating two namespaced consumers and verifying that one consumer cannot create a Deployment in the other consumer’s namespace. The test fails with the previous implementation and passes with this change.

Migration considerations

This PR does not automatically migrate existing consumer ClusterRoleBinding objects.

The change applies to newly created consumer bindings and permissions added through the update command. Legacy consumer bindings are removed by the delete command, but existing bindings are not migrated during update or revoke operations.

I would appreciate guidance on whether this PR should also include a migration path for existing consumers, or whether migration should be handled separately.

Thanks!

Comment thread provider-kubeconfig.py Outdated
# consumer binding
run_command("kubectl delete rolebinding " + sa + " -n " + namespace + " --ignore-not-found" + kubeconfigString)
# legacy consumer binding
run_command("kubectl delete clusterrolebinding " + sa + " --ignore-not-found" + kubeconfigString) # backwards-compatible

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

Comment thread provider-kubeconfig.py
run_command("kubectl delete clusterrolebinding " + sa + kubeconfigString)
run_command("kubectl delete clusterrole " + sa + "-update" + kubeconfigString)
run_command("kubectl delete clusterrolebinding " + sa + "-update" + kubeconfigString)
if entity == "consumer":

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this duplicate of code from 1062?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally kept the sequences of commands in order, but it created that similar-looking conditional, only different by a "-update" in the name. I just added a commit to make it a bit cleaner with only one conditional block

Comment thread tests/tests.py
cmd = f"kubectl auth can-i create deployments.apps -n {ns1} --kubeconfig={consumer2_kubeconfig}"
out, err = TestKubePlus.run_command(cmd)
skip_on_connection_error(err)
self.assertEqual(out.strip(), "no")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@devdattakulkarni
devdattakulkarni merged commit e448587 into cloud-ark:master Jul 15, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants