Skip to content
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

[bitnami/postgresql] permission denied for function pg_ls_waldir #20247

Closed
wroge opened this issue Oct 16, 2023 · 26 comments · Fixed by #29201
Closed

[bitnami/postgresql] permission denied for function pg_ls_waldir #20247

wroge opened this issue Oct 16, 2023 · 26 comments · Fixed by #29201
Labels
postgresql solved tech-issues The user has a technical issue about an application

Comments

@wroge
Copy link

wroge commented Oct 16, 2023

Name and Version

bitnami/postgres

What architecture are you using?

None

What steps will reproduce the bug?

Error in Postgres container:

permission denied for function pg_ls_waldir

Error in Metrics container:

ts=2023-10-16T09:48:46.558Z caller=collector.go:199 level=error msg="collector failed" name=wal duration_seconds=0.01408122 err="pq: permission denied for function pg_ls_waldir"

Are you using any custom parameters or values?

No response

What is the expected behavior?

This command should be executed in init container by default.

GRANT EXECUTE ON FUNCTION pg_ls_waldir() TO <User>

What do you see instead?

User doesn't have the permission to use the function.

Additional information

No response

@wroge wroge added the tech-issues The user has a technical issue about an application label Oct 16, 2023
@wroge wroge changed the title permission denied for function pg_ls_waldir [bitnami/postgres] permission denied for function pg_ls_waldir Oct 16, 2023
@github-actions github-actions bot added the triage Triage is needed label Oct 16, 2023
@javsalgar javsalgar changed the title [bitnami/postgres] permission denied for function pg_ls_waldir [bitnami/postgresql] permission denied for function pg_ls_waldir Oct 17, 2023
@javsalgar
Copy link
Contributor

Hi,

Could you share the values and steps to reproduce the issue?

@wroge
Copy link
Author

wroge commented Oct 20, 2023

These are my values, nothing special. The database user (not admin) simply does not have the permission to use the function.

# postgresql
postgresql:
  auth:
    existingSecret: ...
    database: ...
    username: ...
  architecture: standalone
  serviceAccount:
    create: true
    automountServiceAccountToken: false
  tls:
    enabled: true
    autoGenerated: true
  metrics:
    enabled: true
    prometheusRule:
      enabled: false
    serviceMonitor:
      enabled: true
      labels:
        release: prometheus
    resources:
      limits:
        cpu: 300m
        memory: 64Mi
      requests:
        cpu: 1m
        memory: 16Mi
    containerSecurityContext:
      enabled: true
      runAsUser: 1001
      privileged: false
      runAsNonRoot: true
      readOnlyRootFilesystem: true
      allowPrivilegeEscalation: false
      capabilities:
        drop:
          - ALL
      seccompProfile:
        type: RuntimeDefault
     ...

@github-actions github-actions bot added in-progress and removed triage Triage is needed labels Oct 23, 2023
@bitnami-bot bitnami-bot assigned migruiz4 and unassigned javsalgar Oct 23, 2023
@migruiz4
Copy link
Member

Hi @wroge,

Thank you for reporting this issue. Although adding permissions for the custom user to execute pg_ls_waldir() would resolve the issue, it is not a good practice to have users with more permissions than necessary.

Instead, I have created an internal task to address this issue by implementing some changes in the chart to create a metrics user with only required permissions to obtain the metrics.

If you would like to contribute to this feature, feel free to send a PR and we will be happy to help with anything needed.

@migruiz4 migruiz4 added the on-hold Issues or Pull Requests with this label will never be considered stale label Oct 25, 2023
@michalwilk96
Copy link

Upvoting this, all bitnami/postgresql helm charts starting from version 13.0.x > are having this issue

@thevops
Copy link

thevops commented Nov 20, 2023

I confirm. The issue exists

@github-actions github-actions bot added triage Triage is needed and removed on-hold Issues or Pull Requests with this label will never be considered stale labels Nov 20, 2023
@thevops
Copy link

