Skip to content
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e82102c
gitleaks template
rtrofimenkov-ssdlc Oct 1, 2025
a54fba5
path fix, added stage
rtrofimenkov-ssdlc Oct 1, 2025
cae3213
added docker runner tag
rtrofimenkov-ssdlc Oct 3, 2025
5873642
tags fix
rtrofimenkov-ssdlc Oct 3, 2025
1757f8c
pipeline refactor for shell executor
rtrofimenkov-ssdlc Oct 3, 2025
a5424e6
gitleaks pipe refactor
rtrofimenkov-ssdlc Oct 3, 2025
15c6f4e
Add empty before_script to gitleaks CI template
rtrofimenkov-ssdlc Oct 3, 2025
5beb601
PATH fix
rtrofimenkov-ssdlc Oct 3, 2025
3ab3279
Add gitleaks cleanup stage to CI template
rtrofimenkov-ssdlc Oct 3, 2025
756db32
Update gitleaks CI template to include optional dependencies and rule…
rtrofimenkov-ssdlc Oct 3, 2025
b75394c
updated error parsind and printing to stdout
rtrofimenkov-ssdlc Oct 3, 2025
0682948
stdout fix
rtrofimenkov-ssdlc Oct 3, 2025
f258301
output fix
rtrofimenkov-ssdlc Oct 3, 2025
189b0c2
stdout fix
rtrofimenkov-ssdlc Oct 3, 2025
87fdbb4
fixed cleanup stage
rtrofimenkov-ssdlc Oct 6, 2025
e926559
cleanup fix
rtrofimenkov-ssdlc Oct 6, 2025
a1aaba1
cleanup stage fix
rtrofimenkov-ssdlc Oct 6, 2025
c5f7a6d
depth fix
rtrofimenkov-ssdlc Oct 6, 2025
42792b4
deleted cleanup stage
rtrofimenkov-ssdlc Oct 7, 2025
9e6abde
report fix
rtrofimenkov-ssdlc Oct 7, 2025
bf9395f
Refactor cleanup process in GitLab CI configuration to use after_scri…
rtrofimenkov-ssdlc Oct 7, 2025
db4be4a
Remove redundant stages declaration from gitleaks template
rtrofimenkov-ssdlc Oct 14, 2025
4e1f49e
fix: add GitLab server host to gitleaks blob URLs
rtrofimenkov-ssdlc Oct 14, 2025
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
131 changes: 131 additions & 0 deletions templates/gitleaks.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
variables:
GITLEAKS_VERSION: "v8.28.0"

.gitleaks_scan:
stage: gitleaks
before_script: []
script:
- |
set -euo pipefail

# ========== Install Gitleaks ==========
echo "📥 Installing Gitleaks $GITLEAKS_VERSION..."
file_ver="${GITLEAKS_VERSION#v}"
arch="$(uname -m)"
case "$arch" in
x86_64|amd64) pkg_arch="linux_x64" ;;
aarch64|arm64) pkg_arch="linux_arm64" ;;
*) echo "Unsupported arch: $arch"; exit 1 ;;
esac

base="https://github.com/gitleaks/gitleaks/releases/download/${GITLEAKS_VERSION}"
tgz="gitleaks_${file_ver}_${pkg_arch}.tar.gz"
curl -sSL "$base/$tgz" -o gitleaks.tgz
tar -xzf gitleaks.tgz gitleaks
chmod +x gitleaks
mkdir -p "$HOME/.local/bin"
mv gitleaks "$HOME/.local/bin/"
export PATH="$HOME/.local/bin:$PATH"
gitleaks version

# ========== Check for config ==========
if [[ -f "gitleaks.toml" ]]; then
CONFIG_ARG="-c gitleaks.toml"
echo "✅ Found config: gitleaks.toml"
else
CONFIG_ARG=""
echo "⚠️ Config file not found. Proceeding with default rules."
fi

# ========== Run scan ==========
GITLEAKS_EXIT=0
if [[ "$SCAN_MODE" == "diff" ]]; then
echo "🕵️ Running in DIFF mode..."
git fetch origin "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME" --depth=1
BASE_SHA=$(git merge-base origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME HEAD || echo "")
if [[ -z "$BASE_SHA" ]]; then
echo "❌ BASE_SHA not found. Aborting."
exit 1
fi
echo "▶ Scanning diff: $BASE_SHA...HEAD"
gitleaks detect --no-banner --report-format json --report-path gitleaks.json $CONFIG_ARG --source . --log-opts "$BASE_SHA...HEAD" || GITLEAKS_EXIT=$?
elif [[ "$SCAN_MODE" == "full" ]]; then
echo "🕵️ Running in FULL mode..."
gitleaks detect --no-banner --report-format json --report-path gitleaks.json $CONFIG_ARG --source . || GITLEAKS_EXIT=$?
else
echo "❌ Unknown SCAN_MODE: $SCAN_MODE"
exit 1
fi

echo "🔍 Gitleaks exit code: $GITLEAKS_EXIT"

# ========== Parse and print results ==========
echo "📤 Parsing gitleaks.json for CI log output..."
echo "DEBUG: Checking gitleaks.json file..."
ls -lh gitleaks.json || echo "⚠️ gitleaks.json not found!"

if [[ -s gitleaks.json ]]; then
COUNT=$(jq length gitleaks.json)
echo "❌ Leaks found: $COUNT"
echo ""
echo "DEBUG: Attempting to parse and display leaks..."

jq -r '
def norm:
{
file: (.File // .file // .Target // .Location.File // "unknown"),
line: (.StartLine // .Line // .Location.StartLine // 0),
rule: (.RuleID // .Rule // .Description // "unknown"),
commit: (.Commit // .commit // "")
};
(if type=="object" and has("findings") then .findings
elif type=="array" then .
else [] end)[] | norm
| "• [\(.rule)] \(.file):\(.line) \(.commit[0:7] // "no-commit") '$CI_PROJECT_URL'/blob/\(.commit)/\(.file)#L\(.line)"
' gitleaks.json | head -n 200

echo ""
echo "DEBUG: Finished displaying leaks"

# Fail the job if leaks were found
if [[ "$COUNT" -gt 0 ]]; then
echo ""
echo "❌ Pipeline failed due to $COUNT leak(s). Review gitleaks.json artifact."
exit 1
fi
else
echo "✅ No leaks found."
fi

after_script:
- echo "🧹 Cleaning up runner workspace..."
- rm -f "$HOME/.local/bin/gitleaks" gitleaks.tgz || true

artifacts:
when: always
paths:
- gitleaks.json

allow_failure: false

gitleaks_diff:
extends: .gitleaks_scan
variables:
SCAN_MODE: "diff"
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'

gitleaks_full_manual:
extends: .gitleaks_scan
variables:
SCAN_MODE: "full"
rules:
- if: '$CI_PIPELINE_SOURCE == "web"'

gitleaks_full_scheduled:
extends: .gitleaks_scan
variables:
SCAN_MODE: "full"
rules:
- if: '$CI_PIPELINE_SOURCE == "schedule"'