Skip to content

Commit

Permalink
fix: 🙈 allow user to run proxy on priviledged ports
Browse files Browse the repository at this point in the history
  • Loading branch information
darkweaver87 authored Nov 22, 2023
1 parent e81f716 commit 590f8f3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
7 changes: 4 additions & 3 deletions traefikee/templates/proxy/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ spec:
- NET_RAW
- name: chown
image: {{ template "traefikee-helm-chart.initContainer-image-name" . }}
command: ['chown', '-R', '65532:', '/var/lib/traefikee']
command: ['chown', '-R', '{{.Values.proxy.securityContext.runAsUser}}:', '/var/lib/traefikee']
resources:
requests:
cpu: 10m
Expand Down Expand Up @@ -123,7 +123,8 @@ spec:
{{- end }}
securityContext:
allowPrivilegeEscalation: false
runAsUser: 65532
runAsNonRoot: {{ if eq (int .Values.proxy.securityContext.runAsUser) 0 -}}false{{- else -}}true{{- end }}
runAsUser: {{ .Values.proxy.securityContext.runAsUser }}
readOnlyRootFilesystem: true
seccompProfile:
type: RuntimeDefault
Expand All @@ -137,7 +138,7 @@ spec:
name: distributed
{{- range $port := .Values.proxy.ports }}
{{- $containerPort := ($port.targetPort | default $port.port) }}
{{- if lt (int $containerPort) 1024 }}
{{- if and (lt (int $containerPort) 1024) (ne (int $.Values.proxy.securityContext.runAsUser) 0) }}
{{ fail "ERROR: Cannot set a privileged port on a non-root container" }}
{{- end }}
- containerPort: {{ $containerPort }}
Expand Down
32 changes: 31 additions & 1 deletion traefikee/tests/proxy_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ tests:
rollingUpdate:
maxUnavailable: 0
maxSurge: 1
- it: should fail when using ports < 1024
- it: should fail when using ports < 1024 for non-root users
set:
proxy:
ports:
Expand All @@ -282,6 +282,36 @@ tests:
asserts:
- failedTemplate:
errorMessage: "ERROR: Cannot set a privileged port on a non-root container"
- it: should be possible to run proxies as root (to specify elevated ports)
set:
proxy:
ports:
- name: http
port: 80
securityContext:
runAsUser: 0
asserts:
- contains:
path: spec.template.spec.containers[0].ports
content:
containerPort: 80
name: http
- it: should give the rights on data to the right user (default)
asserts:
- equal:
path: spec.template.spec.initContainers[1].command
value:
['chown', '-R', '65532:', '/var/lib/traefikee']
- it: should give the rights on data to the right user
set:
proxy:
securityContext:
runAsUser: 0
asserts:
- equal:
path: spec.template.spec.initContainers[1].command
value:
[ 'chown', '-R', '0:', '/var/lib/traefikee' ]
- it: should be possible to change ports of deployments
set:
proxy:
Expand Down
4 changes: 3 additions & 1 deletion traefikee/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ controller:
traefik:
address: ":9000"
web:
address: ":7000"
address: ":7080"
websecure:
http:
tls: {}
Expand Down Expand Up @@ -248,6 +248,8 @@ proxy:
port: traefik
initialDelaySeconds: 2
periodSeconds: 5
securityContext:
runAsUser: 65532

# serviceLabels:
# foo: bar
Expand Down

0 comments on commit 590f8f3

Please sign in to comment.