Skip to content
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

Adds container.user configuration #1109

Merged

Conversation

CyrilleH
Copy link
Contributor

@CyrilleH CyrilleH commented Oct 5, 2018

Towards #1029, this PR adds the possibility to sets the username or UID which the process in the container should run as.

For security reason, we prefer to start a tomcat container with non-root user. We have a generic base image with this (in our private registry) :

RUN addgroup -S tomcat && adduser -S -G tomcat tomcat && chown -R tomcat:tomcat /usr/local

@coollog
Copy link
Contributor

coollog commented Oct 5, 2018

Thanks for the contribution! We'll take a look at this soon. For the future, we'd recommend commenting on the issue thread with the design/solution you will be implementing before starting work to help save time potentially changing large portions of the implementation.

@CyrilleH
Copy link
Contributor Author

CyrilleH commented Oct 5, 2018

Ok I understand. It was very easy to implement.
If you want I can close this PR.

@coollog
Copy link
Contributor

coollog commented Oct 5, 2018

We can definitely work with most of this :) It's mostly that we need to decide what we would support for the user configuration. Currently, as proposed in #1029 (comment), we are intending only to support user id and group id and not username, but we might decide to allow username as well. @GoogleContainerTools/java-tools

@chanseokoh
Copy link
Member

chanseokoh commented Oct 5, 2018

Yeah, looks like we can work on this. There are a few things to think about though.

And thinking about it for a while, it might be possible to accept any string as the parameter value, not just numbers, if what we end up doing is to just set the value in the container config metadata. In that case, we may always be able to build an image (need to check), which may error at runtime due to non-existing username. However, on the other hand, this may result in a Dockerfile that is not buildable.

@chanseokoh
Copy link
Member

However, on the other hand, this may result in a Dockerfile that is not buildable.

Never mind. I think it is always buildable. Now I think there is no problem supporting usernames and it is the user's responsibility to use the base image that has the right user database. Same for usual Docker build.

@CyrilleH
Copy link
Contributor Author

CyrilleH commented Oct 5, 2018

If we set the wrong username, we have this error at runtime :

docker: Error response from daemon: linux spec user: unable to find user tomcat2: no matching entries in passwd file.
ERRO[0000] error waiting for container: context canceled 

@chanseokoh
Copy link
Member

If we set the wrong username, we have this error at runtime

Yeah, it's the same story for Dockerfile, so perhaps we should say it's WAI. The big difference is, however, you can easily do adduser or addgroup with Dockerfile to make it work. But with Jib, it's a bit cumbersome in that you need to prepare a base image with the user or have /etc/passwd and /etc/group under /src/main/jib.

@@ -136,14 +137,25 @@ public Builder setEntrypoint(@Nullable List<String> entrypoint) {
return this;
}

/**
* Sets the username or UID which the process in the container should run as.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this can be a mix of user and group.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I changed the javadoc.

@@ -299,6 +311,7 @@ public void generate(Path targetDirectory) throws IOException {
* LABEL [key1]="[value1]" \
* [key2]="[value2]" \
* [...]
* USER [user or UID]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

/**
* Sets the username or UID which the process in the container should run as.
*
* @param user the username or UID
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

/**
* Sets the username or UID which the process in the container should run as.
*
* @param user the username or UID.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Javadoc modified.

@CyrilleH CyrilleH force-pushed the user-container-config branch 3 times, most recently from 3216c1a to dadc2f5 Compare October 8, 2018 19:53
Copy link
Contributor

@coollog coollog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Just some comment nits.

@@ -136,14 +137,26 @@ public Builder setEntrypoint(@Nullable List<String> entrypoint) {
return this;
}

/**
* Sets the user name (or UID) and optionally the user group (or GID) which the process in the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wording suggestion: Sets the user and group to run the container as. {@code user} can be a username or UID along with an optional groupname or GID. The following are all valid: {@code user}, {@code uid}, {@code user:group}, {@code uid:gid}, {@code uid:group}, {@code user:gid}.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -191,6 +192,18 @@ public JavaDockerContextGenerator setEntrypoint(List<String> entrypoint) {
return this;
}

/**
* Sets the user name (or UID) and optionally the user group (or GID) which the process in the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wording suggestion: Sets the user for the {@code USER} directive.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -89,6 +90,18 @@
return this;
}

/**
* Sets the user name (or UID) and optionally the user group (or GID) which the process in the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wording suggestion: Sets the user/group to run the container as.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

* Sets the user name (or UID) and optionally the user group (or GID) which the process in the
* container should run as.
*
* @param user the username and optionally the user group
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the username/UID and optionally the groupname/GID

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

* Sets the user name (or UID) and optionally the user group (or GID) which the process in the
* container should run as.
*
* @param user the username and optionally the user group
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the username/UID and optionally the groupname/GID

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@chanseokoh
Copy link
Member

Looks good to me. Updating some wordings, and I think we're good to go.

@CyrilleH CyrilleH force-pushed the user-container-config branch from dadc2f5 to 0082168 Compare October 9, 2018 21:32
@CyrilleH
Copy link
Contributor Author

CyrilleH commented Oct 9, 2018

Great. I've rebased on master and fixed wordings.

@chanseokoh chanseokoh requested a review from a team October 9, 2018 21:44
@chanseokoh chanseokoh removed the request for review from a team October 9, 2018 22:03
Copy link
Contributor

@coollog coollog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for your contribution again! I think this just fixes #1029. We should also add CHANGELOG entries for this new feature, but that can be done in a follow-up PR.

@chanseokoh chanseokoh merged commit a0bf210 into GoogleContainerTools:master Oct 10, 2018
@CyrilleH CyrilleH deleted the user-container-config branch October 10, 2018 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants