Restrict ClusterRole and ClusterRoleBinding RBAC permissions to managed resources only #1901
+22
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR improves security by restricting the GPU Operator's ClusterRole permissions to only the specific ClusterRoles and ClusterRoleBindings it manages, following the principle of least privilege.
Problem
Previously, the GPU Operator had unrestricted permissions to create, read, update, and delete any ClusterRole or ClusterRoleBinding in the entire Kubernetes cluster:
This violates the principle of least privilege and poses security risks:
Solution
The permissions have been split into two RBAC rules:
resourceNamesrestriction, as Kubernetes doesn't allowresourceNameswith thecreateverb)get,update,patch, anddeleteoperations to only the 14 specific resources managed by the GPU Operator using theresourceNamesfieldResources managed by GPU Operator:
Changes
File:
deployments/gpu-operator/templates/clusterrole.yamlresourceNamesconstraint toget,update,patch, anddeleteverbsSecurity Benefits
Testing
resourceNameslistImplementation Notes
The permission split (create in one rule, modify operations in another with
resourceNames) is a standard Kubernetes RBAC pattern because:resourceNameswith thecreateverb (resource names don't exist at creation time)References
Code locations that manage ClusterRoles/ClusterRoleBindings:
controllers/resource_manager.go:133-140- Loads resources from YAML manifestscontrollers/object_controls.go:421-505- Creates/updates/deletes the RBAC resources