Skip to content

Custom SecurityContext in Postgresql, OperatorConfiguration CRDs #2244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

hshmilo
Copy link

@hshmilo hshmilo commented Feb 27, 2023

This PR extends the Postgresql, OperatorConfiguration CRDs with the following list of properties related to pod/containers SecurityContext.
Postgresql CRD:

  1. spiloSeccompProfile – adds SeccompProfile config property on the cluster pod level.
  2. securityContext for the sidecars configuration – configures securityContext property for particular sidecar container.

OperatorConfiguration CRD:

  1. dropped_pod_capabilities - list of dropped capabilities for spilo container.
  2. spilo_seccompprofile – adds SeccompProfile config property on clusters pod level.
  3. securityContext for the sidecars configuration – configures securityContext property for particular sidecar container.

This PR addresses #2223

@EmilMunksoe
Copy link

+1

1 similar comment
@x3rus
Copy link

x3rus commented May 17, 2023

+1

@ugur99
Copy link

ugur99 commented Aug 8, 2023

Hi everyone, any updates regarding this PR?

@m1m1x
Copy link

m1m1x commented Sep 17, 2023

Hi,

any chance to review this MR please? It would be a good addition for cluster security in depth.

@mattwing
Copy link

mattwing commented Dec 6, 2023

+1 on needing this to comply with restricted profiles, as @EmilMunksoe mentioned #2223 (comment)

@Tahedah
Copy link

Tahedah commented Apr 17, 2024

Hey, this is also a blocker for us since we have strict pod policies for the clusters. Is this something that will be merged soon?

@sj-porter-knime
Copy link

+1

1 similar comment
@BalintCsonka
Copy link

+1

@mrpainte
Copy link

mrpainte commented May 2, 2024

+1 this would allow my team to be able to deploy postgres into our clusters with this operator

@bumarcell
Copy link

Why is this MR (which will make many lives easier) ignored for over a year now? waiting only makes it more complicated to merge and now there are merge conflicts to resolve.
I hope there's a good reason for that.. 😓

@ajchiarello
Copy link

Honestly, the delay on this led me to move from this operator over the CloudNative PostgreSQL Operator, which does everything and is already secure.

@sdesbure
Copy link

Honestly, the delay on this led me to move from this operator over the CloudNative PostgreSQL Operator, which does everything and is already secure.

