Skip to content

Commit e6692a8

Browse files
committed
Added interval, cooldown for dependabot and scan secrets
1 parent 255ec2b commit e6692a8

3 files changed

Lines changed: 134 additions & 11 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: "Scan secrets"
2+
description: "Scan secrets"
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: "Scan secrets"
7+
shell: bash
8+
run: |
9+
# Please do not change this `check=whole-history` setting, as new patterns may be added or history may be rewritten.
10+
check=whole-history ./scripts/githooks/scan-secrets.sh

.github/dependabot.yml

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,48 +7,50 @@ updates:
77
- package-ecosystem: "pip"
88
directory: "/"
99
schedule:
10-
interval: "daily"
10+
interval: "weekly"
1111
target-branch: "master"
12-
labels: ["dependencies", "python", "poetry"]
12+
labels: [ "dependencies", "python", "poetry" ]
1313
open-pull-requests-limit: 10
1414
ignore:
1515
- dependency-name: "*"
16-
update-types: ["version-update:semver-major"]
16+
update-types: [ "version-update:semver-major" ]
1717

1818
# ---------------------------
1919
# NodeJS (root)
2020
# ---------------------------
2121
- package-ecosystem: "npm"
2222
directory: "/"
2323
schedule:
24-
interval: "daily"
24+
interval: "weekly"
2525
target-branch: "master"
26-
labels: ["dependencies", "npm"]
26+
labels: [ "dependencies", "npm" ]
2727
open-pull-requests-limit: 10
2828
ignore:
2929
- dependency-name: "*"
30-
update-types: ["version-update:semver-major"]
30+
update-types: [ "version-update:semver-major" ]
3131

3232
# ---------------------------
3333
# NodeJS (sandbox/)
3434
# ---------------------------
3535
- package-ecosystem: "npm"
3636
directory: "/sandbox"
3737
schedule:
38-
interval: "daily"
38+
interval: "weekly"
3939
target-branch: "master"
40-
labels: ["dependencies", "npm", "sandbox"]
40+
labels: [ "dependencies", "npm", "sandbox" ]
4141
open-pull-requests-limit: 10
4242
ignore:
4343
- dependency-name: "*"
44-
update-types: ["version-update:semver-major"]
44+
update-types: [ "version-update:semver-major" ]
4545

4646
# ---------------------------
4747
# GitHub Actions
4848
# ---------------------------
4949
- package-ecosystem: "github-actions"
5050
directory: "/"
5151
schedule:
52-
interval: "daily"
52+
interval: "weekly"
5353
target-branch: "master"
54-
labels: ["dependencies", "github-actions"]
54+
labels: [ "dependencies", "github-actions" ]
55+
cooldown:
56+
default-days: 7

scripts/githooks/scan-secrets.sh

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#!/bin/bash
2+
3+
# WARNING: Please, DO NOT edit this file! It is maintained in the Repository Template (https://github.com/nhs-england-tools/repository-template). Raise a PR instead.
4+
5+
set -euo pipefail
6+
7+
# Pre-commit git hook to scan for secrets hard-coded in the codebase. This is a
8+
# gitleaks command wrapper. It will run gitleaks natively if it is installed,
9+
# otherwise it will run it in a Docker container.
10+
#
11+
# Usage:
12+
# $ [options] ./scan-secrets.sh
13+
#
14+
# Options:
15+
# check={whole-history,last-commit,staged-changes} # Type of the check to run, default is 'staged-changes'
16+
# FORCE_USE_DOCKER=true # If set to true the command is run in a Docker container, default is 'false'
17+
# VERBOSE=true # Show all the executed commands, default is 'false'
18+
#
19+
# Exit codes:
20+
# 0 - No leaks present
21+
# 1 - Leaks or error encountered
22+
# 126 - Unknown flag
23+
24+
# ==============================================================================
25+
26+
function main() {
27+
28+
cd "$(git rev-parse --show-toplevel)"
29+
30+
if command -v gitleaks > /dev/null 2>&1 && ! is-arg-true "${FORCE_USE_DOCKER:-false}"; then
31+
dir="$PWD"
32+
cmd="$(get-cmd-to-run)" run-gitleaks-natively
33+
else
34+
dir="/workdir"
35+
cmd="$(get-cmd-to-run)" run-gitleaks-in-docker
36+
fi
37+
}
38+
39+
# Get Gitleaks command to execute and configuration.
40+
# Arguments (provided as environment variables):
41+
# dir=[project's top-level directory]
42+
function get-cmd-to-run() {
43+
44+
check=${check:-staged-changes}
45+
case $check in
46+
"whole-history")
47+
cmd="detect --source $dir --verbose --redact"
48+
;;
49+
"last-commit")
50+
cmd="detect --source $dir --verbose --redact --log-opts -1"
51+
;;
52+
"staged-changes")
53+
cmd="protect --source $dir --verbose --staged"
54+
;;
55+
esac
56+
# Include base line file if it exists
57+
if [ -f "$dir/scripts/config/.gitleaks-baseline.json" ]; then
58+
cmd="$cmd --baseline-path $dir/scripts/config/.gitleaks-baseline.json"
59+
fi
60+
# Include the config file
61+
cmd="$cmd --config $dir/scripts/config/gitleaks.toml"
62+
63+
echo "$cmd"
64+
}
65+
66+
# Run Gitleaks natively.
67+
# Arguments (provided as environment variables):
68+
# cmd=[command to run]
69+
function run-gitleaks-natively() {
70+
71+
# shellcheck disable=SC2086
72+
gitleaks $cmd
73+
}
74+
75+
# Run Gitleaks in a Docker container.
76+
# Arguments (provided as environment variables):
77+
# cmd=[command to run]
78+
# dir=[directory to mount as a volume]
79+
function run-gitleaks-in-docker() {
80+
81+
# shellcheck disable=SC1091
82+
source ./scripts/docker/docker.lib.sh
83+
84+
# shellcheck disable=SC2155
85+
local image=$(name=ghcr.io/gitleaks/gitleaks docker-get-image-version-and-pull)
86+
# shellcheck disable=SC2086
87+
docker run --rm --platform linux/amd64 \
88+
--volume "$PWD:$dir" \
89+
--workdir $dir \
90+
"$image" \
91+
$cmd
92+
}
93+
94+
# ==============================================================================
95+
96+
function is-arg-true() {
97+
98+
if [[ "$1" =~ ^(true|yes|y|on|1|TRUE|YES|Y|ON)$ ]]; then
99+
return 0
100+
else
101+
return 1
102+
fi
103+
}
104+
105+
# ==============================================================================
106+
107+
is-arg-true "${VERBOSE:-false}" && set -x
108+
109+
main "$@"
110+
111+
exit 0

0 commit comments

Comments
 (0)