ClusterPermission
is an Open Cluster Management (OCM) custom resource that enables administrators to automatically distribute RBAC resources to managed clusters and manage their lifecycle. It provides centralized management of Roles, ClusterRoles, RoleBindings, and ClusterRoleBindings across multiple Kubernetes clusters.
This project complements ManagedServiceAccount by addressing the authorization aspects of fleet management. While ManagedServiceAccount
handles authentication across clusters, ClusterPermission
manages authorization by distributing and maintaining RBAC resources.
- Automated RBAC Distribution: Automatically deploys RBAC resources to managed clusters
- Lifecycle Management: Uses OCM's ManifestWork API for creation, updates, and deletion
- ManagedServiceAccount Integration: Supports ManagedServiceAccount as a binding subject
- Multi-cluster Authorization: Centralized authorization management across OCM fleet
- Resource Protection: Safeguards distributed RBAC resources against unintended modifications
A ClusterPermission
resource must reside in an OCM managed cluster namespace on the Hub cluster. The controller:
- Validates the ClusterPermission specification
- Generates appropriate RBAC manifests
- Creates ManifestWork resources to deploy RBAC to target managed clusters
- Monitors and maintains the lifecycle of distributed resources
Supported RBAC resources:
- ClusterRole and ClusterRoleBinding
- Role and RoleBinding (with namespace targeting)
- Standard subjects: User, Group, ServiceAccount
- Enhanced subjects: ManagedServiceAccount (requires ManagedServiceAccount addon)
- Open Cluster Management (OCM) environment with Hub and managed clusters
- See OCM Quick Start for setup instructions
- Optional: ManagedServiceAccount addon for enhanced authentication features
- Clone the repository and install CRDs:
git clone https://github.com/open-cluster-management-io/cluster-permission.git
cd cluster-permission/
make install
- Run the controller locally:
make run
Deploy using the provided Helm chart:
helm install cluster-permission ./chart/
Apply the deployment manifests:
kubectl apply -f config/deploy/
Create a ClusterPermission in your managed cluster namespace (replace cluster1
with your managed cluster name):
kubectl apply -f - <<EOF
apiVersion: rbac.open-cluster-management.io/v1alpha1
kind: ClusterPermission
metadata:
name: example-permissions
namespace: cluster1
spec:
clusterRole:
rules:
- apiGroups: ["apps"]
resources: ["deployments"]
verbs: ["get", "list", "watch"]
clusterRoleBinding:
subject:
kind: ServiceAccount
name: my-service-account
namespace: default
EOF
Check the ClusterPermission status:
kubectl -n cluster1 get clusterpermission example-permissions -o yaml
Expected status:
status:
conditions:
- lastTransitionTime: "2023-04-12T15:19:04Z"
message: |-
Run the following command to check the ManifestWork status:
kubectl -n cluster1 get ManifestWork example-permissions-xxxxx -o yaml
reason: AppliedRBACManifestWork
status: "True"
type: AppliedRBACManifestWork
On the managed cluster, verify the RBAC resources were created:
kubectl get clusterrole | grep example-permissions
kubectl get clusterrolebinding | grep example-permissions
Apply the basic sample:
kubectl -n cluster1 apply -f config/samples/rbac.open-cluster-management.io_v1alpha1_clusterpermission.yaml
For user and group-based permissions:
kubectl -n cluster1 apply -f config/samples/clusterpermission_users_groups.yaml
To use ManagedServiceAccount as a subject:
kubectl -n cluster1 apply -f config/samples/clusterpermission_subject_msa.yaml
For complex permission scenarios:
kubectl -n cluster1 apply -f config/samples/clusterpermission_multiple_clusterrolebindings.yaml
Field | Type | Description |
---|---|---|
clusterRole |
ClusterRole |
ClusterRole to create on managed cluster |
clusterRoleBinding |
ClusterRoleBinding |
ClusterRoleBinding to create |
clusterRoleBindings |
[]ClusterRoleBinding |
Multiple ClusterRoleBindings |
roles |
[]Role |
Roles to create with namespace targeting |
roleBindings |
[]RoleBinding |
RoleBindings with namespace support |
- ServiceAccount:
kind: ServiceAccount
- User:
kind: User
- Group:
kind: Group
- ManagedServiceAccount:
kind: ManagedServiceAccount
(requires addon)
-
ClusterPermission not applying
- Verify the namespace is a valid managed cluster namespace
- Check OCM hub cluster connectivity
-
RBAC resources not appearing on managed cluster
- Check ManifestWork status:
kubectl -n <cluster-ns> get manifestwork
- Verify managed cluster agent connectivity
- Check ManifestWork status:
-
ManagedServiceAccount subjects not working
- Ensure ManagedServiceAccount addon is installed
- Verify the referenced ManagedServiceAccount exists
# Check ClusterPermission status
kubectl -n <cluster-namespace> get clusterpermission <name> -o yaml
# Check associated ManifestWork
kubectl -n <cluster-namespace> get manifestwork
# View controller logs
kubectl logs -n cluster-permission-system deployment/cluster-permission-controller-manager
# Build the binary
make build
# Build Docker image
make docker-build
# Run tests
make test
# Generate CRDs
make manifests
# Update generated code
make generate
After modifying API types, regenerate code:
make generate
make manifests
Check the CONTRIBUTING Doc for contribution guidelines.
- Slack: #open-cluster-mgmt
- GitHub Issues: Report bugs and feature requests
- GitHub Discussions: Community questions and discussions
This project is licensed under the Apache License 2.0. See the LICENSE file for details.