Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: Allow running container as non-root UID/GID for ownership issues (docker) #433
feat: Allow running container as non-root UID/GID for ownership issues (docker) #433
Changes from 12 commits
38f2a48
4f3d238
cd766e1
c3a6529
78fdb40
f7871ca
1ac51f8
64ccfa1
9266a93
0b4d72a
281c53e
dc3f996
a019428
0988930
5ad0a7d
367f0a4
ed40055
6b3f6a9
12d8526
c5e4d01
070b8a2
ea6f65f
87541f4
ab15d72
527a521
8df4f20
44263d0
c16e2f4
4064ba1
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
$USERID
instead of${uid}:${gid}
fits better.…/index2"
<- the2
seems to be redundant). Converting path to a variable based on$wdir
could have helped to avoid this.USERID
var has non-existing UID/GID as value? What I mean is down the code you add UID/GID to the container system, so thatsu-exec
can use it, though you do the check before adding UID/GID to the system which seemingly is a failure point 🤔/bin/bash
string is use multiple times across the script, thus might be a good idea to convert it to a variable.ERROR:
(this is not essential, though could help to improve UX). Also it may be a good idea to redirect such messages to stderr (echo … >&2
) 🤔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.
Agreed, included with changes for 3 (
wdir
) and 5 (bash
path) below in 5ad0a7dI chose using braces for consistency, and generally try to follow the google shell style guide which prefers double quoting and braces for variable expansion. But I am certainly not married to this, so will submit a commit with them removed where not necessary
Agreed and thanks, (done with 1 and 5) 5ad0a7d
It shouldn't fail, as
su-exec
doesn't require an existing user or group to successfully execute. We could callsu-exec
out of the gate without doing the adduser, etc, but thesu-exec
session wouldn't have aHOME
, or be a real user. These checks don't need to be before creating the user/group in the container, but I figured it made sense to check before bothering to do that work (especially as populating the user'sHOME
will write some amount of data to the container).The reason I think it makes sense to create a "real" user is to allow pre-populating things like
terrascan
init information, giving a good location forpre-commit
cache, and if hook functionality ends up assuming it's the case.I'm definitely open that my thinking here is wrong, or moving the checks, just let me know!
Agreed (done with 1 and 3), 5ad0a7d
Agreed, added function
echo_error_and_exit
for error reporting with sending tostderr
with script abort 367f0a4There 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 committed ed40055 for the braces issue in 2 above
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.
-D
looks redundant as of-k
/etc/skel
(I guess it's Alpine's base location of skeleton dir) instead of from home dir of the user which whose permissionsadduser
is executed?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.
True, we could specify just -D if we use /etc/skel as skeleton
I used root's directory as skeleton as it already has
terrascan init
output in it from thebuilder
stage, which is copied to later stages. An earlier commit I had copied it into/etc/skel
, and then used that for theadduser
, but it seemed redundant to just turn around and copy it again during theentrypoint
script. Putting it into /etc/skel would allow future configurations to just the user's environment to be placed during the docker image build, so just let me know if you'd want to go that route?