@ministryofjustice/hmpps-precommit-hooks 2.0.0-beta.5 → 2.0.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -29
- package/bin/prepare.sh +0 -7
- package/default-hooks.yaml +8 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
This package aims to automatically install and configure pre-commit hooks using [prek](https://github.com/pre-commit/pre-commit) to help catch potential secrets and code quality issues before committing them to github.
|
|
4
4
|
|
|
5
|
+
This uses devsecops-hooks to run gitleaks - further information about it's use can be found [here](https://github.com/ministryofjustice/devsecops-hooks).
|
|
6
|
+
|
|
5
7
|
## Status
|
|
6
8
|
|
|
7
9
|
**This library is currently: ready to adopt.**
|
|
8
|
-
Teams are
|
|
10
|
+
Teams are encouraged to use this library. Please provide feedback via slack to the `#typescript` channel.
|
|
9
11
|
|
|
10
12
|
## Migration from Husky
|
|
11
13
|
|
|
@@ -43,12 +45,16 @@ The package will create a `.pre-commit-config.yaml` file in your project root th
|
|
|
43
45
|
HMPPS_HOOKS_VERSION: 1
|
|
44
46
|
|
|
45
47
|
repos:
|
|
48
|
+
- repo: https://github.com/ministryofjustice/devsecops-hooks
|
|
49
|
+
rev: v1.4.1
|
|
50
|
+
hooks:
|
|
51
|
+
- id: baseline
|
|
52
|
+
env:
|
|
53
|
+
GITLEAKS_CONFIGURATION_FILE: ./.gitleaks/gitleaks.toml
|
|
54
|
+
GITLEAKS_IGNORE_FILE: ./.gitleaks/.gitleaksignore
|
|
55
|
+
|
|
46
56
|
- repo: local
|
|
47
57
|
hooks:
|
|
48
|
-
- id: gitleaks
|
|
49
|
-
name: Scan commit for secrets
|
|
50
|
-
language: system
|
|
51
|
-
entry: gitleaks git --pre-commit --redact --staged --verbose --config .gitleaks/config.toml --gitleaks-ignore-path .gitleaks/.gitleaksignore
|
|
52
58
|
- id: lint
|
|
53
59
|
name: linting code
|
|
54
60
|
language: system
|
|
@@ -91,6 +97,8 @@ You can modify the `.pre-commit-config.yaml` file in your project to:
|
|
|
91
97
|
|
|
92
98
|
See the [pre-commit documentation](https://pre-commit.com/) for more details on hook configuration.
|
|
93
99
|
|
|
100
|
+
Also see [here](https://github.com/ministryofjustice/devsecops-hooks) for more information about the devsecops-hooks.
|
|
101
|
+
|
|
94
102
|
### Dealing with false positives
|
|
95
103
|
|
|
96
104
|
When a secret is detected, gitleaks will create a fingerprint. If the secret is a false positive then this can be added to the `./gitleaks/.gitleaksignore` to exclude from future scans.
|
|
@@ -133,7 +141,7 @@ prek run --all-files
|
|
|
133
141
|
Or run specific hooks:
|
|
134
142
|
|
|
135
143
|
```bash
|
|
136
|
-
prek run
|
|
144
|
+
prek run baseline
|
|
137
145
|
prek run lint
|
|
138
146
|
```
|
|
139
147
|
|
|
@@ -149,30 +157,41 @@ This should fail similarly to:
|
|
|
149
157
|
|
|
150
158
|
```bash
|
|
151
159
|
> npx -p @ministryofjustice/hmpps-precommit-hooks -c test-secret-protection
|
|
152
|
-
Creating test file containing dummy
|
|
160
|
+
Creating test file containing dummy key: 'fake_key=sk-2949185920abcdef'
|
|
153
161
|
Attempting to commit file containing secret
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
162
|
+
🔐 Ministry of Justice - Scanner.........................................Failed
|
|
163
|
+
- hook id: baseline
|
|
164
|
+
- duration: 1.63s
|
|
165
|
+
- exit code: 1
|
|
166
|
+
|
|
167
|
+
⚡️ Ministry of Justice - Scanner 1.4.0 ⚡️
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
○
|
|
171
|
+
│╲
|
|
172
|
+
│ ○
|
|
173
|
+
○ ░
|
|
174
|
+
░ gitleaks
|
|
175
|
+
|
|
176
|
+
Finding: fake_key=REDACTED
|
|
177
|
+
Secret: REDACTED
|
|
178
|
+
RuleID: generic-api-key
|
|
179
|
+
Entropy: 3.892407
|
|
180
|
+
File: demo-password.txt
|
|
181
|
+
Line: 1
|
|
182
|
+
Fingerprint: demo-password.txt:generic-api-key:1
|
|
183
|
+
|
|
184
|
+
9:51AM INF 0 commits scanned.
|
|
185
|
+
9:51AM INF scanned ~4868 bytes (4.87 KB) in 350ms
|
|
186
|
+
9:51AM WRN leaks found: 1
|
|
187
|
+
linting code.........................................(no files to check)Skipped
|
|
188
|
+
verify types.........................................(no files to check)Skipped
|
|
189
|
+
running tests........................................(no files to check)Skipped
|
|
190
|
+
fix end of files.........................................................Passed
|
|
191
|
+
trim trailing whitespace.................................................Passed
|
|
192
|
+
check json...............................................................Passed
|
|
193
|
+
check yaml...............................................................Passed
|
|
194
|
+
check for merge conflicts................................................Passed
|
|
176
195
|
```
|
|
177
196
|
|
|
178
197
|
(This will create a `./demo-password.txt` file that will need to be deleted separately)
|
package/bin/prepare.sh
CHANGED
|
@@ -40,13 +40,6 @@ if ! command -v brew > /dev/null 2> /dev/null; then
|
|
|
40
40
|
exit 0
|
|
41
41
|
fi
|
|
42
42
|
|
|
43
|
-
# Install gitleaks if not present - this will be used by prek for secret scanning until we move over to devsecops hooks
|
|
44
|
-
if ! command -v gitleaks > /dev/null 2> /dev/null; then
|
|
45
|
-
startStage "Installing gitleaks"
|
|
46
|
-
brew install gitleaks
|
|
47
|
-
endStage " ✅ "
|
|
48
|
-
fi
|
|
49
|
-
|
|
50
43
|
# Install prek
|
|
51
44
|
if ! command -v prek > /dev/null 2> /dev/null; then
|
|
52
45
|
startStage "Installing prek"
|
package/default-hooks.yaml
CHANGED
|
@@ -5,19 +5,16 @@
|
|
|
5
5
|
# Other hooks maybe added or removed as needed to suit individual project requirements.
|
|
6
6
|
|
|
7
7
|
repos:
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
- repo: https://github.com/ministryofjustice/devsecops-hooks
|
|
9
|
+
rev: v1.4.1
|
|
10
|
+
hooks:
|
|
11
|
+
- id: baseline
|
|
12
|
+
env:
|
|
13
|
+
GITLEAKS_CONFIGURATION_FILE: ./.gitleaks/gitleaks.toml
|
|
14
|
+
GITLEAKS_IGNORE_FILE: ./.gitleaks/.gitleaksignore
|
|
15
|
+
|
|
13
16
|
- repo: local
|
|
14
17
|
hooks:
|
|
15
|
-
- id: gitleaks
|
|
16
|
-
name: Scan commit for secrets
|
|
17
|
-
language: system
|
|
18
|
-
entry: gitleaks git --pre-commit --redact --staged --verbose --config .gitleaks/config.toml --gitleaks-ignore-path .gitleaks/.gitleaksignore
|
|
19
|
-
require_serial: true
|
|
20
|
-
pass_filenames: false
|
|
21
18
|
- id: lint
|
|
22
19
|
name: linting code
|
|
23
20
|
language: system
|