kubernetes: libpq-based PostgreSQL clients will no longer read a PGPASSFILE mounted from a secret
/kind bug
What happened: libpq refuses to load my PGPASSFILE, resulting in “no password provided” error messages.
What you expected to happen: libpq reads the database password from the PGPASSFILE I’m pointing to.
How to reproduce it (as minimally and precisely as possible):
- Create a secret, containing a
.pgpass
file. - Create a volume from the secret, taking care to set the mode bits to e.g.
r--------
(256 in decimal). - Mount the volume in a container.
- Let the
PGPASSFILE
environment variable point to the.pgpass
file. - Use SQLAlchemy to connect to a PostgreSQL database, providing all information except the password.
Anything else we need to know?:
- This approach used to work, but likely broke due to #25285.
- libpq not only demands that the PGPASSFILE is only accessible by its owner, but also requires that it is a regular file.
- I’ve tried pointing to
secret-volume/..data/.pgpass
instead ofsecret-volume/.pgpass
directly, but that doesn’t seem to work either. I’m not sure, but maybe libpq really doesn’t like symbolic links in the path to the PGPASSFILE. - I can work around this problem by setting
PGPASSWORD
instead, or by keeping the password in the database connection URL. It seems a tiny bit cleaner to me to be able to switch only the config mapped connection URL while keeping the same passwords file, but I’d understand a wontfix resolution.
Environment:
- Kubernetes version (use
kubectl version
): server v1.7.8-gke.0 - Cloud provider or hardware configuration: Google Cloud Platform
- OS (e.g. from /etc/os-release): Container-Optimized OS from Google
- Kernel (e.g.
uname -a
): 4.4.64+
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 26 (13 by maintainers)
Here the corresponding lines from libpq
and here why it won’t work and probably is rather non trivial to fix
Work around:
cat
the secret mount and write own secret file with according permissions…However, this partly invalidates the original motivation of mode bits: https://github.com/kubernetes/kubernetes/blame/5d0d77df6c4eca0c50b4b91d8ceecf87c339e154/docs/proposals/secret-configmap-downwarapi-file-mode.md#L54
//cc @rata @thockin @pmorie
Maybe using hardlinks could fix this, however not sure if that would sabotage the original intent of atomicity.