Skip to content

Commit 3f3c79f

Browse files
authored
feat: Add trunk rule to detect mParticle API keys (#633)
* feat: Add trunk rule to detect mParticle API keys * Correct location of trunk check * Only check trunk changes on pull request
1 parent a0b2442 commit 3f3c79f

2 files changed

Lines changed: 26 additions & 4 deletions

File tree

.github/workflows/pull-request.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ permissions:
1212
checks: write
1313
id-token: write
1414

15-
# Code quality checks
15+
jobs:
1616
trunk-check:
1717
name: Trunk code check
1818
runs-on: ubuntu-latest
@@ -21,10 +21,7 @@ permissions:
2121
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #v5.0.0
2222
- name: Trunk Check
2323
uses: trunk-io/trunk-action@75699af9e26881e564e9d832ef7dc3af25ec031b # v1.2.4
24-
with:
25-
check-mode: all
2624

27-
jobs:
2825
pr-check-hadcoded-secrets:
2926
name: "Check PR for hardcoded secrets"
3027
uses: mParticle/mparticle-workflows/.github/workflows/security-hardcoded-secrets.yml@main

.trunk/trunk.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,31 @@ lint:
3535
- shellcheck@0.11.0
3636
- shfmt@3.6.0
3737
- trufflehog@3.90.6
38+
- mparticle-api-key-check # Custom rule to prevent mParticle API keys from being committed
39+
definitions:
40+
- name: mparticle-api-key-check
41+
files: [ALL]
42+
commands:
43+
- name: check-mparticle-keys
44+
output: pass_fail
45+
# ──────────────────────────────────────────────────────────────────────
46+
# Matches:
47+
# us2-[32 hex chars]
48+
# us1-...
49+
# us-...
50+
# eu1-...
51+
# Any two lowercase letters + optional digits + hyphen + exactly 32 hex chars
52+
# ──────────────────────────────────────────────────────────────────────
53+
run: >-
54+
sh -c '
55+
if grep -E "(?i)[a-z]{2}[0-9]*-[0-9a-f]{32}" "${target}"; then
56+
echo "ERROR: Possible mParticle API key detected in ${target}"
57+
echo " Format: xx...-[32 hex chars] (e.g. us2-, eu1-, us-, au4-, etc.)"
58+
echo "API keys should never be committed to version control!"
59+
exit 1
60+
fi
61+
'
62+
success_codes: [0, 1]
3863
disabled:
3964
- yamllint
4065
ignore:

0 commit comments

Comments
 (0)