Skip to content

Commit ac2a00c

Browse files
authored
set allowPrivilegeEscalation for deployment templates (zalando#1328)
* set allowPrivilegeEscalation for deployment templates * securityContext of container, not pod * aligning * default service account for pooler
1 parent 5ecb7b4 commit ac2a00c

File tree

6 files changed

+27
-10
lines changed

6 files changed

+27
-10
lines changed

charts/postgres-operator/templates/deployment.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ spec:
5454
{{- end }}
5555
resources:
5656
{{ toYaml .Values.resources | indent 10 }}
57+
securityContext:
58+
{{ toYaml .Values.securityContext | indent 10 }}
5759
{{- if .Values.imagePullSecrets }}
5860
imagePullSecrets:
5961
{{ toYaml .Values.imagePullSecrets | indent 8 }}

charts/postgres-operator/values-crd.yaml

+10-4
Original file line numberDiff line numberDiff line change
@@ -359,18 +359,24 @@ resources:
359359
cpu: 100m
360360
memory: 250Mi
361361

362+
securityContext:
363+
runAsUser: 1000
364+
runAsNonRoot: true
365+
readOnlyRootFilesystem: true
366+
allowPrivilegeEscalation: false
367+
362368
# Affinity for pod assignment
363369
# Ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity
364370
affinity: {}
365371

366-
# Tolerations for pod assignment
367-
# Ref: https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/
368-
tolerations: []
369-
370372
# Node labels for pod assignment
371373
# Ref: https://kubernetes.io/docs/user-guide/node-selection/
372374
nodeSelector: {}
373375

376+
# Tolerations for pod assignment
377+
# Ref: https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/
378+
tolerations: []
379+
374380
controllerID:
375381
# Specifies whether a controller ID should be defined for the operator
376382
# Note, all postgres manifest must then contain the following annotation to be found by this operator

charts/postgres-operator/values.yaml

+10-4
Original file line numberDiff line numberDiff line change
@@ -354,18 +354,24 @@ resources:
354354
cpu: 100m
355355
memory: 250Mi
356356

357+
securityContext:
358+
runAsUser: 1000
359+
runAsNonRoot: true
360+
readOnlyRootFilesystem: true
361+
allowPrivilegeEscalation: false
362+
357363
# Affinity for pod assignment
358364
# Ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity
359365
affinity: {}
360366

361-
# Tolerations for pod assignment
362-
# Ref: https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/
363-
tolerations: []
364-
365367
# Node labels for pod assignment
366368
# Ref: https://kubernetes.io/docs/user-guide/node-selection/
367369
nodeSelector: {}
368370

371+
# Tolerations for pod assignment
372+
# Ref: https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/
373+
tolerations: []
374+
369375
controllerID:
370376
# Specifies whether a controller ID should be defined for the operator
371377
# Note, all postgres manifest must then contain the following annotation to be found by this operator

manifests/complete-postgres-manifest.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ spec:
4545
size: 1Gi
4646
# storageClass: my-sc
4747
# iops: 1000 # for EBS gp3
48-
# throughput: 250 # in MB/s for EBS gp3
48+
# throughput: 250 # in MB/s for EBS gp3
4949
additionalVolumes:
5050
- name: empty
5151
mountPath: /opt/empty

manifests/postgres-operator.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ spec:
3232
runAsUser: 1000
3333
runAsNonRoot: true
3434
readOnlyRootFilesystem: true
35+
allowPrivilegeEscalation: false
3536
env:
3637
# provided additional ENV vars can overwrite individual config map entries
3738
- name: CONFIG_MAP_NAME

pkg/cluster/connection_pooler.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ func (c *Cluster) generateConnectionPoolerPodTemplate(role PostgresRole) (
280280
},
281281
},
282282
},
283+
SecurityContext: &v1.SecurityContext{
284+
AllowPrivilegeEscalation: util.False(),
285+
},
283286
}
284287

285288
podTemplate := &v1.PodTemplateSpec{
@@ -289,7 +292,6 @@ func (c *Cluster) generateConnectionPoolerPodTemplate(role PostgresRole) (
289292
Annotations: c.annotationsSet(c.generatePodAnnotations(spec)),
290293
},
291294
Spec: v1.PodSpec{
292-
ServiceAccountName: c.OpConfig.PodServiceAccountName,
293295
TerminationGracePeriodSeconds: &gracePeriod,
294296
Containers: []v1.Container{poolerContainer},
295297
// TODO: add tolerations to scheduler pooler on the same node

0 commit comments

Comments
 (0)