Skip to content
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

feat(checks): Adding IAC check for secrets inserted into docker layer #7639

Closed
simar7 opened this issue Oct 3, 2024 Discussed in #7570 · 11 comments · Fixed by aquasecurity/trivy-checks#265
Closed

feat(checks): Adding IAC check for secrets inserted into docker layer #7639

simar7 opened this issue Oct 3, 2024 Discussed in #7570 · 11 comments · Fixed by aquasecurity/trivy-checks#265
Assignees
Labels
kind/feature Categorizes issue or PR as related to a new feature. scan/misconfiguration Issues relating to misconfiguration scanning target/filesystem Issues relating to filesystem scanning
Milestone

Comments

@simar7
Copy link
Member

simar7 commented Oct 3, 2024

Discussed in #7570

Originally posted by tzurielweisberg September 22, 2024

Description

Wbserved recently that when the secrets are passed to docker build with --build-args, it saved into the image layers unexposed and that leads to a secret leak if someone inspects the image layers or reviews the scan layers from Aqua UI for the scanned image.

We need a IAC rule for Dockefile to search for Secrets/Password usage.
image

It of course will be matched in secret scanning later, but we want to know about it before

Target

Filesystem

Scanner

Misconfiguration

@simar7 simar7 added kind/feature Categorizes issue or PR as related to a new feature. scan/misconfiguration Issues relating to misconfiguration scanning target/filesystem Issues relating to filesystem scanning labels Oct 3, 2024
@simar7 simar7 added this to the v0.57.0 milestone Oct 3, 2024
@nikpivkin
Copy link
Contributor

Should the check find potential use of secrets in the Dockerfile, or find secrets in the docker history?

@knqyf263
Copy link
Collaborator

knqyf263 commented Oct 4, 2024

find secrets in the docker history?

It's already supported. I think we need the former.

@nikpivkin
Copy link
Contributor

Then I think we can define secrets in the following ways:

We can also take into account setting environment variables in a specific way. You need to add the VITE and REACT_APP prefix to pass environment variables to React or Vite applications, respectively. Here is an example of a Dockerfile (the repository has 2.7k stars) with multiple credentials set up this way: https://github.com/hahahumble/speechgpt/blob/215e3a07a65eafede2ba3257939a4e59cfd01ae6/Dockerfile#L4-L10

Docker has the ability to pass secrets and we need to take this into account to avoid false positives. Example: https://github.com/super-linter/super-linter/blob/c4fe4da1f3bda7fd0f28bf92dd357fb9feeef5bf/Dockerfile#L103

@nikpivkin
Copy link
Contributor

We have the ability to pass user data to the checks, so users will have the ability to extend the check or disable some rules.

@nikpivkin
Copy link
Contributor

Also, we should only analyze the final stage commands

@simar7
Copy link
Member Author

simar7 commented Oct 8, 2024

We have the ability to pass user data to the checks, so users will have the ability to extend the check or disable some rules.

Do you have an example for this? Do you mean define user based exceptions to detections?

@simar7
Copy link
Member Author

simar7 commented Oct 8, 2024

Also, we should only analyze the final stage commands

@nikpivkin Just thinking about this: if the secret was present in an intermediate layer but later removed from subsequent layers, it is still exposed via the history right?

@knqyf263
Copy link
Collaborator

knqyf263 commented Oct 8, 2024

Also, we should only analyze the final stage commands

@nikpivkin Just thinking about this: if the secret was present in an intermediate layer but later removed from subsequent layers, it is still exposed via the history right?

I think @nikpivkin is talking about multi-stage builds.

@nikpivkin
Copy link
Contributor

Also, we should only analyze the final stage commands

@nikpivkin Just thinking about this: if the secret was present in an intermediate layer but later removed from subsequent layers, it is still exposed via the history right?

I meant multi-stage build. The image history only stores information about the final stage.

@nikpivkin
Copy link
Contributor

We have the ability to pass user data to the checks, so users will have the ability to extend the check or disable some rules.

Do you have an example for this? Do you mean define user based exceptions to detections?

We can define the following rule:

included_envs := included if {
	is_array(ds031.included_envs)
	included := {e | some e in ds031.included_envs}
} else := set()

Then the user can include additional environment variables:

❯ cat my-envs.yaml
ds031:
  included_envs: ["MY_SECRET"]

❯ cat Dockerfile.custom
from alpine

arg MY_SECRET

❯ trivy conf -d Dockerfile.custom --config-data my-envs.yaml
CRITICAL: Possible exposure of secret env "MY_SECRET" in ARG
═══════════════════════════════════════════════════════════════════════════════════════════════════════════
Passing secrets via `build-args` or envs or copying secret files can leak them out

See https://avd.aquasec.com/misconfig/ds031
───────────────────────────────────────────────────────────────────────────────────────────────────────────
 Dockerfile.custom:3
───────────────────────────────────────────────────────────────────────────────────────────────────────────
   3 [ arg MY_SECRET
───────────────────────────────────────────────────────────────────────────────────────────────────────────

@nikpivkin
Copy link
Contributor

@simar7 I found a discussion about the parametrization of checks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature. scan/misconfiguration Issues relating to misconfiguration scanning target/filesystem Issues relating to filesystem scanning
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

3 participants