generated from ossf/project-template
-
Notifications
You must be signed in to change notification settings - Fork 128
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
Add secret scanning to SCM guide, fixes #488 #489
Open
david-a-wheeler
wants to merge
8
commits into
main
Choose a base branch
from
add_secret_scanning_scm
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
748ff78
Add secret scanning to SCM guide, fixes #488
david-a-wheeler ad69d7c
Fix markdownlint issues
david-a-wheeler 2af81c8
Update docs/SCM-BestPractices/github/repository/secret_scanning.md
SecurityCRob 7959141
Update docs/SCM-BestPractices/github/repository/secret_scanning.md
SecurityCRob 3447e0f
Update docs/SCM-BestPractices/github/repository/secret_scanning.md
SecurityCRob 76cc1ad
Update docs/SCM-BestPractices/github/repository/secret_scanning.md
SecurityCRob 5d73b59
Update docs/SCM-BestPractices/github/repository/secret_scanning.md
SecurityCRob 6aa08a6
Update docs/SCM-BestPractices/gitlab/project/secret_scanning.md
SecurityCRob File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
docs/SCM-BestPractices/github/repository/secret_scanning.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Secret Scanning | ||
|
||
policy name: secret_scanning | ||
|
||
severity: HIGH | ||
|
||
## Description | ||
|
||
This security control checks for secrets being checked into a repository | ||
and prevents it. | ||
Turning on secret scanning detects many kinds of secrets being checked | ||
into a repository and reports it. | ||
Push protection builds on secret scanning and prevents attempts to add such | ||
secrets (and creates and alert if that it overridden). | ||
SecurityCRob marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Threat Example(s) | ||
|
||
Inserting a secret into a source code repository is unfortunately an easy | ||
mistake to make. Instructions for various services often | ||
encourage putting secrets into a repository (as it's the "simple" way | ||
to do it, though not the secure way). | ||
Once secrets are in a repository, they become available for anyone who | ||
can view the repository (directly or via a copy). | ||
Inserting secrets into a source code repository is a mistake, since | ||
it interferes with the whole point of a secret: keeping it secret. | ||
This is such a common kind of vulnerability that it is identified as | ||
SecurityCRob marked this conversation as resolved.
Show resolved
Hide resolved
|
||
the Common Weakness Enumeration (CWE) | ||
[CWE-540: Inclusion of Sensitive Information in Source Code](https://cwe.mitre.org/data/definitions/540.html). | ||
|
||
## Remediation | ||
|
||
Like practically all tools, secret scanning is subject to false positives | ||
and false negatives. That said, secret scanning can prevent significant | ||
vulnerabilities and should be enabled. | ||
|
||
There are two different steps, scanning and enforcement: | ||
|
||
* On a new project you should enable both scanning and enforcement. | ||
* On an existing project you should enable scanning, ensure it works | ||
well first, and *then* enable enforcement. | ||
|
||
### Enabling Secret Scanning | ||
|
||
[The GitHub documentation describes how to enable secret scanning](https://docs.github.com/en/code-security/secret-scanning/configuring-secret-scanning-for-your-repositories). | ||
|
||
In short, to enable GitHub secret scanning on a repository: | ||
|
||
1. Make sure you have admin permissions | ||
2. Go to the repo's settings page | ||
3. Enter "Security" section of the sidebar, click Code security and analysis. | ||
SecurityCRob marked this conversation as resolved.
Show resolved
Hide resolved
|
||
4. Click "Enable for secret scanning" | ||
5. Click "Save changes" | ||
|
||
You may also choose to enable other secret scanning tools. | ||
For example, those with access to the Linux Foundation's LFX tools should | ||
consider enabling its secret scanning tools as well. | ||
|
||
### Enforcing Secret Scanning | ||
|
||
In GitHub you can enable push protection on secret scanning | ||
for repositories and organizations. | ||
When this is enabled, secret scanning "blocks contributors | ||
from pushing secrets to a repository and generates an alert | ||
whenever a contributor bypasses the block." | ||
|
||
[The GitHub documentation describes how to enable push protection with secret scanning](https://docs.github.com/en/code-security/secret-scanning/push-protection-for-repositories-and-organizations). | ||
|
||
In short, to enforce GitHub secret scanning on a repository: | ||
|
||
1. Make sure you have admin permissions | ||
2. Go to the repo's settings page | ||
3. Enter "Security" section of the sidebar, click Code security and analysis. | ||
SecurityCRob marked this conversation as resolved.
Show resolved
Hide resolved
|
||
4. Under "Code security and analysis", find "GitHub Advanced Security." | ||
5. Under "Secret scanning", under "Push protection", click Enable. | ||
SecurityCRob marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Secret Scanning | ||
|
||
policy name: secret_scanning | ||
|
||
severity: HIGH | ||
|
||
## Description | ||
|
||
This security control checks for secrets being checked into a repository. | ||
Turning on secret detection (also called secret scanning) | ||
detects many kinds of secrets being checked | ||
into a repository and reports it. | ||
At this time GitLab's mechanism for *preventing* this event is experimental. | ||
|
||
## Threat Example(s) | ||
|
||
Inserting a secret into a source code repository is unfortunately an easy | ||
mistake to make. Instructions for various services often | ||
encourage putting secrets into a repository (as it's the "simple" way | ||
to do it, though not the secure way). | ||
Once secrets are in a repository, they become available for anyone who | ||
can view the repository (directly or via a copy). | ||
Inserting secrets into a source code repository is a mistake, since | ||
it interferes with the whole point of a secret: keeping it secret. | ||
This is such a common kind of vulnerability that it is identified as | ||
SecurityCRob marked this conversation as resolved.
Show resolved
Hide resolved
|
||
the Common Weakness Enumeration (CWE) | ||
[CWE-540: Inclusion of Sensitive Information in Source Code](https://cwe.mitre.org/data/definitions/540.html). | ||
|
||
## Remediation | ||
|
||
Like practically all tools, secret scanning is subject to false positives | ||
and false negatives. That said, secret scanning can prevent significant | ||
vulnerabilities and should be enabled. | ||
|
||
GitLab includes | ||
[two different secret detection methods](https://docs.gitlab.com/ee/user/application_security/secret_detection/) | ||
which can be used simultaneously: | ||
|
||
* The pipeline method "detects secrets during the project’s CI/CD pipeline. | ||
This method cannot reject pushes". | ||
* The pre-receive method "detects secrets when users push changes to | ||
the remote Git branch. This method can reject pushes if a secret is detected." | ||
|
||
However, as of 2024-05-14, the pre-receive method is an | ||
experiment with limited availability. Thus, we focus on the pipeline method. | ||
The pipeline method is unfortunately unable to *prevent* this, but at least | ||
it quickly warns you of the event. | ||
|
||
Note that secret scanning is automatically enabled if you enable | ||
[Auto DevOps](https://docs.gitlab.com/ee/topics/autodevops/index.html#enable-or-disable-auto-devops). | ||
|
||
Those with more complex needs must | ||
edit the `.gitlab-ci.yml` file manually. | ||
To do this: | ||
|
||
1. Make sure you can manage project merge requests permissions | ||
2. Go to the project's settings page | ||
3. Select "Build > Pipeline editor" | ||
4. Add the following to the end of the `.gitlab-ci.yml` file: | ||
|
||
~~~~yml | ||
include: | ||
- template: Jobs/Secret-Detection.gitlab-ci.yml | ||
~~~~ | ||
|
||
5. Select the Validate tab, then select Validate pipeline. | ||
The message "Simulation completed successfully" indicates the file is valid. | ||
6. Select the Edit tab. | ||
7. In the Branch text box, enter the name of the default branch. | ||
8. Select Commit changes. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.