diff --git a/.changelog/3549.txt b/.changelog/3549.txt new file mode 100644 index 0000000000..37e42084c8 --- /dev/null +++ b/.changelog/3549.txt @@ -0,0 +1,5 @@ +```release-note:bug +mesh-gw: update capabilities on the security context needed for the dataplane container. +Adds NET_BIND_SERVICE to capabilities.add +Adds ALL to capabilities.drop unless .Values.meshGateway.hostNetwork is true +``` \ No newline at end of file diff --git a/charts/consul/templates/mesh-gateway-deployment.yaml b/charts/consul/templates/mesh-gateway-deployment.yaml index 73b8481fb1..efcc1f910b 100644 --- a/charts/consul/templates/mesh-gateway-deployment.yaml +++ b/charts/consul/templates/mesh-gateway-deployment.yaml @@ -184,6 +184,14 @@ spec: containers: - name: mesh-gateway image: {{ .Values.global.imageConsulDataplane | quote }} + securityContext: + capabilities: + {{ if not .Values.meshGateway.hostNetwork}} + drop: + - ALL + {{- end }} + add: + - NET_BIND_SERVICE {{- if .Values.meshGateway.resources }} resources: {{- if eq (typeOf .Values.meshGateway.resources) "string" }} diff --git a/charts/consul/test/unit/mesh-gateway-deployment.bats b/charts/consul/test/unit/mesh-gateway-deployment.bats index afde4976a7..130e15cb64 100755 --- a/charts/consul/test/unit/mesh-gateway-deployment.bats +++ b/charts/consul/test/unit/mesh-gateway-deployment.bats @@ -1783,4 +1783,32 @@ key2: value2' \ local actual=$(echo "$cmd" | yq 'any(contains("-log-level=warn"))' | tee /dev/stderr) [ "${actual}" = "true" ] +} + +#-------------------------------------------------------------------- +# security context + +@test "meshGateway/Deployment: don't drop ALL capabilities when hostNetwork=true" { + cd `chart_dir` + local actual=$(helm template \ + -s templates/mesh-gateway-deployment.yaml \ + --set 'meshGateway.enabled=true' \ + --set 'connectInject.enabled=true' \ + --set 'meshGateway.hostNetwork=true' \ + . | tee /dev/stderr | + yq -r '.spec.template.spec.containers[0].securityContext' | tee /dev/stderr) + + [ $(echo "${actual}" | yq -r '.capabilities.drop | length') -eq 0 ] +} + +@test "meshGateway/Deployment: drop ALL capabilities when hostNetwork!=true" { + cd `chart_dir` + local actual=$(helm template \ + -s templates/mesh-gateway-deployment.yaml \ + --set 'meshGateway.enabled=true' \ + --set 'connectInject.enabled=true' \ + . | tee /dev/stderr | + yq -r '.spec.template.spec.containers[0].securityContext' | tee /dev/stderr) + + [ $(echo "${actual}" | yq -r '.capabilities.drop[0]') = "ALL" ] } \ No newline at end of file