Skip to content

Commit

Permalink
Add documentation for SecretsUsedInArgOrEnv rule
Browse files Browse the repository at this point in the history
Signed-off-by: Talon Bowler <[email protected]>
  • Loading branch information
daghack committed Jul 2, 2024
1 parent 20f4864 commit 0e524f7
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 1 deletion.
2 changes: 1 addition & 1 deletion frontend/dockerfile/dockerfile2llb/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -2363,7 +2363,7 @@ func validateNoSecretKey(key string, location []parser.Range, lint *linter.Linte
"secret",
"token",
}
pattern := `(?i)(?:_|^)(?:`+strings.Join(secretTokens, "|")+`)(?:_|$)`
pattern := `(?i)(?:_|^)(?:` + strings.Join(secretTokens, "|") + `)(?:_|$)`
if matched, _ := regexp.MatchString(pattern, key); matched {
msg := linter.RuleSecretsUsedInArgOrEnv.Format(key)
lint.Run(&linter.RuleSecretsUsedInArgOrEnv, location, msg)
Expand Down
8 changes: 8 additions & 0 deletions frontend/dockerfile/dockerfile_lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,55 +61,63 @@ ENV git_key=
RuleName: "SecretsUsedInArgOrEnv",
Description: "Potentially sensitive data should not be used in the ARG or ENV commands",
Detail: `Secrets should not be used in the ARG or ENV commands (key named "SECRET_PASSPHRASE")`,
URL: "https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/",
Level: 1,
Line: 3,
},
{
RuleName: "SecretsUsedInArgOrEnv",
Description: "Potentially sensitive data should not be used in the ARG or ENV commands",
Detail: `Secrets should not be used in the ARG or ENV commands (key named "SUPER_Secret")`,
URL: "https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/",
Level: 1,
Line: 4,
},
{
RuleName: "SecretsUsedInArgOrEnv",
Description: "Potentially sensitive data should not be used in the ARG or ENV commands",
Detail: `Secrets should not be used in the ARG or ENV commands (key named "password")`,
URL: "https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/",
Level: 1,
Line: 5,
},
{
RuleName: "SecretsUsedInArgOrEnv",
Description: "Potentially sensitive data should not be used in the ARG or ENV commands",
Detail: `Secrets should not be used in the ARG or ENV commands (key named "secret")`,
URL: "https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/",
Level: 1,
Line: 5,
},
{
RuleName: "SecretsUsedInArgOrEnv",
Description: "Potentially sensitive data should not be used in the ARG or ENV commands",
Detail: `Secrets should not be used in the ARG or ENV commands (key named "super_duper_secret_token")`,
URL: "https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/",
Level: 1,
Line: 6,
},
{
RuleName: "SecretsUsedInArgOrEnv",
Description: "Potentially sensitive data should not be used in the ARG or ENV commands",
Detail: `Secrets should not be used in the ARG or ENV commands (key named "auth")`,
URL: "https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/",
Level: 1,
Line: 6,
},
{
RuleName: "SecretsUsedInArgOrEnv",
Description: "Potentially sensitive data should not be used in the ARG or ENV commands",
Detail: `Secrets should not be used in the ARG or ENV commands (key named "apikey")`,
URL: "https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/",
Level: 1,
Line: 7,
},
{
RuleName: "SecretsUsedInArgOrEnv",
Description: "Potentially sensitive data should not be used in the ARG or ENV commands",
Detail: `Secrets should not be used in the ARG or ENV commands (key named "git_key")`,
URL: "https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/",
Level: 1,
Line: 8,
},
Expand Down
4 changes: 4 additions & 0 deletions frontend/dockerfile/docs/rules/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,9 @@ $ docker build --check .
<td><a href="./redundant-target-platform/">RedundantTargetPlatform</a></td>
<td>Setting platform to predefined $TARGETPLATFORM in FROM is redundant as this is the default behavior</td>
</tr>
<tr>
<td><a href="./secrets-used-in-arg-or-env/">SecretsUsedInArgOrEnv</a></td>
<td>Potentially sensitive data should not be used in the ARG or ENV commands</td>
</tr>
</tbody>
</table>
32 changes: 32 additions & 0 deletions frontend/dockerfile/docs/rules/secrets-used-in-arg-or-env.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
title: SecretsUsedInArgOrEnv
description: Potentially sensitive data should not be used in the ARG or ENV commands
aliases:
- /go/dockerfile/rule/secrets-used-in-arg-or-env/
---

## Output

```text
Potentially sensitive data should not be used in the ARG or ENV commands
```

## Description

While it is common in many local development setups to pass secrets to running
processes through environment variables, setting these within a Dockerfile via
the `ENV` command means that these secrets will be committed to the build
history of the resulting image, exposing the secret. For the same reasons,
passing secrets in as build arguments, via the `ARG` command, will similarly
expose the secret. This rule reports violations where `ENV` and `ARG` key names
appear to be secret-related.

## Examples

❌ Bad: `AWS_SECRET_ACCESS_KEY` is a secret value.

```dockerfile
FROM scratch
ARG AWS_SECRET_ACCESS_KEY
```

24 changes: 24 additions & 0 deletions frontend/dockerfile/linter/docs/SecretsUsedInArgOrEnv.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## Output

```text
Potentially sensitive data should not be used in the ARG or ENV commands
```

## Description

While it is common in many local development setups to pass secrets to running
processes through environment variables, setting these within a Dockerfile via
the `ENV` command means that these secrets will be committed to the build
history of the resulting image, exposing the secret. For the same reasons,
passing secrets in as build arguments, via the `ARG` command, will similarly
expose the secret. This rule reports violations where `ENV` and `ARG` key names
appear to be secret-related.

## Examples

❌ Bad: `AWS_SECRET_ACCESS_KEY` is a secret value.

```dockerfile
FROM scratch
ARG AWS_SECRET_ACCESS_KEY
```
1 change: 1 addition & 0 deletions frontend/dockerfile/linter/ruleset.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ var (
RuleSecretsUsedInArgOrEnv = LinterRule[func(string) string]{
Name: "SecretsUsedInArgOrEnv",
Description: "Potentially sensitive data should not be used in the ARG or ENV commands",
URL: "https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/",
Format: func(secretKey string) string {
return fmt.Sprintf("Secrets should not be used in the ARG or ENV commands (key named %q)", secretKey)
},
Expand Down

0 comments on commit 0e524f7

Please sign in to comment.