Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c79729e

Browse filesBrowse files
fix: redact env var values in agent debug manifest endpoint (#26904) (#27011)
1 parent 21c4092 commit c79729e
Copy full SHA for c79729e

2 files changed

+55-1Lines changed: 55 additions & 1 deletion

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎agent/agent.go‎

Copy file name to clipboardExpand all lines: agent/agent.go
+23-1Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2291,12 +2291,34 @@ func (a *agent) HandleHTTPDebugManifest(w http.ResponseWriter, r *http.Request)
22912291
return
22922292
}
22932293

2294+
// Redact env values. This endpoint is unauthenticated on loopback,
2295+
// reachable by any process regardless of Unix user. Keys are preserved
2296+
// so operators can still see which variables are configured.
2297+
debugManifest := *sdkManifest
2298+
if len(sdkManifest.EnvironmentVariables) > 0 {
2299+
envs := make(map[string]string, len(sdkManifest.EnvironmentVariables))
2300+
for k, v := range sdkManifest.EnvironmentVariables {
2301+
// Preserve empty values, which carry no secret, matching
2302+
// sanitizeEnv in support/support.go.
2303+
if v == "" {
2304+
envs[k] = v
2305+
continue
2306+
}
2307+
envs[k] = redactedManifestEnvValue
2308+
}
2309+
debugManifest.EnvironmentVariables = envs
2310+
}
2311+
22942312
w.WriteHeader(http.StatusOK)
2295-
if err := json.NewEncoder(w).Encode(sdkManifest); err != nil {
2313+
if err := json.NewEncoder(w).Encode(debugManifest); err != nil {
22962314
a.logger.Error(a.hardCtx, "write debug manifest", slog.Error(err))
22972315
}
22982316
}
22992317

2318+
// redactedManifestEnvValue matches the marker used by sanitizeEnv in
2319+
// support/support.go so a support bundle and this endpoint agree.
2320+
const redactedManifestEnvValue = "***REDACTED***"
2321+
23002322
func (a *agent) HTTPDebug() http.Handler {
23012323
r := chi.NewRouter()
23022324

Collapse file

‎agent/agent_test.go‎

Copy file name to clipboardExpand all lines: agent/agent_test.go
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3672,6 +3672,10 @@ func TestAgent_DebugServer(t *testing.T) {
36723672
//nolint:dogsled
36733673
conn, _, _, _, agnt := setupAgentWithSecrets(t, agentsdk.Manifest{
36743674
DERPMap: derpMap,
3675+
EnvironmentVariables: map[string]string{
3676+
"AWS_SECRET_ACCESS_KEY": "env-value-should-be-redacted-67890",
3677+
"EMPTY_VAR": "",
3678+
},
36753679
}, []agentsdk.WorkspaceSecret{
36763680
{EnvName: "DEBUG_SECRET", Value: []byte("super-secret-value-12345")},
36773681
}, 0, func(c *agenttest.Client, o *agent.Options) {
@@ -3800,6 +3804,34 @@ func TestAgent_DebugServer(t *testing.T) {
38003804
require.NoError(t, json.Unmarshal(body, &v))
38013805
})
38023806

3807+
t.Run("ManifestEnvVarValuesRedacted", func(t *testing.T) {
3808+
t.Parallel()
3809+
3810+
ctx := testutil.Context(t, testutil.WaitLong)
3811+
req, err := http.NewRequestWithContext(ctx, http.MethodGet, srv.URL+"/debug/manifest", nil)
3812+
require.NoError(t, err)
3813+
3814+
res, err := srv.Client().Do(req)
3815+
require.NoError(t, err)
3816+
defer res.Body.Close()
3817+
require.Equal(t, http.StatusOK, res.StatusCode)
3818+
3819+
body, err := io.ReadAll(res.Body)
3820+
require.NoError(t, err)
3821+
3822+
require.NotContains(t, string(body), "env-value-should-be-redacted-67890")
3823+
3824+
var v agentsdk.Manifest
3825+
require.NoError(t, json.Unmarshal(body, &v))
3826+
3827+
require.Contains(t, v.EnvironmentVariables, "AWS_SECRET_ACCESS_KEY")
3828+
require.Equal(t, "***REDACTED***", v.EnvironmentVariables["AWS_SECRET_ACCESS_KEY"])
3829+
3830+
// Empty values carry no secret and are preserved as empty.
3831+
require.Contains(t, v.EnvironmentVariables, "EMPTY_VAR")
3832+
require.Equal(t, "", v.EnvironmentVariables["EMPTY_VAR"])
3833+
})
3834+
38033835
t.Run("Logs", func(t *testing.T) {
38043836
t.Parallel()
38053837

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.