Files
karaoke-gen/infrastructure/modules/storage.py
T
Andrew Beveridge ☄️andClaude Opus 4.6 ca0d5507b2 Business continuity: DR backups, read-only SA, deny policies (#639)
## Summary

- Two-tier disaster recovery: GCP-native protections (PITR, versioning,
deny policies) + cross-cloud AWS S3 backups
- Nightly Cloud Function exports Firestore, BigQuery, and GCS job files
to AWS S3
- Read-only Claude SA (`claude-readonly`) and break-glass SA for
emergency access
- IAM deny policy blocking `buckets.delete` and `datasets.delete` for
all principals
- External backup freshness monitor (AWS Lambda alerts if backups go
stale >48h)

## Changes

**Infrastructure (Pulumi):**
- `modules/iam/claude_readonly_sa.py` — new read-only + break-glass SAs
- `modules/backup.py` — backup SA, staging bucket, Cloud Function, Cloud
Scheduler
- `modules/database.py` — enable Firestore PITR
- `modules/storage.py` — enable GCS versioning + soft delete lifecycle
- `modules/secrets.py` — add `discord-alert-webhook` secret
- `__main__.py` — wire new modules

**Backup Cloud Function:**
- `functions/backup_to_aws/` — Firestore export, BigQuery export
(weekly/monthly), GCS delta sync, S3 streaming upload, Discord alerts

**Documentation:**
- `docs/DISASTER-RECOVERY.md` — restore runbook for accidental deletion
+ catastrophic GCP loss
- `docs/archive/2026-03-27-business-continuity-design.md` — full design
spec
- `docs/archive/2026-03-29-business-continuity-plan.md` — implementation
plan
- `docs/archive/2026-03-29-external-services-config.md` —
OAuth/DNS/external service reference

## Already deployed

All infrastructure has been applied via `pulumi up`. First backup run
completed successfully (Firestore + job files in S3). Nightly backups
running at 1 AM ET.

## Test plan

- [x] Pulumi preview — 30 creates, 2 updates, 0 deletes
- [x] Pulumi up — all resources deployed
- [x] Manual backup function trigger — Firestore export (1.4 GB) landed
in S3
- [x] GCS job files sync — 161 files (2.9 GB) in S3
- [x] AWS Lambda freshness check — returned `ok` (3h age)
- [x] IAM deny policy verified active via `gcloud iam policies get`

@coderabbitai ignore

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 03:32:01 +00:00

61 lines
1.9 KiB
Python

"""
Cloud Storage resources.
Manages the GCS bucket for uploads, outputs, and temporary files.
"""
import pulumi
import pulumi_gcp as gcp
from pulumi_gcp import storage
from config import PROJECT_ID
def create_bucket() -> storage.Bucket:
"""
Create the main GCS bucket with lifecycle rules.
Returns:
storage.Bucket: The created bucket resource.
"""
bucket = storage.Bucket(
"karaoke-storage",
name=f"karaoke-gen-storage-{PROJECT_ID}",
location="US-CENTRAL1",
force_destroy=False, # Prevent accidental deletion
uniform_bucket_level_access=True,
cors=[
storage.BucketCorArgs(
origins=[
"https://gen.nomadkaraoke.com",
"https://vocalstar.nomadkaraoke.com",
"https://singa.nomadkaraoke.com",
"http://localhost:3000",
],
methods=["PUT"],
response_headers=["Content-Type"],
max_age_seconds=3600,
),
],
versioning=storage.BucketVersioningArgs(enabled=True),
soft_delete_policy=storage.BucketSoftDeletePolicyArgs(retention_duration_seconds=604800),
lifecycle_rules=[
storage.BucketLifecycleRuleArgs(
action=storage.BucketLifecycleRuleActionArgs(type="Delete"),
condition=storage.BucketLifecycleRuleConditionArgs(
age=7,
matches_prefixes=["temp/", "uploads/"]
),
),
storage.BucketLifecycleRuleArgs(
action=storage.BucketLifecycleRuleActionArgs(type="Delete"),
condition=storage.BucketLifecycleRuleConditionArgs(
num_newer_versions=1,
days_since_noncurrent_time=30,
),
),
],
)
return bucket