Skip to content

Commit c8ee43d

Browse files
jennifer-richardsNGPixel
authored andcommitted
ci: run datatracker pod as non-root user (ietf-tools#7366)
* feat: patch_libraries management command * ci: Patch libraries in docker img build * ci: non-root datatracker user * ci: securityContext for datatracker pod
1 parent 30a4a5a commit c8ee43d

3 files changed

Lines changed: 53 additions & 30 deletions

File tree

dev/build/Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ LABEL maintainer="IETF Tools Team <tools-discuss@ietf.org>"
33

44
ENV DEBIAN_FRONTEND=noninteractive
55

6+
RUN groupadd -g 1000 datatracker && \
7+
useradd -c "Datatracker User" -u 1000 -g datatracker -m -s /bin/false datatracker
8+
69
RUN apt-get purge -y imagemagick imagemagick-6-common
710

811
# Install libreoffice (needed via PPT2PDF_COMMAND)
@@ -15,7 +18,8 @@ COPY ./dev/build/start.sh ./start.sh
1518
COPY ./dev/build/datatracker-start.sh ./datatracker-start.sh
1619
COPY ./dev/build/celery-start.sh ./celery-start.sh
1720

18-
RUN pip3 --disable-pip-version-check --no-cache-dir install -r requirements.txt
21+
RUN pip3 --disable-pip-version-check --no-cache-dir install -r requirements.txt && \
22+
ietf/manage.py patch_libraries
1923

2024
RUN chmod +x start.sh && \
2125
chmod +x datatracker-start.sh && \

helm/values.yaml

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ datatracker:
6767
podAnnotations: {}
6868
podLabels: {}
6969

70-
podSecurityContext: {}
71-
# fsGroup: 2000
72-
7370
#readinessProbe:
7471
# httpGet:
7572
# # /submit/tool-instructions/ just happens to be cheap until we get a real health endpoint
@@ -90,13 +87,17 @@ datatracker:
9087
# cpu: 100m
9188
# memory: 128Mi
9289

93-
securityContext: {}
94-
# capabilities:
95-
# drop:
96-
# - ALL
97-
# readOnlyRootFilesystem: true
98-
# runAsNonRoot: true
99-
# runAsUser: 1000
90+
podSecurityContext:
91+
runAsNonRoot: true
92+
93+
securityContext:
94+
allowPrivilegeEscalation: false
95+
capabilities:
96+
drop:
97+
- ALL
98+
readOnlyRootFilesystem: true
99+
runAsUser: 1000
100+
runAsGroup: 1000
100101

101102
service:
102103
type: ClusterIP
@@ -132,17 +133,9 @@ datatracker:
132133
- name: datatracker-shared-volume
133134
persistentVolumeClaim:
134135
claimName: "datatracker-shared-volume-claim"
135-
# cache-volume and staging-volume are a hack to create paths for debugging without a /a volume
136-
# - name: cache-volume
137-
# emptyDir:
138-
# sizeLimit: 1Gi
139-
# - name: staging-volume
140-
# emptyDir:
141-
# sizeLimit: 1Gi
142-
# - name: foo
143-
# secret:
144-
# secretName: mysecret
145-
# optional: false
136+
- name: datatracker-tmp
137+
emptyDir:
138+
sizeLimit: "2Gi"
146139

147140
# Additional volumeMounts on the output Deployment definition.
148141
volumeMounts:
@@ -152,14 +145,8 @@ datatracker:
152145
readOnly: true
153146
- name: datatracker-shared-volume
154147
mountPath: /a
155-
# cache-volume and staging-volume are a hack to create paths for debugging without a /a volume
156-
# - name: cache-volume
157-
# mountPath: "/a/cache"
158-
# - name: staging-volume
159-
# mountPath: "/test/staging"
160-
# - name: foo
161-
# mountPath: "/etc/foo"
162-
# readOnly: true
148+
- name: datatracker-tmp
149+
mountPath: /tmp
163150

164151
tolerations: []
165152

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright The IETF Trust 2024, All Rights Reserved
2+
import django
3+
import os
4+
5+
from django.conf import settings
6+
from django.core.management.base import BaseCommand, CommandError
7+
from pathlib import Path
8+
9+
from ietf.utils import patch
10+
11+
12+
class Command(BaseCommand):
13+
"""Apply IETF patches to libraries"""
14+
requires_system_checks = tuple()
15+
16+
def handle(self, *args, **options):
17+
library_path = Path(django.__file__).parent.parent
18+
top_dir = Path(settings.BASE_DIR).parent
19+
20+
# All patches in settings.CHECKS_LIBRARY_PATCHES_TO_APPLY must have a
21+
# relative file path starting from the site-packages dir, e.g.
22+
# 'django/db/models/fields/__init__.py'
23+
for patch_file in settings.CHECKS_LIBRARY_PATCHES_TO_APPLY:
24+
patch_set = patch.fromfile(top_dir / Path(patch_file))
25+
if not patch_set:
26+
raise CommandError(f"Could not parse patch file '{patch_file}'")
27+
if not patch_set.apply(root=bytes(library_path)):
28+
raise CommandError(f"Could not apply the patch from '{patch_file}'")
29+
if patch_set.already_patched:
30+
self.stdout.write(f"Patch from '{patch_file}' was already applied")
31+
else:
32+
self.stdout.write(f"Applied the patch from '{patch_file}'")

0 commit comments

Comments
 (0)