Skip to content

Commit 6cab50d

Browse files
authored
Merge pull request #131 from buildkite/fix/env-var-values-are-redacted
Limit redacting env var values
2 parents 20f1344 + c130990 commit 6cab50d

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

s3secrets-helper/secrets/secrets.go

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ const (
2828
BaseJSONOverhead = 50
2929
)
3030

31+
// defaultSecretSuffixes contains the default suffixes that identify secret environment variables
32+
var defaultSecretSuffixes = []string{
33+
"_SECRET",
34+
"_SECRET_KEY",
35+
"_PASSWORD",
36+
"_TOKEN",
37+
"_ACCESS_KEY",
38+
}
39+
3140
// Client represents interaction with AWS S3
3241
type Client interface {
3342
Bucket() string
@@ -171,13 +180,7 @@ func getEnvs(conf Config, results chan<- getResult) {
171180
}
172181

173182
func getSecrets(conf Config, results chan<- getResult) {
174-
suffixes := append(conf.SecretSuffixes, []string{
175-
"_SECRET",
176-
"_SECRET_KEY",
177-
"_PASSWORD",
178-
"_TOKEN",
179-
"_ACCESS_KEY",
180-
}...)
183+
suffixes := append(conf.SecretSuffixes, defaultSecretSuffixes...)
181184

182185
prefixes := []string{
183186
"secret-files",
@@ -271,8 +274,8 @@ func handleEnvs(conf *Config, results <-chan getResult) error {
271274
if err != nil {
272275
log.Printf("Warning: failed to parse env file %s/%s: %v", r.bucket, r.key, err)
273276
} else {
274-
for _, value := range envMap {
275-
if len(value) > 0 {
277+
for key, value := range envMap {
278+
if isSecretVar(key) && len(value) > 0 {
276279
redactSecret(conf, value)
277280
}
278281
}
@@ -374,6 +377,16 @@ func handleSecrets(conf *Config, results <-chan getResult) error {
374377
return nil
375378
}
376379

380+
// isSecretVar checks if an environment variable name contains any of the secret suffixes
381+
func isSecretVar(key string) bool {
382+
for _, suffix := range defaultSecretSuffixes {
383+
if strings.Contains(key, suffix) {
384+
return true
385+
}
386+
}
387+
return false
388+
}
389+
377390
type getResult struct {
378391
bucket string
379392
key string

0 commit comments

Comments
 (0)