Skip to content

Customization of pg_hba.conf #144

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

Open
vladimirfx opened this issue Jan 28, 2025 · 4 comments
Open

Customization of pg_hba.conf #144

vladimirfx opened this issue Jan 28, 2025 · 4 comments

Comments

@vladimirfx
Copy link

In one of test scenarios we need to connect to database from container running in Docker in Docker Daemon. So host on which embedded db is running accessible by its local network IP (something like 10.20.30.40). How I can customize pg_hba.conf to allow such LAN connections?

@tomix26
Copy link
Collaborator

tomix26 commented Jan 30, 2025

Hi @vladimirfx, thanks for your question.

Could you please describe your use case in more detail? From what you're writing, it seems you have two applications - one where you create an embedded database, and another from which you connect to this database? Why not create the embedded database directly in the application where you need it rather than accessing it remotely?

Regarding the customization of the pg_hba.conf file, this is currently not officially supported. As a workaround, you could start the embedded database, then pause it, modify the configuration on the filesystem, and start it again. While not very practical, it might be feasible. The code below shows how to create a repeatedly startable database with a fixed location.

EmbeddedPostgres.Builder builder = EmbeddedPostgres.builder();
builder.setDataDirectory(...); // location for database data
builder.setCleanDataDirectory(false);
EmbeddedPostgres database = builder.start();

Another option could be to implement this functionality in the library. The simplest approach would probably be to support some kind of script callback that would be called after initdb but before starting the database, which would allow any changes to any configuration file. What do you think?

@vladimirfx
Copy link
Author

Use case:
Testing Graalvm native app that build as container image. In such scenarios test runs on JVM but tested app run in separate process in container runtime. I cant embed database in production native app. Tests is pure blackbox.

Why not use container based db?
Because tests are layered: unit (JVM, without db), module (JVM, with db), integration (native, with db). So it would be perfect to use one solution to run db for any kind of tests.

Impl:
It would be ideal to pass lambda (with db dir param) to EmbeddedPostgres.Builder that runs between init and start.

@vladimirfx
Copy link
Author

Do I understand correctly that in the Spring Boot environment, I can define a bean of type Consumer<EmbeddedPostgres.Builder> to fine-tune the database?

Relevant part of io.zonky.test:embedded-database-spring-test lib:

public ZonkyPostgresDatabaseProvider(Environment environment, ObjectProvider<List<Consumer<EmbeddedPostgres.Builder>>> databaseCustomizers)

@tomix26
Copy link
Collaborator

tomix26 commented Feb 6, 2025

Thanks for the description of the situation.

Do I understand correctly that in the Spring Boot environment, I can define a bean of type Consumer<EmbeddedPostgres.Builder> to fine-tune the database?

Yes, that's correct. It's documented here: https://github.com/zonkyio/embedded-database-spring-test?tab=readme-ov-file#zonky-provider-specific-configuration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants