-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -68,7 +68,7 @@ func copyDockerConfigToContainer(ctx context.Context, dockerClient *client.Clien | |||||
|
|
||||||
| // 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 | ||||||
| } | ||||||
|
|
||||||
|
Comment on lines
+71
to
74
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, |
||||||
|
|
@@ -82,17 +82,19 @@ func copyDockerConfigToContainer(ctx context.Context, dockerClient *client.Clien | |||||
|
|
||||||
| // 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 { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the command for creating the directory, this
Suggested change
|
||||||
| return err | ||||||
| } | ||||||
|
|
||||||
| return nil | ||||||
| } | ||||||
|
|
||||||
| func execInContainer(ctx context.Context, dockerClient *client.Client, containerID, cmd string) error { | ||||||
| func execInContainer(ctx context.Context, dockerClient *client.Client, containerID, cmd string, asRoot bool) error { | ||||||
| execConfig := container.ExecOptions{ | ||||||
| Cmd: []string{"sh", "-c", cmd}, | ||||||
| User: "root", | ||||||
| Cmd: []string{"sh", "-c", cmd}, | ||||||
| } | ||||||
| if asRoot { | ||||||
| execConfig.User = "root" | ||||||
| } | ||||||
| execResp, err := dockerClient.ContainerExecCreate(ctx, containerID, execConfig) | ||||||
| if err != nil { | ||||||
|
|
@@ -453,10 +455,10 @@ func CreateControllerContainer(ctx context.Context, dockerClient *client.Client, | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| // Add proxy certificate to the system CA bundle | ||||||
| // Add proxy certificate to the system CA bundle (requires root for update-ca-certificates) | ||||||
| if created && proxyCert != "" { | ||||||
| printer.Printf("Updating CA certificates...\n") | ||||||
| if err := execInContainer(ctx, dockerClient, resp.ID, "update-ca-certificates"); err != nil { | ||||||
| if err := execInContainer(ctx, dockerClient, resp.ID, "update-ca-certificates", true); err != nil { | ||||||
| printer.Printf("Warning: failed to update CA certificates: %v\n", err) | ||||||
| } else { | ||||||
| printer.Printf("Restarting container to apply CA certificate...\n") | ||||||
|
|
||||||
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
mkdirCmdincludes achowncommand, which requires root privileges to execute. WithasRootset tofalse, 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.