Skip to content

Commit 6299701

Browse files
added git secrets sample code for mac and Linux and updated security.md (#142)
1 parent 7707270 commit 6299701

File tree

9 files changed

+520
-3
lines changed

9 files changed

+520
-3
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
repos:
2+
- repo: local
3+
hooks:
4+
- id: git-secrets
5+
name: Git Secrets
6+
description: git-secrets scans commits, commit messages, and --no-ff merges to prevent adding secrets into your git repositories.
7+
entry: 'nhsd-git-secrets/pre-commit-mac.sh'
8+
language: script
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Setup (Mac only)
2+
3+
Ensure you have the pre-commit framework set up first:
4+
5+
https://pre-commit.com/
6+
7+
TL;DR:
8+
9+
* pre-commit --version (to check whether it's installed)
10+
* brew install pre-commit
11+
* cd <texasd infra repo root>
12+
* pre-commit install
13+
14+
Once you have pre-commit installed then:
15+
16+
* cd nhsd-git-secrets
17+
* cp git-secrets ..
18+
19+
Then if you don't have an existing .pre-commit-config.yaml in the root of your repo:
20+
21+
* cp .pre-commit-config.example.yaml ../.pre-commit-config.yaml
22+
23+
Otherwise integrate the git-secrets example config into your existing file.
24+
25+
Then:
26+
27+
* cd ..
28+
* pre-commit install
29+
* git add .pre-commit-config.yaml
30+
31+
Next time you do a commit the git secrets hook should be invoked.
32+
33+
# Custom configuration (per repo / per service team)
34+
35+
* Add individual regex expressions to nhsd-rules.txt
36+
* Add regex rules files within wrapper.sh e.g.
37+
38+
`git secrets --add-provider -- cat git-secrets/nhsd-rules.txt`
39+
40+
* Add file/dir excludes within wrapper.sh e.g.
41+
42+
`git secrets --add --allowed '.*terraform.tfstate.*:*'`
43+
44+
* Control full scan vs staged files scan within wrapper.sh by commenting/uncommenting the mode to run e.g.:
45+
46+
```
47+
# Just scan the files changed in this commit
48+
# git secrets --pre_commit_hook
49+
50+
# Scan all files within this repo for this commit
51+
git secrets --scan
52+
```
53+
54+
# Testing-a
55+
56+
* make sure you have done git add if you have changed anything within git-Secrets
57+
* Run: `pre-commit run git-secrets`
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
cd ..
4+
5+
export PATH=$PATH:.
6+
7+
# # These only need to be run once per workstation/slave/agent but are included to try and ensure they are present
8+
./git-secrets --register-aws
9+
./git-secrets --add-provider -- cat nhsd-git-secrets/nhsd-rules-linux.txt
10+
./git-secrets --add --allowed '.*git-secrets/.*:*'
11+
./git-secrets --add --allowed '.*terraform.tfstate.*:*'
12+
13+
# Scan all files within this repo for this commit
14+
./git-secrets --scan-history

0 commit comments

Comments
 (0)