Skip to content

Commit 9b620fa

Browse files
authored
Merge pull request moby#5410 from daghack/secret-check-allow-list
frontend: add an allow list for secret lint check and add public to said list
2 parents 7c4f6d9 + 98e77d1 commit 9b620fa

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

frontend/dockerfile/dockerfile2llb/convert.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ const (
5757
)
5858

5959
var (
60-
secretsRegexpOnce sync.Once
61-
secretsRegexp *regexp.Regexp
60+
secretsRegexpOnce sync.Once
61+
secretsRegexp *regexp.Regexp
62+
secretsAllowRegexp *regexp.Regexp
6263
)
6364

6465
var nonEnvArgs = map[string]struct{}{
@@ -2445,7 +2446,7 @@ func validateBaseImagePlatform(name string, expected, actual ocispecs.Platform,
24452446
}
24462447
}
24472448

2448-
func getSecretsRegex() *regexp.Regexp {
2449+
func getSecretsRegex() (*regexp.Regexp, *regexp.Regexp) {
24492450
// Check for either full value or first/last word.
24502451
// Examples: api_key, DATABASE_PASSWORD, GITHUB_TOKEN, secret_MESSAGE, AUTH
24512452
// Case insensitive.
@@ -2464,13 +2465,19 @@ func getSecretsRegex() *regexp.Regexp {
24642465
}
24652466
pattern := `(?i)(?:_|^)(?:` + strings.Join(secretTokens, "|") + `)(?:_|$)`
24662467
secretsRegexp = regexp.MustCompile(pattern)
2468+
2469+
allowTokens := []string{
2470+
"public",
2471+
}
2472+
allowPattern := `(?i)(?:_|^)(?:` + strings.Join(allowTokens, "|") + `)(?:_|$)`
2473+
secretsAllowRegexp = regexp.MustCompile(allowPattern)
24672474
})
2468-
return secretsRegexp
2475+
return secretsRegexp, secretsAllowRegexp
24692476
}
24702477

24712478
func validateNoSecretKey(instruction, key string, location []parser.Range, lint *linter.Linter) {
2472-
pattern := getSecretsRegex()
2473-
if pattern.MatchString(key) {
2479+
deny, allow := getSecretsRegex()
2480+
if deny.MatchString(key) && !allow.MatchString(key) {
24742481
msg := linter.RuleSecretsUsedInArgOrEnv.Format(instruction, key)
24752482
lint.Run(&linter.RuleSecretsUsedInArgOrEnv, location, msg)
24762483
}

frontend/dockerfile/dockerfile_lint_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ ENV password=bar secret=baz
223223
ARG super_duper_secret_token=foo auth=bar
224224
ENV apikey=bar sunflower=foo
225225
ENV git_key=
226+
ENV PUBLIC_KEY=
227+
ARG public_token
226228
`)
227229
checkLinterWarnings(t, sb, &lintTestParams{
228230
Dockerfile: dockerfile,

0 commit comments

Comments
 (0)