Skip to content

Commit

Permalink
fix(step): add catch block for disallowed secrets (#272)
Browse files Browse the repository at this point in the history
* add catch block for unallowed secrets

* adding test case
  • Loading branch information
ecrupper authored Feb 15, 2022
1 parent aa87a48 commit 2379755
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 6 additions & 6 deletions executor/linux/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,15 +464,15 @@ func getSecretValues(ctn *pipeline.Container) []string {
secretValues := []string{}
// gather secrets' values from the environment map for masking
for _, secret := range ctn.Secrets {
s := ctn.Environment[strings.ToUpper(secret.Target)]
// capture secret from environment
s, ok := ctn.Environment[strings.ToUpper(secret.Target)]
if !ok {
continue
}
// handle multi line secrets from files
s = strings.ReplaceAll(s, "\n", " ")

// drop any trailing spaces
if strings.HasSuffix(s, " ") {
s = s[:(len(s) - 1)]
}
secretValues = append(secretValues, s)
secretValues = append(secretValues, strings.TrimSuffix(s, " "))
}
return secretValues
}
4 changes: 4 additions & 0 deletions executor/linux/step_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,10 @@ func TestLinux_getSecretValues(t *testing.T) {
Source: "someOtherSource",
Target: "secret_password",
},
{
Source: "disallowedSecret",
Target: "cannot_find",
},
},
},
},
Expand Down

0 comments on commit 2379755

Please sign in to comment.