|
| 1 | +# Setup (Linux/WSL only) |
| 2 | + |
| 3 | +## Setup |
| 4 | + |
| 5 | +Make sure to copy the `nhd-git-secrets` folder into the root of the project repository, and then navigate the terminal to the repo root |
| 6 | + |
| 7 | +* `cd nhsd-git-secrets` |
| 8 | +* `cp .gitallowed-base ../.gitallowed` |
| 9 | +* `./install-linux.sh` |
| 10 | + |
| 11 | +Next time you do a commit the git secrets hook should be invoked. |
| 12 | + |
| 13 | +### Troubleshooting |
| 14 | + |
| 15 | +You should have 3 new files in the `.git/hooks` folder in the repository. If these are not present, then make sure you have ran the install script and that this script ran successfully. |
| 16 | +If you get an output containing: |
| 17 | + |
| 18 | +```bash |
| 19 | +[3/5] Adding Git Hooks |
| 20 | +./install-linux.sh: line 18: git-secrets: command not found |
| 21 | +``` |
| 22 | + |
| 23 | +* Run this command anywhere: `export PATH="$HOME/git-secrets/bin":$PATH` |
| 24 | +* Then re-run the install script (`./nhsd-git-secrets/install-linux.sh`) |
| 25 | + |
| 26 | +### Custom configuration (per repo / per service team) |
| 27 | + |
| 28 | +* Add individual regex expressions to the existing `repo_root/nhsd-git-secrets-nhsd-rules-deny.txt` file |
| 29 | +* Or, create your own file for regex rules and add it as a provider within the [pre-commit script](pre-commit.sh) e.g.: |
| 30 | + `./nhsd-git-secrets/git-secrets --add-provider -- cat nhsd-git-secrets/nhsd-rules-deny.txt` |
| 31 | + |
| 32 | +* Add file/dir excludes within the `repo_root/.gitallowed`, e.g. `.*terraform.tfstate.*:*` |
| 33 | + |
| 34 | +* Control full scan vs staged files scan within [pre-commit script](pre-commit.sh) by commenting/uncommenting the mode to run e.g.: |
| 35 | + |
| 36 | + ```bash |
| 37 | + # Just scan the files changed in this commit |
| 38 | + # ./nhsd-git-secrets/git-secrets --pre_commit_hook |
| 39 | + |
| 40 | + # Scan all files within this repo for this commit |
| 41 | + ./nhsd-git-secrets/git-secrets --scan |
| 42 | + ``` |
| 43 | + |
| 44 | +## Testing and Usage |
| 45 | + |
| 46 | +To test that the hooks have been enabled correctly: |
| 47 | + |
| 48 | +* make sure you have done git add if you have changed anything within git-Secrets |
| 49 | +* create a file containing one or more patterns from the `git-secrets/nhsd-rules-deny.txt` file (e.g.: `password = “test”`) |
| 50 | +* stage and commit the file |
| 51 | + |
| 52 | +You should see an output similar to: `“[ERROR] Matched one or more prohibited patterns…”`. |
| 53 | + |
| 54 | +**Note** This message may appear differently depending on the tools used. |
| 55 | + |
| 56 | +> If you have a *false-positive* match, and your changes do not contain sensitive credentials then you can add the `--no-verify` flag to the commit command to **skip the checking**. |
| 57 | +
|
| 58 | +## Docker version |
| 59 | + |
| 60 | +Alternatively, you might find this [dockerfile](nhsd-git-secrets.dockerfile) convenient, which: |
| 61 | + |
| 62 | +1. Copies your source code into a docker image |
| 63 | +1. Downloads latest version of the secret scanner tool |
| 64 | +1. Downloads latest regex patterns from software-engineering-quality-framework |
| 65 | +1. Runs a scan |
0 commit comments