Skip to content

Commit e528c30

Browse files
Add detect-secrets integration with GitHub Actions and Makefile
Issue: https://github.ibm.com/cloudant/releng/issues/1062 Added GitHub Action to scan secrets on PRs Included Makefile for easy baseline updates Auto-installs detect-secrets and cleans up Added short README for developer usage Configured baseline with exclusions and plugin tweaks
1 parent d347861 commit e528c30

File tree

4 files changed

+207
-0
lines changed

4 files changed

+207
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Detect Secrets Scan
2+
3+
on:
4+
push:
5+
branches: ["**"]
6+
pull_request:
7+
branches: [cloudant]
8+
9+
jobs:
10+
detect-secrets:
11+
name: Scan for Secrets (uses committed baseline config)
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Set up Python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: '3.11'
22+
23+
- name: Install detect-secrets
24+
run: pip install git+https://github.com/ibm/detect-secrets.git@master#egg=detect-secrets
25+
26+
- name: Compare baseline
27+
run: |
28+
cp .secrets.baseline .secrets.baseline.bak
29+
detect-secrets scan --update .secrets.baseline --suppress-unscannable-file-warnings
30+
31+
grep -v '"generated_at":' .secrets.baseline.bak > before.cleaned
32+
grep -v '"generated_at":' .secrets.baseline > after.cleaned
33+
34+
if ! diff before.cleaned after.cleaned > secrets.diff; then
35+
echo "::error::Secrets baseline changed (excluding timestamp)."
36+
cat secrets.diff
37+
rm .secrets.baseline.bak before.cleaned after.cleaned secrets.diff
38+
exit 1
39+
else
40+
echo "✅ No actual secret changes detected."
41+
rm .secrets.baseline.bak before.cleaned after.cleaned secrets.diff
42+
fi

.secrets.baseline

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
{
2+
"exclude": {
3+
"files": "^.secrets.baseline$",
4+
"lines": null
5+
},
6+
"generated_at": "2025-08-01T05:50:53Z",
7+
"plugins_used": [
8+
{
9+
"name": "AWSKeyDetector"
10+
},
11+
{
12+
"name": "ArtifactoryDetector"
13+
},
14+
{
15+
"name": "AzureStorageKeyDetector"
16+
},
17+
{
18+
"base64_limit": 4.5,
19+
"name": "Base64HighEntropyString"
20+
},
21+
{
22+
"name": "BasicAuthDetector"
23+
},
24+
{
25+
"name": "BoxDetector"
26+
},
27+
{
28+
"name": "CloudantDetector"
29+
},
30+
{
31+
"ghe_instance": "github.ibm.com",
32+
"name": "GheDetector"
33+
},
34+
{
35+
"name": "GitHubTokenDetector"
36+
},
37+
{
38+
"hex_limit": 3,
39+
"name": "HexHighEntropyString"
40+
},
41+
{
42+
"name": "IbmCloudIamDetector"
43+
},
44+
{
45+
"name": "IbmCosHmacDetector"
46+
},
47+
{
48+
"name": "JwtTokenDetector"
49+
},
50+
{
51+
"keyword_exclude": null,
52+
"name": "KeywordDetector"
53+
},
54+
{
55+
"name": "MailchimpDetector"
56+
},
57+
{
58+
"name": "NpmDetector"
59+
},
60+
{
61+
"name": "PrivateKeyDetector"
62+
},
63+
{
64+
"name": "SlackDetector"
65+
},
66+
{
67+
"name": "SoftlayerDetector"
68+
},
69+
{
70+
"name": "SquareOAuthDetector"
71+
},
72+
{
73+
"name": "StripeDetector"
74+
},
75+
{
76+
"name": "TwilioKeyDetector"
77+
}
78+
],
79+
"results": {
80+
"examples/cs.config.sample": [
81+
{
82+
"hashed_secret": "0bb078fe348593875f24c6402ea1f766decf7234",
83+
"is_verified": false,
84+
"line_number": 22,
85+
"type": "Base64 High Entropy String",
86+
"verified_result": null
87+
}
88+
],
89+
"rebar.config": [
90+
{
91+
"hashed_secret": "f76bb956cd320d9d363dafdcfa7d3d772632179e",
92+
"is_verified": false,
93+
"line_number": 6,
94+
"type": "Hex High Entropy String",
95+
"verified_result": null
96+
},
97+
{
98+
"hashed_secret": "bccb22846e7379f876d9dea83ece103a2daef8f0",
99+
"is_verified": false,
100+
"line_number": 12,
101+
"type": "Hex High Entropy String",
102+
"verified_result": null
103+
}
104+
]
105+
},
106+
"version": "0.13.1+ibm.62.dss",
107+
"word_list": {
108+
"file": null,
109+
"hash": null
110+
}
111+
}

Makefile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,34 @@ package: package.src
103103

104104
pkgclean: distclean
105105
rm -rf package
106+
107+
.PHONY: update-secrets
108+
109+
update-secrets:
110+
@echo "🚀 Starting detect-secrets workflow..."
111+
112+
# 🧼 Clean any existing virtual environment
113+
@echo "🧹 Cleaning old virtual environment (if any)..."
114+
@rm -rf .venv-ds
115+
116+
# 🛠️ Set up a new virtual environment
117+
@echo "🐍 Creating fresh virtual environment at .venv-ds..."
118+
@python3 -m venv .venv-ds
119+
120+
# 📦 Upgrade pip silently
121+
@echo "📦 Upgrading pip..."
122+
@.venv-ds/bin/pip install --upgrade pip > /dev/null
123+
124+
# 🔍 Install latest detect-secrets
125+
@echo "🔐 Installing detect-secrets..."
126+
@.venv-ds/bin/pip install git+https://github.com/ibm/detect-secrets.git@master#egg=detect-secrets > /dev/null
127+
128+
# 📊 Scan and update the baseline
129+
@echo "🔎 Scanning for secrets and updating .secrets.baseline..."
130+
@.venv-ds/bin/detect-secrets scan --update .secrets.baseline --suppress-unscannable-file-warnings
131+
132+
# 🧽 Cleanup the virtual environment
133+
@echo "🧼 Removing virtual environment..."
134+
@rm -rf .venv-ds
135+
136+
@echo "✅ Done! .secrets.baseline is updated."

README.org

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,26 @@ $ ./priv/gp_latencies.sh
203203

204204
6) A Basho engineer or community maintainer will review your patch
205205
and merge it into the main repository or send you feedback.
206+
207+
* 🔐 Detect Secrets Enforcement
208+
209+
This repository uses [`detect-secrets`](https://github.com/IBM/detect-secrets-stream) to prevent committing sensitive information like API keys, tokens, and passwords.
210+
211+
** 🚀 How It Works
212+
213+
Secrets are tracked using a `.secrets.baseline` file. This file contains a hash of detected secret patterns and is version-controlled.
214+
215+
On every pull request, GitHub Actions will:
216+
- Scan the codebase using the committed baseline.
217+
- Fail the build if new untracked secrets are found.
218+
219+
** 🛠 Update the Baseline
220+
221+
If your PR is failing due to newly detected secrets (false positives or intentional additions), follow the steps below to update the baseline:
222+
223+
*** ✅ One-Command Update
224+
225+
Use the provided `Makefile` to automatically install and run `detect-secrets`, then clean up:
226+
227+
```bash
228+
make update-secrets

0 commit comments

Comments
 (0)