Repository navigation
45 lines (39 loc) · 1.61 KB
/
Copy pathgitleaks.yml
File metadata and controls
45 lines (39 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
name: gitleaks
# Blocks new secrets (passwords, API keys, tokens) from landing in this repo.
# Scans only the commits a push or pull request adds, so old history does not turn CI red.
on:
push:
pull_request:
workflow_dispatch:
permissions:
contents: read
jobs:
scan:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install gitleaks
run: |
curl -sSfL https://github.com/gitleaks/gitleaks/releases/download/v8.24.0/gitleaks_8.24.0_linux_x64.tar.gz \
| tar -xz -C /usr/local/bin gitleaks
- name: Scan new commits for secrets
env:
PR_BASE: ${{ github.event.pull_request.base.sha }}
PR_HEAD: ${{ github.event.pull_request.head.sha }}
BEFORE: ${{ github.event.before }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
run: |
if [ -n "$PR_BASE" ]; then
RANGE="$PR_BASE..$PR_HEAD"
elif [ -n "$BEFORE" ] && ! echo "$BEFORE" | grep -qE '^0+$' && git cat-file -e "$BEFORE^{commit}" 2>/dev/null; then
RANGE="$BEFORE..$GITHUB_SHA"
elif [ "$GITHUB_REF_NAME" != "$DEFAULT_BRANCH" ] && git rev-parse -q --verify "origin/$DEFAULT_BRANCH" >/dev/null; then
RANGE="origin/$DEFAULT_BRANCH..$GITHUB_SHA" # new branch: only its own commits
else
RANGE="-1 $GITHUB_SHA" # first push / force push: latest commit
fi
echo "Scanning: $RANGE"
gitleaks git . --log-opts="$RANGE" --redact --verbose --exit-code 1