Trivy scans any container image, filesystem and git repository to detect exposed secrets like passwords, api keys, and tokens.
Secret scanning is enabled by default.
Trivy will scan every plaintext file, according to builtin rules or configuration. Also, Trivy can detect secrets in compiled Python files (.pyc).
If your secret is not detected properly, please make sure that your file including the secret is not in the allowed paths.
You can disable allow rules via disable-allow-rules.
Trivy tries to detect a base image and skip those layers for secret scanning.
A base image usually contains a lot of files and makes secret scanning much slower.
If a secret is not detected properly, you can see base layers with the --debug flag.
Your project may have some secrets for testing. You can skip them with --skip-dirs or --skip-files.
We would recommend specifying these options so that the secret scanning can be faster if those files don't need to be scanned.
Also, you can specify paths to be allowed in a configuration file. See the detail here.
This section describes secret-specific configuration.
Other common options are documented here.
Trivy has a set of builtin rules for secret scanning, which can be extended or modified by a configuration file.
Trivy tries to load trivy-secret.yaml in the current directory by default.
If the file doesn't exist, only built-in rules are used.
You can customize the config file path via the --secret-config flag.
Warning
Trivy uses Golang regexp package. To use ^ and $ as symbols of begin and end of line use multi-line mode -(?m).
rules:-id:rule1category:generaltitle:Generic Ruleseverity:HIGHpath:.*\.shkeywords:-secretregex:(?i)(?P<key>(secret))(=|:).{0,5}['"](?P<secret>[0-9a-zA-Z\-_=]{8,64})['"]secret-group-name:secretallow-rules:-id:skip-textdescription:skip text filespath:.*\.txt
id (required)
Unique identifier for this rule.
category (required)
String used for metadata and reporting purposes.
title (required)
Short human-readable title of the rule.
severity (required)
How critical this rule is.
Allowed values:
CRITICAL
HIGH
MEDIUM
LOW
regex (required)
Golang regular expression used to detect secrets.
path (optional)
Golang regular expression used to match paths.
keywords (optional, recommended)
Keywords are used for pre-regex check filtering.
Rules that contain keywords will perform a quick string compare check to make sure the keyword(s) are in the content being scanned.
Ideally these values should either be part of the identifier or unique strings specific to the rule's regex.
It is recommended to define for better performance.
allow-rules (optional)
Allow rules for a single rule to reduce false positives with known secrets.
If the detected secret is matched with the specified regex, then that secret will be skipped and not detected.
The same logic applies for path.
allow-rules can be defined globally and per each rule. The fields are the same.
rules:-id:rule1category:generaltitle:Generic Ruleseverity:HIGHregex:(?i)(?P<key>(secret))(=|:).{0,5}['"](?P<secret>[0-9a-zA-Z\-_=]{8,64})['"]allow-rules:-id:skip-textdescription:skip text filespath:.*\.txtallow-rules:-id:social-security-numberdescription:skip social security numberregex:219-09-9999
id (required)
Unique identifier for this allow rule.
description (optional)
Short human-readable description of this allow rule.
regex (optional)
Golang regular expression used to allow detected secrets.
regex or path must be specified.
path (optional)
Golang regular expression used to allow matched paths.
Trivy provides plenty of out-of-box rules and allow rules, but you may not need all of them.
In that case, enable-builtin-rules will be helpful.
If you just need AWS secret detection, you can enable only relevant rules as shown below.
It specifies AWS-related rule IDs in enable-builtin-rules.
All other rules are disabled, so the scanning will be much faster.
We would strongly recommend using this option if you don't need all rules.
Trivy offers built-in rules and allow rules, but you may want to disable some of them.
For example, you don't use Slack, so Slack doesn't have to be scanned.
You can specify the Slack rule IDs, slack-access-token and slack-web-hook in disable-rules so that those rules will be disabled for less false positives.
You should specify either enable-builtin-rules or disable-rules.
If they both are specified, disable-rules takes precedence.
In case github-pat is specified in enable-builtin-rules and disable-rules, it will be disabled.
In addition, there are some allow rules.
Markdown files are ignored by default, but you may want to scan markdown files as well.
You can disable the allow rule by adding markdown to disable-allow-rules.
We would recommend specifying --skip-dirs for faster secret scanning.
In container image scanning, Trivy walks the file tree rooted / and scans all the files other than built-in allowed paths.
It will take a while if your image contains a lot of files even though Trivy tries to avoid scanning layers from a base image.
If you want to make scanning faster, --skip-dirs and --skip-files helps so that Trivy will skip scanning those files and directories.
You can see more options here.
allow-rules is also helpful. See the allow-rules section.
In addition, all the built-in rules are enabled by default, so it takes some time to scan all of them.
If you don't need all those rules, you can use enable-builtin-rules or disable-rules in the configuration file.
You should use enable-builtin-rules if you need only AWS secret detection, for example.
All rules are disabled except for the ones you specify, so it runs very fast.
On the other hand, you should use disable-rules if you just want to disable some built-in rules.
See the enable-rules and disable-rules sections for the detail.
If you don't need secret scanning, you can disable it via the --scanners flag.
trivy-secret.yaml in the working directory is loaded by default.
$ cat trivy-secret.yamlrules:-id:rule1category:generaltitle:Generic Ruleseverity:HIGHregex:(?i)(?P<key>(secret))(=|:).{0,5}['"](?P<secret>[0-9a-zA-Z\-_=]{8,64})['"]allow-rules:-id:social-security-numberdescription:skip social security numberregex:219-09-9999-id:log-dirdescription:skip log directorypath:^\/var\/log\/disable-rules:-slack-access-token-slack-web-hookdisable-allow-rules:-markdown# The following command automatically loads the above configuration.$ trivy image YOUR_IMAGE
Also, you can customize the config file path via --secret-config.
$ cat ./secret-config/trivy.yamlrules:-id:rule1category:generaltitle:Generic Ruleseverity:HIGHregex:(?i)(?P<key>(secret))(=|:).{0,5}['"](?P<secret>[0-9a-zA-Z\-_=]{8,64})['"]allow-rules:-id:skip-textdescription:skip text filespath:.*\.txtenable-builtin-rules:-aws-access-key-id-aws-account-id-aws-secret-access-keydisable-allow-rules:-usr-dirs# Pass the above config with `--secret-config`.$ trivy fs --secret-config ./secret-config/trivy.yaml /path/to/your_project