-
-
Notifications
You must be signed in to change notification settings - Fork 213
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
feat(docker): run service under node user #1014
Conversation
Pull Request Test Coverage Report for Build 917561288
💛 - Coveralls |
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.
LGTM for me. I also would like to know @chrisns thoughts on this
Could you try to also check it works with a controller attached (real use case)? |
docker/Dockerfile
Outdated
COPY --from=build-z2m /usr/src/app /usr/src/app | ||
|
||
WORKDIR /usr/src/app | ||
COPY --chown=node:node --from=build-z2m /usr/src/app /usr/src/app |
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.
why do we need to chown everything?
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.
Maybe we don't. I'll try it without.
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.
I feel like it may need some seccomp config to talk to the zwave interface be it usb/serial etc if it's not root too?
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.
As-is it doesn't work because config/store
needs to open up some .json
files as read/write, and all of the files have a 755 mask. Even with that path mounted as a volume doesn't work because the parent /usr/src/app/store
folder has the same mask.
So we'll either need to chmod
the files at container build time (testing this), or chown
them to node
. Any preference, @chrisns?
I'm still open to working out how to make the UID/GID for the node
user available to modification at runtime by environment vars, but that will require some additional things added to the container to run some scripts as root
at startup to modify the user.
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.
the issue is that we've not defined the VOLUMES more clearly which may have made this slightly less painful
a startup script to chmod kinda defeats the point since it'll need to run as root.
you could introduce a breaking change that checks and bails out early if it fails with some helpful feedback to fix the permissions or do user mapping, user mapping would be preferable anyway to avoid clashing with other things on the host machine
for the minute you could achieve all of what you're setting out to do with an update to the docs, kube+docker-compose config with what we recommend you run it with e.g.
export HOST_UID=123 # some random number that won't clash, or use UID 0 if you want to run just the container namespacing but still root host mapping (ugly)
docker run -u $HOST_UID:1000 -v $(pwd)/data:/data
or whatever
gonna move this PR to a draft if thats ok? until we've got a clear answer that works
I'll fire up this image on my home controller later today. |
This introduces a breaking change using this approach. If the previous The fix for this is the same as the fix for making the UID/GID for the I can either keep this PR open and update it later with that change (good for keeping context), or I can open a new one at that time. |
docker/Dockerfile
Outdated
COPY --from=build-z2m /usr/src/app /usr/src/app | ||
|
||
WORKDIR /usr/src/app | ||
COPY --chown=node:node --from=build-z2m /usr/src/app /usr/src/app |
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.
the issue is that we've not defined the VOLUMES more clearly which may have made this slightly less painful
a startup script to chmod kinda defeats the point since it'll need to run as root.
you could introduce a breaking change that checks and bails out early if it fails with some helpful feedback to fix the permissions or do user mapping, user mapping would be preferable anyway to avoid clashing with other things on the host machine
for the minute you could achieve all of what you're setting out to do with an update to the docs, kube+docker-compose config with what we recommend you run it with e.g.
export HOST_UID=123 # some random number that won't clash, or use UID 0 if you want to run just the container namespacing but still root host mapping (ugly)
docker run -u $HOST_UID:1000 -v $(pwd)/data:/data
or whatever
gonna move this PR to a draft if thats ok? until we've got a clear answer that works
Sounds good.
|
Is there a way to prevent this kind of breaking change? maybe a script that fix the permissions on files on store on startup? |
@robertsLando no. See my response |
If not I'm not 100% sure I want this, as it would break ALL the instances. We should find a workaround |
@robertsLando Yes, hence why I suggested (only) a change to docs unless we can think of a better way and moved this to draft :) |
Yes, I'm confident if I do this the "right way" instead of just changing the running user to |
@ChrisRomp Ok no problem :) |
news here? |
Working on a couple of angles. Been super swamped lately and changed jobs, but I wanted to try a couple of things to either make it work or put it away. I'll know something soon, or just close the PR if I decide I don't have time right now to do it right. The thing is I can do it, but I don't want to bloat the container image, so I'm looking for the lightest way of accomplishing the goal. Also, it's further complicated by the fact that the container currently runs as First I'm going to try and have it just run under UID 1000 which is the Would you want to see this as a separate Dockerfile, or just see this behavior integrated into the main Dockerfile? |
One other - way simpler - option to consider would be to just have the Dockerfile add Existing users would have to But to fix it without introducing a breaking change, I'm just looking for a lightweight init system that will run at container startup as |
Adding this for reference: https://github.com/nodejs/docker-node/blob/main/docs/BestPractices.md#non-root-user
|
Ok here's my lightest-weight approach:
I've added a FYI I'm running this in my home now as my main zwavejs2mqtt instance. It successfully remapped the ownership of the files under (looks like my linter killed a bunch of trailing spaces in |
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.
(requested change/review out of date)
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.
Looks ok to me, I would like to know @chrisns opinion too
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.
What you've done is an anti pattern and I'm not sure really what it's achieving. And worse if you run docker -u 1000 which is the right answer the entry point will fail.
I stand behind previous suggestion that the answer here really is additional documentation not code
Sorry
Let me start by saying I'm super appreciative of all the work that you all put into this project (and zwave-js), and I use this at home. My work here is trying to improve it and take some of that load off of your shoulders. But I've maxed out my spare bandwidth on this for now, so I'm unable to put more time in right now (hopefully I'll be able to again sometime in the near future), so I'm going to close out this PR. With so many platforms making it easier for slightly-more-than-average tech savvy users enabled to run Docker containers, I'm going to suggest that the anti-pattern was having the container run as The "right" fix is to add the |
Hey, I agree to a degree with a lot of your points around running as non-root by default is preferable, and a breaking change applied via semver may be possible and for the greater good. However my reservations with applying this to novice users is largely around Docker and the linux user/volume mapping that occurs and how it might actually cause more problems that would be harder for someone to fix. If the It's only the pesky state that makes this difficult. Alternative container runtimes such as podman do a much better job of isolation in this regard. |
I don't take blunt as bad, no worries. I really am just out of time and it's entirely your call how this operates. I was looking for a way to chip in a little while back and saw an open issue I felt I could take on. If time permits I'll be back trolling your issues list for more later on.
You could make the same argument for the files being owned by |
@ChrisRomp I'm not against this to land, I just want to be sure to don't introduce any breaking change for users. |
This pull-request is stale because it has been open 90 days with no activity. Remove the stale label or comment or this will be closed in 5 days. To ignore this pull-request entirely you can add the no-stale label |
This pull-request is now closed due to inactivity, you can of course reopen or reference this pull-request if you see fit. |
Fixes #783
Run under the existing node user, which as a UID/GID of 1000.