Strip Dockhand control/selector env vars from compose injection - #85
Open
wintech147 wants to merge 1 commit into
Open
Strip Dockhand control/selector env vars from compose injection#85wintech147 wants to merge 1 commit into
wintech147 wants to merge 1 commit into
Conversation
Dockhand resolves secrets server-side and merges them into the deploy request's envVars map, which the agent injects into the docker compose child process. Dockhand strips its bulk-pull control variables only on the successful resolution path; in provider-misconfiguration cases the selector is left in envVars and dispatched to the agent, where it would be injected into the container. Add controlEnvKeys (DOCKHAND_SECRET_SELECTOR, OP_ENVIRONMENT_ID) and strip them before injection so they never reach the compose process or a container. Extract the injection loop into a testable buildComposeEnv helper and add the first unit tests for the package. Behavior for valid, invalid, and dangerous keys is unchanged. Also fix Dockerfile.dev to use ln -sf for the compose cli-plugin symlink, matching the production Dockerfile; the current Wolfi docker-compose package already ships the symlink and ln -s fails the build.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Hardens the agent's handling of resolved secrets for
hawser-edgedeployments andadds the first unit tests for the compose env-injection path.
Dockhand resolves secrets server-side and sends them merged into the deploy
request's
envVarsmap. The agent injects those into thedocker composechildprocess environment. This change ensures Dockhand's bulk-pull control variables
(
DOCKHAND_SECRET_SELECTOR,OP_ENVIRONMENT_ID) are never injected into the composeprocess or a container, even when the server leaves them in the request.
Motivation
Dockhand strips the selector variable from outgoing vars only on the successful
bulk-resolution path (
resolveProviderEnvVarsinsrc/lib/server/stacks.ts). Inthree misconfiguration cases (no provider bound, unregistered provider type, or a
provider without bulk support), the server logs a warning and leaves the selector
variable in
envVars, which is then dispatched to the agent. Without agent-sidehandling, that selector would be injected into the deployed container.
The selector names match Dockhand's
BULK_SELECTOR_VARS(
['DOCKHAND_SECRET_SELECTOR', 'OP_ENVIRONMENT_ID']).Changes
internal/docker/compose.gocontrolEnvKeysdenylist for Dockhand control/selector variables.Executeinto a testablebuildComposeEnvhelper that validates key names, strips control/selector variables, drops
dangerous keys, and returns the entries to append to
cmd.Env.Executenow calls the helper. Behavior for valid, invalid, and dangerous keysis unchanged.
internal/docker/compose_test.go(new)dangerous-key blocking, invalid-key rejection, and preservation of values that
contain
=.Dockerfile.devln -sffor the compose cli-plugin symlink. The current Wolfidocker-composepackage already ships the symlink, soln -sfails the buildwith "File exists". This matches the existing fix in the production
Dockerfile.Behavior
only. They are not written to disk and their values are not logged.
DOCKHAND_SECRET_SELECTORandOP_ENVIRONMENT_IDare stripped before injection,unconditionally and case-insensitively, at debug log level.
deniedEnvKeysdenylist are preserved.Testing
go vet ./...,go build ./..., andgo test ./...all pass (run in agolang:1.26container).TestBuildComposeEnv_*cases cover the injection and stripping logic.linux/arm64image fromDockerfile.devand confirmed the binary runs anddocker composeresolves inside the image.container receives the resolved value, no selector variables reach the container,
and the canary appears in no
.env, no stack file, and no agent log.Risk and compatibility
ComposeOperationis unchanged.not intended to reach containers. If a stack legitimately needed a variable named
DOCKHAND_SECRET_SELECTORorOP_ENVIRONMENT_IDin its container (not a supporteduse), it would no longer receive it.
Checklist
go vet,go build,go testpass