fix(security): bind container ports to localhost and remove credentials from debug logs
- commit
- c454effadfab354a5379b46cc3ee8529fb3d7e20
- author
- bnema · · 2026-02-01 14:32 UTC
- parent
- e27d337
- signature
- unsigned
1 file · +6 -3
M internal/adapters/out/docker/runtime.go +6 -3
| @@ -69,10 +69,13 @@ func (r *Runtime) CreateContainer(ctx context.Context, config *domain.ContainerC | |||
| 69 | 69 | containerPort := nat.Port(fmt.Sprintf("%d/tcp", port)) | |
| 70 | 70 | exposedPorts[containerPort] = struct{}{} | |
| 71 | 71 | ||
| 72 | - | // Bind to random available port on host | |
| 72 | + | // Bind to random available port on localhost only. | |
| 73 | + | // SECURITY: Using 127.0.0.1 prevents direct access from the network, | |
| 74 | + | // forcing all traffic through Gordon's reverse proxy where auth, | |
| 75 | + | // rate limiting, and security headers are applied. | |
| 73 | 76 | portBindings[containerPort] = []nat.PortBinding{ | |
| 74 | 77 | { | |
| 75 | - | HostIP: "0.0.0.0", | |
| 78 | + | HostIP: "127.0.0.1", | |
| 76 | 79 | HostPort: "0", // Docker will assign a random available port | |
| 77 | 80 | }, | |
| 78 | 81 | } | |
| @@ -407,7 +410,7 @@ func (r *Runtime) PullImageWithAuth(ctx context.Context, imageRef, username, pas | |||
| 407 | 410 | ||
| 408 | 411 | log.Debug(). | |
| 409 | 412 | Str("server_address", serverAddress). | |
| 410 | - | Str("auth_json", string(authConfigBytes)). | |
| 413 | + | Bool("has_auth", len(authConfigBytes) > 0). | |
| 411 | 414 | Msg("auth config for pull") | |
| 412 | 415 | ||
| 413 | 416 | // Pull with authentication | |
| @@ -69,10 +69,13 @@ func (r *Runtime) CreateContainer(ctx context.Context, config *domain.ContainerC | |||||
| 69 | containerPort := nat.Port(fmt.Sprintf("%d/tcp", port)) | 69 | containerPort := nat.Port(fmt.Sprintf("%d/tcp", port)) | ||
| 70 | exposedPorts[containerPort] = struct{}{} | 70 | exposedPorts[containerPort] = struct{}{} | ||
| 71 | 71 | ||||
| 72 | - | // Bind to random available port on host | 72 | + | // Bind to random available port on localhost only. |
| 73 | + | // SECURITY: Using 127.0.0.1 prevents direct access from the network, | |||
| 74 | + | // forcing all traffic through Gordon's reverse proxy where auth, | |||
| 75 | + | // rate limiting, and security headers are applied. | |||
| 73 | portBindings[containerPort] = []nat.PortBinding{ | 76 | portBindings[containerPort] = []nat.PortBinding{ | ||
| 74 | { | 77 | { | ||
| 75 | - | HostIP: "0.0.0.0", | 78 | + | HostIP: "127.0.0.1", |
| 76 | HostPort: "0", // Docker will assign a random available port | 79 | HostPort: "0", // Docker will assign a random available port | ||
| 77 | }, | 80 | }, | ||
| 78 | } | 81 | } | ||
| @@ -407,7 +410,7 @@ func (r *Runtime) PullImageWithAuth(ctx context.Context, imageRef, username, pas | |||||
| 407 | 410 | ||||
| 408 | log.Debug(). | 411 | log.Debug(). | ||
| 409 | Str("server_address", serverAddress). | 412 | Str("server_address", serverAddress). | ||
| 410 | - | Str("auth_json", string(authConfigBytes)). | 413 | + | Bool("has_auth", len(authConfigBytes) > 0). |
| 411 | Msg("auth config for pull") | 414 | Msg("auth config for pull") | ||
| 412 | 415 | ||||
| 413 | // Pull with authentication | 416 | // Pull with authentication | ||