Skip to content

Adds container.user configuration - #1109

Merged
chanseokoh merged 4 commits into
GoogleContainerTools:masterfrom
CyrilleH:user-container-config
Oct 10, 2018
Merged

chanseokoh merged 4 commits into
GoogleContainerTools:masterfrom
CyrilleH:user-container-config

Conversation

@CyrilleH

@CyrilleH CyrilleH commented Oct 5, 2018 •

Copy link
Copy Markdown
Contributor

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

coollog commented Oct 5, 2018

Copy link
Copy Markdown
Contributor

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

CyrilleH commented Oct 5, 2018

Copy link
Copy Markdown
Contributor Author

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

@coollog

coollog commented Oct 5, 2018

Copy link
Copy Markdown
Contributor

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

chanseokoh commented Oct 5, 2018 •

Copy link
Copy Markdown
Member

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
Copy Markdown
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

CyrilleH commented Oct 5, 2018

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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.

}

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

Copy link
Copy Markdown
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
Copy Markdown
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.

* LABEL [key1]="[value1]" \
* [key2]="[value2]" \
* [...]
* USER [user or UID]

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

ditto

Copy link
Copy Markdown
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

@coollog coollog left a comment

Copy link
Copy Markdown
Contributor

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.

}

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

Copy link
Copy Markdown
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
Copy Markdown
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

Copy link
Copy Markdown
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
Copy Markdown
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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

CyrilleH commented Oct 9, 2018

Copy link
Copy Markdown
Contributor Author

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

@coollog coollog left a comment

Copy link
Copy Markdown
Contributor

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