Skip to content

Commit b2aa062

Browse files
committed
Bind SA to anyuid SCC for running Jupyter notebook server
Signed-off-by: Shiva Krishna, Merla <smerla@nvidia.com>
1 parent 27e0ff5 commit b2aa062

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed

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

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

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

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)