Last active
January 10, 2022 09:10
-
-
Save viglesiasce/f2dcf3e8818e105c594e557f9687117a to your computer and use it in GitHub Desktop.
RBAC Example for Developer per Namespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export DEV_EMAIL=developer@example.com | |
| export DEV_USERNAME=developer | |
| export ADMIN_EMAIL=admin@example.com | |
| export ADMIN_USERNAME=admin | |
| # Grant the admin the ability to create new roles+bindings | |
| kubectl create clusterrolebinding --clusterrole=cluster-admin --user=$ADMIN_EMAIL admin-$ADMIN_USERNAME | |
| # Create RBAC resources to on | |
| cat > dev-rbac.yaml <<EOF | |
| kind: RoleBinding | |
| apiVersion: rbac.authorization.k8s.io/v1 | |
| metadata: | |
| name: dev-user | |
| namespace: $DEV_USERNAME | |
| subjects: | |
| - kind: User | |
| name: $DEV_EMAIL | |
| apiGroup: rbac.authorization.k8s.io | |
| roleRef: | |
| kind: Role | |
| name: namespace-admin | |
| apiGroup: rbac.authorization.k8s.io | |
| --- | |
| kind: Role | |
| apiVersion: rbac.authorization.k8s.io/v1 | |
| metadata: | |
| name: namespace-admin | |
| namespace: $DEV_USERNAME | |
| rules: | |
| - apiGroups: [""] | |
| resources: ["*"] | |
| verbs: ["get", "list", "watch", "create", "update", "patch"] | |
| --- | |
| kind: ClusterRoleBinding | |
| apiVersion: rbac.authorization.k8s.io/v1 | |
| metadata: | |
| name: cluster-viewer | |
| subjects: | |
| - kind: User | |
| name: $DEV_EMAIL | |
| apiGroup: rbac.authorization.k8s.io | |
| roleRef: | |
| kind: ClusterRole | |
| name: view | |
| apiGroup: rbac.authorization.k8s.io | |
| --- | |
| kind: ClusterRoleBinding | |
| apiVersion: rbac.authorization.k8s.io/v1 | |
| metadata: | |
| name: cluster-viewer | |
| subjects: | |
| - kind: User | |
| name: $DEV_EMAIL | |
| apiGroup: rbac.authorization.k8s.io | |
| roleRef: | |
| kind: ClusterRole | |
| name: view | |
| apiGroup: rbac.authorization.k8s.io | |
| EOF | |
| kubectl apply -f rbac.yaml | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment