Allow running command containers as non-root user with EBS backed (and other) workspace volumes#453
Merged
patrobinson merged 6 commits intomainfrom Dec 18, 2024
Merged
Conversation
Most storage providers (i.e. aws-ebs-csi) create the volume with 755 permissions, which means our checkout and command container can't write to the /workspace directory So we must give that user permission explicitly
patrobinson
commented
Dec 13, 2024
| chown -R %d /workspace`, | ||
| podUser, | ||
| podUser, | ||
| ) |
Contributor
Author
There was a problem hiding this comment.
This could be refactored, it's pretty similar to the createCheckoutContainer code
But gathering early feedback first.
DrJosh9000
reviewed
Dec 16, 2024
Contributor
DrJosh9000
left a comment
There was a problem hiding this comment.
This seems like a good solution.
Contributor
Author
|
@DrJosh9000 thanks, I've marked this as ready for review |
DrJosh9000
approved these changes
Dec 17, 2024
Contributor
DrJosh9000
left a comment
There was a problem hiding this comment.
LGTM with one name change. I also have some minor cleanup suggestions but these also apply to the existing createCheckoutContainer, so feel free to split off into a followup.
Co-authored-by: Josh Deprez <jd@buildkite.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When using a storage provisioner, such as aws-ebs-csi, the default permission mask for the volume mount is 755 and there's no way to change it.
That means when you specify a workspace from one of these provisioners you get a volume owned by root, which is not-writable by non-root users:
config.yaml snipped
configMap pre-checkout hook:
This means using a command container that has the
USERset to something other than root isn't possible.Firstly our agent can't start, because it needs access to write a job-api socket file. You get:
This can be worked around by mounting an in-memory container to the
/workspace/socketsdirectory with the following config snipped:But the command container still has no ability to write to /workspace directory, which is a common use case.
We already handle this issue within the checkout container by ensuring all files are created as the same user as the SecurityContext provided https://github.com/buildkite/agent-stack-k8s/blob/main/internal/controller/scheduler/scheduler.go#L837-L838
But since the volume as mounted as 755, the checkout container has no permission to write to the directory.
I tried to patch this by telling the checkout container to change ownership of the directory to the relevant user before it changes users,
But it causes the agent to fail to start with:
So I landed on this solution, copying the existing implementation that checkout uses to ensure it runs as root then chown the directory in the init container.
Result:
