Merge pull request #627 from w0rmr1d3r/update_documentation

Update documentation
This commit is contained in:
Ramon authored and GitHub committed 2021-09-07 15:32:37 +02:00
commit 0aa05133a9
1 file changed
+22 -24
+22 -24
View File
@@ -43,8 +43,9 @@ brew install gitleaks
##### Docker ##### Docker
```bash ```bash
docker pull zricethezav/gitleaks # To just pull the image
# or docker pull zricethezav/gitleaks:latest
# To run it from your cloned repo
cd to/your/repo/ cd to/your/repo/
docker run -v ${PWD}:/my-repo zricethezav/gitleaks:latest --path="/my-repo" [OPTIONS] docker run -v ${PWD}:/my-repo zricethezav/gitleaks:latest --path="/my-repo" [OPTIONS]
``` ```
@@ -60,8 +61,11 @@ See [pre-commit](https://github.com/pre-commit/pre-commit) for instructions.
Sample `.pre-commit-config.yaml` Sample `.pre-commit-config.yaml`
```yaml ```yaml
# The revision doesn't get updated manually
# check this https://github.com/zricethezav/gitleaks/releases
# to see if there are newer versions
- repo: https://github.com/zricethezav/gitleaks - repo: https://github.com/zricethezav/gitleaks
rev: v7.5.0 rev: v7.6.0
hooks: hooks:
- id: gitleaks - id: gitleaks
``` ```
@@ -167,9 +171,7 @@ The default configuration Gitleaks uses is located [here](https://github.com/zri
The rules are written in [TOML](https://github.com/toml-lang/toml) as defined in [TomlLoader struct](https://github.com/zricethezav/gitleaks/blob/master/config/config.go#L57-L87), and can be summarized as: The rules are written in [TOML](https://github.com/toml-lang/toml) as defined in [TomlLoader struct](https://github.com/zricethezav/gitleaks/blob/master/config/config.go#L57-L87), and can be summarized as:
``` ```toml
[[rules]] [[rules]]
description = "a string describing one of many rule in this config" description = "a string describing one of many rule in this config"
regex = '''one-go-style-regex-for-this-rule''' regex = '''one-go-style-regex-for-this-rule'''
@@ -202,7 +204,7 @@ Regular expressions are _NOT_ the full Perl set, so there are no look-aheads or
### Examples ### Examples
#### Example 1 #### Example 1
The first and most commonly edited array of tables is `[[rules]]`. This is where you can define your own custom rules for Gitleaks to use while scanning repos. Example keys/values within the `[[rules]]` table: The first and most commonly edited array of tables is `[[rules]]`. This is where you can define your own custom rules for Gitleaks to use while scanning repos. Example keys/values within the `[[rules]]` table:
``` ```toml
[[rules]] [[rules]]
description = "generic secret regex" description = "generic secret regex"
regex = '''secret(.{0,20})([0-9a-zA-Z-._{}$\/\+=]{20,120})''' regex = '''secret(.{0,20})([0-9a-zA-Z-._{}$\/\+=]{20,120})'''
@@ -210,13 +212,13 @@ The first and most commonly edited array of tables is `[[rules]]`. This is where
``` ```
#### Example 2 #### Example 2
We can also **combine** regular expressions AND entropy: We can also **combine** regular expressions AND entropy:
``` ```toml
[[rules]] [[rules]]
description = "entropy and regex example" description = "entropy and regex example"
regex = '''secret(.{0,20})['|"]([0-9a-zA-Z-._{}$\/\+=]{20,120})['|"]''' regex = '''secret(.{0,20})['|"]([0-9a-zA-Z-._{}$\/\+=]{20,120})['|"]'''
[[rules.Entropies]] [[rules.Entropies]]
Min = "4.5" Min = "4.5"
Max = "4.7" Max = "4.7"
``` ```
Translating this rule to English, this rule states: "if we encounter a line of code that matches *regex* AND the line falls within the bounds of a [Shannon entropy](https://en.wikipedia.org/wiki/Entropy_(information_theory)) of 4.5 to 4.7, then the line must be a leak" Translating this rule to English, this rule states: "if we encounter a line of code that matches *regex* AND the line falls within the bounds of a [Shannon entropy](https://en.wikipedia.org/wiki/Entropy_(information_theory)) of 4.5 to 4.7, then the line must be a leak"
@@ -228,17 +230,16 @@ aws_secret='ABCDEF+c2L7yXeGvUyrPgYsDnWRRC1AYEXAMPLE'
and and
``` ```
aws_secret=os.getenv('AWS_SECRET_ACCESS_KEY') aws_secret=os.getenv('AWS_SECRET_ACCESS_KEY')
``` ```
The first line of code is an example of a hardcoded secret being assigned to the variable `aws_secret`. The second line of code is an example of a secret being assigned via env variables to `aws_secret`. Both would be caught by the rule defined in *example 2* but only the first line is actually a leak. Let's define a new rule that will capture only the first line of code. We can do this by combining regular expression **groups** and entropy. The first line of code is an example of a hardcoded secret being assigned to the variable `aws_secret`. The second line of code is an example of a secret being assigned via env variables to `aws_secret`. Both would be caught by the rule defined in *example 2* but only the first line is actually a leak. Let's define a new rule that will capture only the first line of code. We can do this by combining regular expression **groups** and entropy.
``` ```toml
[[rules]] [[rules]]
description = "entropy and regex example" description = "entropy and regex example"
regex = '''secret(.{0,20})['|"]([0-9a-zA-Z-._{}$\/\+=]{20,120})['|"]''' regex = '''secret(.{0,20})['|"]([0-9a-zA-Z-._{}$\/\+=]{20,120})['|"]'''
[[rules.Entropies]] [[rules.Entropies]]
Min = "4.5" Min = "4.5"
Max = "4.7" Max = "4.7"
Group = "2" Group = "2"
``` ```
Notice how we added `Group = "2"` to this rule. We can translate this rule to English: "if we encounter a line of code that matches regex AND the entropy of the *second regex group* falls within the bounds of a [Shannon entropy](https://en.wikipedia.org/wiki/Entropy_(information_theory)) of 4.5 to 4.7, then the line must be a leak" Notice how we added `Group = "2"` to this rule. We can translate this rule to English: "if we encounter a line of code that matches regex AND the entropy of the *second regex group* falls within the bounds of a [Shannon entropy](https://en.wikipedia.org/wiki/Entropy_(information_theory)) of 4.5 to 4.7, then the line must be a leak"
@@ -254,18 +255,16 @@ without any delimiters. This will make a false negative for, say:
foo=+awsSecretAccessKeyisBase64=40characters foo=+awsSecretAccessKeyisBase64=40characters
``` ```
So you can use the following to effectively create the proper Perl regex: So you can use the following to effectively create the proper Perl regex:
``` ```toml
[[rules]] [[rules]]
description = "AWS secret key regardless of labeling" description = "AWS secret key regardless of labeling"
regex = '''.?[A-Za-z0-9\\+=]{40}.?''' regex = '''.?[A-Za-z0-9\\+=]{40}.?'''
[rules.allowlist] [rules.allowlist]
description = "41 base64 characters is not an AWS secret key" description = "41 base64 characters is not an AWS secret key"
regexes = ['''[A-Za-z0-9\\+=]{41}'''] regexes = ['''[A-Za-z0-9\\+=]{41}''']
``` ```
### Exit Codes ### Exit Codes
You can always set the exit code when leaves are encountered with the `--leaks-exit-code` flag. Default exit codes below: You can always set the exit code when leaves are encountered with the `--leaks-exit-code` flag. Default exit codes below:
``` ```
@@ -285,6 +284,5 @@ These users are [sponsors](https://github.com/sponsors/zricethezav) of gitleaks:
- [Ben "Ihavespoons"](https://github.com/ihavespoons) - [Ben "Ihavespoons"](https://github.com/ihavespoons)
- [Henry Sachs](https://github.com/henrysachs) - [Henry Sachs](https://github.com/henrysachs)
#### Logo Attribution #### Logo Attribution
The Gitleaks logo uses the Git Logo created <a href="https://twitter.com/jasonlong">Jason Long</a> is licensed under the <a href="https://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0 Unported License</a>. The Gitleaks logo uses the Git Logo created <a href="https://twitter.com/jasonlong">Jason Long</a> is licensed under the <a href="https://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0 Unported License</a>.