postgres-operator icon indicating copy to clipboard operation
postgres-operator copied to clipboard

issues with ssl when trying the example custom-config-ssl

Open atinsood opened this issue 7 years ago • 12 comments

Describe the bug trying to create a cluster with the replica following the example https://github.com/CrunchyData/postgres-operator/tree/master/examples/custom-config-ssl using the command:

pgo create cluster customsslcluster --custom-config pgo-custom-ssl-config --replica-count=1 -n ${PGO_NAMESPACE}

the primary and the backrest pod seem to come up fine, but the replica pod seems to be failing with the below logs

Fri Jun 14 18:09:50 UTC 2019 INFO: Setting PGROOT to /usr/pgsql-11.
Fri Jun 14 18:09:50 UTC 2019 INFO: The PGUSER secret exists.
Fri Jun 14 18:09:50 UTC 2019 INFO: The PGROOT secret exists.
Fri Jun 14 18:09:50 UTC 2019 INFO: The PGPRIMARY secret exists.
Fri Jun 14 18:09:50 UTC 2019 INFO: Cleaning up the old postmaster.pid file..
Fri Jun 14 18:09:50 UTC 2019 INFO: User ID is set to uid=26(postgres) gid=26(postgres) groups=26(postgres).
Fri Jun 14 18:09:50 UTC 2019 INFO: Setting LOG_MIN_DURATION_STATEMENT to 60000.
Fri Jun 14 18:09:50 UTC 2019 INFO: Setting LOG_STATEMENT to none.
Fri Jun 14 18:09:50 UTC 2019 INFO: Working on replica..
Fri Jun 14 18:09:50 UTC 2019 INFO: Initializing the replica.
Fri Jun 14 18:09:50 UTC 2019 INFO: Waiting to allow the primary database time to successfully start before performing the initial backup..
customsslcluster:5432 - no response
customsslcluster:5432 - no response
customsslcluster:5432 - no response
customsslcluster:5432 - no response
customsslcluster:5432 - accepting connections
Fri Jun 14 18:10:06 UTC 2019 INFO: The database is ready.
psql: FATAL:  connection requires a valid client certificate
FATAL:  no pg_hba.conf entry for host "10.1.195.68", user "primaryuser", database "userdb", SSL off
Fri Jun 14 18:10:06 UTC 2019 INFO: Attempting pg_isready on primary..
psql: FATAL:  connection requires a valid client certificate
FATAL:  no pg_hba.conf entry for host "10.1.195.68", user "primaryuser", database "userdb", SSL off

the output of the /etc/hosts file inside the replica is


cat /etc/hosts
# Kubernetes-managed hosts file.
127.0.0.1	localhost
::1	localhost ip6-localhost ip6-loopback
fe00::0	ip6-localnet
fe00::0	ip6-mcastprefix
fe00::1	ip6-allnodes
fe00::2	ip6-allrouters
10.1.195.68	customsslcluster-mwtr-c6bd99fb5-bd484

get pods has the output


NAME                                                     READY   STATUS    RESTARTS   AGE   IP             NODE             NOMINATED NODE
customsslcluster-685776cb5f-2lspt                        1/1     Running   0          20m   10.1.195.127   172.16.26.99     <none>
customsslcluster-backrest-shared-repo-6fbc4bd58d-46cg8   1/1     Running   0          20m   10.1.229.7     172.16.176.134   <none>
customsslcluster-mwtr-c6bd99fb5-bd484                    0/1     Running   0          20m   10.1.195.68    172.16.26.99     <none>

and get services has the output


NAME                                    TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)                                         AGE   SELECTOR
customsslcluster                        ClusterIP   10.0.87.50    <none>        5432/TCP,9100/TCP,10000/TCP,2022/TCP,9187/TCP   21m   service-name=customsslcluster
customsslcluster-backrest-shared-repo   ClusterIP   10.0.38.43    <none>        2022/TCP                                        21m   name=customsslcluster-backrest-shared-repo
customsslcluster-replica                ClusterIP   10.0.77.102   <none>        5432/TCP,9100/TCP,10000/TCP,2022/TCP,9187/TCP   21m   service-name=customsslcluster-replica

hba conf inside the replica looks like below
cat /pgconf/pg_hba.conf
# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             postgres                                 trust
local   all             testuser                                 trust
hostssl replication     replication     0.0.0.0/0                cert clientcert=1
hostssl replication     replication     127.0.0.1/32             cert clientcert=1
# IPv4 local connections:
hostssl all             testuser        127.0.0.1/32             cert clientcert=1 map=ssl-testuser
hostssl all             testuser        0.0.0.0/0                cert clientcert=1 map=ssl-testuser
hostssl all             all             127.0.0.1/32             cert clientcert=1
hostssl all             all             0.0.0.0/0                cert clientcert=1

Please tell us about your environment:

  • Operating System:
  • Where is this running ( Local, Cloud Provider) :
  • Storage being used (NFS, Hostpath, Gluster, etc):
  • Container Image Tag:
  • PostgreSQL Version:
  • Platform (Docker, Kubernetes, OpenShift):
  • Platform Version: 4.0.0/latest code

Additional context Add any other context about the problem here.

atinsood avatar Jun 17 '19 14:06 atinsood

@jmccormick2001 Hey Jeff, we are hitting this same issue and it is blocking us. Any thought on this?

fanzhang15 avatar Jun 25 '19 16:06 fanzhang15

we'll take a look.

jmccormick2001 avatar Jun 25 '19 16:06 jmccormick2001

@jmccormick2001 were you able to look into this, or replicate this at your end?

atinsood avatar Jul 03 '19 04:07 atinsood

@atinsood we are still working on it and should have something soon, just trying to make sure we can document the changes required to make ssl work with the replicas and the impacts of those changes.

cahoonpwork avatar Jul 03 '19 12:07 cahoonpwork

@cahoonpwork thanks for the reply. I guess the biggest thing for me was if I was doing anything incorrectly, and from your reply it seems like you will update the documentation on how to make ssl work correctly with replicas. appreciate you looking into this.

atinsood avatar Jul 04 '19 02:07 atinsood

@atinsood the current example didn't include replicas setup in the configuration so we are documenting a new example that includes replicas as there are more config changes that need to happen. We should have it checked in this week.

cahoonpwork avatar Jul 09 '19 13:07 cahoonpwork

@atinsood take a look at this example and see if that helps out: https://github.com/CrunchyData/postgres-operator/tree/develop/examples/primary-replica-custom-ssl

cahoonpwork avatar Jul 12 '19 13:07 cahoonpwork

@cahoonpwork I can give this a try later in the day. do you mind summarizing what was the change that you had to make to get this to work (for my own understanding)

atinsood avatar Jul 12 '19 15:07 atinsood

@cahoonpwork I believe the sample you provided uses md5 encrypted passwords for communication between primary and slave, can the operator be configured so that client certs are used instead? This issue seems related: https://github.com/CrunchyData/postgres-operator/issues/892

frnckdlprt avatar Aug 26 '19 16:08 frnckdlprt

@frnckdlprt That issue is related, the Operator doesn't currently support the configuration of certs for that piece of communication yet.

cahoonpwork avatar Aug 26 '19 17:08 cahoonpwork

The custom SSL example has been updated for v4.2.0

jkatz avatar Dec 31 '19 23:12 jkatz

is there a new example? all links seem non-working. I basically just want to connect from a node.js app with no additional configuration

VGerris avatar Nov 25 '22 15:11 VGerris