[stable/postgresql] PostgreSQL does not configure password correctly
Is this a request for help?: Yes
Is this a BUG REPORT or FEATURE REQUEST? (choose one): BUG REPORT
Version of Helm and Kubernetes: Helm: v2.13.1 Kubernetes: MiniKube v1.0.0
Which chart: stable/postgresql
What happened: Exception in thread "main" org.postgresql.util.PSQLException: FATAL: password authentication failed for user "keyboardcat"
What you expected to happen: Deployment of PostgreSQL with correct password.
How to reproduce it (as minimally and precisely as possible):
helm install \
--name postgresql \
--set global.postgresql.postgresqlDatabase=prisma \
--set global.postgresql.postgresqlUsername=keyboardcat \
--set global.postgresql.postgresqlPassword=kittensinmittens \
--set global.postgresql.servicePort=5432 \
stable/postgresql;
helm install \
--name prisma \
--set database.host=postgresql-postgresql.default.svc.cluster.local \
--set database.port=5432 \
--set database.user=keyboardcat \
--set database.password=kittensinmittens \
stable/prisma;
Experiencing the same issue. For some reason password is not being set though its being sent as value.
Welcome to the Bitnami postgresql container
Subscribe to project updates by watching https://github.com/bitnami/bitnami-docker-postgresql
Submit issues and feature requests at https://github.com/bitnami/bitnami-docker-postgresql/issues
nami INFO Initializing postgresql
postgre INFO ==> No injected postgresql.conf file found. Creating default postgresql.conf file...
postgre INFO ==> pg_hba.conf file found...
postgre INFO ==> Deploying PostgreSQL from scratch...
postgre INFO ==> Creating database postgres...
Error executing 'postInstallation': psql: FATAL: password authentication failed for user "postgres"
This is my current state:
helm del --purge \
postgresql \
prisma;
helm install \
--name postgresql \
--set postgresqlDatabase=prisma \
--set postgresqlPassword=kittensinmittens \
stable/postgresql;
helm install \
--name prisma \
--set database.host=postgresql-postgresql.default.svc.cluster.local \
--set database.port=5432 \
--set database.user=postgres \
--set database.password=kittensinmittens \
stable/prisma;
Welcome to the Bitnami postgresql container
Subscribe to project updates by watching https://github.com/bitnami/bitnami-docker-postgresql
Submit issues and feature requests at https://github.com/bitnami/bitnami-docker-postgresql/issues
nami INFO Initializing postgresql
postgre INFO ==> No injected postgresql.conf file found. Creating default postgresql.conf file...
postgre INFO ==> No injected pg_hba.conf file found. Creating default pg_hba.conf file...
postgre INFO ==> Deploying PostgreSQL with persisted data...
postgre INFO ==> Configuring PostgreSQL...
postgre INFO ==> Configuring replication parameters...
postgre INFO ==> Configuring permissions for config files...
postgre INFO
postgre INFO ########################################################################
postgre INFO Installation parameters for postgresql:
postgre INFO Persisted data and properties have been restored.
postgre INFO Any input specified will not take effect.
postgre INFO This installation requires no credentials.
postgre INFO ########################################################################
postgre INFO
nami INFO postgresql successfully initialized
INFO ==> Starting postgresql...
2019-04-05 14:50:23.601 GMT [71] LOG: listening on IPv4 address "0.0.0.0", port 5432
2019-04-05 14:50:23.601 GMT [71] LOG: listening on IPv6 address "::", port 5432
2019-04-05 14:50:23.607 GMT [71] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"
2019-04-05 14:50:23.631 GMT [78] LOG: database system was shut down at 2019-04-05 14:50:01 GMT
2019-04-05 14:50:23.665 GMT [71] LOG: database system is ready to accept connections
2019-04-05 14:50:31.839 GMT [91] FATAL: database "prisma" does not exist
2019-04-05 14:50:32.711 GMT [92] FATAL: password authentication failed for user "postgres"
2019-04-05 14:50:32.711 GMT [92] DETAIL: User "postgres" has no password assigned.
Connection matched pg_hba.conf line 95: "host all all 0.0.0.0/0 md5"
2019-04-05 14:50:32.751 GMT [93] FATAL: password authentication failed for user "postgres"
2019-04-05 14:50:32.751 GMT [93] DETAIL: User "postgres" has no password assigned.
Connection matched pg_hba.conf line 95: "host all all 0.0.0.0/0 md5"
2019-04-05 14:50:32.768 GMT [94] FATAL: password authentication failed for user "postgres"
2019-04-05 14:50:32.768 GMT [94] DETAIL: User "postgres" has no password assigned.
Connection matched pg_hba.conf line 95: "host all all 0.0.0.0/0 md5"
So I agree, postgresql doesn't seem to set a password.
I am getting the exact same state when I try to use yaml files to do the configuring of these parameters and values listed above with --set. Also putting them on one line or multiple lines doesn't matter, so the problem lies with the chart implementations and not the passing of the arguments I think :-)
The error is here:
https://github.com/helm/charts/blob/master/stable/postgresql/templates/secrets.yaml#L13
postgresql-password: {{ include "postgresql.password" . | b64enc | quote }}
if I change my call to --set postgresql.password=kittensinmittens it still does not work.
@adityabyreddy74 Maybe you know how this postgresql.password value is passed around the YAML files?
[debug] Created tunnel using local port: '38787'
[debug] SERVER: "127.0.0.1:38787"
[debug] Original chart version: ""
[debug] Fetched stable/postgresql to /home/tom/.helm/cache/archive/postgresql-3.16.1.tgz
[debug] CHART PATH: /home/tom/.helm/cache/archive/postgresql-3.16.1.tgz
NAME: postgresql
REVISION: 1
RELEASED: Sat Apr 6 20:21:51 2019
CHART: postgresql-3.16.1
USER-SUPPLIED VALUES:
postgresql:
password: kittensinmittens
postgresqlDatabase: prisma
COMPUTED VALUES:
extraEnv: {}
global:
postgresql: {}
image:
debug: false
pullPolicy: Always
registry: docker.io
repository: bitnami/postgresql
tag: 10.7.0
livenessProbe:
enabled: true
failureThreshold: 6
initialDelaySeconds: 30
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 5
master:
affinity: {}
nodeSelector: {}
podAnnotations: {}
podLabels: {}
tolerations: []
metrics:
enabled: false
image:
pullPolicy: IfNotPresent
registry: docker.io
repository: wrouesnel/postgres_exporter
tag: v0.4.7
livenessProbe:
enabled: true
failureThreshold: 6
initialDelaySeconds: 5
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 5
readinessProbe:
enabled: true
failureThreshold: 6
initialDelaySeconds: 5
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 5
service:
annotations:
prometheus.io/port: "9187"
prometheus.io/scrape: "true"
loadBalancerIP: null
type: ClusterIP
networkPolicy:
allowExternal: true
enabled: false
persistence:
accessModes:
- ReadWriteOnce
annotations: {}
enabled: true
mountPath: /bitnami/postgresql
size: 8Gi
subPath: ""
postgresql:
password: kittensinmittens
postgresqlDataDir: /bitnami/postgresql
postgresqlDatabase: prisma
postgresqlUsername: postgres
readinessProbe:
enabled: true
failureThreshold: 6
initialDelaySeconds: 5
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 5
replication:
applicationName: my_application
enabled: false
numSynchronousReplicas: 0
password: repl_password
slaveReplicas: 1
synchronousCommit: "off"
user: repl_user
resources:
requests:
cpu: 250m
memory: 256Mi
securityContext:
enabled: true
fsGroup: 1001
runAsUser: 1001
service:
annotations: {}
port: 5432
type: ClusterIP
slave:
affinity: {}
nodeSelector: {}
podAnnotations: {}
podLabels: {}
tolerations: []
updateStrategy:
type: RollingUpdate
volumePermissions:
enabled: true
image:
pullPolicy: Always
registry: docker.io
repository: bitnami/minideb
tag: latest
securityContext:
runAsUser: 0
HOOKS:
MANIFEST:
---
# Source: postgresql/templates/secrets.yaml
apiVersion: v1
kind: Secret
metadata:
name: postgresql-postgresql
labels:
app: postgresql
chart: postgresql-3.16.1
release: "postgresql"
heritage: "Tiller"
type: Opaque
data:
postgresql-password: "QTdvVVl3RExZTA=="
---
# Source: postgresql/templates/svc-headless.yaml
apiVersion: v1
kind: Service
metadata:
name: postgresql-postgresql-headless
labels:
app: postgresql
chart: postgresql-3.16.1
release: "postgresql"
heritage: "Tiller"
spec:
type: ClusterIP
clusterIP: None
ports:
- name: postgresql
port: 5432
targetPort: postgresql
selector:
app: postgresql
release: "postgresql"
---
# Source: postgresql/templates/svc.yaml
apiVersion: v1
kind: Service
metadata:
name: postgresql-postgresql
labels:
app: postgresql
chart: postgresql-3.16.1
release: "postgresql"
heritage: "Tiller"
spec:
type: ClusterIP
ports:
- name: postgresql
port: 5432
targetPort: postgresql
selector:
app: postgresql
release: "postgresql"
role: master
---
# Source: postgresql/templates/statefulset.yaml
apiVersion: apps/v1beta2
kind: StatefulSet
metadata:
name: postgresql-postgresql
labels:
app: postgresql
chart: postgresql-3.16.1
release: "postgresql"
heritage: "Tiller"
spec:
serviceName: postgresql-postgresql-headless
replicas: 1
updateStrategy:
type: RollingUpdate
selector:
matchLabels:
app: postgresql
release: "postgresql"
role: master
template:
metadata:
name: postgresql-postgresql
labels:
app: postgresql
chart: postgresql-3.16.1
release: "postgresql"
heritage: "Tiller"
role: master
spec:
securityContext:
fsGroup: 1001
initContainers:
- name: init-chmod-data
image: docker.io/bitnami/minideb:latest
imagePullPolicy: "Always"
resources:
requests:
cpu: 250m
memory: 256Mi
command:
- sh
- -c
- |
chown -R 1001:1001 /bitnami
if [ -d /bitnami/postgresql/data ]; then
chmod 0700 /bitnami/postgresql/data;
fi
securityContext:
runAsUser: 0
volumeMounts:
- name: data
mountPath: /bitnami/postgresql
subPath:
containers:
- name: postgresql-postgresql
image: docker.io/bitnami/postgresql:10.7.0
imagePullPolicy: "Always"
resources:
requests:
cpu: 250m
memory: 256Mi
securityContext:
runAsUser: 1001
env:
- name: PGDATA
value: "/bitnami/postgresql"
- name: POSTGRES_USER
value: "postgres"
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: postgresql-postgresql
key: postgresql-password
- name: POSTGRES_DB
value: "prisma"
ports:
- name: postgresql
containerPort: 5432
livenessProbe:
exec:
command:
- sh
- -c
- exec pg_isready -U "postgres" -d "prisma" -h localhost
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
successThreshold: 1
failureThreshold: 6
readinessProbe:
exec:
command:
- sh
- -c
- exec pg_isready -U "postgres" -d "prisma" -h localhost
initialDelaySeconds: 5
periodSeconds: 10
timeoutSeconds: 5
successThreshold: 1
failureThreshold: 6
volumeMounts:
- name: data
mountPath: /bitnami/postgresql
subPath:
volumes:
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes:
- "ReadWriteOnce"
resources:
requests:
storage: "8Gi"
This is where the value changed:
https://github.com/helm/charts/commit/7ca2c9a1873e2216f79463523547b266d4bfcafc#diff-55277ba53f205867d3498bc5c67e178b
This is where the value is defined:
https://github.com/helm/charts/blob/master/stable/postgresql/templates/_helpers.tpl#L78
After doing
helm install \
--debug \
--dry-run \
--name postgresql \
--set postgresqlDatabase=prisma \
--set global.postgresql.postgresqlPassword=kittensinglobals \
--set postgresqlPassword=kittensinmittens \
stable/postgresql;
I still can't get it to work. There must be something wrong with the definition above in _helpers.tpl.
@javsalgar Hi! Maybe you can help :question: :sunglasses:
@Industrial postgresql.password is a custom function that chooses between user provided password vs. random string. I tried and i'm still trying to understand the reason why the password is not being set.
Hi,
I was not able to reproduce the issue
± |RedisSentinel → origin {1} ✓| → kubectl logs postgresql-postgresql-0
Welcome to the Bitnami postgresql container
Subscribe to project updates by watching https://github.com/bitnami/bitnami-docker-postgresql
Submit issues and feature requests at https://github.com/bitnami/bitnami-docker-postgresql/issues
nami INFO Initializing postgresql
postgre INFO ==> No injected postgresql.conf file found. Creating default postgresql.conf file...
postgre INFO ==> No injected pg_hba.conf file found. Creating default pg_hba.conf file...
postgre INFO ==> Deploying PostgreSQL from scratch...
postgre INFO ==> Creating database prisma...
postgre INFO ==> Creating postgres user with unrestricted access...
postgre INFO ==> Configuring PostgreSQL...
postgre INFO ==> Configuring replication parameters...
postgre INFO ==> Configuring permissions for config files...
postgre INFO
postgre INFO ########################################################################
postgre INFO Installation parameters for postgresql:
postgre INFO Root User: postgres
postgre INFO Password: **********
postgre INFO Database: prisma
postgre INFO (Passwords are not shown for security reasons)
postgre INFO ########################################################################
postgre INFO
nami INFO postgresql successfully initialized
INFO ==> Starting postgresql...
2019-04-16 10:20:42.037 GMT [130] LOG: listening on IPv4 address "0.0.0.0", port 5432
2019-04-16 10:20:42.038 GMT [130] LOG: listening on IPv6 address "::", port 5432
2019-04-16 10:20:42.042 GMT [130] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"
2019-04-16 10:20:42.055 GMT [137] LOG: database system was shut down at 2019-04-16 10:20:41 GMT
2019-04-16 10:20:42.060 GMT [130] LOG: database system is ready to accept connections
It looks to me that you have persistence from a previous install. Note that helm delete --purge will not delete the PVCs. Could you try deleteing them and try again?
Deploying it in a straight way using helm works. But if we use it as a sub-chart, it doesn't.
Do you have an example chart that I can use to reproduce?
helm install \
--debug \
--dry-run \
--name postgresql \
--set postgresqlDatabase=prisma \
--set global.postgresql.postgresqlPassword=kittensinglobals \
--set postgresqlPassword=kittensinmittens \
stable/postgresql;
That's the reproducible example :-)
This comment might explain the issue seen @Industrial https://github.com/helm/charts/commit/2d50b559445eccb75af97beffa1502417211d688#r32993334
@Industrial could you confirm that's the reproducible example? I did not find any issue
○ → helm install --name postgresql --set postgresqlDatabase=prisma --set global.postgresql.postgresqlPassword=kittensinglobals --set postgresqlPassword=kittensinmittens stable/postgresql;
NAME: postgresql
LAST DEPLOYED: Thu Apr 18 11:40:04 2019
NAMESPACE: default
STATUS: DEPLOYED
RESOURCES:
==> v1/Secret
NAME AGE
postgresql-postgresql 1s
==> v1/Service
postgresql-postgresql-headless 1s
postgresql-postgresql 1s
==> v1beta2/StatefulSet
postgresql-postgresql 1s
==> v1/Pod(related)
NAME READY STATUS RESTARTS AGE
postgresql-postgresql-0 0/1 Pending 0 0s
NOTES:
** Please be patient while the chart is being deployed **
PostgreSQL can be accessed via port 5432 on the following DNS name from within your cluster:
postgresql-postgresql.default.svc.cluster.local - Read/Write connection
To get the password for "postgres" run:
export POSTGRES_PASSWORD=$(kubectl get secret --namespace default postgresql-postgresql -o jsonpath="{.data.postgresql-password}" | base64 --decode)
To connect to your database run the following command:
kubectl run postgresql-postgresql-client --rm --tty -i --restart='Never' --namespace default --image docker.io/bitnami/postgresql:10.7.0 --env="PGPASSWORD=$POSTGRES_PASSWORD" --command -- psql --host postgresql-postgresql -U postgres -d prisma
To connect to your database from outside the cluster execute the following commands:
kubectl port-forward --namespace default svc/postgresql-postgresql 5432:5432 &
PGPASSWORD="$POSTGRES_PASSWORD" psql --host 127.0.0.1 -U postgres -d prisma
2019-04-18 11:40:06 ⌚ javsalgar-MacBookPro in /tmp/bitnami-wordpress-info-20190416-120600-27889
○ → kubectl get pods
NAME READY STATUS RESTARTS AGE
postgresql-postgresql-0 1/1 Running 0 2m26s
2019-04-18 11:42:32 ⌚ javsalgar-MacBookPro in /tmp/bitnami-wordpress-info-20190416-120600-27889
○ → kubectl logs postgresql-postgresql-0
Welcome to the Bitnami postgresql container
Subscribe to project updates by watching https://github.com/bitnami/bitnami-docker-postgresql
Submit issues and feature requests at https://github.com/bitnami/bitnami-docker-postgresql/issues
nami INFO Initializing postgresql
postgre INFO ==> No injected postgresql.conf file found. Creating default postgresql.conf file...
postgre INFO ==> No injected pg_hba.conf file found. Creating default pg_hba.conf file...
postgre INFO ==> Deploying PostgreSQL from scratch...
postgre INFO ==> Creating database prisma...
postgre INFO ==> Creating postgres user with unrestricted access...
postgre INFO ==> Configuring PostgreSQL...
postgre INFO ==> Configuring replication parameters...
postgre INFO ==> Configuring permissions for config files...
postgre INFO
postgre INFO ########################################################################
postgre INFO Installation parameters for postgresql:
postgre INFO Root User: postgres
postgre INFO Password: **********
postgre INFO Database: prisma
postgre INFO (Passwords are not shown for security reasons)
postgre INFO ########################################################################
postgre INFO
nami INFO postgresql successfully initialized
INFO ==> Starting postgresql...
2019-04-18 09:41:16.082 GMT [134] LOG: listening on IPv4 address "0.0.0.0", port 5432
2019-04-18 09:41:16.082 GMT [134] LOG: listening on IPv6 address "::", port 5432
2019-04-18 09:41:16.121 GMT [134] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"
2019-04-18 09:41:16.187 GMT [141] LOG: database system was shut down at 2019-04-18 09:41:15 GMT
2019-04-18 09:41:16.217 GMT [134] LOG: database system is ready to accept connections
@javsalgar
It runs, that is correct.
If you add --debug --dry-run then you can see that the actual password being set is not the one that you configured.
helm install \
--debug \
--dry-run \
--name postgresql \
--set postgresqlDatabase=prisma \
--set global.postgresql.postgresqlPassword=kittensinglobals \
--set postgresqlPassword=kittensinmittens \
stable/postgresql | grep 'postgresql-password';
You can also, as the output suggests, try running kubectl get secret --namespace default postgresql-postgresql -o jsonpath="{.data.postgresql-password}" | base64 --decode on a running version.
Hi,
I tried it and I got
○ → echo "a2l0dGVuc2luZ2xvYmFscw==" | base64 -d
kittensinglobals
This is expected. The global.postgresql.postgresqlPassword has priority over postgresqlPassword. The global version is meant to be used in very specific context where you have various sub-charts that depend on a same postgresql chart. Otherwise, using the regular postgresqlPassword should be enough.
I can't reproduce my earlier state now, sorry. It works for me so I'm closing the ticket.
didn't work for me either :( until I removed all PVC from previous installations :)
Two things helped me here:
- Ensure that if you specify a
postgresqlUsernamethat you also specify apostgresqlDatabase.
# in your values.yaml
global:
postgresql:
postgresqlDatabase: foo-db
postgresqlUsername: some-user-of-foo-db
- Per @maslick -- Delete any persistent volume claims before re-deploying. An old PVC will keep the same credential settings in place even though you think you are changing them as you debug.
kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
data-some-lingering-pvc Bound pvc-8f081789-7b11-456d-b644-375ad2d292b6 8Gi RWO standard 9m55s
Note how long that PVC has been alive. Likely as long as you've been debugging. Normally, we'd want the PVC to hang around (wouldn't want your data vanishing each time you re-deploy). But when getting started, deleting it is ok. Of course don't delete if it contains data you don't want to lose.
kubectl delete pvc data-some-lingering-pvc
And try again...