Skip to content

safekeys/secret-injection [built] ​

Injection is how a resolved secret reaches a consumer without passing through model context. The MVP supports four methods — environment variable, 0600 temp file, Unix socket/pipe, and exec wrapper — chosen by what the consuming process needs. The agent receives only a success code, a placeholder name, or a path it cannot usefully read.

Status: built

Why this exists ​

A resolved secret is useless unless the process that needs it can actually get it. Most such processes are CLIs and services that expect an env var or a file path, not an in-process API — and returning the value to the agent would defeat the design. Injection bridges that gap while keeping the value on the non-LLM side of the boundary.

Design decisions ​

four-methods-not-one [accepted] ​

Decision: Support env, 0600 temp file, socket/pipe, and exec rather than a single injection mode.

Rationale: Consumers differ — some read env, some need a file path, some are long-running services. Forcing one mode would push integrators to work around the tool and handle plaintext themselves, which is the failure mode being designed out.

exec-wrapper-preferred [accepted] ​

Decision: Make the exec wrapper the preferred and best-documented path.

Rationale: It gives the strongest guarantee — the value exists only in the child's environment for the life of the command — and keeps the caller's return surface to an exit code.

placeholder-over-value [accepted] ​

Decision: Return a placeholder name or path instead of a value whenever a return is needed.

Rationale: It preserves the ergonomics of "here is something to use" without giving the agent anything sensitive.

mvp-scope-socket-pipe-deferred [accepted] ​

Decision: Ship env, file, and exec injection in the MVP; defer the long-running socket/pipe method.

Rationale: The three shipped methods cover every CLI and service consumer the two-agent demo exercises. The socket/pipe method exists for long-running local services, which is not an MVP shape, and the injector explicitly refuses the method rather than silently falling back to another — so a caller cannot be misled about which channel was used.

Consequences: inject: socket injection is not implemented in the MVP. The method enum is closed and the injector errors on it.

Date: 2026-09-22

How it works ​

Inject as an environment variable (inject-env) ​

For a child process that already reads env — CLIs and SDKs.

  1. Receive — Sidecar receives a resolve request scoped to inject-env for a named variable.
  2. Setup — Resolve and decrypt the object.
  3. Send — Spawn the consumer with the value in its environment; do not inherit it in the agent's env.
  4. Observe — Return a success code only.

Inject as a 0600 temp file (inject-file) ​

For tools that require a file — kubeconfig, certificates.

  1. Receive — Sidecar receives a resolve request scoped to inject-file.
  2. Setup — Write the value to a temporary file owned by the consumer with mode 0600.
  3. Send — Return the path to the consumer.
  4. Delete — Remove the file when the consumer exits.

Inject over a Unix socket or pipe (inject-socket) ​

For long-running local services.

  1. Receive — Sidecar receives a resolve request scoped for a socket or pipe consumer.
  2. Send — Deliver the value over the established local channel.
  3. Delete — Zeroise after delivery.

Inject via the exec wrapper (inject-exec) ​

Run a command with secrets injected and the environment scrubbed.

  1. Receive — Sidecar receives safekeys exec --token ... -- <command>.
  2. Resolve — Resolve all tokens required by the command.
  3. Setup — Spawn the command as a child of the sidecar with a minimal environment and injected values.
  4. Observe — Return the command's exit code; values never reach the caller.

Guarantees ​

prefer-exec-and-env ​

Exec-wrapper and env injection are preferred over returning values to a caller.

Acceptance criteria:

  • [ ] Documentation steers integrators to exec-wrapper and inject-env first
  • [ ] Returning resolved values on an agent's stdout is not a supported mode
  • [ ] A placeholder name or path is returned in place of a value

value-scoped-to-consumer ​

An injected value is visible only to the intended consuming process.

Acceptance criteria:

  • [ ] Temp files are mode 0600 and owned by the consumer
  • [ ] Env injection targets the child process, not the agent's own environment
  • [ ] The agent's process cannot read the injected value back

injection-is-cleaned-up ​

Transient injection artefacts do not outlive the consumer.

Acceptance criteria:

  • [ ] Temp files are removed when the consumer exits
  • [ ] Plaintext buffers are zeroised after delivery
  • [ ] No injection artefact is left in a world-readable location

Test specifications ​

env-injection-not-visible-to-agent ​

Given:

  • injection_method: "inject-env"
  • consumer: "printenv MY_TOKEN"

When: inject-env

Then:

  • assertion: the child process sees the value
  • assertion: the agent's own environment does not contain the value
  • assertion: the sidecar response contains no value

Contracts verified: value-scoped-to-consumer, prefer-exec-and-env

temp-file-permissions ​

Given:

  • injection_method: "inject-file"

When: inject-file

Then:

  • assertion: the temp file is mode 0600
  • assertion: the file is owned by the consumer, not the agent
  • assertion: the file is removed after the consumer exits

Contracts verified: value-scoped-to-consumer, injection-is-cleaned-up

exec-returns-only-exit-code ​

Given:

  • command: "sh -c 'test -n "$API_KEY"'"

When: inject-exec

Then:

  • assertion: the caller receives an exit code, not the value
  • assertion: the command's stdout is not augmented with the secret

Contracts verified: prefer-exec-and-env

Implementation ​

  • Primary: pkg/inject/inject.go
  • Test code: pkg/inject/inject_test.go
  • Test code status: manual

See Also ​

  • safekeys/sidecar-resolution
  • safekeys/exec-wrapper