In ubuntu, add the ca-cert as described here:
https://askubuntu.com/questions/73287/how-do-i-install-a-root-certificate
wget https://s3.amazonaws.com/rds-downloads/rds-ca-2019-root.pem
sudo mkdir /usr/local/share/ca-certificates/aws
sudo mv rds-ca-2019-root.pem /usr/local/share/ca-certificates/aws
sudo openssl x509 \
-in /usr/local/share/ca-certificates/aws/rds-ca-2019-root.pem \
-inform PEM \
-out /usr/local/share/ca-certificates/aws/rds-ca-2019-root.crt
sudo update-ca-certificates
: sudo update-ca-certificates
Updating certificates in /etc/ssl/certs...
1 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
Adding debian:rds-ca-2019-root.pem
done.
done.
This link describes how to set the ssl cert location for a django application:
https://www.digitalocean.com/community/questions/how-to-connect-managed-database-postgres-with-ssl-mode-varify-full-in-django-app
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': '<name>',
'USER': '<user>',
'PASSWORD': '<password>',
'HOST' : '<host>',
'PORT' : '25060',
'OPTIONS':{
'sslmode':'verify-full',
'sslrootcert': os.path.join(BASE_DIR, 'ca-certificate.crt')
}
This post in Stackoverflow https://stackoverflow.com/a/58214922/1415254 describes how to connect using commandline parameters for psql.
psql "host={hostname} sslmode=prefer sslrootcert={ca-cert.pem} \
sslcert={client-cert.pem} sslkey={client-key.pem} port={port} user={user} \
dbname={db}"
Also
psqlrc and ~/.psqlrc
Unless it is passed an -X or -c option, psql attempts to read and execute commands
from the system-wide startup file (psqlrc) and then the user's personal startup
file (~/.psqlrc), after connecting to the database but before accepting normal
commands. These files can be used to set up the client and/or the server to taste,
typically with \set and SET commands.
And more detail here (right at the end): https://info.crunchydata.com/blog/ssl-certificate-authentication-postgresql-docker-containers
# the first parameter specifies which TLS mode to use to connect
export PGSSLMODE="verify-full"
# the following two parameters point to the client key/certificate
export PGSSLCERT="`pwd`/certs/client.crt"
export PGSSLKEY="`pwd`/keys/client.key"
# this parameter points to the trusted root CA certificate
export PGSSLROOTCERT="`pwd`/certs/ca.crt"
Full list of environment variables here: https://www.postgresql.org/docs/9.2/libpq-envars.html