Skip to content

Commit da0bd50

Browse files
committed
chore: harden secret-leak prevention
1 parent 8051cb3 commit da0bd50

6 files changed

Lines changed: 127 additions & 3 deletions

File tree

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,8 @@ repos:
2424
- id: check-yaml
2525
- id: check-added-large-files
2626
- id: check-merge-conflict
27+
28+
- repo: https://github.com/gitleaks/gitleaks
29+
rev: v8.30.1
30+
hooks:
31+
- id: gitleaks

CHANGELOG.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
we don# Changelog
1+
# Changelog
22

33
All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/), and this project adheres to [Semantic Versioning](https://semver.org/).
66

77
## [Unreleased]
88

9+
### Added
10+
11+
- `docs/private-repo.md` — "Protecting secrets in your overlay" section covering GitHub push protection (server-side block that survives `--no-verify`), a gitleaks pre-commit hook, and a one-time trufflehog history sweep. Aimed at overlay maintainers whose configs reference Slack tokens, LLM API keys, and OAuth client secrets via `{ENV_VAR}` placeholders.
12+
- `slack-agents init` now prints a visible "SECURITY: protect your secrets before pushing" banner at the end of scaffolding, linking to the new docs section.
13+
- `SECURITY.md` — pointer for overlay maintainers to the overlay security guidance.
14+
915
## [0.8.1] - 2026-05-07
1016

1117
### Fixed
@@ -101,15 +107,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/), and this
101107

102108
### Added
103109

104-
- `slack-agents init` now generates `.gitignore`
110+
- `slack-agents init` now generates `.gitignore`
105111
- `.env.example` template includes comments explaining where to get each token and links to setup guide
106112
- `build-docker` lists required environment variables after build completes
107113
- `build-docker` errors if `req*.txt` files are found (dependencies must be in `pyproject.toml`)
108114
- `init` warns when `req*.txt` files are found with migration instructions
109115

110116
### Changed
111117

112-
- `pyproject.toml` template uses `python-slack-agents<2` (no minimum pin)
118+
- `pyproject.toml` template uses `python-slack-agents<2` (no minimum pin)
113119
- Setup flow uses venv-first approach: create venv, install package, then `slack-agents init`
114120
- Updated README, docs/setup.md, and docs/private-repo.md with new setup flow
115121

