Skip to content

Commit 1bdd71f

Browse files
feat(gitleaks): add centralized config distribution
- Add gitleaks.base.toml with base rules from deckhouse/deckhouse - Copy centralized config to ${RUNNER_TEMP} (safe for Werf/giterminism) - Update config detection logic to use centralized config by default - Support local .gitleaks.toml for repository-specific customization This enables centralized rule management while keeping git state clean. Signed-off-by: Roman Trofimenkov <roman.trofimenkov@flant.com>
1 parent 1d0204d commit 1bdd71f

File tree

2 files changed

+78
-5
lines changed

2 files changed

+78
-5
lines changed

gitleaks/action.yml

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,33 @@ runs:
5151
echo "$install_dir" >> "$GITHUB_PATH"
5252
gitleaks version
5353
54+
- name: Setup centralized config
55+
shell: bash
56+
run: |
57+
set -euo pipefail
58+
# Copy centralized config to temporary directory (safe for Werf/giterminism)
59+
BASE_CONFIG="${{ github.action_path }}/config/gitleaks.base.toml"
60+
if [[ -f "$BASE_CONFIG" ]]; then
61+
cp "$BASE_CONFIG" "${RUNNER_TEMP}/gitleaks.base.toml"
62+
echo "✅ Centralized config copied to ${RUNNER_TEMP}/gitleaks.base.toml"
63+
else
64+
echo "⚠️ Warning: Centralized config not found at $BASE_CONFIG"
65+
exit 1
66+
fi
67+
5468
- name: Check for optional config
5569
id: config
5670
shell: bash
5771
run: |
5872
set -euo pipefail
59-
if [[ -f "gitleaks.toml" ]]; then
60-
echo "config_arg=-c gitleaks.toml" >> "$GITHUB_OUTPUT"
61-
echo "✅ Found config: gitleaks.toml"
73+
if [[ -f ".gitleaks.toml" ]]; then
74+
# Local config exists - it should extend the centralized one
75+
echo "config_arg=--config .gitleaks.toml" >> "$GITHUB_OUTPUT"
76+
echo "✅ Found local config: .gitleaks.toml (should extend base config)"
6277
else
63-
echo "config_arg=" >> "$GITHUB_OUTPUT"
64-
echo "⚠️ Config file not found. Proceeding with default rules."
78+
# Use centralized config only
79+
echo "config_arg=--config ${RUNNER_TEMP}/gitleaks.base.toml" >> "$GITHUB_OUTPUT"
80+
echo "🔹 Using centralized config only (no local customization)"
6581
fi
6682
6783
- name: Gitleaks scan (full)

gitleaks/config/gitleaks.base.toml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Centralized Gitleaks configuration for all Deckhouse repositories
2+
# This file is distributed via modules-actions/gitleaks action
3+
#
4+
# Repositories can extend this config by creating local .gitleaks.toml:
5+
# [extend]
6+
# useDefault = false
7+
# path = "${RUNNER_TEMP}/gitleaks.base.toml"
8+
9+
# Use default Gitleaks rules
10+
[extend]
11+
useDefault = true
12+
13+
# Global allowlists
14+
[allowlist]
15+
16+
# === Safe files/directories ===
17+
# NOTE: Use exact paths, NOT glob patterns like **/go.mod
18+
19+
paths = [
20+
# Go dependencies - public hashes
21+
"go.mod",
22+
"go.sum",
23+
24+
# Specific files with known false positives
25+
# "modules/101-cert-manager/docs/USAGE.md",
26+
# "modules/101-cert-manager/docs/USAGE_RU.md",
27+
]
28+
29+
# === Safe patterns ===
30+
regexes = [
31+
# Go module checksums - always public
32+
'''h1:[A-Za-z0-9+/=]{40,}''',
33+
34+
# Public certificates (only ca.crt, NOT private keys!)
35+
'''data:\s*\n\s*ca\.crt:\s*[A-Za-z0-9+/=\s]+''',
36+
37+
# AWS Example values from official documentation - exact match
38+
'''AKIAIOSFODNN7EXAMPLE''',
39+
'''wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY''',
40+
]
41+
42+
# Custom rules for hashi/openbao/werf tokens
43+
[[rules]]
44+
id = "werf-secret-key"
45+
description = "Identified a Werf Secret Key."
46+
regex = '''\b([a-f0-9]{32})\b'''
47+
path = '''\.werf_secret_key$'''
48+
49+
[[rules]]
50+
id = "hashicorp-vault-token"
51+
description = "Identified a HashiCorp Vault token (hvs, hvb, or hvr prefix)."
52+
regex = '''\b(hv[sbr]\.[A-Za-z0-9_-]{20,})\b'''
53+
54+
[[rules]]
55+
id = "openbao-token"
56+
description = "Identified an OpenBao token (S. prefix)."
57+
regex = '''\b(S\.[A-Za-z0-9_-]{20,})\b'''

0 commit comments

Comments
 (0)