Skip to content

feat(spec): add HostCommand and Refresh to CredentialSource#41

Draft
zampani-docker wants to merge 1 commit into
mainfrom
zampani/host-command-credential-source
Draft

feat(spec): add HostCommand and Refresh to CredentialSource#41
zampani-docker wants to merge 1 commit into
mainfrom
zampani/host-command-credential-source

Conversation

@zampani-docker
Copy link
Copy Markdown

Summary

Extends spec.CredentialSource with two new optional fields that enable credential helpers — shell commands that run on the host to obtain credential values:

  • hostCommand — a POSIX sh -c command whose trimmed stdout becomes the credential value. Executed at sandbox creation time (CLI), on-demand by the daemon proxy, and periodically on the refresh cadence while sbx run is attached.

  • refresh — a positive Go duration string (e.g. "15m", "1h") controlling how often the sandbox runtime re-runs the command and syncs the fresh token while the sandbox is attached. Requires hostCommand to be set.

Motivation

Some credentials live in platform-specific locations (Docker Desktop backend socket, vault read, aws sts get-session-token, gcloud auth print-access-token) and cannot be captured via env vars or static files. hostCommand provides a first-class credential helper interface for these cases.

Validation changes

ValidateCredentialPolicy is updated to:

  • Accept hostCommand alone as a valid source (env, file, or hostCommand — at least one required)
  • Reject blank/whitespace-only hostCommand
  • Reject refresh without hostCommand
  • Reject non-positive or unparseable refresh durations

The error message for empty sources changes from "must have at least one of env or file" to "must have at least one of env, file, or hostCommand".

Example spec.yaml usage

credentials:
  sources:
    my-service:
      hostCommand: |
        vault read -field=token secret/my-service
      refresh: 15m

Context

This unblocks a companion PR in the sandboxes engine that adds the full hostCommand credential source implementation. The strict YAML decoder (KnownFields(true)) in spec/artifact.go rejects any spec.yaml containing hostCommand: or refresh: until these fields are present — so merging here is a prerequisite for kit authors to use the feature.

Test plan

  • go test ./spec/... — existing tests pass, 7 new subtests added for hostCommand/refresh validation

Comment drafted by Claude Code.

Extends spec.CredentialSource with two new optional fields:

- HostCommand: a POSIX sh -c command run on the host whose trimmed
  stdout becomes the credential value. Useful for credential helpers
  (vault, aws sts, gcloud auth print-access-token) that don't write
  to env vars or files.

- Refresh: a positive Go duration string (e.g. "15m", "1h") that
  controls how often the sandbox runtime re-runs the command and
  syncs the fresh token while `sbx run` is attached. Requires
  HostCommand to be set.

ValidateCredentialPolicy is updated to:
- Accept HostCommand alone as a valid source (at least one of
  env, file, or hostCommand is now required per source)
- Reject blank/whitespace-only HostCommand
- Reject Refresh without HostCommand
- Reject non-positive or unparseable Refresh durations

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Michael Zampani <michael.zampani@docker.com>
@zampani-docker zampani-docker force-pushed the zampani/host-command-credential-source branch from f75c586 to 3b8ea87 Compare May 20, 2026 00:12
@zampani-docker zampani-docker marked this pull request as ready for review May 20, 2026 15:59
@zampani-docker zampani-docker requested a review from a team as a code owner May 20, 2026 15:59
@zampani-docker zampani-docker marked this pull request as draft May 22, 2026 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant