Skip to content

Commit 8c97e43

Browse files
committed
feat(cli): add --proxy-cert flag for proxy SSL inspection support
Signed-off-by: Dorin Geman <[email protected]>
1 parent 5796242 commit 8c97e43

File tree

6 files changed

+54
-5
lines changed

6 files changed

+54
-5
lines changed

cmd/cli/commands/install-runner.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func ensureStandaloneRunnerAvailable(ctx context.Context, printer standalone.Sta
138138
port = standalone.DefaultControllerPortCloud
139139
environment = "cloud"
140140
}
141-
if err := standalone.CreateControllerContainer(ctx, dockerClient, port, host, environment, false, gpu, "", modelStorageVolume, printer, engineKind, debug, false); err != nil {
141+
if err := standalone.CreateControllerContainer(ctx, dockerClient, port, host, environment, false, gpu, "", modelStorageVolume, printer, engineKind, debug, false, ""); err != nil {
142142
return nil, fmt.Errorf("unable to initialize standalone model runner container: %w", err)
143143
}
144144

@@ -172,6 +172,7 @@ type runnerOptions struct {
172172
doNotTrack bool
173173
pullImage bool
174174
pruneContainers bool
175+
proxyCert string
175176
}
176177

177178
// runInstallOrStart is shared logic for install-runner and start-runner commands
@@ -285,7 +286,7 @@ func runInstallOrStart(cmd *cobra.Command, opts runnerOptions, debug bool) error
285286
return fmt.Errorf("unable to initialize standalone model storage: %w", err)
286287
}
287288
// Create the model runner container.
288-
if err := standalone.CreateControllerContainer(cmd.Context(), dockerClient, port, opts.host, environment, opts.doNotTrack, gpu, opts.backend, modelStorageVolume, asPrinter(cmd), engineKind, debug, vllmOnWSL); err != nil {
289+
if err := standalone.CreateControllerContainer(cmd.Context(), dockerClient, port, opts.host, environment, opts.doNotTrack, gpu, opts.backend, modelStorageVolume, asPrinter(cmd), engineKind, debug, vllmOnWSL, opts.proxyCert); err != nil {
289290
return fmt.Errorf("unable to initialize standalone model runner container: %w", err)
290291
}
291292

@@ -300,6 +301,7 @@ func newInstallRunner() *cobra.Command {
300301
var backend string
301302
var doNotTrack bool
302303
var debug bool
304+
var proxyCert string
303305
c := &cobra.Command{
304306
Use: "install-runner",
305307
Short: "Install Docker Model Runner (Docker Engine only)",
@@ -312,6 +314,7 @@ func newInstallRunner() *cobra.Command {
312314
doNotTrack: doNotTrack,
313315
pullImage: true,
314316
pruneContainers: false,
317+
proxyCert: proxyCert,
315318
}, debug)
316319
},
317320
ValidArgsFunction: completion.NoComplete,
@@ -323,6 +326,7 @@ func newInstallRunner() *cobra.Command {
323326
Backend: &backend,
324327
DoNotTrack: &doNotTrack,
325328
Debug: &debug,
329+
ProxyCert: &proxyCert,
326330
})
327331
return c
328332
}

cmd/cli/commands/reinstall-runner.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ func newReinstallRunner() *cobra.Command {
1212
var backend string
1313
var doNotTrack bool
1414
var debug bool
15+
var proxyCert string
1516
c := &cobra.Command{
1617
Use: "reinstall-runner",
1718
Short: "Reinstall Docker Model Runner (Docker Engine only)",
@@ -24,6 +25,7 @@ func newReinstallRunner() *cobra.Command {
2425
doNotTrack: doNotTrack,
2526
pullImage: true,
2627
pruneContainers: true,
28+
proxyCert: proxyCert,
2729
}, debug)
2830
},
2931
ValidArgsFunction: completion.NoComplete,
@@ -35,6 +37,7 @@ func newReinstallRunner() *cobra.Command {
3537
Backend: &backend,
3638
DoNotTrack: &doNotTrack,
3739
Debug: &debug,
40+
ProxyCert: &proxyCert,
3841
})
3942
return c
4043
}

cmd/cli/commands/restart-runner.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ func newRestartRunner() *cobra.Command {
1111
var gpuMode string
1212
var doNotTrack bool
1313
var debug bool
14+
var proxyCert string
1415
c := &cobra.Command{
1516
Use: "restart-runner",
1617
Short: "Restart Docker Model Runner (Docker Engine only)",
@@ -30,6 +31,7 @@ func newRestartRunner() *cobra.Command {
3031
gpuMode: gpuMode,
3132
doNotTrack: doNotTrack,
3233
pullImage: false,
34+
proxyCert: proxyCert,
3335
}, debug)
3436
},
3537
ValidArgsFunction: completion.NoComplete,
@@ -40,6 +42,7 @@ func newRestartRunner() *cobra.Command {
4042
GpuMode: &gpuMode,
4143
DoNotTrack: &doNotTrack,
4244
Debug: &debug,
45+
ProxyCert: &proxyCert,
4346
})
4447
return c
4548
}

