Skip to content

Commit 2806662

Browse files
committed
Use RUNNER_TEMP for gitleaks and add flags
Download and extract gitleaks into a temporary RUNNER_TEMP directory ($toolDir) and remove any existing copy before extraction. Adjust Expand-Archive/tar commands to use $toolDir and resolve the executable from that path. Add a step to remove vendored tool docs from the scan scope to avoid known false positives. Run gitleaks with --no-git and --exit-code 1 so the scan targets the working tree and fails the job on findings.
1 parent 594a3c4 commit 2806662

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

.github/workflows/ci-devsecops.yml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,29 @@ jobs:
6868
$baseUrl = "https://github.com/gitleaks/gitleaks/releases/download/v$version"
6969
$zipAsset = "gitleaks_${version}_windows_x64.zip"
7070
$tarAsset = "gitleaks_${version}_windows_x64.tar.gz"
71+
$toolDir = Join-Path $env:RUNNER_TEMP "gitleaks-bin"
72+
73+
if (Test-Path $toolDir) {
74+
Remove-Item -Path $toolDir -Recurse -Force
75+
}
7176
7277
try {
7378
Invoke-WebRequest -Uri "$baseUrl/$zipAsset" -OutFile "gitleaks.zip"
74-
Expand-Archive -Path "gitleaks.zip" -DestinationPath ".\\gitleaks-bin" -Force
79+
Expand-Archive -Path "gitleaks.zip" -DestinationPath $toolDir -Force
7580
}
7681
catch {
7782
Invoke-WebRequest -Uri "$baseUrl/$tarAsset" -OutFile "gitleaks.tar.gz"
78-
New-Item -ItemType Directory -Force -Path ".\\gitleaks-bin" | Out-Null
79-
tar -xzf "gitleaks.tar.gz" -C ".\\gitleaks-bin"
83+
New-Item -ItemType Directory -Force -Path $toolDir | Out-Null
84+
tar -xzf "gitleaks.tar.gz" -C $toolDir
85+
}
86+
87+
# Remove vendored tool docs from scan scope to avoid known upstream sample false positives.
88+
if (Test-Path ".\\gitleaks-bin") {
89+
Remove-Item -Path ".\\gitleaks-bin" -Recurse -Force
8090
}
8191
82-
$gitleaksExe = Resolve-Path ".\\gitleaks-bin\\gitleaks.exe"
83-
& $gitleaksExe detect --source "." --redact --verbose --report-format json --report-path gitleaks-report.json
92+
$gitleaksExe = Resolve-Path (Join-Path $toolDir "gitleaks.exe")
93+
& $gitleaksExe detect --source "." --no-git --exit-code 1 --redact --verbose --report-format json --report-path gitleaks-report.json
8494
8595
- name: Upload security artifacts
8696
if: always()

0 commit comments

Comments
 (0)