-
Notifications
You must be signed in to change notification settings - Fork 79
refactor(standalone): add asRoot parameter to execInContainer #513
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
Conversation
Require callers to explicitly opt-in to root privileges when executing commands in containers. This avoids running all execs as root, which could violate security expectations for containers that define a non-root default user. Signed-off-by: Dorin Geman <[email protected]>
Summary of ChangesHello @doringeman, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a significant security enhancement by modifying the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request introduces a beneficial security enhancement by refactoring execInContainer to require an explicit asRoot parameter, preventing commands from running with root privileges by default. The implementation of this change is sound. However, I've identified two instances where this new parameter is used incorrectly in copyDockerConfigToContainer. The commands being executed require root privileges because they use chown, but they are called with asRoot: false. This will lead to errors in containers with a non-root default user. My review provides specific suggestions to correct these calls.
| // Ensure the .docker directory exists | ||
| mkdirCmd := "mkdir -p /home/modelrunner/.docker && chown modelrunner:modelrunner /home/modelrunner/.docker" | ||
| if err := execInContainer(ctx, dockerClient, containerID, mkdirCmd); err != nil { | ||
| if err := execInContainer(ctx, dockerClient, containerID, mkdirCmd, false); err != nil { |
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.
The mkdirCmd includes a chown command, which requires root privileges to execute. With asRoot set to false, this command will fail if the container's default user is not root. To ensure the directory ownership can be set as intended, this command should be executed with root privileges.
| if err := execInContainer(ctx, dockerClient, containerID, mkdirCmd, false); err != nil { | |
| if err := execInContainer(ctx, dockerClient, containerID, mkdirCmd, true); err != nil { |
| // Set correct ownership and permissions | ||
| chmodCmd := "chown modelrunner:modelrunner /home/modelrunner/.docker/config.json && chmod 600 /home/modelrunner/.docker/config.json" | ||
| if err := execInContainer(ctx, dockerClient, containerID, chmodCmd); err != nil { | ||
| if err := execInContainer(ctx, dockerClient, containerID, chmodCmd, false); err != nil { |
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.
Similar to the command for creating the directory, this chmodCmd also includes chown, which requires root privileges. Setting asRoot to false will cause this command to fail if the container is not running as root. To ensure the file's ownership and permissions are correctly set, this should be run as root.
| if err := execInContainer(ctx, dockerClient, containerID, chmodCmd, false); err != nil { | |
| if err := execInContainer(ctx, dockerClient, containerID, chmodCmd, true); err != nil { |
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.
Hey there - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `cmd/cli/pkg/standalone/containers.go:71-74` </location>
<code_context>
// Ensure the .docker directory exists
mkdirCmd := "mkdir -p /home/modelrunner/.docker && chown modelrunner:modelrunner /home/modelrunner/.docker"
- if err := execInContainer(ctx, dockerClient, containerID, mkdirCmd); err != nil {
+ if err := execInContainer(ctx, dockerClient, containerID, mkdirCmd, false); err != nil {
return err
}
</code_context>
<issue_to_address>
**issue (bug_risk):** Running chown/chmod without root is likely to fail and silently change behavior compared to the previous implementation.
Before this change, `execInContainer` always ran as root, so these `chown`/`chmod` calls would normally succeed. With `asRoot` now set to `false`, they run as the container’s default user, and `chown` (and sometimes `chmod` on root-owned paths) will often fail without error handling for permission issues. Please either run these commands with `asRoot = true` or rework the ownership/permission handling so it doesn’t depend on root, to avoid a behavioral regression that only shows up on some environments.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| if err := execInContainer(ctx, dockerClient, containerID, mkdirCmd, false); err != nil { | ||
| return err | ||
| } | ||
|
|
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.
issue (bug_risk): Running chown/chmod without root is likely to fail and silently change behavior compared to the previous implementation.
Before this change, execInContainer always ran as root, so these chown/chmod calls would normally succeed. With asRoot now set to false, they run as the container’s default user, and chown (and sometimes chmod on root-owned paths) will often fail without error handling for permission issues. Please either run these commands with asRoot = true or rework the ownership/permission handling so it doesn’t depend on root, to avoid a behavioral regression that only shows up on some environments.
ilopezluna
left a comment
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.
thanks!
Require callers to explicitly opt-in to root privileges when executing commands in containers. This avoids running all execs as root, which could violate security expectations for containers that define a non-root default user.
Based on #511 (comment).