Skip to content

Commit 01886c4

Browse files
feat(trufflehog): add Grafana Bench metrics reporting to Prometheus (#133)
Add grafana-bench job to reusable-trufflehog.yml that sends TruffleHog scan results to Prometheus after each scan. Mirrors the zizmor integration pattern — runs after trufflehog-scan (including on failure), gated to grafana org and non-fork PRs, uses ghcr.io/grafana/grafana-bench:v1.0.4. Add id-token: write to org-required-trufflehog.yml to allow Vault access for Prometheus credentials.
1 parent 3babf65 commit 01886c4

2 files changed

Lines changed: 60 additions & 0 deletions

File tree

.github/workflows/org-required-trufflehog.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ permissions:
1616
contents: read
1717
pull-requests: write
1818
checks: write
19+
id-token: write
1920

2021
jobs:
2122
secret-scan:

.github/workflows/reusable-trufflehog.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ on:
1818
required: false
1919
default: "ubuntu-latest"
2020
type: string
21+
send-bench-metrics:
22+
description: "If true, run Grafana Bench after scan (requires Vault Prometheus creds). Job only runs for grafana org and non-fork PRs; fork PRs have no OIDC/Vault access."
23+
required: false
24+
default: true
25+
type: boolean
2126

2227
permissions:
2328
contents: read
@@ -308,3 +313,57 @@ jobs:
308313
echo "Workflow failed due to secrets found (verified: ${VERIFIED_COUNT}, unverified: ${UNVERIFIED_COUNT})"
309314
exit 1
310315
fi
316+
317+
grafana-bench:
318+
name: Send TruffleHog metrics to Prometheus via Grafana Bench
319+
needs: [trufflehog-scan]
320+
# Only run for grafana org and non-fork PRs (fork PRs have no OIDC/Vault access).
321+
if: ${{ github.repository_owner == 'grafana' && (github.event_name != 'pull_request' || !github.event.pull_request.head.repo.fork) && inputs.send-bench-metrics && always() && !cancelled() && (needs.trufflehog-scan.result == 'success' || needs.trufflehog-scan.result == 'failure') }}
322+
runs-on: ubuntu-latest
323+
permissions:
324+
contents: read
325+
id-token: write
326+
steps:
327+
- name: Get Prometheus secrets from Vault
328+
uses: grafana/shared-workflows/actions/get-vault-secrets@078c4a8af09e06d646077550f9e0f68171d5881e # get-vault-secrets/v1.3.1
329+
with:
330+
common_secrets: |
331+
PROMETHEUS_URL=grafana-bench:prometheus_url
332+
PROMETHEUS_USER=grafana-bench:prometheus_user
333+
PROMETHEUS_PASSWORD=grafana-bench:prometheus_token
334+
335+
- name: Download TruffleHog scan artifact
336+
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
337+
with:
338+
name: trufflehog_scan
339+
340+
- name: Send TruffleHog metrics to Prometheus via Grafana Bench
341+
env:
342+
BENCH_SERVICE: ${{ format('grafana-{0}', github.event.repository.name) }}
343+
BENCH_SUITE_NAME: ${{ github.event.repository.name }}/trufflehog
344+
BENCH_SERVICE_VERSION: ${{ github.sha }}
345+
run: |
346+
if [ -z "${PROMETHEUS_URL}" ]; then
347+
echo "::error::PROMETHEUS_URL not set; Vault step may have failed."
348+
exit 1
349+
fi
350+
if ! docker pull ghcr.io/grafana/grafana-bench:v1.0.4; then
351+
echo "Could not pull Bench image; skipping bench step."
352+
exit 0
353+
fi
354+
docker run --rm \
355+
--network=host \
356+
--volume="${PWD}:/tests/" \
357+
-e PROMETHEUS_URL="${PROMETHEUS_URL}" \
358+
-e PROMETHEUS_USER="${PROMETHEUS_USER}" \
359+
-e PROMETHEUS_PASSWORD="${PROMETHEUS_PASSWORD}" \
360+
ghcr.io/grafana/grafana-bench:v1.0.4 report \
361+
--report-input trufflehog \
362+
--service "${BENCH_SERVICE}" \
363+
--service-version "${BENCH_SERVICE_VERSION}" \
364+
--suite-name "${BENCH_SUITE_NAME}" \
365+
--run-stage ci \
366+
--report-output log \
367+
--log-level debug \
368+
--prometheus-metrics \
369+
/tests/results.json

0 commit comments

Comments
 (0)