Skip to content

Custom Security Context in postgresql #2223

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
olivejing opened this issue Feb 16, 2023 · 8 comments
Open

Custom Security Context in postgresql #2223

olivejing opened this issue Feb 16, 2023 · 8 comments

Comments

@olivejing
Copy link

  • **Which image of the operator are you using?
    postgres-operator:v1.9.0
  • **Where do you run it - cloud or metal?
    Kubernetes and OpenShift
  • Type of issue?
    feature request

Hi, i checked postgres operator configuration and postgresql manifest, there is no parameter to custom SecurityContext. Parameter additional_pod_capabilities only supports adding capabilities in container level SecurityContex. Actually, i want to custom pod level and container lever SecurityContext, example:

pod level SecurityContext:

        securityContext:
          fsGroup: 7777
          runAsNonRoot: true
          runAsUser: 7777

container level SecurityContext:

          securityContext:
            allowPrivilegeEscalation: false
            capabilities:
              drop:
              - ALL
            privileged: false
            readOnlyRootFilesystem: true
            seccompProfile:
              type: RuntimeDefault
@hshmilo
Copy link

hshmilo commented Feb 27, 2023

Postgresql, OperatorConfiguration CRDs provide a rather limited set of SecurityContext configuration properties. I could not find a way how to configure the following properties:

  1. seccompProfile for the pod SecurityContext. It supports the spiloRunAsUser, spiloRunAsGroup, spiloFSGroup only.
  2. SecurityContext configuration for the sidecar containers is not supported.
  3. For the spilo container level is supported only adding capabilities list by the additional_pod_capabilities parameter.

Created the #2244 PR which implements the above features.

@mjdazz
Copy link

mjdazz commented Apr 18, 2023

I hate to be that guy but is there a timeline when (and if) this will be merged? It is a critical thing for the decision for our current setup...

@theobolo
Copy link

@EmilMunksoe
Copy link

This MR is very much needed if you are trying to enforce restricted pod policies: https://kubernetes.io/docs/concepts/security/pod-security-standards/ (Yes I know pod policies are deprecated - but you can do the same restricted policy management with Pod Security Admission)

@ajchiarello
Copy link

Is there any timeline on when this will be merged, or anything we can do to help it along?

@mattwing
Copy link

mattwing commented Dec 6, 2023

+1 on needing this to comply with restricted profiles, as @EmilMunksoe mentioned here

There's an open PR here: #2244, just needs a review.

@yyvess
Copy link

yyvess commented Jul 2, 2024

As Workaround you can use a kyverno ClusterPolicy

apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
  name: postgresql-securitycontext
spec:
  rules:
    - name: mutate-postgresql-sts
      match:
        any:
          - resources:
              kinds:
                - Pod
              selector:
                matchLabels:
                  application: spilo
      mutate:
        patchStrategicMerge:
          spec:
            containers:
              - (name): "*"
                securityContext:
                  allowPrivilegeEscalation: false
                  capabilities:
                    drop:
                      - ALL
                  seccompProfile:
                    type: RuntimeDefault
            securityContext:
              runAsNonRoot: true

@zacharyljones
Copy link

+1 - Is there anything that I can do to help move this along?

I'm using this operator within vClusters, and can't use the Kyverno Policy workaround until vCluster's next major release (https://www.vcluster.com/docs/platform/integrations/host-kyverno). It seems like my only option would be to wait for that release or switch to the CNPG Operator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants