Skip to content

Wire all secret callers to scoped and user providers#4343

Draft
amirejaz wants to merge 3 commits intoscoped-secret-providersfrom
phase4-migration
Draft

Wire all secret callers to scoped and user providers#4343
amirejaz wants to merge 3 commits intoscoped-secret-providersfrom
phase4-migration

Conversation

@amirejaz
Copy link
Contributor

Summary

  • All secret provider call sites were previously using the bare CreateSecretProvider, giving every caller access to the full flat keyspace. This PR wires each caller to the appropriate wrapper introduced in Phase 1 (Add scoped and user secret providers with system key isolation #4229), so secrets are isolated by design rather than by convention.
  • System callers (workload auth tokens, registry OAuth credentials, build auth files) now use CreateScopedSecretProvider, writing and reading under the __thv_<scope>_ prefix. These keys are invisible to user-facing secret commands.
  • User-facing callers (thv secret commands, REST API, MCP tool server, header secrets, build-env-from-secrets) now use CreateUserSecretProvider, which blocks access to any __thv_* reserved key.
  • RunConfig.WithSecrets and ValidateSecrets now take separate systemProvider and userProvider arguments so auth-token resolution and --secret flag resolution use the correct scope independently.

This is Phase 3 of the scoped secret store (part of #4192), tracking issue #4227. It must be released together with Phase 4 (#4244 — migration infrastructure).

Release note: Both this PR and the migration PR (#4244) must be merged before releasing. Neither is a breaking change on its own when no release occurs between the two merges.

Type of change

  • New feature (non-breaking change which adds functionality)

Test plan

  • go build ./... — clean build
  • go test ./pkg/runner/... ./pkg/auth/secrets/... ./pkg/workloads/... ./pkg/mcp/server/... — all pass
  • golangci-lint run — 0 issues

Special notes for reviewers

The WithSecrets signature change (one provider → two providers) is the most structurally significant change. The split is:

  • systemProvider — used for RemoteAuthConfig.ClientSecret, RemoteAuthConfig.BearerToken (both written by the workload auth subsystem under ScopeWorkloads)
  • userProvider — used for c.Secrets (--secret flags) and HeaderForward.AddHeadersFromSecret (both user-specified key names)

config_buildauthfile.go gets its own getScopedWorkloadsSecretsManager() helper rather than reusing the user-facing getSecretsManager(), since build auth files are system-owned (stored by thv config buildauthfile set, not by thv secret set).

Generated with Claude Code

amirejaz and others added 3 commits March 19, 2026 16:00
…elpers

Expose convenience constructors that wrap the base secret provider in either
a UserProvider (blocks system-reserved __thv_ keys for user-facing callers)
or a ScopedProvider (namespaces all operations under a given scope for
internal callers such as the registry or workloads subsystems).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Update every call site that creates a secrets provider to use the
appropriate wrapper introduced in Phase 1:

- System callers (workload auth tokens, registry credentials, build auth
  files) now use CreateScopedSecretProvider, placing secrets under the
  __thv_<scope>_ prefix and hiding them from user-facing commands.
- User-facing callers (thv secret commands, REST API, MCP tool server,
  header secrets, build-env-from-secrets) now use CreateUserSecretProvider,
  blocking access to __thv_* reserved keys.
- RunConfig.WithSecrets and ValidateSecrets now accept separate system and
  user providers so auth-token resolution and --secret flag resolution use
  the correct scope independently.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Existing users may have registry tokens and workload auth secrets stored
under bare keys (BEARER_TOKEN_, OAUTH_CLIENT_SECRET_, REGISTRY_OAUTH_,
etc.) that pre-date the scoped provider wrappers. This migration renames
them into the __thv_<scope>_ namespace on first startup so they are
accessible via the new scoped providers and hidden from user-facing secret
commands.

Key design properties:
- Write-before-delete ordering: the new key is written before the old is
  deleted, so a crash mid-migration leaves the secret reachable.
- Idempotent: a missing old key is silently skipped, making retries safe.
- One-shot: guarded by the SecretScopeMigration config flag; once set,
  the migration is a cheap config read and returns immediately.
- Discovery-based: DiscoverMigrations lists all secrets and matches known
  system prefixes, so no static registry of workload names is required.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions github-actions bot added the size/M Medium PR: 300-599 lines changed label Mar 24, 2026
@codecov
Copy link

codecov bot commented Mar 24, 2026

Codecov Report

❌ Patch coverage is 47.36842% with 50 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.31%. Comparing base (e52d21b) to head (bfbee20).

Files with missing lines Patch % Lines
pkg/migration/secret_scope.go 0.00% 32 Missing ⚠️
pkg/runner/runner.go 0.00% 6 Missing ⚠️
pkg/runner/config.go 66.66% 2 Missing and 1 partial ⚠️
pkg/runner/protocol.go 0.00% 2 Missing ⚠️
pkg/workloads/manager.go 0.00% 2 Missing ⚠️
pkg/api/v1/secrets.go 0.00% 1 Missing ⚠️
pkg/auth/secrets/secrets.go 0.00% 1 Missing ⚠️
pkg/mcp/server/list_secrets.go 0.00% 1 Missing ⚠️
pkg/mcp/server/set_secret.go 0.00% 1 Missing ⚠️
pkg/runner/env.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@                     Coverage Diff                     @@
##           scoped-secret-providers    #4343      +/-   ##
===========================================================
+ Coverage                    68.82%   69.31%   +0.48%     
===========================================================
  Files                          469      471       +2     
  Lines                        47189    47201      +12     
===========================================================
+ Hits                         32480    32717     +237     
+ Misses                       12007    11973      -34     
+ Partials                      2702     2511     -191     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@amirejaz amirejaz marked this pull request as draft March 24, 2026 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Medium PR: 300-599 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant