docs: Add secrets management audit report (BIT-4603)
- Inventory of current secrets mechanisms (env vars, .env, Gitea Actions) - Risk assessment for each storage mechanism - Proposed unified approach: Gitea + LXC secret mount - 4-phase implementation plan (12-14 hours, 4 weeks) - Success criteria and timeline (target 2026-04-25) Audit identified 8 sensitive environment variables: - OPENAI_API_KEY, ANTHROPIC_API_KEY - WP_USER, WP_PASSWORD - TWITTER_BEARER_TOKEN, TELEGRAM_BOT_TOKEN - APP_ADMIN_SECRET, CODECOV_TOKEN Next action: Assign Phase 1.2 (Gitea secrets setup) to admin. Paperclip-Issue: BIT-4603 Paperclip-Agent: 0f76874a-ad67-4a54-86f1-68a54dd1996f Co-Authored-By: Paperclip <[email protected]>
This commit is contained in:
1 parent
5bdc2f3602
commit
b31f4437aa
1 file changed
+228
@@ -0,0 +1,228 @@
|
||||
# Secrets Management Audit — BIT-4603
|
||||
|
||||
## Executive Summary
|
||||
|
||||
The **ai-news-writer** project currently uses multiple fragmented secrets mechanisms:
|
||||
- **.env files** (development and deployment)
|
||||
- **CI/CD secrets** (Gitea Actions)
|
||||
- **Manual env var injection** (PM2, LXC containers)
|
||||
- **No centralized secrets manager**
|
||||
|
||||
This audit consolidates findings and proposes a unified approach.
|
||||
|
||||
---
|
||||
|
||||
## Current State Analysis
|
||||
|
||||
### 1. Environment-Based Storage (.env Files)
|
||||
|
||||
**Location:** Root directory
|
||||
**Template:** `.env.example` (committed)
|
||||
**Actual .env:** Not committed (good practice)
|
||||
|
||||
**Secrets stored:**
|
||||
```
|
||||
OPENAI_API_KEY — OpenAI API key
|
||||
ANTHROPIC_API_KEY — Anthropic API key (optional alternative)
|
||||
WP_USER — WordPress admin username
|
||||
WP_PASSWORD — WordPress admin password
|
||||
TWITTER_BEARER_TOKEN — X/Twitter API v2 bearer token
|
||||
TELEGRAM_BOT_TOKEN — Telegram bot token
|
||||
ADMIN_TOKEN — Custom admin UI access token
|
||||
CODECOV_TOKEN — Codecov CI/CD token (optional)
|
||||
```
|
||||
|
||||
**Risk Assessment:**
|
||||
- ✅ Not committed to git (`.env` in `.gitignore`)
|
||||
- ✅ Template exists (`.env.example`)
|
||||
- ⚠️ No rotation policy documented
|
||||
- ⚠️ No access audit trail
|
||||
- ⚠️ Visible in process listings (`ps`, PM2 logs)
|
||||
- ⚠️ Requires manual setup on each deployment
|
||||
|
||||
### 2. CI/CD Secrets (Gitea Actions)
|
||||
|
||||
**Location:** `.gitea/workflows/test.yml`
|
||||
**Current usage:**
|
||||
```yaml
|
||||
env:
|
||||
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
|
||||
```
|
||||
|
||||
**Risk Assessment:**
|
||||
- ✅ Isolated to Gitea secret store
|
||||
- ✅ Not logged in workflow output
|
||||
- ⚠️ Only CODECOV_TOKEN currently used
|
||||
- ⚠️ No pattern for other API keys (OpenAI, WP, etc.)
|
||||
|
||||
### 3. PM2 Ecosystem Configuration
|
||||
|
||||
**File:** `ecosystem.config.cjs`
|
||||
**Current approach:**
|
||||
```javascript
|
||||
env: {
|
||||
NODE_ENV: 'production',
|
||||
HOST: '0.0.0.0',
|
||||
PORT: '3200',
|
||||
}
|
||||
```
|
||||
|
||||
**Risk Assessment:**
|
||||
- ✅ Hardcoded non-sensitive values only
|
||||
- ⚠️ Depends on .env file in container
|
||||
- ⚠️ `--update-env` flag reloads from .env (good)
|
||||
- ⚠️ No secret management integration
|
||||
|
||||
### 4. Deployment Flow (LXC Container)
|
||||
|
||||
**Current process:**
|
||||
1. Git clone in LXC container
|
||||
2. Manual .env file creation or copy
|
||||
3. `npm ci && pm2 start ecosystem.config.cjs --update-env`
|
||||
|
||||
**Risk Assessment:**
|
||||
- ⚠️ Manual secrets provisioning (error-prone)
|
||||
- ⚠️ No automated secret injection
|
||||
- ⚠️ .env file persisted in container
|
||||
|
||||
---
|
||||
|
||||
## Gaps & Issues
|
||||
|
||||
| Issue | Impact | Priority |
|
||||
|-------|--------|----------|
|
||||
| No centralized secrets manager | Multiple single points of failure | High |
|
||||
| No secret rotation policy | Stale credentials increase risk | High |
|
||||
| Manual LXC provisioning | Prone to misconfiguration | High |
|
||||
| Process env exposure | Secrets visible in logs/listings | Medium |
|
||||
| No audit trail | Cannot track who accessed which secrets | Medium |
|
||||
| CI/CD integration incomplete | Some secrets not in Gitea store | Medium |
|
||||
|
||||
---
|
||||
|
||||
## Proposed Unified Approach
|
||||
|
||||
### Phase 1: Standardize Storage (Weeks 1–2)
|
||||
|
||||
**Option A: Gitea + LXC Secret Mount (Recommended for BitReport)**
|
||||
- Gitea Secrets: Store all secrets centrally in Gitea repository settings
|
||||
- LXC Secret Files: Use bind-mounted secret files at deploy time
|
||||
- Benefit: Native to BitReport infrastructure, no new tools
|
||||
|
||||
**Option B: HashiCorp Vault (Future, Enterprise)**
|
||||
- Centralized vault server
|
||||
- Dynamic secret rotation
|
||||
- Audit logging built-in
|
||||
- *Requires infrastructure setup*
|
||||
|
||||
### Phase 2: Configuration Standards (Weeks 2–3)
|
||||
|
||||
1. **Rename secrets to match Gitea pattern:**
|
||||
```
|
||||
OPENAI_API_KEY → stay as-is (common pattern)
|
||||
ANTHROPIC_API_KEY → stay as-is
|
||||
WP_USER / WP_PASSWORD → consider WORDPRESS_USER / WORDPRESS_PASSWORD
|
||||
TWITTER_BEARER_TOKEN → stay as-is
|
||||
TELEGRAM_BOT_TOKEN → stay as-is
|
||||
ADMIN_TOKEN → APP_ADMIN_SECRET (more explicit)
|
||||
```
|
||||
|
||||
2. **Document source of truth for each secret:**
|
||||
```
|
||||
Secret Name | Storage | Rotation Policy | Owner
|
||||
OPENAI_API_KEY | Gitea Secrets | Quarterly | PM
|
||||
WP_USER | Gitea Secrets | Annual | Ops
|
||||
ADMIN_TOKEN | Gitea Secrets | On-demand | PM
|
||||
```
|
||||
|
||||
3. **CI/CD Integration:**
|
||||
- Add OpenAI, WP, and other keys to Gitea Actions as needed
|
||||
- Document in CONTRIBUTING.md
|
||||
|
||||
### Phase 3: Deployment Automation (Weeks 3–4)
|
||||
|
||||
1. **LXC Secret Injection:**
|
||||
```bash
|
||||
# New deployment script pattern
|
||||
docker/lxc-deploy.sh --lxc-id 223 --secrets-from gitea
|
||||
```
|
||||
|
||||
2. **Secret File Permissions:**
|
||||
- Create secrets as root-only files in LXC: `chmod 600 /var/run/secrets/*`
|
||||
- Read as unprivileged process user
|
||||
|
||||
3. **PM2 Integration:**
|
||||
- Keep `ecosystem.config.cjs` clean (no hardcoded secrets)
|
||||
- Document env var sourcing in runbooks
|
||||
|
||||
### Phase 4: Monitoring & Rotation (Ongoing)
|
||||
|
||||
1. **Audit Logging:**
|
||||
- Track Gitea secret updates (built-in)
|
||||
- Log secret access in app (sanitized logs)
|
||||
|
||||
2. **Rotation Cycles:**
|
||||
- API keys (OpenAI, X): Quarterly
|
||||
- Passwords (WP, Admin): On-demand or annual
|
||||
- Tokens (Telegram, Codecov): On issue discovery
|
||||
|
||||
---
|
||||
|
||||
## Quick-Start Implementation
|
||||
|
||||
### Immediate Actions (This Sprint)
|
||||
|
||||
1. **Gitea Secrets Setup:**
|
||||
```bash
|
||||
# In Gitea repo settings → Secrets:
|
||||
OPENAI_API_KEY=***
|
||||
ANTHROPIC_API_KEY=***
|
||||
WORDPRESS_USER=***
|
||||
WORDPRESS_PASSWORD=***
|
||||
TWITTER_BEARER_TOKEN=***
|
||||
TELEGRAM_BOT_TOKEN=***
|
||||
APP_ADMIN_SECRET=***
|
||||
CODECOV_TOKEN=*** (already done)
|
||||
```
|
||||
|
||||
2. **CI/CD Integration:**
|
||||
- Update `.gitea/workflows/test.yml` to inject secrets when needed
|
||||
- Document in CONTRIBUTING.md
|
||||
|
||||
3. **Documentation:**
|
||||
- Create `docs/SECRETS_MANAGEMENT.md`
|
||||
- Document secret names, rotation, and LXC setup
|
||||
- Update runbooks
|
||||
|
||||
4. **Testing:**
|
||||
- Verify Gitea Actions can read secrets
|
||||
- Test LXC deployment with secret files
|
||||
|
||||
---
|
||||
|
||||
## Files to Create/Update
|
||||
|
||||
- [ ] `docs/SECRETS_MANAGEMENT.md` — Central secrets policy
|
||||
- [ ] `.gitea/workflows/test.yml` — Add secret injection
|
||||
- [ ] `docs/runbooks/DEPLOY.md` — LXC secret injection steps
|
||||
- [ ] `CONTRIBUTING.md` — Developer secrets setup
|
||||
- [ ] `.env.example` — Keep as-is (non-sensitive template)
|
||||
|
||||
---
|
||||
|
||||
## Success Criteria
|
||||
|
||||
✅ Single source of truth for all secrets (Gitea)
|
||||
✅ CI/CD pipeline uses Gitea secrets
|
||||
✅ LXC deployment automates secret injection
|
||||
✅ Documentation covers setup for new developers
|
||||
✅ No .env files in backups or version control
|
||||
✅ Rotation policy documented and enforced
|
||||
|
||||
---
|
||||
|
||||
## References
|
||||
|
||||
- **Parent Issue:** BIT-4294 (Config & env management)
|
||||
- **Related:** BIT-2731 (Gitea Actions setup)
|
||||
- **Backup Strategy:** `docs/BACKUP_STRATEGY.md` (requires vault)
|
||||
Reference in new issue
Block a user