SECURITY.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ Please report security vulnerabilities privately using [GitHub's security adviso
77
Do **not** open public issues for security concerns.
88

99
We will acknowledge reports within 72 hours and aim to release fixes promptly.
10+
11+
## For overlay maintainers
12+
13+
If you operate an overlay repository (your own `agents/`, `src/`, and configs built on top of this framework), see [Protecting secrets in your overlay](docs/private-repo.md#protecting-secrets-in-your-overlay) for the recommended setup: GitHub push protection, a gitleaks pre-commit hook, and a one-time trufflehog history sweep.

docs/private-repo.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,50 @@ No custom Dockerfile needed — `python-slack-agents` bundles one that auto-dete
7979
slack-agents build-docker agents/my-agent
8080
slack-agents build-docker agents/my-agent --push registry.example.com
8181
```
82+
83+
## Protecting secrets in your overlay
84+
85+
Overlay configs reference secrets via `{ENV_VAR}` placeholders — Slack tokens, LLM API keys, and OAuth client secrets. The scaffolded `.gitignore` keeps `.env` out of git, but that's a single layer. A few minutes of setup adds defense in depth.
86+
87+
### 1. Enable GitHub push protection
88+
89+
GitHub refuses pushes that contain known provider tokens (Slack `xoxb-`/`xapp-`, Anthropic `sk-ant-`, OpenAI `sk-`, AWS, etc.) before they ever reach the remote. It cannot be bypassed by `git commit --no-verify` — the check runs server-side. Free on public repos, and included in GitHub Advanced Security on private/organisation repos.
90+
91+
Toggle it in **Settings → Code security → Secret scanning** (enable both *Secret scanning* and *Push protection*), or in one shot via the CLI:
92+
93+
```bash
94+
gh api -X PATCH repos/<org>/<repo> --input - <<'EOF'
95+
{
96+
"security_and_analysis": {
97+
"secret_scanning": {"status": "enabled"},
98+
"secret_scanning_push_protection": {"status": "enabled"},
99+
"secret_scanning_non_provider_patterns": {"status": "enabled"}
100+
}
101+
}
102+
EOF
103+
```
104+
105+
### 2. Add a gitleaks pre-commit hook
106+
107+
Catches secrets on the developer's machine before they ever reach a remote — useful as a first line of defense and as the only layer for contributors who fork the repo. Add to your overlay's `.pre-commit-config.yaml`:
108+
109+
```yaml
110+
repos:
111+
- repo: https://github.com/gitleaks/gitleaks
112+
rev: v8.30.1 # pin to a tag; bump via `pre-commit autoupdate`
113+
hooks:
114+
- id: gitleaks
115+
```
116+
117+
Then run `pre-commit install` once per clone. Pre-commit requires a pinned `rev` for reproducibility and supply-chain safety. Keep it fresh either by running `pre-commit autoupdate` periodically or by adding a `package-ecosystem: "pre-commit"` entry to `.github/dependabot.yml` so Dependabot opens hook-bump PRs.
118+
119+
### 3. Sweep history once
120+
121+
Before turning the layers above on, check whether anything already leaked. Trufflehog walks every commit in your history and reports candidate secrets:
122+
123+
```bash
124+
docker run --rm -v "$PWD:/repo" trufflesecurity/trufflehog:latest \
125+
git file:///repo --no-update
126+
```
127+
128+
If trufflehog finds a real secret, **rotate it immediately** at the issuer (Slack, Anthropic, OpenAI, etc.). Rewriting git history with `git-filter-repo` is optional — once a token has been pushed publicly, assume it's compromised and prioritise rotation over removal.

llms-full.txt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,3 +1309,50 @@ No custom Dockerfile needed — `python-slack-agents` bundles one that auto-dete
13091309
slack-agents build-docker agents/my-agent
13101310
slack-agents build-docker agents/my-agent --push registry.example.com
13111311
```
1312+
1313+
## Protecting secrets in your overlay
1314+
1315+
Overlay configs reference secrets via `{ENV_VAR}` placeholders — Slack tokens, LLM API keys, and OAuth client secrets. The scaffolded `.gitignore` keeps `.env` out of git, but that's a single layer. A few minutes of setup adds defense in depth.
1316+
1317+
### 1. Enable GitHub push protection
1318+
1319+
GitHub refuses pushes that contain known provider tokens (Slack `xoxb-`/`xapp-`, Anthropic `sk-ant-`, OpenAI `sk-`, AWS, etc.) before they ever reach the remote. It cannot be bypassed by `git commit --no-verify` — the check runs server-side. Free on public repos, and included in GitHub Advanced Security on private/organisation repos.
1320+
1321+
Toggle it in **Settings → Code security → Secret scanning** (enable both *Secret scanning* and *Push protection*), or in one shot via the CLI:
1322+
1323+
```bash
1324+
gh api -X PATCH repos/<org>/<repo> --input - <<'EOF'
1325+
{
1326+
"security_and_analysis": {
1327+
"secret_scanning": {"status": "enabled"},
1328+
"secret_scanning_push_protection": {"status": "enabled"},
1329+
"secret_scanning_non_provider_patterns": {"status": "enabled"}
1330+
}
1331+
}
1332+
EOF
1333+
```
1334+
1335+
### 2. Add a gitleaks pre-commit hook
1336+
1337+
Catches secrets on the developer's machine before they ever reach a remote — useful as a first line of defense and as the only layer for contributors who fork the repo. Add to your overlay's `.pre-commit-config.yaml`:
1338+
1339+
```yaml
1340+
repos:
1341+
- repo: https://github.com/gitleaks/gitleaks
1342+
rev: v8.30.1 # pin to a tag; bump via `pre-commit autoupdate`
1343+
hooks:
1344+
- id: gitleaks
1345+
```
1346+
1347+
Then run `pre-commit install` once per clone. Pre-commit requires a pinned `rev` for reproducibility and supply-chain safety. Keep it fresh either by running `pre-commit autoupdate` periodically or by adding a `package-ecosystem: "pre-commit"` entry to `.github/dependabot.yml` so Dependabot opens hook-bump PRs.
1348+
1349+
### 3. Sweep history once
1350+
1351+
Before turning the layers above on, check whether anything already leaked. Trufflehog walks every commit in your history and reports candidate secrets:
1352+
1353+
```bash
1354+
docker run --rm -v "$PWD:/repo" trufflesecurity/trufflehog:latest \
1355+
git file:///repo --no-update
1356+
```
1357+
1358+
If trufflehog finds a real secret, **rotate it immediately** at the issuer (Slack, Anthropic, OpenAI, etc.). Rewriting git history with `git-filter-repo` is optional — once a token has been pushed publicly, assume it's compromised and prioritise rotation over removal.

src/slack_agents/cli/init.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,18 @@ def execute(args):
107107
print(" cp .env.example .env # add your tokens")
108108
print(" pip install -r requirements.txt # install the framework")
109109
print(" slack-agents run agents/hello-world # run the example agent")
110+
print()
111+
print("=" * 70)
112+
print(" SECURITY: protect your secrets before pushing")
113+
print("=" * 70)
114+
print(" Your config.yaml will reference Slack tokens and LLM API keys")
115+
print(" via {ENV_VAR} placeholders. The scaffolded .gitignore keeps")
116+
print(" .env out of git, but that is one layer. Before your first push,")
117+
print(" enable GitHub push protection and add a gitleaks pre-commit hook.")
118+
print()
119+
print(" Full guide:")
120+
print(
121+
" https://github.com/CompareNetworks/python-slack-agents/blob/main/"
122+
"docs/private-repo.md#protecting-secrets-in-your-overlay"
123+
)
124+
print("=" * 70)

0 commit comments

Comments
 (0)