same here :(

@zacharyljones
Copy link

+1

@mheers
Copy link

mheers commented Aug 9, 2024

I circumvented the problem with a MutatingWebhookConfiguration and the corresponding controller:

https://github.com/mheers/pod-spec-mutator

You create a deployment with an env var that specifies how the pod will modified before starting:
https://github.com/mheers/pod-spec-mutator/blob/main/deploy/deployment.yaml#L38

With this one can easily specify the SecurityContext and have it merged in the starting pods specification on-the-fly.

@ajchiarello
Copy link

I circumvented the problem with a MutatingWebhookConfiguration and the corresponding controller:

I circumvented the problem by moving to the CNPG Operator which does everything securely by default.

@mheers
Copy link

mheers commented Aug 9, 2024

I circumvented the problem with a MutatingWebhookConfiguration and the corresponding controller:

I circumvented the problem by moving to the CNPG Operator which does everything securely by default.

I also checked CNPG and indeed it offers to set the SecurityContext, but I also need to define additional volumes and hostAliases - which is also not supported by CNPG so I sticked with zalando and built the admission-hook.

@chef-6229
Copy link

please merge this PR

@FxKu FxKu added this to the 1.14.0 milestone Aug 21, 2024
@FxKu FxKu added the minor label Aug 23, 2024
@sj-porter-knime
Copy link

I think labeling this PR as minor might be a bit of an understatement - setting restricted security contexts is a best practice for any database running in Kubernetes and increasingly becoming a hard requirement. Almost every company we see using Kubernetes is installing tools like Kyverno or Gatekeeper to enforce security policies, making Postgres instances controlled via this operator a security exception in every single case. Using mutation policies with Kyverno is a creative workaround for those brave enough to use mutation policies, but also a bit of an anti-pattern.

Could we please get an acknowledgement or response from the PR reviewers (or other repo maintainers) with current status and/or some steps that community members can take to help it along? Do you need testers, or is there something else you're concerned about that we can help with? Migrating to another Postgres Operator would be a large undertaking for us, but if we can't get these security exceptions resolved, we may be forced to migrate at some point like others already have.

@@ -324,8 +328,17 @@ spec:
type: integer
spilo_runasgroup:
type: integer
spilo_runasnonroot:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need this if there is a spilo_runasuser?

Copy link

@tomsozolins tomsozolins Aug 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@szuecs such field is required to conform with pod security standards restricted profile
https://kubernetes.io/docs/concepts/security/pod-security-standards/#restricted

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok then let's have it!
Please resolve all the comments related with this one.
Thanks for your work!

@@ -466,8 +466,17 @@ spec:
type: integer
spiloRunAsGroup:
type: integer
spiloRunAsNonRoot:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -196,10 +200,15 @@ configKubernetes:
# set user and group for the spilo container (required to run Spilo as non-root process)
# spilo_runasuser: 101
# spilo_runasgroup: 103
# spilo_runasnonroot: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cluster to access buckets to write WAL-E logs: Workload Identity (recommended)
or using a GCP Service Account Key (legacy).

#### Workload Identity setup
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this all dropped?
I have no idea about GCP, but the PR seems to be about CRD change to allow to customize SecurityContext.
Please make sure the focus of the PR stays in line with the changes.

@@ -78,13 +78,26 @@ These parameters are grouped directly under the `spec` key in the manifest.
This must be set to run the container without root. By default the container
runs with root. This option only works for Spilo versions >= 1.6-p3.

* **spiloRunAsNonRoot**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -453,12 +453,25 @@ configuration they are grouped under the `kubernetes` key.
This must be set to run the container without root. By default the container
runs with root. This option only works for Spilo versions >= 1.6-p3.

* **spilo_runasnonroot**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

capabilities:
drop:
- ALL
runAsNonRoot: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -93,7 +93,11 @@ spec:
enableShmVolume: true
# spiloRunAsUser: 101
# spiloRunAsGroup: 103
# spiloRunAsNonRoot: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# capabilities:
# drop:
# - ALL
# runAsNonRoot: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -150,7 +151,11 @@ data:
spilo_allow_privilege_escalation: "true"
# spilo_runasuser: 101
# spilo_runasgroup: 103
# spilo_runasnonroot: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -322,8 +326,17 @@ spec:
type: integer
spilo_runasgroup:
type: integer
spilo_runasnonroot:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -100,7 +102,11 @@ configuration:
spilo_allow_privilege_escalation: true
# spilo_runasuser: 101
# spilo_runasgroup: 103
# spilo_runasnonroot: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -464,8 +464,17 @@ spec:
type: integer
spiloRunAsGroup:
type: integer
spiloRunAsNonRoot:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -728,9 +728,23 @@ var PostgresCRDResourceValidation = apiextv1.CustomResourceValidation{
"spiloRunAsGroup": {
Type: "integer",
},
"spiloRunAsNonRoot": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -64,8 +64,11 @@ type KubernetesMetaConfiguration struct {
SpiloAllowPrivilegeEscalation *bool `json:"spilo_allow_privilege_escalation,omitempty"`
SpiloRunAsUser *int64 `json:"spilo_runasuser,omitempty"`
SpiloRunAsGroup *int64 `json:"spilo_runasgroup,omitempty"`
SpiloRunAsNonRoot *bool `json:"spilo_runasnonroot,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -32,12 +32,15 @@ type Resources struct {
PodTerminateGracePeriod time.Duration `name:"pod_terminate_grace_period" default:"5m"`
SpiloRunAsUser *int64 `name:"spilo_runasuser"`
SpiloRunAsGroup *int64 `name:"spilo_runasgroup"`
SpiloRunAsNonRoot *bool `name:"spilo_runasnonroot"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -2346,6 +2396,8 @@ func (c *Cluster) generateLogicalBackupPodEnvVars() []v1.EnvVar {
envVars = append(envVars, v1.EnvVar{Name: "AWS_SECRET_ACCESS_KEY", Value: c.OpConfig.LogicalBackup.LogicalBackupS3SecretAccessKey})
}

c.logger.Debugf("Generated logical backup env vars")
c.logger.Debugf("%v", envVars)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, not sure if I would like this as security enhancement

@szuecs
Copy link
Member

szuecs commented Aug 29, 2024

I am not part of postgres-operator maintainers, but from kubernetes point of view I have some idea. I hope my questions are fine and help to get some things sorted out.

@FxKu FxKu modified the milestones: 1.14.0, 2.0 Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Open Questions
Development

Successfully merging this pull request may close these issues.