Skip to content

Commit 5057724

Browse files
committed
Bind SA to anyuid SCC for running Jupyter notebook server
Signed-off-by: Shiva Krishna, Merla <[email protected]>
1 parent 27e0ff5 commit 5057724

File tree

5 files changed

+70
-0
lines changed

5 files changed

+70
-0
lines changed

test/e2e/nemo-dependencies/jupyter/tasks/main.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,31 @@
2020
stdin: "{{ lookup('template', 'pvc.yaml.j2') }}"
2121
executable: /bin/bash
2222

23+
- name: Get Kube API resources
24+
command: kubectl api-resources --verbs=list --namespaced -o name
25+
register: api_resources
26+
27+
- name: Check if the current cluster is OpenShift
28+
set_fact:
29+
is_openshift: "{{ 'routes.route.openshift.io' in api_resources.stdout_lines }}"
30+
31+
- name: OpenShift - Prepare RBAC to use anyuid SCC
32+
ansible.builtin.template:
33+
src: ocp-rbac.yaml.j2
34+
dest: jupyter-ocp-rbac.yaml
35+
when: is_openshift
36+
37+
- name: OpenShift - apply RBAC to use anyuid SCC
38+
command: kubectl apply -f jupyter-ocp-rbac.yaml
39+
when: is_openshift
40+
41+
- name: Create a service account
42+
ansible.builtin.shell: |
43+
kubectl apply -f -
44+
args:
45+
stdin: "{{ lookup('template', 'serviceaccount.yaml.j2') }}"
46+
executable: /bin/bash
47+
2348
- name: Deploy Jupyter Notebook
2449
ansible.builtin.shell: |
2550
kubectl apply -f -

test/e2e/nemo-dependencies/jupyter/tasks/uninstall.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@
2020
shell: kubectl delete configmap notebook-config -n {{ namespace }}
2121
ignore_errors: true
2222

23+
- name: Delete Jupyter ServiceAccount
24+
shell: kubectl delete sa jupyter -n {{ namespace }}
25+
ignore_errors: true
26+

test/e2e/nemo-dependencies/jupyter/templates/deployment.yaml.j2

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ spec:
1212
metadata:
1313
labels:
1414
app: jupyter-notebook
15+
annotations:
16+
openshift.io/scc: anyuid
1517
spec:
18+
serviceAccountName: jupyter
19+
securityContext:
20+
fsGroup: 2000 # Allows shared access to config volume for group ID 2000
1621
initContainers:
1722
- name: copy-notebook-config
1823
image: busybox
@@ -35,6 +40,11 @@ spec:
3540
env:
3641
- name: JUPYTER_TOKEN
3742
value: "{{ jupyter_token }}"
43+
securityContext:
44+
runAsUser: 1000
45+
runAsGroup: 2000
46+
runAsNonRoot: true
47+
allowPrivilegeEscalation: false
3848
volumeMounts:
3949
- name: notebook-storage
4050
mountPath: {{ mount_path }}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: Role
4+
metadata:
5+
name: scc-anyuid
6+
namespace: {{ namespace }}
7+
rules:
8+
- apiGroups: ['security.openshift.io']
9+
resources: ['securitycontextconstraints']
10+
verbs: ['use']
11+
resourceNames: ['anyuid']
12+
13+
---
14+
apiVersion: rbac.authorization.k8s.io/v1
15+
kind: RoleBinding
16+
metadata:
17+
name: jupyter-scc-anyuid-binding
18+
namespace: {{ namespace }}
19+
subjects:
20+
- kind: ServiceAccount
21+
name: jupyter
22+
namespace: {{ namespace }}
23+
roleRef:
24+
kind: Role
25+
name: scc-anyuid
26+
apiGroup: rbac.authorization.k8s.io
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
name: jupyter
5+
namespace: {{ namespace }}

0 commit comments

Comments
 (0)