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

[PP-1775] Ensure ssl connections to postgres work when ssl required #286

Conversation

dbernstein
Copy link
Contributor

@dbernstein dbernstein commented Oct 23, 2024

Description

When we upgraded to Postgres 16 in the tpp-dev environment, VLC was failing because PG 16 requires SSL connections by default.

This update fixes the problem in the docker container. In order to verify SSL connections are happening I enabled SSL for postgres 16 in the docker compose script and for extra certainty that the client is using SSL I updated the dev settings to specify the pg ssl mode.

THIS PR should be merged after #285 is merged.

Motivation and Context

https://ebce-lyrasis.atlassian.net/browse/PP-1775

How Has This Been Tested?

Manually tested using docker compose up. Without the update to the docker image I was getting the same error we were seeing in tpp-dev. With it I, I am able to connect.

Checklist

  • I have updated the documentation accordingly.
  • All new and existing tests passed.

@dbernstein dbernstein force-pushed the PP-1775-ensure-ssl-connections-to-postgres-work-when-ssl-required branch 2 times, most recently from d39ee8c to 0f19917 Compare October 23, 2024 18:38
Copy link

codecov bot commented Oct 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.15%. Comparing base (1b1c78c) to head (95125f3).
Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #286   +/-   ##
=======================================
  Coverage   88.15%   88.15%           
=======================================
  Files          37       37           
  Lines        2271     2271           
  Branches      304      304           
=======================================
  Hits         2002     2002           
  Misses        215      215           
  Partials       54       54           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dbernstein dbernstein force-pushed the PP-1775-ensure-ssl-connections-to-postgres-work-when-ssl-required branch 2 times, most recently from d025abf to d69aeea Compare October 23, 2024 19:43
@dbernstein dbernstein force-pushed the PP-1775-ensure-ssl-connections-to-postgres-work-when-ssl-required branch from 492ff49 to de5e2f4 Compare October 23, 2024 22:45
…uired.

Additional updates:
   * upgrades image to python 3.12
   * upgrades postgres to 16 (to match latest RDS deployment)
@dbernstein dbernstein force-pushed the PP-1775-ensure-ssl-connections-to-postgres-work-when-ssl-required branch from de5e2f4 to c19bb60 Compare October 23, 2024 22:53
Copy link
Member

@jonathangreen jonathangreen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made a few comments that would be good to clean up before merging.

There is also a reference to postgres:12 in the README that should get updated to postgres:16

### 2. Create PostgreSQL Container (Only for testing)
Either create a new database in the production PostgreSQL Database. Or use the docker PostgreSQL container for testing.
docker run -d --name pg --rm -e POSTGRES_USER=vlc -e POSTGRES_PASSWORD=test -e POSTGRES_DB=virtual_library_card postgres:12

Dockerfile Outdated
@@ -1,4 +1,4 @@
FROM python:3.10-slim
FROM python:3.12-slim
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change updates the Python version in the container to Python 3.12. Probably don't want to make this change until we update CI to test against Python 3.12 as well. Maybe leave this at Python 3.10 for now, since all our other containers are using 3.10 at the moment.

Dockerfile Outdated
# required for postgres ssl: the crt file doesn't exist
# but the path must point to a visible directory otherwise we
# get a permissions error
ENV PGSSLCERT /tmp/postgresql.crt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should update this to the new env var format to fix the deprecation warning.

Suggested change
ENV PGSSLCERT /tmp/postgresql.crt
ENV PGSSLCERT=/tmp/postgresql.crt

Comment on lines +30 to +33
command: >
-c ssl=on
-c ssl_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
-c ssl_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be helpful to our future selves to add a comment here about why these lines are required. I'm thinking something like:

AWS RDS requires SSL, so we enable SSL for the database with a self signed snakeoil cert, so this database mimics the production databases as closely as we can.

tox.ini Outdated
environment =
POSTGRES_USER=vlc
POSTGRES_PASSWORD=test
POSTGRES_DB=test_virtual_library_card_dev

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Unnecessary space added

tox.ini Outdated
@@ -14,6 +14,8 @@ docker =
docker: minio-vlc
setenv =
COVERAGE_FILE = .coverage.{envname}
PG_SSL_MODE = allow

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Unnecessary space added

@@ -22,6 +22,7 @@
"PASSWORD": "test",
"HOST": os.environ.get("VLC_DEV_DB_HOST", "pg"),
"PORT": os.environ.get("VLC_DEV_DB_PORT", "5432"),
"OPTIONS": {"sslmode": os.environ.get("PG_SSL_MODE", "require")},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should follow the same naming scheme we already have for these environment variables. Based on the name, I assumed it was a PG environment variable and I was looking in the PG docs to try to figure out what it did, until I found it defined here.

I'd suggest something like VLC_DEV_DB_SSL_MODE.

@dbernstein
Copy link
Contributor Author

Thank you for the thorough review :)

@dbernstein dbernstein merged commit f5b625d into main Oct 24, 2024
8 checks passed
@dbernstein dbernstein deleted the PP-1775-ensure-ssl-connections-to-postgres-work-when-ssl-required branch October 24, 2024 17:37
@dbernstein dbernstein added the bug Something isn't working label Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants