- Enabling secret scanning
- Viewing and managing results
- Introducing a test secret
- Excluding files from secret scanning
- Managing access to alerts
Secret scanning can be enabled in the settings of an organization or a repository. If Advanced Security is not enabled yet, then enable that first (same settings screen).
- Go to the repository settings and enable secret scanning in the
Code security and analysis
section.
After a few minutes, the Security
tab in the repository will indicate that there are new security alerts.
- Go to the
Secret scanning
section to view the detected secrets.
For each secret, look at the options to close it and determine which one is most suitable.
When developing test cases, you might find that secrets are introduced that cannot be abused when disclosed. Secret scanning will still detect and alert on these secrets.
- In the GitHub repository file explorer, create a test file that contains a test secret.
- For example the file
storage-service/src/main/resources/application.dev.properties
with the secretsAWS_ACCESS_KEY_ID="AKIAZBQE345LKPTEAHQD" AWS_SECRET_ACCESS_KEY="wt6lVzza0QFx/U33PU8DrkMbnKiu+bv9jheR0h/D"
- For example the file
- Determine if the secret is detected when the file is stored.
- How would you like to manage results from test files?
While we can close a detected secret as being used in a test, we can also configure secret scanning to exclude files from being scanned.
-
Create the file
.github/secret_scanning.yml
if it doesn't already exist. -
Add a list of paths to exclude from secret scanning. You can use filter patterns to specify paths.
paths-ignore: - '**/test/**'
Note: The characters
*
,[
, and!
are special characters in YAML. If you start a pattern with*
,[
, or!
, you must enclose the pattern in quotes.Use a pattern to exclude the file
storage-service/src/main/resources/application.dev.properties
Merge your changes to
.github/secret_scanning.yml
to your default branch before going to the next step.Solution
A possible solution is:paths-ignore: - '**/test/**' - '**/application.dev.properties'
-
Test the pattern by adding another secret or to the file
storage-service/src/main/resources/application.dev.properties
For example change the
secretKey
toAWS_SECRET_ACCESS_KEY="6L=yQr6Ivxxj/XG+YdFPdH/xWDcbSV9ch/EjmHCL"
Secret scanning supports finding other secret patterns, which are specified by regex patterns and use the Hyperscan library.
-
Add a custom secret pattern by going to the
Code security and analysis
settings and under the header "Custom patterns" click onNew pattern
. -
Add a custom pattern name, a secret format and test cases.
For example:
Custom pattern name: My secret pattern Secret format: my_custom_secret_[a-z0-9]{3} Test string: my_custom_secret_123
-
Save your pattern and observe the secret scanning alerts page to see if your custom secret pattern has been detected.
Due to the nature of secrets, the alerts are only visible to organization and repository administrators and users with write
or higher access to the repo .
Access to other members and teams can be given in the Code security and analysis
setting.
Note: The member or teams require write privileges before access to alerts can be given.
- In the
Access to alerts
section, add another team member or team to provide access to your repository alerts.
💡Now that we're familiar with secret scanning, let's head over to the code scanning section, and learn more about it! 💡