fergusstrange / embedded-postgres

Run a real Postgres database locally on Linux, OSX or Windows as part of another Go application or test
MIT License
819 stars 85 forks source link

Add running binaries with specific attributes #61

Closed mbfr closed 2 years ago

mbfr commented 2 years ago

I have a simple use case where I just want to be able to run the spawned postgres binaries with some specific atttributes (specifically, in CI where I can't stop the CI container running as root, which postgres doesn't like). This adds an extra configuration option to allow specified a SysProcAttr setting for the commands which are spawned when the database is started/stopped/etc. This is only exposed on targets which actually support it (ie, not Windows).

I've included an example of how to use it to run the binaries as a specific user.

I'm not sure how to document this because it's not a setting that most people will ever want to use, it's only available on some platforms, and it's quite low level. Is it sensible to add another sub-section into the README explaining it rather than adding it to the existing table of configuration options?

mbfr commented 2 years ago

I've also added running in a specific directory, as this causes issues when the directory that the test runs in it not accessible by the user you're trying to switch to.

mbfr commented 2 years ago

I'm actually going to close this until I can come up with a better strategy. There are still issues with things like the run directory and the pwfile permissions, I think there needs to be some kind of more invasive "sandbox as user" functionality.