-
-
Notifications
You must be signed in to change notification settings - Fork 677
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
non-root users for Dockerfiles #300
Conversation
I tested this locally by altering docker-compose.yml to point to each edited Dockerfile. I was able to successfully build and start each corresponding built container to serve localhost:5006 |
Syncing works as of the latest commit Expand details below for some details related to confirming functionalityEdit: This was not be due to this PR, but a mis-configured security context in my kubernetes clusterhmmm got an error while syncing
|
I recommend bumping major version as the non-root user wouldn't have access to read/write files owned by root. This can be fixed by 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.
@hkiang01 the app code should remain root, so the runtime user can't manipulate the code. Runtime users should just be able to influence the config and data dir.
This is a good point, but I think that's a bit of a blocker for us for now. We also have to consider users already running on pikapods and fly.io @hkiang01 I think as an iteration, adding the user, but not setting it as the run user for entry. Chowning the data directory contents on entry to the new user, and then running the app as the new user will set us up to switchover in a major release. |
549a4fe
to
1de859e
Compare
Requested changes made. I expect a retry of the build jobs will succeed. Please retry the jobs and re-review |
failing builds are due to #287 which is out of scope of this PR |
confirmed non-breaking change with manual steps:
|
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.
@hkiang01 this looks like a good first step, and I think we can move forward with this change after a few minor tweaks for users who want to set the user to 1001 when running from their very first run. (Like in your helm chart). But the swap from root to app user does not currently work without manual chowning of the data. (database files will be readonly by the appuser)
A followup (doesn't have to block this PR). Would be to move our current RUN command to a startup script, then earlier in that script check if the running uid is 0, if so, chown all data (at runtime this time) to our non-root user, and then exec our tini command as that user. Else we just exec the tini command like normal.
Bitnami has some examples of using chroot to change the user at runtime if running as root by just chrooting to /
again but with userspace. https://github.com/bitnami/containers/blob/8a67664e7a937c6aa603a9b0477561b9af7abb0e/bitnami/postgresql/16/debian-11/prebuildfs/opt/bitnami/scripts/libos.sh#L653
This would allow us to get everyone running as non-root, and in a later major change we could just drop the extra work for the USER line in the dockerfile.
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.
Thanks @hkiang01
This is a good first step towards moving the container to always run non-root.
* Optional non-root users for Dockerfiles
category: Maintenance
authors: hkiang01
Non-root users for Dockerfiles
As a regular Node application, the default user doesn't need to be root. For why this is important, see Why non-root containers are important for security