Skip to content

fix(support): sanitize agent env #12554

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
redact all the things
  • Loading branch information
johnstcn committed Mar 12, 2024
commit da0fb1e360472bbf88137cbbf45008b800cb575e
7 changes: 3 additions & 4 deletions support/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,9 @@ func Run(ctx context.Context, d *Deps) (*Bundle, error) {
// sanitizeEnv modifies kvs in place and erases the values of keys containing
// the strings "secret", "token", or "pass"
func sanitizeEnv(kvs map[string]string) {
for k := range kvs {
kl := strings.ToLower(k)
if strings.Contains(kl, "secret") || strings.Contains(kl, "token") || strings.Contains(kl, "pass") {
kvs[k] = ""
for k, v := range kvs {
if v != "" {
kvs[k] = "***REDACTED***"
}
}
}
6 changes: 1 addition & 5 deletions support/support_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"io"
"net/http"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -148,10 +147,7 @@ func assertSanitizedWorkspace(t *testing.T, ws codersdk.Workspace) {
for _, res := range ws.LatestBuild.Resources {
for _, agt := range res.Agents {
for k, v := range agt.EnvironmentVariables {
kl := strings.ToLower(k)
if strings.Contains(kl, "secret") || strings.Contains(kl, "token") || strings.Contains(kl, "pass") {
assert.Empty(t, v, "environment variable %q not sanitized", k)
}
assert.Equal(t, "***REDACTED***", v, "environment variable %q not sanitized", k)
}
}
}
Expand Down