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

feat(postgres): ssl for postgres #2473

Merged
merged 48 commits into from
Jan 7, 2025

Conversation

bearrito
Copy link
Contributor

@bearrito bearrito commented Apr 8, 2024

What does this PR do?

Enables SSL for postgres

The main thing to recognize when reviewing this is that the secret material must be owned by the postgres user.
The docker file copy api doesn't allowfor setting a user when copying. The only way I could think was to take wrap the entrypoint script with one that does what we want.

Why is it important?

User ran into issue trying to use SSL. It's not obviously supported (able) due to file permissions.

Related issues

Link related issues below. Insert the issue link or reference after the word "Closes" if merging this should automatically close it.

How to test this PR

Unit tests will work when complete.

@bearrito bearrito requested a review from a team as a code owner April 8, 2024 18:45
Copy link

netlify bot commented Apr 8, 2024

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit 314d1cf
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-go/deploys/677d14234d05eb00087446e6
😎 Deploy Preview https://deploy-preview-2473--testcontainers-go.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@bearrito bearrito changed the title [DRAFT] feat:SSL for postgres feat:SSL for postgres Apr 8, 2024
Copy link
Member

@mdelapenya mdelapenya left a comment

Choose a reason for hiding this comment

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

We are in the right track with this one, although I left some comments that need to be addressed.

Besides that, we need to include the new option in the docs. Please check the docs/modules/postgres.md file for that. Remember adding this right after the option title:

- Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a>

Thanks!

modules/postgres/postgres_test.go Outdated Show resolved Hide resolved
modules/postgres/postgres.go Outdated Show resolved Hide resolved
modules/postgres/options.go Outdated Show resolved Hide resolved
@mdelapenya
Copy link
Member

@bearrito could you please take a look at #2478? I'm adding helper code to deal with TLS certificates in order to simplify the story for the client code. Wdyt?

@bearrito
Copy link
Contributor Author

bearrito commented Apr 10, 2024

@mdelapenya That makes a lot of sense. Much cleaner.

Do you want me to wait until that's done then base this on top of that?

@mdelapenya
Copy link
Member

@bearrito I went ahead and extracted the TLS cert generation to a separate go package, which makes more sense: https://github.com/mdelapenya/tlscert

Please take a look and use it as you need here!

@bearrito
Copy link
Contributor Author

@mdelapenya Updated to use your package.

Copy link
Member

@mdelapenya mdelapenya left a comment

Choose a reason for hiding this comment

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

Just one final concern regarding the entrypoint: do you think we need to pass it? Or is it something we can internally handle in the module, being transparent to the end users?

modules/postgres/go.mod Outdated Show resolved Hide resolved
modules/postgres/testdata/docker-entrypoint-ssl.bash Outdated Show resolved Hide resolved
@bearrito
Copy link
Contributor Author

@mdelapenya Update so that the entrypoint is coupled with the ssl settings. What about doing something similar for the conf file?

@bearrito
Copy link
Contributor Author

@mdelapenya added docs.

Copy link
Collaborator

@stevenh stevenh left a comment

Choose a reason for hiding this comment

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

Thanks for the changes, there's some outstanding bits needed to complete the switch to parameters, think I've caught them all in this pass.

modules/postgres/options.go Outdated Show resolved Hide resolved
modules/postgres/postgres_test.go Outdated Show resolved Hide resolved
modules/postgres/postgres_test.go Outdated Show resolved Hide resolved
modules/postgres/resources/customEntrypoint.sh Outdated Show resolved Hide resolved
modules/postgres/options.go Outdated Show resolved Hide resolved
@bearrito bearrito changed the title feat:SSL for postgres feat(postgres):SSL for postgres Dec 24, 2024
@bearrito bearrito changed the title feat(postgres):SSL for postgres feat(postgres): SSL for postgres Dec 24, 2024
@bearrito bearrito changed the title feat(postgres): SSL for postgres feat(postgres): ssl for postgres Dec 24, 2024
@bearrito
Copy link
Contributor Author

