Skip to content

Commit 30a4a5a

Browse files
jennifer-richardsNGPixel
authored andcommitted
ci: run rabbitmq as non-root (ietf-tools#7362)
* ci: securityContext for rabbitmq * ci: logs from rabbitmq as json to console * ci: tmp volume for rabbitmq Needed since rootfs is now read-only * ci: fix permissions on /var/lib/rabbitmq vol Rabbitmq needs to be able to write to the fs at /var/lib/rabbitmq. It may be possible to get rid of the initContainer and use fsGroup in the pod securityContext to manage this, but that does not work for the hostVolume mounts I use for dev. The solution here moves the actual mount to the rabbitmq/ directory in the rabbitmq-data volume and uses an initContainer to set the permissions on that. That should work for any volume type.
1 parent 2c9c61d commit 30a4a5a

3 files changed

Lines changed: 42 additions & 17 deletions

File tree

helm/templates/configmap.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,9 @@ data:
6161
# absolute number because relative will be proprtional to the full machine
6262
# memory.
6363
vm_memory_high_watermark.absolute = 1600MB
64+
65+
# Logging
66+
log.file = false
67+
log.console = true
68+
log.console.level = info
69+
log.console.formatter = json

helm/templates/statefulsets/rabbitmq.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ spec:
2626
serviceAccountName: {{ include "datatracker.serviceAccountName.rabbitmq" . }}
2727
securityContext:
2828
{{- toYaml $podValues.podSecurityContext | nindent 8 }}
29+
initContainers:
30+
- name: init-rabbitmq
31+
image: busybox:stable
32+
command:
33+
- "sh"
34+
- "-c"
35+
- "mkdir -p -m700 /mnt/rabbitmq && chown 100:101 /mnt/rabbitmq"
36+
securityContext:
37+
runAsNonRoot: false
38+
runAsUser: 0
39+
readOnlyRootFilesystem: true
40+
volumeMounts:
41+
- name: "rabbitmq-data"
42+
mountPath: "/mnt"
2943
containers:
3044
- name: {{ .Chart.Name }}
3145
securityContext:

helm/values.yaml

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,6 @@ rabbitmq:
405405
repository: "ghcr.io/ietf-tools/datatracker-mq"
406406
pullPolicy: IfNotPresent
407407
tag: "3.12-alpine"
408-
409408
imagePullSecrets: []
410409
nameOverride: ""
411410
fullnameOverride: ""
@@ -419,9 +418,6 @@ rabbitmq:
419418
podAnnotations: {}
420419
podLabels: {}
421420

422-
podSecurityContext: {}
423-
# fsGroup: 2000
424-
425421
replicaCount: 1
426422

427423
resources: {}
@@ -436,13 +432,18 @@ rabbitmq:
436432
# cpu: 100m
437433
# memory: 128Mi
438434

439-
securityContext: {}
440-
# capabilities:
441-
# drop:
442-
# - ALL
443-
# readOnlyRootFilesystem: true
444-
# runAsNonRoot: true
445-
# runAsUser: 1000
435+
podSecurityContext:
436+
runAsNonRoot: true
437+
438+
securityContext:
439+
allowPrivilegeEscalation: false
440+
capabilities:
441+
drop:
442+
- ALL
443+
readOnlyRootFilesystem: true
444+
# rabbitmq image sets up uid/gid 100/101
445+
runAsUser: 100
446+
runAsGroup: 101
446447

447448
service:
448449
type: ClusterIP
@@ -476,6 +477,9 @@ rabbitmq:
476477
- name: "rabbitmq-config"
477478
configMap:
478479
name: "rabbitmq-configmap"
480+
- name: "rabbitmq-tmp"
481+
emptyDir:
482+
sizeLimit: 50Mi
479483
# - name: foo
480484
# secret:
481485
# secretName: mysecret
@@ -484,12 +488,12 @@ rabbitmq:
484488
# Additional volumeMounts on the output Deployment definition.
485489
volumeMounts:
486490
- name: "rabbitmq-data"
487-
mountPath: "/var/lib/rabbitmq/mnesia"
491+
mountPath: "/var/lib/rabbitmq"
492+
subPath: "rabbitmq"
488493
- name: "rabbitmq-config"
489494
mountPath: "/etc/rabbitmq"
490-
# - name: foo
491-
# mountPath: "/etc/foo"
492-
# readOnly: true
495+
- name: "rabbitmq-tmp"
496+
mountPath: "/tmp"
493497

494498
tolerations: []
495499

@@ -531,15 +535,16 @@ memcached:
531535

532536
podSecurityContext:
533537
runAsNonRoot: true
534-
runAsUser: 11211
535-
runAsGroup: 11211
536538

537539
securityContext:
538540
allowPrivilegeEscalation: false
539541
capabilities:
540542
drop:
541543
- ALL
542544
readOnlyRootFilesystem: true
545+
# memcached image sets up uid/gid 11211
546+
runAsUser: 11211
547+
runAsGroup: 11211
543548

544549
service:
545550
type: ClusterIP

0 commit comments

Comments
 (0)