feat: runtime user secrets injection into workspaces (#24313)

Injects user secrets into workspace agents at runtime via the agent
manifest. Secrets with an environment variable name are set as
environment variables in every agent session and startup script. Secrets
with a file path are written to disk before startup scripts run.

- Fetch user secrets in GetManifest and convert to proto
- Defensively strip secrets from manifests received by the agent to
   avoid accidental leakage
- Add WorkspaceSecret type and proto conversion helpers to agentsdk
- Write secret files eagerly on manifest fetch (0600 perms, 0700 dirs)
- Inject secret env vars per-session in updateCommandEnv
- Expand ~/paths using caller-resolved home directory
- Log file write errors without blocking workspace startup
This commit is contained in:
Zach
2026-04-17 16:55:24 -06:00
committed by GitHub
parent 8e2343f59c
commit 72f35e1cd3
9 changed files with 685 additions and 4 deletions
+16
View File
@@ -40,6 +40,21 @@ func NewClient(t testing.TB,
manifest agentsdk.Manifest,
statsChan chan *agentproto.Stats,
coordinator tailnet.Coordinator,
) *Client {
return NewClientWithSecrets(t, logger, agentID, manifest, nil, statsChan, coordinator)
}
// NewClientWithSecrets is like NewClient but also injects user
// secrets into the agent's proto manifest. Separate from NewClient
// because agentsdk.Manifest intentionally does not carry secrets;
// see the Manifest doc comment in codersdk/agentsdk.
func NewClientWithSecrets(t testing.TB,
logger slog.Logger,
agentID uuid.UUID,
manifest agentsdk.Manifest,
secrets []agentsdk.WorkspaceSecret,
statsChan chan *agentproto.Stats,
coordinator tailnet.Coordinator,
) *Client {
if manifest.AgentID == uuid.Nil {
manifest.AgentID = agentID
@@ -58,6 +73,7 @@ func NewClient(t testing.TB,
require.NoError(t, err)
mp, err := agentsdk.ProtoFromManifest(manifest)
require.NoError(t, err)
mp.Secrets = agentsdk.ProtoFromSecrets(secrets)
fakeAAPI := NewFakeAgentAPI(t, logger, mp, statsChan)
err = agentproto.DRPCRegisterAgent(mux, fakeAAPI)
require.NoError(t, err)