Skip to content

feat(security): run gitleaks in the commit hook and in CI #7221

Description

@dan-petty

Problem or Motivation

No secret scanner stops a commit, a push or a merge.

  • .pre-commit-config.yaml has only detect-private-key.
  • grep -n -i -E "gitleaks|trufflehog|detect-secrets" .github/workflows/*.yml finds only the tool install of copilot-setup-steps.yml.
  • The CI step Security Scan of ci.yml writes a SARIF report and sets no failure threshold.
  • GitHub secret scanning with push protection is on, but it covers provider patterns only: secret_scanning_non_provider_patterns is disabled (read from the repository settings on 2026-11-25).

So a generic password, a token of an internal service or a key of an unlisted provider can reach a public repository. The repository already has a gitleaks scanner in devops scan (tests/security/test_security_gitleaks.py), but no hook and no workflow runs it.

Found by the workflow gap analysis of 2026-11-25.

Proposed Solution

Disposition: change the configuration.

  • Add the gitleaks hook of the gitleaks project to .pre-commit-config.yaml (pre-commit stage).
  • Run gitleaks on the pull request range in the job Static Analysis and fail on a finding.
  • A person can also turn on the non-provider patterns in the repository settings.

Proof: a commit with a test token in a scratch branch fails the hook, and uv run devops ci --check --only actionlint,zizmor passes.

Existing Tool Considered

gitleaks (MIT), with its own pre-commit hook. No new code.

Alternatives check of 2026-11-25: in-use.
The repository already uses this tool.
Tool: gitleaks/gitleaks (https://github.com/gitleaks/gitleaks), MIT, last activity 2026-11-25, maintained.
Reason: Searches found gitleaks as the maintained MIT scanner with its own pre-commit hook and a CLI for a pull-request range; the issue already names it as the scanner in devops scan, and it covers the hook and CI need.

Covers:

  • Pre-commit hook that fails a commit with a secret
  • CLI scan of a commit or pull request range
  • Configurable rules for generic passwords and internal tokens

Lacks:

  • GitHub non-provider patterns still need a person to enable
  • Needs a gitleaks config and a step in Static Analysis
  • Scans no history until someone runs it on old commits

Proposed design

Problem statement

No secret scanner stops a commit, a push or a merge. The repository holds a gitleaks scanner in devops scan, but no hook and no workflow runs it. A generic password, a token of an internal service or a key of an unlisted provider can reach a public repository.

Acceptance criteria

Requirement: Gitleaks hook on commit

The repository MUST run the gitleaks scanner at the pre-commit stage of each commit.

Scenario: A staged test token stops the commit

  • WHEN A person stages a file that holds a test token and runs pre-commit run gitleaks
  • THEN The hook exits 1 and prints the gitleaks rule ID of the match.

Requirement: Gitleaks configuration accepts the test fixtures

The repository SHALL hold a .gitleaks.toml that extends the default rules and allowlists the paths of the test fixtures.

Scenario: A staged fake GitHub token in a test passes the hook

  • WHEN A person stages a new line with ghp_1234567890abcdefghijklmnopqrstuvwxyz in tests/security/test_security_gitleaks.py and runs pre-commit run gitleaks
  • THEN The hook exits 0 and prints no leaks found.

Requirement: Gitleaks scans the pull request range in CI

The Static Analysis job MUST install gitleaks and run it on the commits of the pull request range, and MUST fail on a finding.

Scenario: A test token in a scratch pull request fails the job

  • WHEN A person pushes a scratch branch with a test token and opens a draft pull request
  • THEN The gitleaks step exits 1 and the Static Analysis job reports a failure.

Requirement: The workflow files pass the workflow checks

The changed workflow file MUST pass the workflow checks of the repository.

Scenario: The workflow checks pass

  • WHEN A person runs uv run devops ci --check --only actionlint,zizmor
  • THEN The command exits 0 and reports no finding.

Requirement: Pending a person after the merge

A person MUST enable secret scanning non-provider patterns for the repository after the merge.

Scenario: The repository reports the non-provider patterns enabled

  • WHEN A person runs uv run devops gh api repos/dan-petty/devops-cli --jq '.security_and_analysis.secret_scanning_non_provider_patterns.status'
  • THEN The command prints enabled.

Existing Tool Considered

gitleaks (https://github.com/gitleaks/gitleaks), MIT, verdict in-use: the repository already runs it in devops scan. The alternatives check in the issue body states what the tool covers and lacks. The proposal supplies what the tool lacks: a .gitleaks.toml that allowlists the test fixtures, and a step in the Static Analysis job that installs gitleaks and scans the pull request range. The change builds no code of its own.

Key questions

  • Which form of the gitleaks hook goes into .pre-commit-config.yaml?: A local hook with language: system runs gitleaks git --pre-commit --redact --staged --verbose --config .gitleaks.toml. The devtools image ships the gitleaks binary and each local hook of this file uses language: system. (best practice) [sources: .pre-commit-config.yaml]
    • Chosen: local hook with language system. The devtools image copies the gitleaks binary to /usr/local/bin and the local hooks of this file run system commands, so no hook environment is built.
    • Rejected: upstream hook repository with language golang. pre-commit builds the tool with the Go toolchain at install time in each environment, while the image already holds the binary.
  • How does the hook accept the test fixtures that hold fake tokens?: Add .gitleaks.toml that extends the default rules and allowlists the paths of the test fixtures. The hook and the CI step pass --config .gitleaks.toml. (best practice) [sources: tests/security/test_security_gitleaks.py, .pre-commit-config.yaml]
    • Chosen: .gitleaks.toml with a path allowlist. The config holds the allowlist for the fixture paths, and one file serves the hook and the CI step.
    • Rejected: .gitleaksignore with fingerprints. A fingerprint changes when the line changes, so the allowlist stops working after an edit.
    • Rejected: exclude the paths in the hook arguments. The gitleaks command has no path exclude for the staged scan, so the config holds the allowlist.
  • Where does the CI scan run, and how does it get the gitleaks binary?: Add a step to the Static Analysis job of .github/workflows/ci.yml. The step installs gitleaks with the tool install of .github/workflows/copilot-setup-steps.yml line 71 and runs gitleaks git on the range from the base branch to HEAD. (best practice) [sources: .github/workflows/ci.yml, .github/workflows/copilot-setup-steps.yml:71]
    • Chosen: step in the Static Analysis job. The job already runs the devops ci rows and is a required check, so a finding stops the merge (ADR 0004).
    • Rejected: step in the Security Scan step. That step uploads a SARIF report and sets no failure threshold, so a finding does not stop the merge.
    • Rejected: a new workflow. A second workflow adds a required check to configure and repeats the setup of the static analysis job.
  • Does the hook scan the staged index or the working tree?: The hook scans the staged index with --staged. It judges the commit only and ignores the untracked scratch files under .data/agent/. (best practice) [sources: .pre-commit-config.yaml, AGENTS.md]
    • Chosen: staged index. The hook judges what the commit adds, and it skips untracked scratch files.
    • Rejected: working tree scan. It reads the untracked files of .data/agent/ and each gitignored file, so a scratch secret stops an unrelated commit.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    type/feature
    on Nov 25, 2026
  2. dan-petty commented on Nov 25, 2026

    @dan-petty
    OwnerAuthor
  3. added
    scope/security
    source/agent
    status/new
    effort/low
    value/high
    priority/p2-medium
    on Nov 25, 2026
  4. devops-cli-service commented on Nov 25, 2026

    @devops-cli-service
    Contributor

    The result in the alternatives block of the issue body changed. Before this check: no check. A person decides what the new result means for the item.

    Searches (4)

    Tools considered:

    Searches run:

    • trufflehog vs gitleaks CI secret scanning pre-commit, results: 5
    • gitleaks pre-commit hook secret scanning, results: 5
    • gitleaks github secret scanner repository, results: 5
    • pre-commit secret scanning hook gitleaks trufflehog detect-secrets comparison, results: 5

    Sources:

  5. added
    status/ready
    and removed
    status/new
    on Nov 28, 2026
  6. devops-cli-service commented on Nov 28, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See the section Proposed design of the body.

  7. added
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 29, 2026
  8. removed
    status/in-review
    owner/agent
    on Nov 29, 2026
  9. devops-cli-service commented on Nov 29, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-29 11:55 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/lowpriority/p2-mediumscope/securitysource/agenttype/featurevalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions