23
loading...
This website collects cookies to deliver better user experience
git-secrets
scans the commits and prevents adding secrets to a commit according to a pre-configured regular expression.brew install git-secrets
.const credentials = {
accessKeyId: 'asdfsdfse33SSDFFF',
secretAccessKey: 'GHGSDFS@###RWSDFSZssssss',
};
console.log(credentials);
git secrets --add 'credentials'
. You could replace 'Credentials' with any regular expression of your choice.git secrets --scan src/*.js
- index.js lives under the src folder in this case. Notice the response you:
src/index.js:1:const credentials = {
src/index.js:6:console.log(credentials);
[ERROR] Matched one or more prohibited patterns
Possible mitigations:
- Mark false positives as allowed using: git config --add secrets.allowed
- Mark false positives as allowed by adding regular expressions to .gitallowed at repository's root directory
- List your configured patterns: git config --get-all secrets.patterns
- List your configured allowed patterns: git config --get-all secrets.allowed
- List your configured allowed patterns in .gitallowed at repository's root directory
- Use --no-verify if this is a one-time false positive
- In your repository, open `.git/config` and delete the patterns line under the [secrets] tag
git-secrets
enables us to check against common AWS patterns using the --register-aws
option. To add these patterns, run: git secrets --register-aws
. Notice the following patterns added to the .git/config
file:providers = git secrets --aws-provider
patterns = (A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}
patterns = (\"|')?(AWS|aws|Aws)?_?(SECRET|secret|Secret)?_?(ACCESS|access|Access)?_?(KEY|key|Key)(\"|')?\\s*(:|=>|=)\\s*(\"|')?[A-Za-z0-9/\\+=]{40}(\"|')?
patterns = (\"|')?(AWS|aws|Aws)?_?(ACCOUNT|account|Account)_?(ID|id|Id)?(\"|')?\\s*(:|=>|=)\\s*(\"|')?[0-9]{4}\\-?[0-9]{4}\\-?[0-9]{4}(\"|')?
allowed = AKIAIOSFODNN7EXAMPLE
allowed = wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
~/.aws/credentials
into the index.js file, then run git secrets --scan src/*.js
. Notice the matched pattern.git secrets --install
- Once the hooks are installed for a git repository, commits, and non-fast-forward merges for that repository will be prevented from committing secrets. Also, it could be a good idea to scan your repository as part of CI/CD and fail the pipeline if secrets exposure occurred - this enables you to take immediate actions as soon as possible, even though after the fact.23