Addressed latest.

stevenh
stevenh previously approved these changes Dec 25, 2024
Copy link
Collaborator

@stevenh stevenh left a comment

Choose a reason for hiding this comment

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

Thanks for the fast turnaround on the changes, looks good to me, happy holidays!

@bearrito
Copy link
Contributor Author

@mdelapenya Is this good to go from your end?

@bearrito
Copy link
Contributor Author

bearrito commented Jan 5, 2025

@mdelapenya Is this good?

Copy link
Member

@mdelapenya mdelapenya left a comment

Choose a reason for hiding this comment

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

@mdelapenya Is this good?

@bearrito sorry, I was on XMas PTO, and finish it tomorrow 7th. I left some minor comments that need to be addressed before merging.

As a follow-up, not for this PR to make progress and see it into main asap, I'd allow different users than postgres when enabling SSL.

Other than that, once the comments are addressed, LGTM

docs/modules/postgres.md Outdated Show resolved Hide resolved
docs/modules/postgres.md Outdated Show resolved Hide resolved
modules/postgres/postgres_test.go Outdated Show resolved Hide resolved
modules/postgres/postgres_test.go Outdated Show resolved Hide resolved
modules/postgres/postgres_test.go Outdated Show resolved Hide resolved
modules/postgres/postgres_test.go Outdated Show resolved Hide resolved
@mdelapenya
Copy link
Member

@bearrito I went ahead and added a few commits with my suggestions to avoid causing you more trouble 🙏

Hopefully this build will pass and we can proceed with the merge.

Sorry about it taking too long 🙇

@mdelapenya mdelapenya self-assigned this Jan 7, 2025
@mdelapenya mdelapenya added the feature New functionality or new behaviors on the existing one label Jan 7, 2025
Copy link
Member

@mdelapenya mdelapenya left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for your patience and the long time it took for the review. My apologies

@mdelapenya mdelapenya merged commit 3330dc1 into testcontainers:main Jan 7, 2025
124 checks passed
mdelapenya added a commit to mdelapenya/testcontainers-go that referenced this pull request Jan 8, 2025
* main: (103 commits)
  feat(postgres): ssl for postgres (testcontainers#2473)
  feat(ollama): support calling the Ollama local process (testcontainers#2923)
  chore(deps): bump jinja2 from 3.1.4 to 3.1.5 (testcontainers#2935)
  chore(deps): bump sonarsource/sonarcloud-github-action (testcontainers#2933)
  feat(termination)!: make container termination timeout configurable (testcontainers#2926)
  chore(deps): bump slackapi/slack-github-action from 1.26.0 to 2.0.0 (testcontainers#2934)
  chore(deps): bump github/codeql-action from 3.25.15 to 3.28.0 (testcontainers#2932)
  feat(wait): log sub match callback (testcontainers#2929)
  fix: Handle nil value in CleanupNetwork (testcontainers#2928)
  fix: avoid double lock in DockerProvider.DaemonHost() (testcontainers#2900)
  feat!: build log writer for container request (testcontainers#2925)
  feat(gcloud)!: add support to seed data when using RunBigQueryContainer (testcontainers#2523)
  security(deps): bump golang.org/x/crypto from 0.28.0 to 0.31.0 (testcontainers#2916)
  chore(ci): add Github labels based on PR title (testcontainers#2914)
  chore(gha): Use official setup-docker-action (testcontainers#2913)
  chore(ci): enforce conventional commits syntax in PR titles (testcontainers#2911)
  feat(nats): WithConfigFile - pass a configuration file to nats server (testcontainers#2905)
  chore: enable implicit default logger only in testing with -v (testcontainers#2877)
  fix: container binds syntax (testcontainers#2899)
  refactor(cockroachdb): to use request driven options (testcontainers#2883)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality or new behaviors on the existing one
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: File permissions with custom PostgreSQL image
3 participants