-
Notifications
You must be signed in to change notification settings - Fork 25
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
Unable to make it work in Kubernetes #21
Comments
Oh, now that's a weird error message. It's likely coming from when these lines run: docker-pgautoupgrade/docker-entrypoint.sh Lines 491 to 494 in 430eb92
Any idea why it would be unable to look up the effective uid in your environment? |
I think that is caused by the chart setting the security context similar to this. securityContext:
runAsUser: 1001 but the container does not have a user with uid 1001. when you do a Dockerfile like this FROM pgautoupgrade/pgautoupgrade:16-alpine
RUN adduser -u 1001 -G root -s /bin/sh -D pgautoupgrade and build it, it works fine You will then hit postgresql.conf not being present, bcs bitnami generates it on the startup into |
Any idea if there's something (preferably simple) we can change with our images to get it working? Hmmm, I wonder if changing the (note that I've just woken up and haven't had coffee yet, so that could be an obviously bad idea in 10 mins... 😉) |
Not sure yet, I gave up on it(due to the missing configs, and just went with a pg_dump) I wonder if you just add a user with uid 1001 if it will impact something else? from my testing so far(you don't have to do bitnami themselfs don't add the user, but instead just set |
Couldn't you just add a values.yaml for the chart with: securityContext:
runAsUser: 0 using helm I think the container entrypoint needs to run as root here, but I don't see much of a security concern running a small upgrade script as root in the cluster as one time only. Probably best to use I could update this wiki guide for a sample of using a Kubernetes initContainer at some point, if useful 😃 |
I also tried to get a initcontainer going to update bitnami postgresql charts automatically, and reached the same blocker with the missing postgresql.conf (there's an empty postgresql.auto.conf though) and pg_hba.conf Permissions issues are no big deal, worst case after running the migration with root it can chown the files again. Lacking the configs, however, is very annoying to workaround. Please share your ideas if you have any! Posting here my current non-working config for reference (see later comment)
|
I fixed the missing files problem by copying them as a postStart to the main container. It needs to run at least once before any migrations, but it's good enough. I am encountering another issue now where it cannot connect to the database after copying it to
|
@p4block We could look at adding Bitnami compatibility if doing so seems to be reasonably straight forward. For your install, where's the location of the missing files that you needed to copy? It is just the two files from Are there any soft links between files in that directory and the PostgreSQL data directory? As a data point, if you need to change the directory that PostgreSQL looks for its data files in, then the In the output you've pasted above, you have this as the final lines:
That |
@justinclift I worked around the problem by adding a hook to the bitnami container that copies them to the postgres data dir, but that's a hack imo I don't think they are truly needed, maybe an option to use some pgautoupgrade-shipped ones on the spot is enough.
As for the error log, sadly I can't see anything aside from a shutdown request.
This is the part that makes no sense to me, why would the script break here this way?
|
Ahhh. I think that error:
...lines up with the
It looks like they're supplying a Instead of copying over the one they provide, I'd probably try one with
If that turns out to work, is the Am thinking we could do something like this:
That would let us potentially automatically use the above |
Hmmm, thinking about that a bit more, we could just check if the That might only make sense for 'one shot' mode too, as we probably don't want to try running PG itself afterwards without the user supplied version of those files (which could potentially be very customised). |
The init container has a different filesystem than the main one, aside from the shared postgres folder. It would need to be told to ship default files. I saw a way to detect a high likelihood the postgres data folder being used in a bitnami container before.
When I changed auth to local (oops, didn't see before) I get a different error Coincidentally, the root user for this postgres instance is a "closed the cell and threw the keys to the river" situation. I've had the upgrade before using user accounts in docker, maybe it's something else entirely related to which user is being active at that moment in the script. I tried with the postgres docker image's pg_hba.conf with the same result, here for reference.
Now that I think of it, needing a database superuser account to perform the upgrade makes sense (although it's hella annoying for my usecase), and the postgres container makes the POSTGRES_USER account a superuser 🤔 So yeah, this part is PEBKAC. I am supplying a regular user to pgautoupgrade. I will find a way to reset the root password. I now wonder if the pgautoupgrade process even needs credentials at all, as it could just modify pghba to let itself in and do the upgrade. Thanks for your help, awesome project |
Yup. Got it to work. Using the stock postgres container I reset the password for the
This should work if you also manually put the permissive pg_hba.conf and bitnami's stock postgresql.conf in the postgres folder. Shipping some example postgresql.conf and pg_hba.conf, and maybe even ignoring existing auth patterns altogether and jamming the upgrade process (maybe optional) would be a nice feature I wouldn't complain about 😄 |
Nice work @p4block ! Looks like great info to make a wiki article from 😁 (although as you say, perhaps in the future pgautoupgrade could bypass auth / superuser requirement during the upgrade, making the process easier) |
Cool. Yeah, it sounds like with a bit of patience and testing stuff we should be able to automate this. Hopefully you're up for a bit of back-and-forth communication and experimentation @p4block? On that note, with the |
@p4block Oh, on a related topic does your database use any PG extensions? ie stuff loaded using We don't have the updating of those automated yet (there's the beginnings of a PR for it), so if you do you'll still need to manually check if they need updating. @spwoodcock Which reminds me, it's probably not a bad idea for us to have some kind of "things you should still do post-upgrade" wiki page, until the extension upgrading is automated too. Any interest in throwing something like that together? |
@justinclift rg is grep in rust, I just tried to look for signs of bitnami I can more or less go back and forth these days, I am very interested in getting this project more developed. I do have one postgres that uses extensions (the one for Immich) and it uses bitnami chart but with pgvecto-rs container. I haven't tackled it yet. |
Not to hijack this thread, but I guess in the interest of driving the development.
I've just attempted this with a Postgres database housing several databases including one for Looks like the process fails because the library in question wasn't available during the upgrade:
@justinclift I did have a look at that PR but I'm failing to see how that would specifically address this requirement, happy to give it a try tomorrow and report back my findings though. If you would like me to move this to a separate issue happy to do so. |
Hi @nightah The PR mentioned by @justinclift does not help in your specific. What this PR encapsules is that In your case, the |
so I've read through the rest of the thread and I've worked on adding better support for Bitnami containers in our image. What worked fine was adding a Things fell apart with file permissions and "one shot" mode. So Bitnami assigns the UID 1001 to its postgres user, while the PG image uses 999. As our container starts up as root, it is able to adjust the file permission to the UID 999 regardless of what was set before. The rest of the script is then executed as the postgres user and so the upgraded data directory is also assigned to the postgres user with UID 999 instead of 1001. So if we now want to support "one shot" mode for Bitnami containers, we would need a way to change back permissions, as the Bitnami container would complain otherwise when starting up again. Running My suggestion at this point is: We can add support to upgrade from a Bitnami container to our container, but I don't see a good way for adding "one shot" mode support because of the file permissions. Happy to add @p4block K8s configuration into the wiki since this seems to work. Opinions? Other findings? (@justinclift @spwoodcock) |
This is excellent information and research @andyundso ! While I agree using root is typically bad security practice, in this specific scenario would it not be an acceptable tradeoff? If the issue is ONESHOT mode, then the container is likely ran as an ephemeral initContainer, shutting down when complete. Running the upgrade initContainer for a short period if time as root is a pretty minimal attack surface, as it's not a long running application. Is this an acceptable tradeoff for more flexible support of different Postgres deployments? We could be sure to document the different approaches and the pros and cons of each 👍 |
I'm personally very time limited for the next week, so probably won't be able to read through the history of this to re-familiarise and get involved in that time. Already have a PG issue I need to figure out time for as-is. 😬 Not sure if it's relevant here, but if we add the capability to run user provided before/after hook scripts (ie I'm thinking "probably not" (for this issue) as the problem seems more user/permissions related than anything else. |
Should be possible. Let me check today or tomorrow if it has other implications. For example, I already noted that Postgres does not start when running as root, but I am sure there should be a work-around for that somehow. |
hello, would anyone in this thread (mainly looking at @p4block @xeruf @kaplan-michael @Maddin-M) be willing to test out a development build which should make upgrades on Bitnami DB's (both in-place and one-shot) work? The Docker tag for it is:
|
Hi @andyundso As I'm interested in a solution for the migrating a postgres database deployed using the bitnami chart (version 12.4.2), I just tested your development image (in-place mode). Here is the log:
I would be happy to offer my help if you need it. |
Hi @NeutrinoXY, did you run the container as |
Hi! Also currently testing this for a bitnami:14 container. Running pgautoupgrade as root as recommended, I am stuck, first with this:
and if I pass initdb args manually, then:
So I think these command lines need to be adjusted. I will continue trying to make progress, but if you have a fix and can push a new dev image, this would make testing simpler for me :) Also I lost time understanding that, as I just wanted to perform the upgrade in one-shot mode (not run PG afterwards, I prefer using bitnami:17 when migration is done), I needed to make sure Many thanks for this tool! |
I also think the call to |
Hi @dwyart, yeah this is correct, |
The user downgrade is done at line |
I could go further by doing manual changes, but now I feel stuck at
So all goes well until |
Note that the "superuser" it's talking about is the PostgreSQL superuser (ie the OS user who initialised the database directory), not the system superuser ( Generally the PostgreSQL superuser is |
With a few manual workarounds, I could finally complete the migration and have binami/postgresql:17 run on the new data. This is a 100% test DB, we plan to run this in prod later this year, so performing some exploration for now. Will continue testing (right now this testbed is quite messed up with all manual operations, so will retry from a clean DB in v14 and aim at a minimal procedure to migrate to v17) and report back in the coming days. |
You do not have to modify |
@dwyart Yeah, we added that |
So after an additional day of testing, things are much clearer now on my side 😌 Will try to not be too verbose, here are my main remarks/questions:
Thanks again for you help and hope the branch can be merged soon! Do not hesitate to ask further questions if some of my points are unclear. |
Hi @dwyart Thanks for the summary. I suppose you used different file permissions on your Postgres data directory, because in my tests, it did have to modify the user and group for the Postgres user and the upgrade still work. But actually it should not matter if the UID is 1000 or 1001, it is still not 999, which is the UID that is given by our container. I think we have to add another line here to apply the permissions that usually the Postgres container does on creation (here and here). would you mind to share the final K8s manifest that you used? I think it would be helpful for future users to see how they can invoke one shot mode in K8s.
... I mean, could be a feature, or would at least align how the upstream Postgres image behaves. @justinclift any opinion about that? I think personally it is somewhat questionable if anyone would want to start our container to just invoke a shell. maybe you want to peak around in Postgres data without actually starting Postgres to debug some issue? I don't know.
For your use case, it was actually not needed. Still I think it is a good fallback if somebody overwrites the entrypoint. could also be removed again. |
Indeed, on this test, the parent directory of
so this is why the Today I tested on another usecase where the parent directory has:
and this time, it worked out of the box (no additional command was needed contrary to my first case), the
was not sure with my first manifest as it has customizations and people could be tempted to copy/paste, but as today's test was simpler, I can share it:
(I just redacted two values that are not relevant here) Thanks for your answers! |
Awesome, sounds like we're potentially close to a solution then! 😄 |
@dwyart I need to bother you one last time. I pushed another version of the dev image where we reassign the permissions for the Postgres folder. Do you have another chance to test this (ideally again with your test environment where you needed to change the Postgres user). if not, I can check to do it on my own, but takes some time to prepare a setup. |
The new change has not impact in my case, the parent of the Postgres folder still has I don't think you should try to handle my case (or any other unusual scenario), there can be too much variation between combinations of files/folder permissions and the "standard" 999/1000/1001 users... |
Yeah, that's not something we can fix from inside a Docker container, but instead will have to be adjusted by some external process (ie script or whatever) before our Docker container is started. 😄 |
so I removed the last commit and adjusted the example in the README. maybe @justinclift can have one final look, and then I think we could merge it. |
Thought I could spare myself the frenzy of reproducing the configuration outside by temporarily replacing the bitnami postgresql image in my cluster by this one.
But getting this error:
postgres: could not look up effective user ID 1001: user does not exist
The text was updated successfully, but these errors were encountered: