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

Kingfisher: PostgresSQL sslmode=verify-full #152

Closed
3 tasks
jpmckinney opened this issue May 12, 2020 · 1 comment
Closed
3 tasks

Kingfisher: PostgresSQL sslmode=verify-full #152

jpmckinney opened this issue May 12, 2020 · 1 comment
Labels
postgresql Relating to PostgreSQL services

Comments

@jpmckinney
Copy link
Member

jpmckinney commented May 12, 2020

We are changing pg_hba.conf to require SSL for remote connections, effectively changing clients from the default sslmode=prefer to the stronger sslmode=require.

To prevent man-in-the-middle (MITM) attacks, we'd need to use sslmode=verify-full, but this requires clients to configure sslcert and sslkey sslrootcert connection parameters.

All other connections are local. If we move Kingfisher Process or Views to a different server than the database, they can be configured to use sslmode=verify-full.

A quick search turns up this article on how to do it with Docker. I figure the steps would be quite similar for a traditional deployment: https://info.crunchydata.com/blog/ssl-certificate-authentication-postgresql-docker-containers

@jpmckinney jpmckinney added the S: kingfisher Relating to the Kingfisher servers label May 12, 2020
@jpmckinney jpmckinney added postgresql Relating to PostgreSQL services for: Dogsbody and removed S: kingfisher Relating to the Kingfisher servers labels May 20, 2020
@jpmckinney
Copy link
Member Author

jpmckinney commented Dec 11, 2022

Using verify-full means that if the replica server or main server goes down, then we can't simply bring them back up as new servers; we'll also have to update the root certificates on any client servers (at this time, redash and kingfisher-replica). (PostgreSQL server naming was discussed at #86 (comment))

We can already use verify-full with a command like:

psql -vv "dbname=ocdskingfisherprocess user=jmckinney host=replica1.kingfisher.open-contracting.org sslmode=verify-full sslrootcert=root.crt"

Where root.crt on the local machine has the contents of /etc/ssl/private/ssl-cert-snakeoil.pem from the remote server. The certificate is for the specific server (replica1.kingfisher.open-contracting.org), not the service (postgres-readonly.kingfisher.open-contracting.org), and the host needs to be set accordingly.

It's easy to similarly configure Redash at, for example, https://redash.open-contracting.org/data_sources/5

Since we want to remain flexible and generally identify services rather than servers, I'll close this issue as unplanned.

The only case (with respect to PostgreSQL) where we identify the server is between the replica and main servers (they use the process1.kingfisher and replica1.kingfisher server names rather than the service names). That said, the likelihood of MITM attacks are low, and it's not really worth configuring verify-full for only one case.

Docs: https://www.postgresql.org/docs/current/ssl-tcp.html


I had added these states while exploring this, before realizing that /etc/postgresql/postgresql.conf sets ssl_cert_key and ssl_key_file to /etc/ssl/private/ssl-cert-snakeoil.pem and /etc/ssl/private/ssl-cert-snakeoil.key. If we want to generate own own private key and public certificate, we'd have to change those lines.

{% if 'ssl' in pillar.postgres %}
/var/lib/postgresql/{{ pillar.postgres.version }}/main/server.crt:
  file.managed:
    - contents_pillar: postgres:ssl:pubcert
    - user: postgres
    - group: postgres
    - mode: 644
    - watch_in:
      - module: postgresql-reload

/var/lib/postgresql/{{ pillar.postgres.version }}/main/server.key:
  file.managed:
    - contents_pillar: postgres:ssl:privkey
    - user: postgres
    - group: postgres
    - mode: 600
    - watch_in:
      - module: postgresql-reload
{% endif %}

jpmckinney added a commit that referenced this issue Dec 11, 2022
…to PostgreSQL if replacing default cert and using verify-full) #152
@jpmckinney jpmckinney closed this as not planned Won't fix, can't repro, duplicate, stale Dec 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
postgresql Relating to PostgreSQL services
Projects
None yet
Development

No branches or pull requests

1 participant