Skip to content

Commit 8f10ba3

Browse files
fix(trufflehog): robust exclude fetch (gh api, curl raw, synced fallback)
- Drop sparse checkout + sed; fetch global-exclude.txt via GitHub API then raw URL - Fallback heredoc matches trufflehog/global-exclude.txt when both fail - Remove obsolete .trufflehog-shared exclude; clarify how to edit org-wide patterns Made-with: Cursor
1 parent cd1532d commit 8f10ba3

2 files changed

Lines changed: 49 additions & 18 deletions

File tree

.github/workflows/reusable-trufflehog.yml

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,52 @@ jobs:
5151
run: git config --unset-all http.https://github.com/.extraheader
5252

5353
- name: Fetch org-wide TruffleHog exclude patterns
54-
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
55-
with:
56-
repository: grafana/security-github-actions
57-
ref: main
58-
path: .trufflehog-shared
59-
sparse-checkout: |
60-
trufflehog/global-exclude.txt
61-
sparse-checkout-cone-mode: false
62-
63-
- name: Stage exclude file for TruffleHog
54+
env:
55+
GH_TOKEN: ${{ github.token }}
6456
run: |
65-
cp .trufflehog-shared/trufflehog/global-exclude.txt /tmp/trufflehog-exclude.txt
66-
echo "Using org-wide exclude patterns:"
67-
cat /tmp/trufflehog-exclude.txt
57+
DEST=/tmp/trufflehog-exclude.txt
58+
REPO=grafana/security-github-actions
59+
REF=main
60+
# Load trufflehog/global-exclude.txt from main (edit that file for org-wide excludes).
61+
RAW_URL="https://raw.githubusercontent.com/grafana/security-github-actions/${REF}/trufflehog/global-exclude.txt"
62+
if gh api "repos/${REPO}/contents/trufflehog/global-exclude.txt?ref=${REF}" \
63+
-H "Accept: application/vnd.github.v3.raw" -o "${DEST}" 2>/dev/null && [[ -s "${DEST}" ]]; then
64+
echo "Loaded exclude patterns from ${REPO}@${REF} (GitHub API)"
65+
elif curl -fsSL "${RAW_URL}" -o "${DEST}" 2>/dev/null && [[ -s "${DEST}" ]]; then
66+
echo "Loaded exclude patterns from raw.githubusercontent.com (${REF})"
67+
else
68+
echo "::warning::Could not fetch trufflehog/global-exclude.txt from ${REPO}@${REF} (not on branch yet, or GITHUB_TOKEN cannot read that repo). Using bundled fallback — merge exclusions to main or allow workflows to read internal repos."
69+
# Keep in sync with trufflehog/global-exclude.txt (used only when fetch fails).
70+
cat > "${DEST}" <<'EOF'
71+
# TruffleHog --exclude-paths: one Go regexp per non-blank, non-# line.
72+
#
73+
# To change org-wide behavior: edit this file and merge to security-github-actions main.
74+
# Consumer repos load it at runtime via the GitHub API (no changes needed in those repos).
75+
76+
# Lock files and checksums (contain hashes, not secrets)
77+
path:go\.sum$
78+
path:go\.mod$
79+
80+
# Dependency manifests (contain URLs that trigger false positives)
81+
path:package\.json$
82+
path:package-lock\.json$
83+
path:pnpm-lock\.yaml$
84+
path:yarn\.lock$
85+
path:poetry\.lock$
86+
path:Pipfile\.lock$
87+
path:uv\.lock$
88+
path:Cargo\.lock$
89+
path:Gemfile\.lock$
90+
91+
# Grafana plugin metadata
92+
path:grafana\.json$
93+
94+
# Go vendored dependencies (third-party blobs; high false-positive rate)
95+
(^|[/\\])vendor([/\\]|$)
96+
EOF
97+
fi
98+
echo "--- effective exclude file ---"
99+
cat "${DEST}"
68100
69101
- name: Install TruffleHog
70102
run: |

trufflehog/global-exclude.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
# TruffleHog --exclude-paths patterns (one Go regexp per non-empty, non-comment line).
2-
# Edit this file to tune false positives for all repos that use reusable-trufflehog.yml.
3-
4-
# Sparse checkout of security-github-actions used only to load this file in CI
5-
(^|[/\\])\.trufflehog-shared([/\\]|$)
1+
# TruffleHog --exclude-paths: one Go regexp per non-blank, non-# line.
2+
#
3+
# To change org-wide behavior: edit this file and merge to security-github-actions main.
4+
# Consumer repos load it at runtime via the GitHub API (no changes needed in those repos).
65

76
# Lock files and checksums (contain hashes, not secrets)
87
path:go\.sum$

0 commit comments

Comments
 (0)