Skip to content

Commit 9e93c0a

Browse files
neelasha-09Neelam SharmaFxKu
authored
Fix for AllowPrivilegeEscalation : issue-1403 (zalando#1412)
* Fix for AllowPrivilegeEscalation : issue-1403 * fixed syntax error * Aligned the value for parameter * Aligned the value for parameter * Update crds.go * Aligned the parameter spilo_allow_privilege_escalation * Parameters sorted in Alphabetical order in manifests yaml * Parameters sorted in Alphabetical order in manifests yaml * Update pkg/controller/operator_config.go * Update docs/reference/operator_parameters.md Co-authored-by: Neelam Sharma <[email protected]> Co-authored-by: Felix Kunde <[email protected]>
1 parent f54435e commit 9e93c0a

File tree

12 files changed

+29
-1
lines changed

12 files changed

+29
-1
lines changed

charts/postgres-operator/crds/operatorconfigurations.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ spec:
264264
secret_name_template:
265265
type: string
266266
default: "{username}.{cluster}.credentials.{tprkind}.{tprgroup}"
267+
spilo_allow_privilege_escalation:
268+
type: boolean
269+
default: true
267270
spilo_runasuser:
268271
type: integer
269272
spilo_runasgroup:

charts/postgres-operator/values-crd.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ configKubernetes:
155155

156156
# whether the Spilo container should run in privileged mode
157157
spilo_privileged: false
158+
# whether the Spilo container should run with additional permissions other than parent.
159+
# required by cron which needs setuid
160+
spilo_allow_privilege_escalation: true
158161
# storage resize strategy, available options are: ebs, pvc, off
159162
storage_resize_mode: pvc
160163
# operator watches for postgres objects in the given namespace

charts/postgres-operator/values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ configKubernetes:
147147

148148
# whether the Spilo container should run in privileged mode
149149
spilo_privileged: "false"
150+
# whether the Spilo container should run with additional permissions other than parent.
151+
# required by cron which needs setuid
152+
spilo_allow_privilege_escalation: true
150153
# storage resize strategy, available options are: ebs, pvc, off
151154
storage_resize_mode: pvc
152155
# operator watches for postgres objects in the given namespace

docs/reference/operator_parameters.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,11 @@ configuration they are grouped under the `kubernetes` key.
374374
used for AWS volume resizing and not required if you don't need that
375375
capability. The default is `false`.
376376

377+
* **spilo_allow_privilege_escalation**
378+
Controls whether a process can gain more privileges than its parent
379+
process. Required by cron which needs setuid. Without this parameter,
380+
certification rotation & backups will not be done. The default is `true`.
381+
377382
* **additional_pod_capabilities**
378383
list of additional capabilities to be added to the postgres container's
379384
SecurityContext (e.g. SYS_NICE etc.). Please, make sure first that the

manifests/configmap.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ data:
114114
secret_name_template: "{username}.{cluster}.credentials"
115115
# sidecar_docker_images: ""
116116
# set_memory_request_to_limit: "false"
117+
spilo_allow_privilege_escalation: "true"
117118
# spilo_runasuser: 101
118119
# spilo_runasgroup: 103
119120
# spilo_fsgroup: 103

manifests/operatorconfiguration.crd.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ spec:
260260
secret_name_template:
261261
type: string
262262
default: "{username}.{cluster}.credentials.{tprkind}.{tprgroup}"
263+
spilo_allow_privilege_escalation:
264+
type: boolean
265+
default: true
263266
spilo_runasuser:
264267
type: integer
265268
spilo_runasgroup:

manifests/postgresql-operator-default-configuration.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ configuration:
7979
# pod_service_account_role_binding_definition: ""
8080
pod_terminate_grace_period: 5m
8181
secret_name_template: "{username}.{cluster}.credentials.{tprkind}.{tprgroup}"
82+
spilo_allow_privilege_escalation: true
8283
# spilo_runasuser: 101
8384
# spilo_runasgroup: 103
8485
# spilo_fsgroup: 103

pkg/apis/acid.zalan.do/v1/crds.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,9 @@ var OperatorConfigCRDResourceValidation = apiextv1.CustomResourceValidation{
11621162
"spilo_privileged": {
11631163
Type: "boolean",
11641164
},
1165+
"spilo_allow_privilege_escalation": {
1166+
Type: "boolean",
1167+
},
11651168
"storage_resize_mode": {
11661169
Type: "string",
11671170
Enum: []apiextv1.JSON{

pkg/apis/acid.zalan.do/v1/operator_configuration_type.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ type KubernetesMetaConfiguration struct {
5656
PodServiceAccountRoleBindingDefinition string `json:"pod_service_account_role_binding_definition,omitempty"`
5757
PodTerminateGracePeriod Duration `json:"pod_terminate_grace_period,omitempty"`
5858
SpiloPrivileged bool `json:"spilo_privileged,omitempty"`
59+
SpiloAllowPrivilegeEscalation bool `json:"spilo_allow_privilege_escalation,omitempty"`
5960
SpiloRunAsUser *int64 `json:"spilo_runasuser,omitempty"`
6061
SpiloRunAsGroup *int64 `json:"spilo_runasgroup,omitempty"`
6162
SpiloFSGroup *int64 `json:"spilo_fsgroup,omitempty"`

pkg/cluster/k8sres.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ func generateContainer(
442442
envVars []v1.EnvVar,
443443
volumeMounts []v1.VolumeMount,
444444
privilegedMode bool,
445+
privilegeEscalationMode bool,
445446
additionalPodCapabilities *v1.Capabilities,
446447
) *v1.Container {
447448
return &v1.Container{
@@ -466,7 +467,7 @@ func generateContainer(
466467
VolumeMounts: volumeMounts,
467468
Env: envVars,
468469
SecurityContext: &v1.SecurityContext{
469-
AllowPrivilegeEscalation: &privilegedMode,
470+
AllowPrivilegeEscalation: &privilegeEscalationMode,
470471
Privileged: &privilegedMode,
471472
ReadOnlyRootFilesystem: util.False(),
472473
Capabilities: additionalPodCapabilities,
@@ -1162,6 +1163,7 @@ func (c *Cluster) generateStatefulSet(spec *acidv1.PostgresSpec) (*appsv1.Statef
11621163
deduplicateEnvVars(spiloEnvVars, c.containerName(), c.logger),
11631164
volumeMounts,
11641165
c.OpConfig.Resources.SpiloPrivileged,
1166+
c.OpConfig.Resources.SpiloAllowPrivilegeEscalation,
11651167
generateCapabilities(c.OpConfig.AdditionalPodCapabilities),
11661168
)
11671169

@@ -1915,6 +1917,7 @@ func (c *Cluster) generateLogicalBackupJob() (*batchv1beta1.CronJob, error) {
19151917
envVars,
19161918
[]v1.VolumeMount{},
19171919
c.OpConfig.SpiloPrivileged, // use same value as for normal DB pods
1920+
c.OpConfig.SpiloAllowPrivilegeEscalation,
19181921
nil,
19191922
)
19201923

0 commit comments

Comments
 (0)