-
Notifications
You must be signed in to change notification settings - Fork 39
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
Allow running command containers as non-root user with EBS backed (and other) workspace volumes #453
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
chown -R %d /workspace`, | ||
podUser, | ||
podUser, | ||
) |
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.
This could be refactored, it's pretty similar to the createCheckoutContainer code
But gathering early feedback first.
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.
This seems like a good solution.
@DrJosh9000 thanks, I've marked this as ready for review |
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 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>
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
USER
set 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/sockets
directory 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: