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
53 changes: 53 additions & 0 deletions .github/workflows/gitleaks.yml
Original file line number Diff line number Diff line change
@@ -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
51 changes: 51 additions & 0 deletions oss_release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,54 @@ func TestCIWorkflowPinsTheLintToolchain(t *testing.T) {
}
}
}

func TestGitleaksWorkflowIsDedicatedAndFailClosed(t *testing.T) {
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")
}
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)
}
}
}
Loading