From a269d079daeb728b7caa37c0cc6ebd4f52908e5e Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 3 Nov 2026 01:05:04 +0000 Subject: [PATCH 1/2] ci: add a dedicated gitleaks secret scan Keep secret scanning in its own workflow so every pull request is scanned, pin gitleaks 8.30.1, and limit the token to contents and pull-request reads. Co-authored-by: Nico S --- .github/workflows/gitleaks.yml | 53 ++++++++++++++++++++++++++++++++++ oss_release_test.go | 51 ++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 .github/workflows/gitleaks.yml diff --git a/.github/workflows/gitleaks.yml b/.github/workflows/gitleaks.yml new file mode 100644 index 0000000..849fca0 --- /dev/null +++ b/.github/workflows/gitleaks.yml @@ -0,0 +1,53 @@ +name: gitleaks + +on: + push: + branches: [main] + pull_request: + workflow_dispatch: + +permissions: + contents: read + pull-requests: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +# Range job (push/PR): gitleaks-action scans base^..head only. +# fetch-depth: 0 is required so that parent exists. +# Full-history job is workflow_dispatch only — not on every PR. +jobs: + gitleaks: + if: github.event_name != 'workflow_dispatch' + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 0 + persist-credentials: false + - name: Secret scan + uses: gitleaks/gitleaks-action@e0c47f4f8be36e29cdc102c57e68cb5cbf0e8d1e # v3.0.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITLEAKS_VERSION: "8.30.1" + GITLEAKS_ENABLE_COMMENTS: false + GITLEAKS_ENABLE_UPLOAD_ARTIFACT: false + + gitleaks-full-history: + if: github.event_name == 'workflow_dispatch' + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 0 + persist-credentials: false + - name: Secret scan (full history) + uses: gitleaks/gitleaks-action@e0c47f4f8be36e29cdc102c57e68cb5cbf0e8d1e # v3.0.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITLEAKS_VERSION: "8.30.1" + GITLEAKS_ENABLE_COMMENTS: false + GITLEAKS_ENABLE_UPLOAD_ARTIFACT: false diff --git a/oss_release_test.go b/oss_release_test.go index a7f147b..39e6dea 100644 --- a/oss_release_test.go +++ b/oss_release_test.go @@ -75,3 +75,54 @@ func TestCIWorkflowPinsTheLintToolchain(t *testing.T) { } } } + +func TestGitleaksWorkflowIsDedicatedAndFailClosed(t *testing.T) { + body := readOSSTestFile(t, filepath.Join(".github", "workflows", "gitleaks.yml")) + ci := readOSSTestFile(t, filepath.Join(".github", "workflows", "ci.yml")) + release := readOSSTestFile(t, filepath.Join(".github", "workflows", "release-beta.yml")) + if strings.Contains(ci, "gitleaks") || strings.Contains(release, "gitleaks") { + t.Fatal("secret scan is folded into another workflow") + } + for _, required := range []string{ + "push:\n branches: [main]\n pull_request:\n workflow_dispatch:", + "permissions:\n contents: read\n pull-requests: read\n", + " gitleaks:\n if: github.event_name != 'workflow_dispatch'", + " gitleaks-full-history:\n if: github.event_name == 'workflow_dispatch'", + "actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1", + "fetch-depth: 0", + "persist-credentials: false", + "gitleaks/gitleaks-action@e0c47f4f8be36e29cdc102c57e68cb5cbf0e8d1e # v3.0.0", + `GITLEAKS_VERSION: "8.30.1"`, + "GITLEAKS_ENABLE_COMMENTS: false", + "GITLEAKS_ENABLE_UPLOAD_ARTIFACT: false", + } { + if !strings.Contains(body, required) { + t.Errorf("gitleaks workflow is missing %q", required) + } + } + for _, pinned := range []string{ + "actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1", + "gitleaks/gitleaks-action@e0c47f4f8be36e29cdc102c57e68cb5cbf0e8d1e # v3.0.0", + " fetch-depth: 0\n", + " persist-credentials: false\n", + ` GITLEAKS_VERSION: "8.30.1"`, + " GITLEAKS_ENABLE_COMMENTS: false", + " GITLEAKS_ENABLE_UPLOAD_ARTIFACT: false", + } { + if strings.Count(body, pinned) != 2 { + t.Errorf("gitleaks workflow has %d copies of %q, want 2", strings.Count(body, pinned), pinned) + } + } + for _, forbidden := range []string{ + "paths-ignore:", + "paths:", + "write", + "8.24.3", + "pre-commit", + "GITLEAKS_LICENSE", + } { + if strings.Contains(body, forbidden) { + t.Errorf("gitleaks workflow contains %q", forbidden) + } + } +} From a4ffed039df05a59b1999d3a7ccd8d336da2d8bd Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 3 Nov 2026 01:08:22 +0000 Subject: [PATCH 2/2] test: accept CRLF when checking the gitleaks workflow Windows runners check the workflow out with CRLF, so the contract test normalizes line endings before it compares the workflow text. Co-authored-by: Nico S --- oss_release_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/oss_release_test.go b/oss_release_test.go index 39e6dea..b0aebd3 100644 --- a/oss_release_test.go +++ b/oss_release_test.go @@ -77,9 +77,9 @@ func TestCIWorkflowPinsTheLintToolchain(t *testing.T) { } func TestGitleaksWorkflowIsDedicatedAndFailClosed(t *testing.T) { - body := readOSSTestFile(t, filepath.Join(".github", "workflows", "gitleaks.yml")) - ci := readOSSTestFile(t, filepath.Join(".github", "workflows", "ci.yml")) - release := readOSSTestFile(t, filepath.Join(".github", "workflows", "release-beta.yml")) + body := strings.ReplaceAll(readOSSTestFile(t, filepath.Join(".github", "workflows", "gitleaks.yml")), "\r\n", "\n") + ci := strings.ReplaceAll(readOSSTestFile(t, filepath.Join(".github", "workflows", "ci.yml")), "\r\n", "\n") + release := strings.ReplaceAll(readOSSTestFile(t, filepath.Join(".github", "workflows", "release-beta.yml")), "\r\n", "\n") if strings.Contains(ci, "gitleaks") || strings.Contains(release, "gitleaks") { t.Fatal("secret scan is folded into another workflow") }