cmd/cli/commands/start-runner.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ func newStartRunner() *cobra.Command {
1111
var backend string
1212
var doNotTrack bool
1313
var debug bool
14+
var proxyCert string
1415
c := &cobra.Command{
1516
Use: "start-runner",
1617
Short: "Start Docker Model Runner (Docker Engine only)",
@@ -21,6 +22,7 @@ func newStartRunner() *cobra.Command {
2122
backend: backend,
2223
doNotTrack: doNotTrack,
2324
pullImage: false,
25+
proxyCert: proxyCert,
2426
}, debug)
2527
},
2628
ValidArgsFunction: completion.NoComplete,
@@ -31,6 +33,7 @@ func newStartRunner() *cobra.Command {
3133
Backend: &backend,
3234
DoNotTrack: &doNotTrack,
3335
Debug: &debug,
36+
ProxyCert: &proxyCert,
3437
})
3538
return c
3639
}

cmd/cli/commands/utils.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,15 @@ func requireMinArgs(n int, cmdName string, usageArgs string) cobra.PositionalArg
182182
}
183183
}
184184

185-
// runnerOptions holds common runner configuration options
185+
// runnerFlagOptions holds common runner configuration options
186186
type runnerFlagOptions struct {
187187
Port *uint16
188188
Host *string
189189
GpuMode *string
190190
Backend *string
191191
DoNotTrack *bool
192192
Debug *bool
193+
ProxyCert *string
193194
}
194195

195196
// addRunnerFlags adds common runner flags to a command
@@ -213,4 +214,7 @@ func addRunnerFlags(cmd *cobra.Command, opts runnerFlagOptions) {
213214
if opts.Debug != nil {
214215
cmd.Flags().BoolVar(opts.Debug, "debug", false, "Enable debug logging")
215216
}
217+
if opts.ProxyCert != nil {
218+
cmd.Flags().StringVar(opts.ProxyCert, "proxy-cert", "", "Path to a CA certificate file for proxy SSL inspection")
219+
}
216220
}

cmd/cli/pkg/standalone/containers.go

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ func copyDockerConfigToContainer(ctx context.Context, dockerClient *client.Clien
9191

9292
func execInContainer(ctx context.Context, dockerClient *client.Client, containerID, cmd string) error {
9393
execConfig := container.ExecOptions{
94-
Cmd: []string{"sh", "-c", cmd},
94+
Cmd: []string{"sh", "-c", cmd},
95+
User: "root",
9596
}
9697
execResp, err := dockerClient.ContainerExecCreate(ctx, containerID, execConfig)
9798
if err != nil {
@@ -267,8 +268,12 @@ func tryGetBindAscendMounts(printer StatusPrinter, debug bool) []mount.Mount {
267268
return newMounts
268269
}
269270

271+
// proxyCertContainerPath is the path where the proxy certificate will be mounted in the container.
272+
// This location is used by update-ca-certificates to add the cert to the system trust store.
273+
const proxyCertContainerPath = "/usr/local/share/ca-certificates/proxy-ca.crt"
274+
270275
// CreateControllerContainer creates and starts a controller container.
271-
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 {
276+
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 {
272277
imageName := controllerImageName(gpu, backend)
273278

274279
// Set up the container configuration.
@@ -288,6 +293,7 @@ func CreateControllerContainer(ctx context.Context, dockerClient *client.Client,
288293
env = append(env, proxyVar+"="+value)
289294
}
290295
}
296+
291297
config := &container.Config{
292298
Image: imageName,
293299
Env: env,
@@ -316,6 +322,15 @@ func CreateControllerContainer(ctx context.Context, dockerClient *client.Client,
316322
hostConfig.Mounts = append(hostConfig.Mounts, ascendMounts...)
317323
}
318324

325+
if proxyCert != "" {
326+
hostConfig.Mounts = append(hostConfig.Mounts, mount.Mount{
327+
Type: mount.TypeBind,
328+
Source: proxyCert,
329+
Target: proxyCertContainerPath,
330+
ReadOnly: true,
331+
})
332+
}
333+
319334
portBindings := []nat.PortBinding{{HostIP: host, HostPort: portStr}}
320335
if os.Getenv("_MODEL_RUNNER_TREAT_DESKTOP_AS_MOBY") != "1" {
321336
// Don't bind the bridge gateway IP if we're treating Docker Desktop as Moby.
@@ -437,6 +452,23 @@ func CreateControllerContainer(ctx context.Context, dockerClient *client.Client,
437452
printer.Printf("Warning: failed to copy Docker config: %v\n", err)
438453
}
439454
}
455+
456+
// Add proxy certificate to the system CA bundle
457+
if created && proxyCert != "" {
458+
printer.Printf("Adding proxy certificate to CA bundle...\n")
459+
// Append the proxy cert to the system CA bundle
460+
appendCmd := "cat " + proxyCertContainerPath + " >> /etc/ssl/certs/ca-certificates.crt"
461+
if err := execInContainer(ctx, dockerClient, resp.ID, appendCmd); err != nil {
462+
printer.Printf("Warning: failed to add proxy certificate to CA bundle: %v\n", err)
463+
} else {
464+
// Restart the container so the model-runner process picks up the new CA bundle
465+
printer.Printf("Restarting container to apply CA certificate...\n")
466+
if err := dockerClient.ContainerRestart(ctx, resp.ID, container.StopOptions{}); err != nil {
467+
printer.Printf("Warning: failed to restart container after adding CA certificate: %v\n", err)
468+
}
469+
}
470+
}
471+
440472
return nil
441473
}
442474

0 commit comments

Comments
 (0)