Skip to content

Commit

Permalink
Improved demo for impersonation
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasdille committed May 8, 2024
1 parent d3a62c6 commit aea8d4c
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 105 deletions.
109 changes: 105 additions & 4 deletions 120_kubernetes/rbac/impersonation.demo
Original file line number Diff line number Diff line change
@@ -1,16 +1,117 @@
# Impersonation using RBAC

# Deploy namespace
kubectl apply -f test-namespace.yaml
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Namespace
metadata:
name: test
EOF

# Deploy namespace admin
kubectl apply -f test-admin.yaml
cat <<EOF | kubectl apply -f -
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: admin
namespace: test
rules:
- apiGroups:
- "*"
resources:
- "*"
verbs:
- "*"
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: admin
namespace: test
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: admin
subjects:
- kind: User
name: test-admin
EOF

# Deploy namespace reader
kubectl apply -f test-reader.yaml
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: ServiceAccount
metadata:
name: reader
namespace: test
---
apiVersion: v1
kind: Secret
metadata:
name: reader
namespace: test
annotations:
kubernetes.io/service-account.name: reader
type: kubernetes.io/service-account-token
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: reader
namespace: test
rules:
- apiGroups:
- "*"
resources:
- "*"
verbs:
- "get"
- "list"
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: reader
namespace: test
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: reader
subjects:
- kind: ServiceAccount
name: reader
namespace: test
EOF

# Deploy impersonation role
kubectl apply -f test-impersonation.yaml
cat <<EOF | kubectl apply -f -
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: admin-impersonator
rules:
- apiGroups:
- ""
resources:
- "users"
verbs:
- "impersonate"
resourceNames:
- "test-admin"
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: admin-impersonator
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: admin-impersonator
subjects:
- kind: ServiceAccount
name: reader
namespace: test
EOF

# Create new user in kubeconfig
TOKEN="$(
Expand Down
26 changes: 0 additions & 26 deletions 120_kubernetes/rbac/test-admin.yaml

This file was deleted.

27 changes: 0 additions & 27 deletions 120_kubernetes/rbac/test-impersonation.yaml

This file was deleted.

5 changes: 0 additions & 5 deletions 120_kubernetes/rbac/test-namespace.yaml

This file was deleted.

43 changes: 0 additions & 43 deletions 120_kubernetes/rbac/test-reader.yaml

This file was deleted.

0 comments on commit aea8d4c

Please sign in to comment.