Skip to content
This repository was archived by the owner on Oct 21, 2020. It is now read-only.
This repository was archived by the owner on Oct 21, 2020. It is now read-only.

Default SSL settings on postgres #325

Closed

Description

@tomhoule

We recently changed the default of the accept_invalid_certs option for postgres connections in quaint to false. Users are reporting that they can't connect because of this (prisma/orm#884 for example). This can be worked around by adding the sslaccept=accept_invalid_certs to the database url in prisma.schema.

Since this appears to be a big issue for some users, I investigated in what ways SSL can be configured when connecting to a postgres database, and what the defaults are in other tools.

For a good overview of the SSL modes supported by postgres clients and their security properties, this blog post is helpful.

Clients

  • The psql CLI client supports six different sslmode variants. You can read about them in the official docs. Those are the same parameters as libpq. Only the last two levels will verify the server certificates against a trusted CA.
  • Rails uses libpq with a default sslmode of prefer, so there is no certificate verification.
  • The docs for node-postgres imply that certificates are verified, but the default settings, or ssl: true will not check the certificate. If you force the client to check the certificate with ssl: { rejectUnauthorized: true }, on DO for example, the connection will be refused. I can share the code to reproduce this if needed.
  • quaint will by default check the server certificate, which will not work unless you downloaded and configured the certificate correctly on your machine.

Providers

  • AWS RDS links to root certificates to use with their postgres databases in their docs.
  • Azure similarly provides a root certificate you can download and use.
  • Google CloudSQL uses self-signed certificates
  • I haven't been able to find docs on what the setup is for DigitalOcean hosted postgres, but it is definitely not signed by a common trusted CA. node-postgres with forced certificate verification returns (node:388342) UnhandledPromiseRejectionWarning: Error: self signed certificate in certificate chain.

Conclusion

Our default settings (without the sslaccept=accept_invalid_certs) is stricter than other clients, and it will fail to connect unless the user sets up the connection with the specific certificate the server uses. For ergonomics, we could couple sslaccept with the passing in of a server certificate file, but at minimum, I think we should flip the default to trust "invalid" certificates, and optionally validate them.

Activity

  1. changed the title [-]Reseach: postgres SSL setttings[/-] [+]Spec our default postgres SSL setttings[/+] on Nov 15, 2019
  2. tomhoule commented on Nov 15, 2019

    @tomhoule
    ContributorAuthor
  3. changed the title [-]Spec our default postgres SSL setttings[/-] [+]Spec our default postgres SSL settings[/+] on Nov 16, 2019
  4. changed the title [-]Spec our default postgres SSL settings[/-] [+]Spec our default SSL settings on postgres[/+] on Nov 16, 2019
  5. schickling commented on Nov 17, 2019

    @schickling
    Member

    I agree with your conclusion.

    Additionally @nikolasburk should document the various options extensively and provide information on best practices.

  6. added
    process/candidate
    on Nov 26, 2019
  7. janpio commented on Nov 26, 2019

    @janpio
    Contributor

    We should probably just go ahead and create a connectors folder with a README.md that links to a postgres.md where you collect this information in a spec like way @tomhoule

  8. changed the title [-]Spec our default SSL settings on postgres[/-] [+]Default SSL settings on postgres[/+] on Nov 27, 2019
  9. tomhoule commented on Dec 4, 2019

    @tomhoule
    ContributorAuthor

    The change was made in quaint, I'll propagate it to the engines today so it will land in preview 18. Specs PR: #346

  10. added this to the Preview 18 milestone on Dec 4, 2019
  11. removed
    process/candidate
    on Dec 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions