-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathS03L03-setup.yml
69 lines (59 loc) · 1.82 KB
/
S03L03-setup.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
apiVersion: v1
kind: Namespace
metadata:
name: sa-permissions-test
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: shared-sa
namespace: sa-permissions-test
automountServiceAccountToken: true
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: shared-sa-role
namespace: sa-permissions-test
rules:
- apiGroups: [""]
resources: ["deployments", "pods", "secrets"]
verbs: ["get", "list"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: shared-sa-rb
namespace: sa-permissions-test
subjects:
- kind: ServiceAccount
name: shared-sa
namespace: auth
roleRef:
kind: Role
name: shared-sa-role
apiGroup: rbac.authorization.k8s.io
---
apiVersion: v1
kind: Pod
metadata:
name: deployment-viewer-pod
namespace: sa-permissions-test
spec:
serviceAccountName: shared-sa
containers:
- name: busybox
image: radial/busyboxplus:curl
command: ['sh', '-c', 'TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token); while true; do if curl -s -o /dev/null -k -m 3 -H "Authorization: Bearer $TOKEN" https://kubernetes.default.svc.cluster.local/api/v1/namespaces/auth/deployments/; then echo "[SUCCESS] Successfully viewed Deployments!"; else echo "[FAIL] Failed to view Deployments!"; fi; sleep 5; done']
---
apiVersion: v1
kind: Pod
metadata:
name: pod-viewer-pod
namespace: sa-permissions-test
spec:
serviceAccountName: shared-sa
containers:
- name: busybox
image: radial/busyboxplus:curl
command: ['sh', '-c', 'TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token); while true; do if curl -s -o /dev/null -k -m 3 -H "Authorization: Bearer $TOKEN" https://kubernetes.default.svc.cluster.local/api/v1/namespaces/auth/pods/; then echo "[SUCCESS] Successfully viewed Pods!"; else echo "[FAIL] Failed to view Pods!"; fi; sleep 5; done']