thevops commented Nov 20, 2023

Quick (and not safe as @migruiz4 wrote) workaround.
Execute: GRANT EXECUTE ON FUNCTION pg_ls_waldir TO mycustomuser;

@michalwilk96
Copy link

@migruiz4 any plans to fix this major issue? As mentioned earlier - all bitnami/postgresql helm charts starting from version 13.0.x > are having this issue. It's blocker, because no one wants to do a workaround with security gap.

@jouve
Copy link
Contributor

jouve commented Nov 21, 2023

this is part of upstream postgres_exporter (prometheus-community/postgres_exporter#858)

There is flag to control the collectors https://github.com/prometheus-community/postgres_exporter#flags :

[no-]collector.wal Enable the wal collector (default: enabled).

@str1k3r
Copy link

str1k3r commented Dec 7, 2023

I would say that the issue is still there with latest chart and disabled metrics. I haven't tried to delete all databases since they are in use.

Any other suggestions?

@masikrus
Copy link

GRANT pg_monitor TO readonly_user;

@FraPazGal
Copy link
Contributor

Hi all! Thank you for providing your workarounds for this bug. Seeing the issue activity I have increased the priority of our internal task related to this ticket. That said, if anyone wants to contribute with a fix feel free to create a PR and the team will gladly review it.

@FraPazGal FraPazGal added on-hold Issues or Pull Requests with this label will never be considered stale and removed in-progress labels Dec 14, 2023
@jouve
Copy link
Contributor

jouve commented Dec 14, 2023

since I implemented #21162 , I use this to disable the wal collector:

metrics:
  collectors:
    wal: false

maybe it should be set as a chart default

@cnwaldron
Copy link

This also needs to be fixed on postgresql-ha chart as well.

@kakaNo1
Copy link

kakaNo1 commented Jan 3, 2024

image
i encountered the same problem

@ecamper
Copy link

ecamper commented Jan 5, 2024

same problem on postgresql-ha

@Astolincres
Copy link

I used ALTER USER postgres_exporter WITH SUPERUSER; and it worked. After that, I also ran GRANT EXECUTE ON FUNCTION pg_ls_waldir() TO postgres_exporter;. Additionally, I learned that pg_monitor is the role that uses pg_ls_waldir, so either the user needs to be a superuser or granted the pg_monitor role.

@meysam81
Copy link

meysam81 commented Apr 5, 2024

+1 for this 🙏

@hiteshnayak305
Copy link

👍 +1

@mike667
Copy link

mike667 commented May 1, 2024

+1 for this 🙏

@zentavr
Copy link

zentavr commented Aug 23, 2024

since I implemented #21162 , I use this to disable the wal collector:

metrics:
  collectors:
    wal: false

maybe it should be set as a chart default

Don't know why that had not been added to the HA chart version. probably WAL monitoring is required when Posgre is in HA, who knows. As a workaround is to mount the sql sqript inside the postgresql pod and add the permissions.

# ...helm values
extraDeploy:
  - apiVersion: v1
    kind: ConfigMap
    metadata:
      name: pg-initdb-dot-d
    data:
      01-pg_ls_waldir-grant.sql: |
        GRANT EXECUTE ON FUNCTION pg_ls_waldir TO your-user-here;

postgresql:
  extraVolumes:
    - name:  pg-initdb-cm
      configMap:
        name: pg-initdb-dot-d
  extraVolumeMounts:
    - name: pg-initdb-cm
      mountPath: /docker-entrypoint-initdb.d
  extraEnvVars:
    - name: "POSTGRESQL_INITSCRIPTS_USERNAME"
      value: "postgres"
    - name: "POSTGRESQL_INITSCRIPTS_PASSWORD"
      value: "password"

@github-actions github-actions bot added solved and removed on-hold Issues or Pull Requests with this label will never be considered stale labels Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
postgresql solved tech-issues The user has a technical issue about an application
Projects
None yet
Development

Successfully merging a pull request may close this issue.