Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions .github/workflows/secrets-scan.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Secrets scan

# Reusable secrets-scan workflow for DVSA repositories.
# Standardised on awslabs/git-secrets with the AWS provider patterns —
# matches the convention used across DVSA (MOT, CVS, RSP, theory-test, …).
#
# Invoke from a repo via:
# jobs:
# secrets:
# uses: dvsa/.github/.github/workflows/secrets-scan.yaml@main

on:
workflow_call:
inputs:
fail-on-detection:
description: Fail the job when leaks are found.
type: boolean
default: true
scan-history:
description: Also run `git secrets --scan-history` (full git log). Slower; off by default for PR runs.
type: boolean
default: false

permissions:
contents: read
pull-requests: read

jobs:
git-secrets:
name: git-secrets
runs-on: ubuntu-latest
steps:
- name: Checkout (full history)
uses: actions/checkout@v6
with:
fetch-depth: 0
Comment on lines +33 to +36
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The workflow always checks out full git history (fetch-depth: 0) even when inputs.scan-history is false, which undermines the “fast on PRs” intent and can be slow for large repositories. Consider using a conditional/parameterized fetch-depth (0 only when scan-history is true; otherwise default/shallow).

Suggested change
- name: Checkout (full history)
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: ${{ inputs.scan-history && 0 || 1 }}

Copilot uses AI. Check for mistakes.

- name: Install git-secrets
run: |
set -euo pipefail
tmp="$(mktemp -d)"
git clone --quiet --depth 1 https://github.com/awslabs/git-secrets "$tmp"
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This installs git-secrets by cloning and executing build scripts from GitHub at runtime and then running sudo make install. To reduce supply-chain risk and improve reproducibility, pin the clone to a specific tag/commit (or use a packaged/released artifact with integrity verification) rather than the repo’s moving default branch.

Suggested change
git clone --quiet --depth 1 https://github.com/awslabs/git-secrets "$tmp"
git clone --quiet --depth 1 --branch 1.3.0 --single-branch https://github.com/awslabs/git-secrets "$tmp"

Copilot uses AI. Check for mistakes.
sudo make -C "$tmp" install >/dev/null
git secrets --version || git --exec-path
# Register canonical AWS patterns into the workspace's repo config.
git secrets --register-aws

- name: Scan working tree
id: scan-tree
continue-on-error: ${{ !inputs.fail-on-detection }}
run: |
set +e
out="$(git secrets --scan -r 2>&1)"
rc=$?
if [ -n "$out" ]; then
printf '%s\n' "$out"
fi
if [ $rc -ne 0 ]; then
echo
echo "::error::git-secrets found potential secrets in the working tree."
fi
exit $rc

- name: Scan full history
if: ${{ inputs.scan-history }}
continue-on-error: ${{ !inputs.fail-on-detection }}
run: |
set +e
out="$(git secrets --scan-history 2>&1)"
rc=$?
if [ -n "$out" ]; then
printf '%s\n' "$out"
fi
if [ $rc -ne 0 ]; then
echo
echo "::error::git-secrets found potential secrets in repository history."
fi
exit $rc
7 changes: 7 additions & 0 deletions workflow-templates/secrets-scan.properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "Secrets scan (git-secrets)",
"description": "Scan the repository for committed secrets using awslabs/git-secrets with the canonical AWS pattern set. Calls the shared dvsa/.github reusable workflow.",
"iconName": "octicon shield-lock",
"categories": ["Security"],
"filePatterns": [".*"]
}
21 changes: 21 additions & 0 deletions workflow-templates/secrets-scan.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Secrets scan

on:
pull_request:
push:
branches: [main, master]
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This template hard-codes branches: [main, master] for push. Other workflow templates in this repo use the $default-branch placeholder so the template works in repos whose default branch is neither main nor master (e.g. workflow-templates/php-security.yml:5). Consider switching to branches: [ $default-branch ] for consistency and correctness.

Suggested change
branches: [main, master]
branches: [ $default-branch ]

Copilot uses AI. Check for mistakes.
schedule:
# Weekly on Monday at 00:00 UTC, matching workflow-templates/php-security.yml.
- cron: 0 0 * * 1
workflow_dispatch:

permissions:
contents: read
pull-requests: read

jobs:
secrets:
uses: dvsa/.github/.github/workflows/secrets-scan.yaml@main
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The template references the reusable workflow with @main. In this repo’s other templates, reusable workflows are pinned to a released version tag (e.g. workflow-templates/php-security.yml:13 uses @v5.0.6) to avoid unexpected breaking changes for consumers. Consider pinning to a version tag and updating it on release.

Suggested change
uses: dvsa/.github/.github/workflows/secrets-scan.yaml@main
uses: dvsa/.github/.github/workflows/secrets-scan.yaml@v5.0.6

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes would want to do that @fibble

with:
# Run a full-history scan on the weekly cron only (fast on PRs).
scan-history: ${{ github.event_name == 'schedule' }}
Loading