Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions cmd/cli/pkg/standalone/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

high

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.

Suggested change
if err := execInContainer(ctx, dockerClient, containerID, mkdirCmd, false); err != nil {
if err := execInContainer(ctx, dockerClient, containerID, mkdirCmd, true); err != nil {

return err
}

Comment on lines +71 to 74
Copy link
Contributor

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.

Expand All @@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

high

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.

Suggested change
if err := execInContainer(ctx, dockerClient, containerID, chmodCmd, false); err != nil {
if err := execInContainer(ctx, dockerClient, containerID, chmodCmd, true); err != nil {

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 {
Expand Down Expand Up @@ -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")
Expand Down
Loading