Files
karaoke-gen/infrastructure/modules/secrets.py
T
Andrew Beveridge ☄️andClaude Opus 4.8 6fa4400d3d feat(dr): back up all GitHub repos to S3 (survive a GitHub ban) (#929)
## Summary

Extends the nightly DR backup Cloud Function (`backup-to-aws`) to bundle
**every git repo under `github.com/nomadkaraoke` and
`github.com/beveradb`** into a per-repo `git bundle` on S3, so code +
full history survive a complete loss of GitHub access (e.g. an automated
copyright-strike account ban). Each bundle is directly cloneable —
restore is `git clone --mirror <bundle>` → `git push --mirror
<new-remote>`.

## Changes

- **`git_repos_export.py`** (new): enumerate repos via GitHub
`/user/repos` (includes private), mirror-clone + `git bundle create
--all`, upload to `git-repos/{owner}/{repo}.bundle` in staging, plus a
`manifest.json` inventory. Forks excluded, oversized/empty repos
skipped, per-repo errors non-fatal, org backed up **before** the
personal account for deadline resilience. PAT is read from Secret
Manager at **runtime** (not a deploy-time secret env var) so the
function deploys before the secret has a value and skips gracefully if
absent.
- **`main.py`**: new nightly Step 4b (between secrets export and S3
upload).
- **`infrastructure/modules/backup.py`**: bump function to 4Gi/2CPU
(mirror-clone uses in-memory `/tmp`); add `GIT_BACKUP_OWNERS` env.
- **`infrastructure/modules/secrets.py`**: new `github-backup-token`
secret (value added manually).
- **`.github/workflows/dr-backup-freshness.yml`**: monitor `git-repos/`
at 36h, counting only `.bundle` objects.
- **`docs/DISASTER-RECOVERY.md`**: new "Scenario 3: Loss of GitHub
access" + restore steps + token setup.

## Security

- The GitHub PAT is injected via a `GIT_CONFIG_*` `Authorization` header
(like `actions/checkout`), never in the clone URL/argv — so it can't
leak via `ps`, `TimeoutExpired`, or captured stderr. Token is also
redacted from any error text persisted into `manifest.json`.

## Testing

- 14 new unit tests for the module
(enumerate/filter/bundle/skip/error/security paths); full
`backup_to_aws` suite: **27 passing**.
- CodeRabbit local review (cycle 1) completed; all 4 findings (1
critical PAT leak, 2 major, 1 minor) addressed. Cycle-2 verification was
rate-limited (free-tier), so **left for the GitHub bot to review the
final diff**.

## Deploy notes

- **Pulumi already applied locally** (`github-backup-token` secret
created + function on 4Gi/2CPU) — CI re-run is a no-op.
- After merge, run `infrastructure/functions/backup_to_aws/deploy.sh` to
ship the new function source, then set the PAT:
`printf %s '<PAT>' | gcloud secrets versions add github-backup-token
--data-file=- --project=nomadkaraoke`
- Requires a classic GitHub PAT (owner: beveradb, member of nomadkaraoke
org) with `repo` + `read:org`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---
@coderabbitai ignore

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-23 00:44:52 -04:00

105 lines
3.5 KiB
Python

"""
Secret Manager resources.
Manages all secrets for the application. Secret values are added manually
via gcloud or the Cloud Console after resources are created.
"""
from pulumi_gcp import secretmanager
def create_secrets() -> dict[str, secretmanager.Secret]:
"""
Create all Secret Manager secrets.
Returns:
dict: Dictionary mapping secret names to Secret resources.
"""
# Define all secret names
# Note: Private tracker secrets (red-*, ops-*) are managed by flacfetch repo
secret_names = [
# Audio processing
"audioshake-api-key",
"genius-api-key",
"audio-separator-api-url",
# Payment and email
"stripe-secret-key",
"stripe-webhook-secret",
"postmark-server-token",
# Observability (Langfuse for LLM tracing)
"langfuse-public-key",
"langfuse-secret-key",
"langfuse-host",
# AI auto-correct suggestions (Claude models via Anthropic API)
"anthropic-api-key",
# Service authentication
"flacfetch-api-key",
"flacfetch-api-url",
"encoding-worker-api-key",
# Capacity-fallback VMs config (JSON list of {vm,zone,ip,machine_type?}).
# machine_type (e.g. "c4-highcpu-32") drives the shared speed-rank
# ordering; optional for legacy entries (inferred from the vm name).
# Stored as a secret because --set-env-vars on Cloud Run is
# comma-delimited and the JSON value contains commas; the value itself is
# non-secret (just public IPs of fallback VMs).
"encoding-worker-fallback-vms",
# Notifications
"pushbullet-api-key",
# Internal service URLs
"gdrive-validator-url",
# Web Push (VAPID keys for mobile push notifications)
"vapid-public-key",
"vapid-private-key",
# GitHub
"github-runner-pat",
"github-webhook-secret", # For runner manager webhook verification
# DR: PAT (repo + read:org) the nightly backup uses to clone every repo
# under github.com/nomadkaraoke + github.com/beveradb into git bundles on
# S3, so code survives loss of GitHub access. Value added manually.
"github-backup-token",
# E2E Testing
"e2e-bypass-key",
# KaraokeNerds API
"karaokenerds-api-key",
# Notifications (Discord)
"discord-alert-webhook",
# Divebar on-demand refresh trigger (shared bearer token: kjbox's
# "Refresh catalog" button -> divebar-lookup `refresh` action). Gates
# an otherwise-public endpoint that re-runs the mirror/sync/xref
# scheduler jobs on demand, so it's anti-abuse, not data-sensitive.
"divebar-refresh-token",
# Cloudflare edge origin lock: shared secret Cloudflare injects as the
# X-Edge-Auth header on proxied requests; the backend edge-auth
# middleware rejects public requests that lack it (blocks direct-to-
# origin bypass of the WAF). Value added manually; also provided to
# Pulumi as `edge:originSecret` for the Cloudflare header transform.
# See modules/edge_security.py.
"edge-origin-secret",
]
secrets = {}
for secret_id in secret_names:
secrets[secret_id] = secretmanager.Secret(
secret_id,
secret_id=secret_id,
replication=secretmanager.SecretReplicationArgs(
auto=secretmanager.SecretReplicationAutoArgs(),
),
)
return secrets