Skip to content

Commit 9ff0baf

Browse files
authored
fix(support): also sanitize agent environment (#12615)
1 parent 6f0ba5b commit 9ff0baf

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

support/support.go

+1
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ func AgentInfo(ctx context.Context, client *codersdk.Client, log slog.Logger, ag
298298
if err != nil {
299299
return xerrors.Errorf("fetch workspace agent: %w", err)
300300
}
301+
sanitizeEnv(agt.EnvironmentVariables)
301302
a.Agent = &agt
302303
return nil
303304
})

support/support_test.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ func TestRun(t *testing.T) {
7373
assertNotNilNotEmpty(t, bun.Workspace.TemplateFileBase64, "workspace template file should be present")
7474
require.NotNil(t, bun.Workspace.Parameters, "workspace parameters should be present")
7575
assertNotNilNotEmpty(t, bun.Agent.Agent, "agent should be present")
76+
assertSanitizedAgent(t, *bun.Agent.Agent)
7677
assertNotNilNotEmpty(t, bun.Agent.ListeningPorts, "agent listening ports should be present")
7778
assertNotNilNotEmpty(t, bun.Agent.Logs, "agent logs should be present")
7879
assertNotNilNotEmpty(t, bun.Agent.AgentMagicsockHTML, "agent magicsock should be present")
@@ -163,13 +164,18 @@ func assertSanitizedWorkspace(t *testing.T, ws codersdk.Workspace) {
163164
t.Helper()
164165
for _, res := range ws.LatestBuild.Resources {
165166
for _, agt := range res.Agents {
166-
for k, v := range agt.EnvironmentVariables {
167-
assert.Equal(t, "***REDACTED***", v, "environment variable %q not sanitized", k)
168-
}
167+
assertSanitizedAgent(t, agt)
169168
}
170169
}
171170
}
172171

172+
func assertSanitizedAgent(t *testing.T, agt codersdk.WorkspaceAgent) {
173+
t.Helper()
174+
for k, v := range agt.EnvironmentVariables {
175+
assert.Equal(t, "***REDACTED***", v, "agent %q environment variable %q not sanitized", agt.Name, k)
176+
}
177+
}
178+
173179
func setupWorkspaceAndAgent(ctx context.Context, t *testing.T, client *codersdk.Client, db database.Store, user codersdk.CreateFirstUserResponse) (codersdk.Workspace, codersdk.WorkspaceAgent) {
174180
// This is a valid zip file
175181
zipBytes := make([]byte, 22)

0 commit comments

Comments
 (0)