-
Notifications
You must be signed in to change notification settings - Fork 303
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
[FIX] 20-postgres-wait: avoid assuming you have permission to list database #621
Conversation
We never had this issue (using different users for different databases and list was always possible) however we have a patched version that detects when the password for the postgres user doesn't match (and the current loop would loop forever) and instead exits the container so we are able to detect it as an erroneous odoo container. (and we also call psql --list with Edit: the linked issue describes running Odoo without Create DB privileges, i'm not sure that is supported as we have run into issues when Odoo doesn't create the database itself (with the correct settings). How are you creating your databases? |
entrypoint.d/20-postgres-wait
Outdated
@@ -6,6 +6,12 @@ fi | |||
|
|||
log INFO Waiting until postgres is listening at $PGHOST... | |||
while true; do | |||
psql --list > /dev/null 2>&1 && break | |||
if [ -n "$PGDATABASE" ]; then | |||
echo "SELECT 1;" | psql "$PGDATABASE" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this breaks waiting for postgres container when $PGDATABASE is defined and the database would be created by Odoo but the database does not exist yet when entrypoint.d/20-postgres-wait is running.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error from postgres during tests:
psql: error: connection to server at "db" (172.16.2.194), port 5432 failed: FATAL: database "prod" does not exist
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, what about a simple or
between the two ? Would that fix this issue for you ?
For the case I described, this would allow to pass this script safely, and for your case also, while making sure we checked the access (HOST/PORT/USER/PASSWORD) to postgres...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes an or should work, as the (error) output is redirected to /dev/null no errors are shown by default anyways so having a try a the correct database first seems ok.
Edit: clarified that i was worried about errors showing up during startup.
Hmm, there might be some misunderstanding on various levels:
To put it simply, the image you provide introduce an additional unnecessary burden to integrators wishing to connect their odoo to an external postgres provider or any standard production-ready restricted access. It is done by assuming wrongly that odoo will always have createdb or listdb access. And that assumption is unnecessary if you just want to test if your database params are okay, and the postgres connection is up and available before running odoo. |
7392081
to
a1d4a5c
Compare
I updated the commit. Is that better ? Many thanks for your attention. I'll be happy to make more change if anything is amiss. |
Can you rebase, please? |
a1d4a5c
to
df7fbe1
Compare
Done ;-) |
What do you think @ap-wtioit ? Is it OK for you? |
@josep-tecnativa yes it looks like a good improvement to me. my initial feedback was based on the tests failing for the change and the code looks good now. |
When having to connect to external database access, you often only have access to a specific user/password on a single database, with no rights to access 'postgres' database, and thus no rights to list databases. (Using:
REVOKE ALL ON DATABASE postgres FROM PUBLIC;
, which is a common security practice). Notice that OVH for instance seems to do that on their mutualized postgres offersIf odoo itself has known issues into supporting this scenario, it is easily patchable (cf: odoo/odoo#12850 (comment) ).
If you can't list databases, you probably have the
$PGDATABASE
set, so I triggered the change on the existence of this variable. Although, I'm not sure how other people use this image, so I'd be happy to have your feedback on the pertinence of this patch in your perspective.Also, it should probably be a good idea to set
$DB_FILTER
to be empty (to override the default of the current image which is.*
, which by defaults, prevents odoo to actually usedb_name
option, cf: https://github.com/odoo/odoo/blob/master/odoo/service/db.py#L413-L418 ).With my patch, the tecnativa image won't stop forever asking for something it can't have in the aforementioned scenario.
Many thanks for your work on this image.