-
Notifications
You must be signed in to change notification settings - Fork 72
feat(cli): add --proxy-cert flag for proxy SSL inspection support #511
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -91,7 +91,8 @@ func copyDockerConfigToContainer(ctx context.Context, dockerClient *client.Clien | |
|
|
||
| func execInContainer(ctx context.Context, dockerClient *client.Client, containerID, cmd string) error { | ||
| execConfig := container.ExecOptions{ | ||
| Cmd: []string{"sh", "-c", cmd}, | ||
| Cmd: []string{"sh", "-c", cmd}, | ||
| User: "root", | ||
| } | ||
| execResp, err := dockerClient.ContainerExecCreate(ctx, containerID, execConfig) | ||
| if err != nil { | ||
|
|
@@ -267,8 +268,12 @@ func tryGetBindAscendMounts(printer StatusPrinter, debug bool) []mount.Mount { | |
| return newMounts | ||
| } | ||
|
|
||
| // proxyCertContainerPath is the path where the proxy certificate will be mounted in the container. | ||
| // This location is used by update-ca-certificates to add the cert to the system trust store. | ||
| const proxyCertContainerPath = "/usr/local/share/ca-certificates/proxy-ca.crt" | ||
|
|
||
| // CreateControllerContainer creates and starts a controller container. | ||
| func CreateControllerContainer(ctx context.Context, dockerClient *client.Client, port uint16, host string, environment string, doNotTrack bool, gpu gpupkg.GPUSupport, backend string, modelStorageVolume string, printer StatusPrinter, engineKind types.ModelRunnerEngineKind, debug bool, vllmOnWSL bool) error { | ||
| func CreateControllerContainer(ctx context.Context, dockerClient *client.Client, port uint16, host string, environment string, doNotTrack bool, gpu gpupkg.GPUSupport, backend string, modelStorageVolume string, printer StatusPrinter, engineKind types.ModelRunnerEngineKind, debug bool, vllmOnWSL bool, proxyCert string) error { | ||
| imageName := controllerImageName(gpu, backend) | ||
|
|
||
| // Set up the container configuration. | ||
|
|
@@ -288,6 +293,7 @@ func CreateControllerContainer(ctx context.Context, dockerClient *client.Client, | |
| env = append(env, proxyVar+"="+value) | ||
| } | ||
| } | ||
|
|
||
| config := &container.Config{ | ||
| Image: imageName, | ||
| Env: env, | ||
|
|
@@ -316,6 +322,15 @@ func CreateControllerContainer(ctx context.Context, dockerClient *client.Client, | |
| hostConfig.Mounts = append(hostConfig.Mounts, ascendMounts...) | ||
| } | ||
|
|
||
| if proxyCert != "" { | ||
| hostConfig.Mounts = append(hostConfig.Mounts, mount.Mount{ | ||
| Type: mount.TypeBind, | ||
| Source: proxyCert, | ||
| Target: proxyCertContainerPath, | ||
| ReadOnly: true, | ||
| }) | ||
|
Comment on lines
+325
to
+331
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. suggestion (bug_risk): Binding the proxy cert path without validation may produce a non-obvious Docker error if the file is missing or invalid. If Suggested implementation: import (
"os" if proxyCert != "" {
info, err := os.Stat(proxyCert)
if err != nil {
// Fail fast with a clear, targeted error instead of a generic Docker bind error
return nil, nil, fmt.Errorf("proxy certificate path %q is not accessible: %w", proxyCert, err)
}
if !info.Mode().IsRegular() {
return nil, nil, fmt.Errorf("proxy certificate path %q is not a regular file", proxyCert)
}
hostConfig.Mounts = append(hostConfig.Mounts, mount.Mount{
Type: mount.TypeBind,
Source: proxyCert,
Target: proxyCertContainerPath,
ReadOnly: true,
})
}Because I cannot see the full function, you will need to:
|
||
| } | ||
|
|
||
| portBindings := []nat.PortBinding{{HostIP: host, HostPort: portStr}} | ||
| if os.Getenv("_MODEL_RUNNER_TREAT_DESKTOP_AS_MOBY") != "1" { | ||
| // Don't bind the bridge gateway IP if we're treating Docker Desktop as Moby. | ||
|
|
@@ -437,6 +452,20 @@ func CreateControllerContainer(ctx context.Context, dockerClient *client.Client, | |
| printer.Printf("Warning: failed to copy Docker config: %v\n", err) | ||
| } | ||
| } | ||
|
|
||
| // Add proxy certificate to the system CA bundle | ||
| if created && proxyCert != "" { | ||
| printer.Printf("Updating CA certificates...\n") | ||
| if err := execInContainer(ctx, dockerClient, resp.ID, "update-ca-certificates"); err != nil { | ||
| printer.Printf("Warning: failed to update CA certificates: %v\n", err) | ||
| } else { | ||
| printer.Printf("Restarting container to apply CA certificate...\n") | ||
| if err := dockerClient.ContainerRestart(ctx, resp.ID, container.StopOptions{}); err != nil { | ||
| printer.Printf("Warning: failed to restart container after adding CA certificate: %v\n", err) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return 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.
🚨 issue (security): Running all execs as root may be unnecessarily privileged and surprising for containers that define a non-root default user.
This change alters behavior for images that deliberately run as non-root and may violate security expectations by always elevating to root. Please consider limiting root usage to the specific privileged operations that need it (e.g., via an
asRootflag or a separate helper), and keep default execs running as the container’s configured user.