Skip to content

Commit

Permalink
set default SecurityContext for EG components (#3940)
Browse files Browse the repository at this point in the history
* set SecurityContext

Signed-off-by: Huabing Zhao <[email protected]>

* set SecurityContext for RateLimit container

Signed-off-by: Huabing Zhao <[email protected]>

* set SecurityContext for shutdown manager

Signed-off-by: Huabing Zhao <[email protected]>

* set SecurityContext for envoy proxy

Signed-off-by: Huabing Zhao <[email protected]>

* use nobody user for rate limit image

Signed-off-by: Huabing Zhao <[email protected]>

* fix shutdown test

Signed-off-by: Huabing Zhao <[email protected]>

* add write permission to envoy

Signed-off-by: Huabing Zhao <[email protected]>

---------

Signed-off-by: Huabing Zhao <[email protected]>
  • Loading branch information
zhaohuabing authored Jul 30, 2024
1 parent 36764c0 commit ddf2178
Show file tree
Hide file tree
Showing 62 changed files with 1,013 additions and 44 deletions.
16 changes: 12 additions & 4 deletions charts/gateway-helm/templates/certgen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,20 @@ spec:
resources:
{{- toYaml . | nindent 10 }}
{{- end }}
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
privileged: false
readOnlyRootFilesystem: true
runAsNonRoot: true
runAsGroup: 65534
runAsUser: 65534
seccompProfile:
type: RuntimeDefault
{{- include "eg.image.pullSecrets" . | nindent 6 }}
restartPolicy: Never
securityContext:
runAsGroup: 65534
runAsNonRoot: true
runAsUser: 65534
serviceAccountName: {{ include "eg.fullname" . }}-certgen
{{- if not ( kindIs "invalid" .Values.certgen.job.ttlSecondsAfterFinished) }}
ttlSecondsAfterFinished: {{ .Values.certgen.job.ttlSecondsAfterFinished }}
Expand Down
9 changes: 7 additions & 2 deletions charts/gateway-helm/templates/envoy-gateway-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ spec:
}}
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
privileged: false
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
volumeMounts:
- mountPath: /config
name: envoy-gateway-config
Expand All @@ -103,8 +110,6 @@ spec:
name: certs
readOnly: true
{{- include "eg.image.pullSecrets" . | nindent 6 }}
securityContext:
runAsNonRoot: true
serviceAccountName: envoy-gateway
terminationGracePeriodSeconds: 10
volumes:
Expand Down
22 changes: 21 additions & 1 deletion internal/infrastructure/kubernetes/proxy/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func expectedProxyContainers(infra *ir.ProxyInfra,
Args: args,
Env: expectedContainerEnv(containerSpec),
Resources: *containerSpec.Resources,
SecurityContext: containerSpec.SecurityContext,
SecurityContext: expectedEnvoySecurityContext(containerSpec),
Ports: ports,
VolumeMounts: expectedContainerVolumeMounts(containerSpec),
TerminationMessagePolicy: corev1.TerminationMessageReadFile,
Expand Down Expand Up @@ -296,6 +296,7 @@ func expectedProxyContainers(infra *ir.ProxyInfra,
},
},
},
SecurityContext: expectedShutdownManagerSecurityContext(),
},
}

Expand Down Expand Up @@ -435,3 +436,22 @@ func calculateMaxHeapSizeBytes(envoyResourceRequirements *corev1.ResourceRequire

return 0
}

func expectedEnvoySecurityContext(containerSpec *egv1a1.KubernetesContainerSpec) *corev1.SecurityContext {
if containerSpec != nil && containerSpec.SecurityContext != nil {
return containerSpec.SecurityContext
}

sc := resource.DefaultSecurityContext()
// Envoy container needs to write to the log file/UDS socket.
sc.ReadOnlyRootFilesystem = nil
return sc
}

func expectedShutdownManagerSecurityContext() *corev1.SecurityContext {
sc := resource.DefaultSecurityContext()
// ShutdownManger creates a file to indicate the connection drain process is completed,
// so it needs file write permission.
sc.ReadOnlyRootFilesystem = nil
return sc
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ spec:
requests:
cpu: 100m
memory: 512Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
privileged: false
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
startupProbe:
failureThreshold: 30
httpGet:
Expand Down Expand Up @@ -151,6 +160,15 @@ spec:
requests:
cpu: 10m
memory: 32Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
privileged: false
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
startupProbe:
failureThreshold: 30
httpGet:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,15 @@ spec:
requests:
cpu: 10m
memory: 32Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
privileged: false
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
startupProbe:
failureThreshold: 30
httpGet:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,15 @@ spec:
requests:
cpu: 10m
memory: 32Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
privileged: false
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
startupProbe:
failureThreshold: 30
httpGet:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,15 @@ spec:
requests:
cpu: 100m
memory: 512Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
privileged: false
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
startupProbe:
failureThreshold: 30
httpGet:
Expand Down Expand Up @@ -318,6 +327,15 @@ spec:
requests:
cpu: 10m
memory: 32Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
privileged: false
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
startupProbe:
failureThreshold: 30
httpGet:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,15 @@ spec:
requests:
cpu: 100m
memory: 512Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
privileged: false
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
startupProbe:
failureThreshold: 30
httpGet:
Expand Down Expand Up @@ -289,6 +298,15 @@ spec:
requests:
cpu: 10m
memory: 32Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
privileged: false
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
startupProbe:
failureThreshold: 30
httpGet:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,15 @@ spec:
requests:
cpu: 10m
memory: 32Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
privileged: false
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
startupProbe:
failureThreshold: 30
httpGet:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,15 @@ spec:
requests:
cpu: 100m
memory: 512Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
privileged: false
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
startupProbe:
failureThreshold: 30
httpGet:
Expand Down Expand Up @@ -329,6 +338,15 @@ spec:
requests:
cpu: 10m
memory: 32Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
privileged: false
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
startupProbe:
failureThreshold: 30
httpGet:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,15 @@ spec:
requests:
cpu: 100m
memory: 512Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
privileged: false
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
startupProbe:
failureThreshold: 30
httpGet:
Expand Down Expand Up @@ -318,6 +327,15 @@ spec:
requests:
cpu: 10m
memory: 32Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
privileged: false
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
startupProbe:
failureThreshold: 30
httpGet:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,15 @@ spec:
requests:
cpu: 100m
memory: 512Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
privileged: false
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
startupProbe:
failureThreshold: 30
httpGet:
Expand Down Expand Up @@ -330,7 +339,15 @@ spec:
cpu: 100m
memory: 64Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
privileged: false
runAsNonRoot: true
runAsUser: 1234
seccompProfile:
type: RuntimeDefault
startupProbe:
failureThreshold: 30
httpGet:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,15 @@ spec:
requests:
cpu: 10m
memory: 32Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
privileged: false
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
startupProbe:
failureThreshold: 30
httpGet:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,15 @@ spec:
requests:
cpu: 100m
memory: 512Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
privileged: false
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
startupProbe:
failureThreshold: 30
httpGet:
Expand Down Expand Up @@ -323,6 +332,15 @@ spec:
requests:
cpu: 10m
memory: 32Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
privileged: false
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
startupProbe:
failureThreshold: 30
httpGet:
Expand Down
Loading

0 comments on commit ddf2178

Please sign in to comment.