diff --git a/CLAUDE.md b/CLAUDE.md index 819997f4..56b4592d 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -92,6 +92,7 @@ See `docs/TESTING.md` § "Ad-Hoc Production Debugging" for full details. ### Infrastructure - **All GCP changes via Pulumi PRs** - changes in `infrastructure/` deploy automatically on merge to main +- **`infrastructure/` is the shared platform IaC home**: the GCP project (`infrastructure/`) and the Nomad Karaoke Cloudflare account (`infrastructure/cloudflare/`, own Pulumi project + stack, see its README). Never hand-edit Cloudflare config that stack manages; app repos keep only app-specific stacks - **Always run `pulumi up` locally BEFORE merging PRs** - CI deploys run on spot VMs that can be preempted mid-apply, causing partial state. Apply locally first, then merge (CI re-runs as no-op) - Never modify GCP resources directly via console or `gcloud` CLI - `gcloud` CLI for reading/debugging only (e.g., checking logs, SSH to VMs) diff --git a/infrastructure/README.md b/infrastructure/README.md index 1e68b80d..e9fb0aee 100644 --- a/infrastructure/README.md +++ b/infrastructure/README.md @@ -1,6 +1,16 @@ # Infrastructure as Code with Pulumi -This directory contains Pulumi infrastructure code that manages all Google Cloud Platform resources for the karaoke generator backend. +This directory is the home of Nomad Karaoke's **shared platform IaC**. It holds two Pulumi projects: + +| Project | Path | Stack | Manages | +|---|---|---|---| +| `karaoke-gen-infrastructure` | `infrastructure/` | `prod` | The `nomadkaraoke` GCP project: gen's backend plus shared services (runner manager, divebar, KN sync, error monitor, monitoring, backups, IAM, secrets), and gen's Cloudflare edge security on `api.nomadkaraoke.com` | +| `nomad-cloudflare` | `infrastructure/cloudflare/` | `nomadkaraoke/prod` | The Nomad Karaoke Cloudflare account: zones, DNS, rulesets, email routing, tunnels, Zero Trust, Pages/Worker domains. See [cloudflare/README.md](cloudflare/README.md) | + +**Boundary rule:** infra that isn't specific to one app lives here. App repos keep only +app-specific stacks (e.g. karaoke-decide's Cloud Run and its API-proxy Worker + route). Every +Cloudflare zone ruleset phase has exactly one owner; see the exclusions table in `cloudflare/README.md`. +CI never runs `pulumi up` for either project: apply locally, then merge. ## Directory Structure diff --git a/infrastructure/cloudflare/Pulumi.prod.yaml b/infrastructure/cloudflare/Pulumi.prod.yaml new file mode 100644 index 00000000..74d56e55 --- /dev/null +++ b/infrastructure/cloudflare/Pulumi.prod.yaml @@ -0,0 +1,4 @@ +config: + cloudflare:apiToken: + secure: AAABAJQoc2aprEO7/4n8Jc+tLlEH9FOc/r3QxCfq3qM3khE3kize3trhuWhFCELZFMQ4ZVZ2KsuAYr4Z9zveF9SQqsx8/jJn/zTIhFvFHyQFx8E3wQ== + nomad-cloudflare:accountId: 4585249dcf5d2f9fb4e075c5382cd071 diff --git a/infrastructure/cloudflare/Pulumi.yaml b/infrastructure/cloudflare/Pulumi.yaml new file mode 100644 index 00000000..4463618a --- /dev/null +++ b/infrastructure/cloudflare/Pulumi.yaml @@ -0,0 +1,6 @@ +name: nomad-cloudflare +runtime: + name: python + options: + virtualenv: venv +description: Nomad Karaoke Cloudflare account (zones, DNS, rules, email, tunnels, Access, Pages/Workers domains). See README.md. diff --git a/infrastructure/cloudflare/README.md b/infrastructure/cloudflare/README.md new file mode 100644 index 00000000..f3b9de39 --- /dev/null +++ b/infrastructure/cloudflare/README.md @@ -0,0 +1,81 @@ +# nomad-cloudflare: the Nomad Karaoke Cloudflare account as code + +Pulumi project for the dedicated **Nomad Karaoke** Cloudflare account +(`4585249dcf5d2f9fb4e075c5382cd071`, owner admin@nomadkaraoke.com). Stack: `nomadkaraoke/prod` +on Pulumi Cloud (`nomadkaraoke/nomad-cloudflare/prod`). + +It sits beside the GCP platform project in `infrastructure/`. Both are **shared platform IaC**: +`karaoke-gen/infrastructure` is the home for infra that isn't specific to one app. App repos keep +only app-specific stacks (e.g. karaoke-decide's Cloud Run + its API-proxy Worker). + +## What's managed here + +| Module | Resources | +|---|---| +| `zones.py` | The 5 zones (**protected**) and the `ssl` mode of each | +| `dns.py` | 84 DNS records across all zones (exclusions below) | +| `rulesets.py` | Zone ruleset entrypoints: dynamic redirects (all zones), config settings + origin rules (nomadkaraoke.com: flacfetch), karaokehunt.com's custom WAF rule | +| `email_routing.py` | Gmail destination address; Email Routing enablement (**protected**), catch-all and `google@` rules for nomadkaraoke.com, nomadkaroke.com, karaokehunt.com | +| `tunnels.py` | `nomad-kjbox` (NomadPC: sing, kjbox, kjssh, kjvnc) and `nomad-hf2` (fiverrbot) tunnels (**protected**) + ingress | +| `access.py` | Zero Trust org (**protected**), one-time-PIN IdP, `claude-code-kjbox` service token, reusable policies and the KJ Controller / FiverrBot noVNC apps | +| `pages_workers.py` | Pages projects `karaoke-gen` + `karaoke-gen-tenant`, `gen.nomadkaraoke.com` Pages domain, nomadkaraoke.com/www Worker custom domains, `create.karaokehunt.com/*` route | + +All resource IDs (`ids.py`) are non-secret. Removing a non-protected resource from code deletes it +on the next `pulumi up`, and `pulumi preview` always shows that first. + +## Deliberately NOT managed here + +| What | Owner | +|---|---| +| `api` / `api-edge-test` DNS, nomadkaraoke.com `http_request_firewall_custom` / `http_ratelimit` / `http_request_late_transform` phases, `security_level` | GCP platform project, `infrastructure/modules/edge_security.py` | +| Tenant portal CNAMEs (`.nomadkaraoke.com`) and `karaoke-gen-tenant` custom domains | Created at runtime by `backend/services/tenant_domain_service.py` | +| `decide.nomadkaraoke.com/api/*` route + `karaoke-decide-api-proxy` Worker | karaoke-decide's Pulumi stack | +| Worker/Pages **code** deploys | gen CI (`wrangler pages deploy`), public-website Workers Builds, `karaokehunt-interceptor/deploy.sh` (its route + DNS "ensure" steps match what's declared here) | +| Read-only DNS records (Email Routing MX/DKIM, Worker custom-domain AAAAs) | Owned by Email Routing / Workers custom domains | +| karaokehunt.com `http_config_settings` ("SSL for create.karaokehunt.com", "Disable challenge for create API") | Dashboard. pulumi-cloudflare 6.22.1 drops `set_config bic:false`, so every refresh fails | +| Tunnel connector tokens / cloudflared processes | NomadPC systemd `cloudflared-nomad`, hf2 `~/nomad-tunnel` compose | +| Registrar, billing, API tokens, account members | Dashboard (admin@nomadkaraoke.com) | + +## Usage + +```bash +cd infrastructure/cloudflare +python3 -m venv venv && venv/bin/pip install -r requirements.txt # first time +pulumi stack select nomadkaraoke/prod +pulumi preview # must be clean (0 changes) before you start +# edit code, preview, then: +pulumi up +``` + +Unit tests for the import-list builder: `venv/bin/pip install pytest && venv/bin/python -m pytest tests -c /dev/null` +(`-c /dev/null` skips the repo-root pytest config, which needs the backend's plugins). + +As with the GCP project, **CI does not run Pulumi**. Apply locally, then merge the PR. + +The `cloudflare:apiToken` in `Pulumi.prod.yaml` is the account-owned token +`nomad-cloudflare-pulumi`. It is scoped to zones/DNS/rules/email routing/Workers routes on all +zones, plus tunnels/Access/Pages/Worker domains on the account, and cannot manage tokens or billing. + +## Adopting resources created outside Pulumi + +`scripts/build_import_list.py` lists the account's resources minus the exclusions above in +`pulumi import --file` format: + +```bash +source ../../../.envrc # workspace: CLOUDFLARE_API_TOKEN / CLOUDFLARE_ACCOUNT_ID (Nomad account) +python3 scripts/build_import_list.py > /tmp/import.json +# keep only the new entries, then: +pulumi import --file /tmp/import.json --out /tmp/generated.py +``` + +Paste the generated code into the right module, replace literal IDs with `ACCOUNT_ID` / +`ZONE_IDS[...]`, and drop `protect=True` unless it belongs to the protected set above. + +## Provider gotchas (pulumi-cloudflare 6.22.1) + +- Codegen drops `false` values. It lost `bic: false` above, and `support_subaddress=False` must be + explicit on `EmailRoutingSettings` or every preview shows a no-op update. +- After an import, Email Routing / Access resources can show an "update" with no property diff. + It is a one-time state settlement, and applying it was verified as a live no-op (2026-10-15). +- Reusable Access policies default to a 24h session. Set `session_duration` to match the app (730h). +- `ZeroTrustAccessApplication`: use `destinations`, not the deprecated `self_hosted_domains` (both together fail validation). diff --git a/infrastructure/cloudflare/__main__.py b/infrastructure/cloudflare/__main__.py new file mode 100644 index 00000000..f5eeecca --- /dev/null +++ b/infrastructure/cloudflare/__main__.py @@ -0,0 +1,8 @@ +"""Nomad Karaoke Cloudflare account. Each module declares its resources on import.""" +import access # noqa: F401 +import dns # noqa: F401 +import email_routing # noqa: F401 +import pages_workers # noqa: F401 +import rulesets # noqa: F401 +import tunnels # noqa: F401 +import zones # noqa: F401 diff --git a/infrastructure/cloudflare/access.py b/infrastructure/cloudflare/access.py new file mode 100644 index 00000000..a114eff9 --- /dev/null +++ b/infrastructure/cloudflare/access.py @@ -0,0 +1,83 @@ +"""Zero Trust: organization (protected), identity provider, service token and self-hosted Access apps. + +Adopted from the live account with `pulumi import` (2026-10-15); see README.md. +""" +import pulumi +import pulumi_cloudflare as cloudflare + +from ids import ACCOUNT_ID, ZONE_IDS + +access_organization = cloudflare.ZeroTrustOrganization("access-organization", + account_id=ACCOUNT_ID, + auth_domain="nomadkaraoke.cloudflareaccess.com", + name="Nomad Karaoke", + strict_service_token_auth=True, + opts=pulumi.ResourceOptions(protect=True)) +access_idp_onetimepin = cloudflare.ZeroTrustAccessIdentityProvider("access-idp-onetimepin", + account_id=ACCOUNT_ID, + config={}, + name="One-time PIN", + type="onetimepin") +access_service_token_claude_code_kjbox = cloudflare.ZeroTrustAccessServiceToken("access-service-token-claude-code-kjbox", + account_id=ACCOUNT_ID, + duration="forever", + enabled=True, + name="claude-code-kjbox") + +# Reusable policies (the rules themselves live here, not in the dashboard). session_duration is +# pinned to the apps' 730h because a reusable policy otherwise imposes Cloudflare's 24h default. +policy_kj_controller_users = cloudflare.ZeroTrustAccessPolicy("access-policy-kj-controller-users", + account_id=ACCOUNT_ID, + name="KJ Controller: Andrew, David, @nomadkaraoke.com, @beveridge.uk", + decision="allow", + session_duration="730h", + includes=[ + {"email": {"email": "andrew.d.beveridge@gmail.com"}}, + {"email": {"email": "david.t.axe@gmail.com"}}, + {"email_domain": {"domain": "nomadkaraoke.com"}}, + {"email_domain": {"domain": "beveridge.uk"}}, + ]) +policy_kj_controller_service_token = cloudflare.ZeroTrustAccessPolicy("access-policy-kj-controller-service-token", + account_id=ACCOUNT_ID, + name="KJ Controller: claude-code-kjbox service token", + decision="non_identity", + includes=[{"service_token": {"token_id": access_service_token_claude_code_kjbox.id}}]) +policy_fiverrbot_users = cloudflare.ZeroTrustAccessPolicy("access-policy-fiverrbot-users", + account_id=ACCOUNT_ID, + name="FiverrBot: Andrew only (explicit emails)", + decision="allow", + session_duration="730h", + includes=[ + {"email": {"email": "andrew.d.beveridge@gmail.com"}}, + {"email": {"email": "andrew@beveridge.uk"}}, + {"email": {"email": "admin@nomadkaraoke.com"}}, + ]) +access_app_fiverrbot_nomadkaraoke_com = cloudflare.ZeroTrustAccessApplication("access-app-fiverrbot-nomadkaraoke-com", + account_id=ACCOUNT_ID, + app_launcher_visible=True, + destinations=[{ + "type": "public", + "uri": "fiverrbot.nomadkaraoke.com", + }], + domain="fiverrbot.nomadkaraoke.com", + http_only_cookie_attribute=True, + name="FiverrBot noVNC", + policies=[{"id": policy_fiverrbot_users.id, "precedence": 1}], + session_duration="730h", + type="self_hosted") +access_app_kjbox_nomadkaraoke_com = cloudflare.ZeroTrustAccessApplication("access-app-kjbox-nomadkaraoke-com", + account_id=ACCOUNT_ID, + app_launcher_visible=True, + destinations=[{ + "type": "public", + "uri": "kjbox.nomadkaraoke.com", + }], + domain="kjbox.nomadkaraoke.com", + http_only_cookie_attribute=True, + name="KJ Controller", + policies=[ + {"id": policy_kj_controller_users.id, "precedence": 1}, + {"id": policy_kj_controller_service_token.id, "precedence": 2}, + ], + session_duration="730h", + type="self_hosted") diff --git a/infrastructure/cloudflare/dns.py b/infrastructure/cloudflare/dns.py new file mode 100644 index 00000000..64b65a9e --- /dev/null +++ b/infrastructure/cloudflare/dns.py @@ -0,0 +1,549 @@ +"""DNS records. Excludes: api/api-edge-test (gen GCP stack, modules/edge_security.py), tenant-portal CNAMEs +(gen backend tenant_domain_service, at runtime), and read-only records owned by Email Routing / Workers custom domains. + +Adopted from the live account with `pulumi import` (2026-10-15); see README.md. +""" +import pulumi +import pulumi_cloudflare as cloudflare + +from ids import ACCOUNT_ID, ZONE_IDS + +dns_karaokehunt_com_dmarc_txt = cloudflare.DnsRecord("dns-karaokehunt-com-dmarc-txt", + content="v=DMARC1; p=none;", + name="_dmarc.karaokehunt.com", + ttl=1, + type="TXT", + zone_id=ZONE_IDS["karaokehunt.com"]) +dns_karaokehunt_com_domainconnect_cname = cloudflare.DnsRecord("dns-karaokehunt-com-domainconnect-cname", + content="connect.domains.google.com", + name="_domainconnect.karaokehunt.com", + proxied=True, + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["karaokehunt.com"]) +dns_karaokehunt_com_app_a = cloudflare.DnsRecord("dns-karaokehunt-com-app-a", + content="34.136.28.237", + name="app.karaokehunt.com", + proxied=True, + ttl=1, + type="A", + zone_id=ZONE_IDS["karaokehunt.com"]) +dns_karaokehunt_com_buy_cname = cloudflare.DnsRecord("dns-karaokehunt-com-buy-cname", + content="shops.myshopify.com", + name="buy.karaokehunt.com", + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["karaokehunt.com"]) +dns_karaokehunt_com_cka_domainkey_cname = cloudflare.DnsRecord("dns-karaokehunt-com-cka-domainkey-cname", + content="dkim.dm-0m71zxnm.sg6.convertkit.com", + name="cka._domainkey.karaokehunt.com", + ttl=3600, + type="CNAME", + zone_id=ZONE_IDS["karaokehunt.com"]) +dns_karaokehunt_com_ckespa_cname = cloudflare.DnsRecord("dns-karaokehunt-com-ckespa-cname", + content="spf.dm-0m71zxnm.sg6.convertkit.com", + name="ckespa.karaokehunt.com", + ttl=3600, + type="CNAME", + zone_id=ZONE_IDS["karaokehunt.com"]) +dns_karaokehunt_com_create_a = cloudflare.DnsRecord("dns-karaokehunt-com-create-a", + content="23.137.104.20", + name="create.karaokehunt.com", + proxied=True, + ttl=1, + type="A", + zone_id=ZONE_IDS["karaokehunt.com"]) +dns_karaokehunt_com_emailreturn_cname = cloudflare.DnsRecord("dns-karaokehunt-com-emailreturn-cname", + content="return.smtp2go.net", + name="emailreturn.karaokehunt.com", + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["karaokehunt.com"]) +dns_karaokehunt_com_apex_aaaa = cloudflare.DnsRecord("dns-karaokehunt-com-apex-aaaa", + content="100::", + name="karaokehunt.com", + proxied=True, + ttl=1, + type="AAAA", + zone_id=ZONE_IDS["karaokehunt.com"]) +dns_karaokehunt_com_apex_txt = cloudflare.DnsRecord("dns-karaokehunt-com-apex-txt", + content="\"google-site-verification=zyr_Yj2Zl7CncopI4H2gIU_yTyLxNAVyx4gxF1VAhdo\"", + name="karaokehunt.com", + ttl=1, + type="TXT", + zone_id=ZONE_IDS["karaokehunt.com"]) +dns_karaokehunt_com_apex_txt_2 = cloudflare.DnsRecord("dns-karaokehunt-com-apex-txt-2", + content="\"v=spf1 include:_spf.mx.cloudflare.net ~all\"", + name="karaokehunt.com", + ttl=1, + type="TXT", + zone_id=ZONE_IDS["karaokehunt.com"]) +dns_karaokehunt_com_apex_txt_3 = cloudflare.DnsRecord("dns-karaokehunt-com-apex-txt-3", + content="google-site-verification=qYoRMbH2lydeYmXjgcEY8tIpZ6gXV7qhwi_ysYq256M", + name="karaokehunt.com", + ttl=3600, + type="TXT", + zone_id=ZONE_IDS["karaokehunt.com"]) +dns_karaokehunt_com_link_cname = cloudflare.DnsRecord("dns-karaokehunt-com-link-cname", + content="track.smtp2go.net", + name="link.karaokehunt.com", + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["karaokehunt.com"]) +dns_karaokehunt_com_roadmap_cname = cloudflare.DnsRecord("dns-karaokehunt-com-roadmap-cname", + content="karaokehunt.com", + name="roadmap.karaokehunt.com", + proxied=True, + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["karaokehunt.com"]) +dns_karaokehunt_com_s680586_domainkey_cname = cloudflare.DnsRecord("dns-karaokehunt-com-s680586-domainkey-cname", + content="dkim.smtp2go.net", + name="s680586._domainkey.karaokehunt.com", + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["karaokehunt.com"]) +dns_karaokehunt_com_static_cname = cloudflare.DnsRecord("dns-karaokehunt-com-static-cname", + content="beveradb.com", + name="static.karaokehunt.com", + proxied=True, + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["karaokehunt.com"]) +dns_karaokehunt_com_tools_cname = cloudflare.DnsRecord("dns-karaokehunt-com-tools-cname", + content="beveradb.com", + name="tools.karaokehunt.com", + proxied=True, + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["karaokehunt.com"]) +dns_karaokehunt_com_www_app_cname = cloudflare.DnsRecord("dns-karaokehunt-com-www-app-cname", + content="karaokay-karaoke-song-choice-helper-eiqxrt.custom-domain-proxy.flutterflow.app", + name="www.app.karaokehunt.com", + proxied=True, + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["karaokehunt.com"]) +dns_karaokehunt_com_www_aaaa = cloudflare.DnsRecord("dns-karaokehunt-com-www-aaaa", + content="100::", + name="www.karaokehunt.com", + proxied=True, + ttl=1, + type="AAAA", + zone_id=ZONE_IDS["karaokehunt.com"]) +dns_kjbox_cc_apex_a = cloudflare.DnsRecord("dns-kjbox-cc-apex-a", + comment="placeholder - all traffic 302s to sing.nomadkaraoke.com via redirect rules", + content="192.0.2.1", + name="kjbox.cc", + proxied=True, + ttl=1, + type="A", + zone_id=ZONE_IDS["kjbox.cc"]) +dns_kjbox_cc_l_a = cloudflare.DnsRecord("dns-kjbox-cc-l-a", + content="192.168.8.170", + name="l.kjbox.cc", + ttl=1, + type="A", + zone_id=ZONE_IDS["kjbox.cc"]) +dns_kjbox_cc_www_cname = cloudflare.DnsRecord("dns-kjbox-cc-www-cname", + comment="redirects like apex", + content="kjbox.cc", + name="www.kjbox.cc", + proxied=True, + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["kjbox.cc"]) +dns_kjtip_me_apex_a = cloudflare.DnsRecord("dns-kjtip-me-apex-a", + comment="placeholder — zone-level redirect to nomadkaraoke.com/tip", + content="192.0.2.1", + name="kjtip.me", + proxied=True, + ttl=1, + type="A", + zone_id=ZONE_IDS["kjtip.me"]) +dns_kjtip_me_www_cname = cloudflare.DnsRecord("dns-kjtip-me-www-cname", + comment="placeholder — zone-level redirect to nomadkaraoke.com/tip", + content="kjtip.me", + name="www.kjtip.me", + proxied=True, + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["kjtip.me"]) +dns_nomadkaraoke_com_20260427041918pm_domainkey_txt = cloudflare.DnsRecord("dns-nomadkaraoke-com-20260427041918pm-domainkey-txt", + content="\"k=rsa;p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCWwk+JgZT0PPmvs2AVxrWIE6fV1HKWGm/xYnvA5/5FEiWemKvZzebZXTWoEivJoY+4BUCqU3i3q/Wwo3y6gkhUzk1tfLdGv4RCCwyVdzt6wBMdt/Hzdr/F+KzOsNBw4jTdnh6L2WCJDZXs2VJi6fuW5Jory1IUoUBx22UKrgvhXQIDAQAB\"", + name="20260427041918pm._domainkey.nomadkaraoke.com", + ttl=1, + type="TXT", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_58424611_cname = cloudflare.DnsRecord("dns-nomadkaraoke-com-58424611-cname", + content="sendgrid.net", + name="58424611.nomadkaraoke.com", + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_dmarc_txt = cloudflare.DnsRecord("dns-nomadkaraoke-com-dmarc-txt", + content="\"v=DMARC1; p=none; rua=mailto:71983fc0bec54aafa35bce88a6f426f0@dmarc-reports.cloudflare.net\"", + name="_dmarc.nomadkaraoke.com", + ttl=1, + type="TXT", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_dmarc_support_shop_txt = cloudflare.DnsRecord("dns-nomadkaraoke-com-dmarc-support-shop-txt", + content="\"v=DMARC1; p=reject; pct=100; rua=mailto:dmarc@fourthwall.com\"", + name="_dmarc.support.shop.nomadkaraoke.com", + ttl=1, + type="TXT", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_github_pages_challenge_beveradb_lyrics_txt = cloudflare.DnsRecord("dns-nomadkaraoke-com-github-pages-challenge-beveradb-lyrics-txt", + content="\"74b598a15a8e1561615ecd838a34d6\"", + name="_github-pages-challenge-beveradb.lyrics.nomadkaraoke.com", + ttl=1, + type="TXT", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_github_pages_challenge_beveradb_txt = cloudflare.DnsRecord("dns-nomadkaraoke-com-github-pages-challenge-beveradb-txt", + content="49046bf3b3a5fe753be8b124622268", + name="_github-pages-challenge-beveradb.nomadkaraoke.com", + ttl=1, + type="TXT", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_github_pages_challenge_nomadkaraoke_txt = cloudflare.DnsRecord("dns-nomadkaraoke-com-github-pages-challenge-nomadkaraoke-txt", + content="\"1f4390b7b2e73e05924af315a4b457\"", + name="_github-pages-challenge-nomadkaraoke.nomadkaraoke.com", + ttl=1, + type="TXT", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_create_a = cloudflare.DnsRecord("dns-nomadkaraoke-com-create-a", + content="23.137.104.20", + name="create.nomadkaraoke.com", + ttl=1, + type="A", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_decide_cname = cloudflare.DnsRecord("dns-nomadkaraoke-com-decide-cname", + content="nomadkaraoke.github.io", + name="decide.nomadkaraoke.com", + proxied=True, + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_discord_cname = cloudflare.DnsRecord("dns-nomadkaraoke-com-discord-cname", + content="nomadkaraoke.com", + name="discord.nomadkaraoke.com", + proxied=True, + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_em_fw_support_shop_cname = cloudflare.DnsRecord("dns-nomadkaraoke-com-em-fw-support-shop-cname", + content="u48267109.wl110.sendgrid.net", + name="em-fw.support.shop.nomadkaraoke.com", + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_em9596_cname = cloudflare.DnsRecord("dns-nomadkaraoke-com-em9596-cname", + content="u58424611.wl112.sendgrid.net", + name="em9596.nomadkaraoke.com", + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_emailreturn_cname = cloudflare.DnsRecord("dns-nomadkaraoke-com-emailreturn-cname", + content="return.smtp2go.net", + name="emailreturn.nomadkaraoke.com", + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_fiverrbot_cname = cloudflare.DnsRecord("dns-nomadkaraoke-com-fiverrbot-cname", + content="531403b1-bcfa-4f6e-912e-a10bd8e5ebd5.cfargotunnel.com", + name="fiverrbot.nomadkaraoke.com", + proxied=True, + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_flacfetch_a = cloudflare.DnsRecord("dns-nomadkaraoke-com-flacfetch-a", + content="152.53.245.109", + name="flacfetch.nomadkaraoke.com", + proxied=True, + ttl=1, + type="A", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_flacup_a = cloudflare.DnsRecord("dns-nomadkaraoke-com-flacup-a", + content="152.53.245.109", + name="flacup.nomadkaraoke.com", + ttl=1, + type="A", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_gen_cname = cloudflare.DnsRecord("dns-nomadkaraoke-com-gen-cname", + content="karaoke-gen-9k4.pages.dev", + name="gen.nomadkaraoke.com", + proxied=True, + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_kjbox_cname = cloudflare.DnsRecord("dns-nomadkaraoke-com-kjbox-cname", + content="04c88337-f076-45ed-bc19-4ac1222b4228.cfargotunnel.com", + name="kjbox.nomadkaraoke.com", + proxied=True, + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_kjssh_cname = cloudflare.DnsRecord("dns-nomadkaraoke-com-kjssh-cname", + content="04c88337-f076-45ed-bc19-4ac1222b4228.cfargotunnel.com", + name="kjssh.nomadkaraoke.com", + proxied=True, + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_kjvnc_cname = cloudflare.DnsRecord("dns-nomadkaraoke-com-kjvnc-cname", + content="04c88337-f076-45ed-bc19-4ac1222b4228.cfargotunnel.com", + name="kjvnc.nomadkaraoke.com", + proxied=True, + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_link_cname = cloudflare.DnsRecord("dns-nomadkaraoke-com-link-cname", + content="track.smtp2go.net", + name="link.nomadkaraoke.com", + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_list_a = cloudflare.DnsRecord("dns-nomadkaraoke-com-list-a", + content="3.13.222.255", + name="list.nomadkaraoke.com", + ttl=1, + type="A", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_list_a_2 = cloudflare.DnsRecord("dns-nomadkaraoke-com-list-a-2", + content="3.13.246.91", + name="list.nomadkaraoke.com", + ttl=1, + type="A", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_list_a_3 = cloudflare.DnsRecord("dns-nomadkaraoke-com-list-a-3", + content="3.130.60.26", + name="list.nomadkaraoke.com", + ttl=1, + type="A", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_lyrics_cname = cloudflare.DnsRecord("dns-nomadkaraoke-com-lyrics-cname", + content="nomadkaraoke.github.io", + name="lyrics.nomadkaraoke.com", + proxied=True, + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_nginx_cname = cloudflare.DnsRecord("dns-nomadkaraoke-com-nginx-cname", + content="advinvps.beveradb.com", + name="nginx.nomadkaraoke.com", + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_apex_txt = cloudflare.DnsRecord("dns-nomadkaraoke-com-apex-txt", + content="\"google-site-verification=jXOuxy5qwd2KEkrdi-ML94QHMC7gaziRkTWEnr0-FV0\"", + name="nomadkaraoke.com", + ttl=3600, + type="TXT", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_apex_txt_2 = cloudflare.DnsRecord("dns-nomadkaraoke-com-apex-txt-2", + content="\"v=spf1 include:_spf.mx.cloudflare.net ~all\"", + name="nomadkaraoke.com", + ttl=1, + type="TXT", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_apex_txt_3 = cloudflare.DnsRecord("dns-nomadkaraoke-com-apex-txt-3", + comment="Facebook domain verification (added 2026-08-24)", + content="facebook-domain-verification=fviv2nkwuj710dqi5plurfv73vfent", + name="nomadkaraoke.com", + ttl=300, + type="TXT", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_apex_txt_4 = cloudflare.DnsRecord("dns-nomadkaraoke-com-apex-txt-4", + content="google-site-verification=A-0Rh0rOXYFF3nosQK7g3F-1ieyoHCvIfwUBl035eEs", + name="nomadkaraoke.com", + ttl=3600, + type="TXT", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_apex_txt_5 = cloudflare.DnsRecord("dns-nomadkaraoke-com-apex-txt-5", + content="google-site-verification=WndCzajlPYFkQbhZxVhWLl5Ok3SdD016ZiGLq2dl_lE", + name="nomadkaraoke.com", + ttl=3600, + type="TXT", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_pay_cname = cloudflare.DnsRecord("dns-nomadkaraoke-com-pay-cname", + content="nomadkaraoke.com", + name="pay.nomadkaraoke.com", + proxied=True, + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_pm_bounces_cname = cloudflare.DnsRecord("dns-nomadkaraoke-com-pm-bounces-cname", + content="pm.mtasv.net", + name="pm-bounces.nomadkaraoke.com", + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_requests_cname = cloudflare.DnsRecord("dns-nomadkaraoke-com-requests-cname", + comment="Requests voting board vanity subdomain → redirect rule to gen/en/requests (added by Claude, PR #975)", + content="gen.nomadkaraoke.com", + name="requests.nomadkaraoke.com", + proxied=True, + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_s1_domainkey_cname = cloudflare.DnsRecord("dns-nomadkaraoke-com-s1-domainkey-cname", + content="s1.domainkey.u58424611.wl112.sendgrid.net", + name="s1._domainkey.nomadkaraoke.com", + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_s1_domainkey_support_shop_cname = cloudflare.DnsRecord("dns-nomadkaraoke-com-s1-domainkey-support-shop-cname", + content="s1.domainkey.u48267109.wl110.sendgrid.net", + name="s1._domainkey.support.shop.nomadkaraoke.com", + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_s2_domainkey_cname = cloudflare.DnsRecord("dns-nomadkaraoke-com-s2-domainkey-cname", + content="s2.domainkey.u58424611.wl112.sendgrid.net", + name="s2._domainkey.nomadkaraoke.com", + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_s2_domainkey_support_shop_cname = cloudflare.DnsRecord("dns-nomadkaraoke-com-s2-domainkey-support-shop-cname", + content="s2.domainkey.u48267109.wl110.sendgrid.net", + name="s2._domainkey.support.shop.nomadkaraoke.com", + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_s680586_domainkey_cname = cloudflare.DnsRecord("dns-nomadkaraoke-com-s680586-domainkey-cname", + content="dkim.smtp2go.net", + name="s680586._domainkey.nomadkaraoke.com", + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_shop_a = cloudflare.DnsRecord("dns-nomadkaraoke-com-shop-a", + content="34.117.223.165", + name="shop.nomadkaraoke.com", + ttl=1, + type="A", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_sing_cname = cloudflare.DnsRecord("dns-nomadkaraoke-com-sing-cname", + content="04c88337-f076-45ed-bc19-4ac1222b4228.cfargotunnel.com", + name="sing.nomadkaraoke.com", + proxied=True, + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_status_cname = cloudflare.DnsRecord("dns-nomadkaraoke-com-status-cname", + content="nomadkaraoke.github.io", + name="status.nomadkaraoke.com", + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_support_shop_mx = cloudflare.DnsRecord("dns-nomadkaraoke-com-support-shop-mx", + content="mx1.improvmx.com", + name="support.shop.nomadkaraoke.com", + priority=10, + ttl=1, + type="MX", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_support_shop_mx_2 = cloudflare.DnsRecord("dns-nomadkaraoke-com-support-shop-mx-2", + content="mx2.improvmx.com", + name="support.shop.nomadkaraoke.com", + priority=20, + ttl=1, + type="MX", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_support_shop_txt = cloudflare.DnsRecord("dns-nomadkaraoke-com-support-shop-txt", + content="\"v=spf1 include:_spf.google.com include:mail.zendesk.com include:spf.improvmx.com include:sendgrid.net ~all\"", + name="support.shop.nomadkaraoke.com", + ttl=1, + type="TXT", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_url5625_cname = cloudflare.DnsRecord("dns-nomadkaraoke-com-url5625-cname", + content="sendgrid.net", + name="url5625.nomadkaraoke.com", + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_www_shop_cname = cloudflare.DnsRecord("dns-nomadkaraoke-com-www-shop-cname", + content="shop.nomadkaraoke.com", + name="www.shop.nomadkaraoke.com", + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_zendesk1_domainkey_support_shop_cname = cloudflare.DnsRecord("dns-nomadkaraoke-com-zendesk1-domainkey-support-shop-cname", + content="zendesk1._domainkey.zendesk.com", + name="zendesk1._domainkey.support.shop.nomadkaraoke.com", + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_zendesk1_support_shop_cname = cloudflare.DnsRecord("dns-nomadkaraoke-com-zendesk1-support-shop-cname", + content="mail1.zendesk.com", + name="zendesk1.support.shop.nomadkaraoke.com", + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_zendesk2_domainkey_support_shop_cname = cloudflare.DnsRecord("dns-nomadkaraoke-com-zendesk2-domainkey-support-shop-cname", + content="zendesk2._domainkey.zendesk.com", + name="zendesk2._domainkey.support.shop.nomadkaraoke.com", + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_zendesk2_support_shop_cname = cloudflare.DnsRecord("dns-nomadkaraoke-com-zendesk2-support-shop-cname", + content="mail2.zendesk.com", + name="zendesk2.support.shop.nomadkaraoke.com", + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_zendesk3_support_shop_cname = cloudflare.DnsRecord("dns-nomadkaraoke-com-zendesk3-support-shop-cname", + content="mail3.zendesk.com", + name="zendesk3.support.shop.nomadkaraoke.com", + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_zendesk4_support_shop_cname = cloudflare.DnsRecord("dns-nomadkaraoke-com-zendesk4-support-shop-cname", + content="mail4.zendesk.com", + name="zendesk4.support.shop.nomadkaraoke.com", + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaraoke_com_zendeskverification_support_shop_txt = cloudflare.DnsRecord("dns-nomadkaraoke-com-zendeskverification-support-shop-txt", + content="\"522669a6479b6a3a\"", + name="zendeskverification.support.shop.nomadkaraoke.com", + ttl=1, + type="TXT", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +dns_nomadkaroke_com_dmarc_txt = cloudflare.DnsRecord("dns-nomadkaroke-com-dmarc-txt", + content="\"v=DMARC1; p=none; rua=mailto:e768a3e8bc384309949f21b306f944bf@dmarc-reports.cloudflare.net\"", + name="_dmarc.nomadkaroke.com", + ttl=1, + type="TXT", + zone_id=ZONE_IDS["nomadkaroke.com"]) +dns_nomadkaroke_com_apex_cname = cloudflare.DnsRecord("dns-nomadkaroke-com-apex-cname", + content="nomadkaraoke.com", + name="nomadkaroke.com", + proxied=True, + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["nomadkaroke.com"]) +dns_nomadkaroke_com_apex_txt = cloudflare.DnsRecord("dns-nomadkaroke-com-apex-txt", + content="\"v=spf1 include:_spf.mx.cloudflare.net ~all\"", + name="nomadkaroke.com", + ttl=1, + type="TXT", + zone_id=ZONE_IDS["nomadkaroke.com"]) +dns_nomadkaroke_com_apex_txt_2 = cloudflare.DnsRecord("dns-nomadkaroke-com-apex-txt-2", + content="google-site-verification=0MUqA36GQzF3lYA0zZQf2rwOL6DeAUCQbPCvIHYGiVM", + name="nomadkaroke.com", + ttl=3600, + type="TXT", + zone_id=ZONE_IDS["nomadkaroke.com"]) +dns_nomadkaroke_com_apex_txt_3 = cloudflare.DnsRecord("dns-nomadkaroke-com-apex-txt-3", + content="google-site-verification=uwQkq29GTwZmzrvVX2VXezlbiFZ6_U13PrVbDmhsAJU", + name="nomadkaroke.com", + ttl=3600, + type="TXT", + zone_id=ZONE_IDS["nomadkaroke.com"]) +dns_nomadkaroke_com_www_cname = cloudflare.DnsRecord("dns-nomadkaroke-com-www-cname", + content="nomadkaraoke.com", + name="www.nomadkaroke.com", + proxied=True, + ttl=1, + type="CNAME", + zone_id=ZONE_IDS["nomadkaroke.com"]) diff --git a/infrastructure/cloudflare/email_routing.py b/infrastructure/cloudflare/email_routing.py new file mode 100644 index 00000000..36eb7353 --- /dev/null +++ b/infrastructure/cloudflare/email_routing.py @@ -0,0 +1,96 @@ +"""Email Routing: destination address, per-zone enablement (protected), catch-all and literal rules. + +Adopted from the live account with `pulumi import` (2026-10-15); see README.md. +""" +import pulumi +import pulumi_cloudflare as cloudflare + +from ids import ACCOUNT_ID, ZONE_IDS + +email_routing_karaokehunt_com = cloudflare.EmailRoutingSettings("email-routing-karaokehunt-com", zone_id=ZONE_IDS["karaokehunt.com"], + support_subaddress=False, # explicit, else the provider plans a no-op update every run + opts=pulumi.ResourceOptions(protect=True)) +email_catchall_karaokehunt_com = cloudflare.EmailRoutingCatchAll("email-catchall-karaokehunt-com", + actions=[{ + "type": "forward", + "values": ["andrew.d.beveridge@gmail.com"], + }], + enabled=True, + matchers=[{ + "type": "all", + }], + source="api", + zone_id=ZONE_IDS["karaokehunt.com"]) +email_rule_google_karaokehunt_com = cloudflare.EmailRoutingRule("email-rule-google-karaokehunt-com", + actions=[{ + "type": "forward", + "values": ["andrew.d.beveridge@gmail.com"], + }], + enabled=True, + matchers=[{ + "field": "to", + "type": "literal", + "value": "google@karaokehunt.com", + }], + name="google@ forward", + source="api", + zone_id=ZONE_IDS["karaokehunt.com"]) +email_routing_nomadkaraoke_com = cloudflare.EmailRoutingSettings("email-routing-nomadkaraoke-com", zone_id=ZONE_IDS["nomadkaraoke.com"], + support_subaddress=False, # explicit, else the provider plans a no-op update every run + opts=pulumi.ResourceOptions(protect=True)) +email_catchall_nomadkaraoke_com = cloudflare.EmailRoutingCatchAll("email-catchall-nomadkaraoke-com", + actions=[{ + "type": "forward", + "values": ["andrew.d.beveridge@gmail.com"], + }], + enabled=True, + matchers=[{ + "type": "all", + }], + source="api", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +email_rule_google_nomadkaraoke_com = cloudflare.EmailRoutingRule("email-rule-google-nomadkaraoke-com", + actions=[{ + "type": "forward", + "values": ["andrew.d.beveridge@gmail.com"], + }], + enabled=True, + matchers=[{ + "field": "to", + "type": "literal", + "value": "google@nomadkaraoke.com", + }], + name="google@ forward", + source="api", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +email_routing_nomadkaroke_com = cloudflare.EmailRoutingSettings("email-routing-nomadkaroke-com", zone_id=ZONE_IDS["nomadkaroke.com"], + support_subaddress=False, # explicit, else the provider plans a no-op update every run + opts=pulumi.ResourceOptions(protect=True)) +email_catchall_nomadkaroke_com = cloudflare.EmailRoutingCatchAll("email-catchall-nomadkaroke-com", + actions=[{ + "type": "forward", + "values": ["andrew.d.beveridge@gmail.com"], + }], + enabled=True, + matchers=[{ + "type": "all", + }], + source="api", + zone_id=ZONE_IDS["nomadkaroke.com"]) +email_rule_google_nomadkaroke_com = cloudflare.EmailRoutingRule("email-rule-google-nomadkaroke-com", + actions=[{ + "type": "forward", + "values": ["andrew.d.beveridge@gmail.com"], + }], + enabled=True, + matchers=[{ + "field": "to", + "type": "literal", + "value": "google@nomadkaroke.com", + }], + name="google@ forward", + source="api", + zone_id=ZONE_IDS["nomadkaroke.com"]) +email_dest_andrew_d_beveridge_gmail_com = cloudflare.EmailRoutingAddress("email-dest-andrew-d-beveridge-gmail-com", + account_id=ACCOUNT_ID, + email="andrew.d.beveridge@gmail.com") diff --git a/infrastructure/cloudflare/ids.py b/infrastructure/cloudflare/ids.py new file mode 100644 index 00000000..5d2454f9 --- /dev/null +++ b/infrastructure/cloudflare/ids.py @@ -0,0 +1,11 @@ +"""Identifiers of the Nomad Karaoke Cloudflare account (not secret).""" + +ACCOUNT_ID = "4585249dcf5d2f9fb4e075c5382cd071" + +ZONE_IDS = { + "karaokehunt.com": "a9136845466472d41ea82a156059ad9b", + "kjbox.cc": "4e0225d020cf411d0eab74f53d9c673a", + "kjtip.me": "c0a3c3c5ad22a575144912c5f6ff9c83", + "nomadkaraoke.com": "2324a342622e93343cf4e08227d82c02", + "nomadkaroke.com": "8e08d34f1bd63ba2166af94a765da1fd", +} diff --git a/infrastructure/cloudflare/pages_workers.py b/infrastructure/cloudflare/pages_workers.py new file mode 100644 index 00000000..19abc309 --- /dev/null +++ b/infrastructure/cloudflare/pages_workers.py @@ -0,0 +1,72 @@ +"""Pages projects + non-tenant custom domains, Worker custom domains and routes. Code deploys stay with +each repo (gen CI wrangler, public-website Workers Builds); karaoke-decide's route lives in decide's stack. + +Adopted from the live account with `pulumi import` (2026-10-15); see README.md. +""" +import pulumi +import pulumi_cloudflare as cloudflare + +from ids import ACCOUNT_ID, ZONE_IDS + +worker_route_create_karaokehunt_com = cloudflare.WorkersRoute("worker-route-create-karaokehunt-com", + pattern="create.karaokehunt.com/*", + script="karaokehunt-interceptor", + zone_id=ZONE_IDS["karaokehunt.com"]) +pages_karaoke_gen_tenant = cloudflare.PagesProject("pages-karaoke-gen-tenant", + account_id=ACCOUNT_ID, + build_config={ + "destination_dir": "out", + }, + deployment_configs={ + "preview": { + "build_image_major_version": 3, + "compatibility_date": "2026-03-03", + "fail_open": True, + "usage_model": "standard", + }, + "production": { + "build_image_major_version": 3, + "compatibility_date": "2026-03-03", + "fail_open": True, + "usage_model": "standard", + "wrangler_config_hash": "ff1efaa0ae71bb4a166ec448ed5ced3225ec3ccd9bfdb4ecc88e143b95806b29", + }, + }, + name="karaoke-gen-tenant", + production_branch="main") +pages_karaoke_gen = cloudflare.PagesProject("pages-karaoke-gen", + account_id=ACCOUNT_ID, + deployment_configs={ + "preview": { + "build_image_major_version": 3, + "compatibility_date": "2026-03-03", + "fail_open": True, + "usage_model": "standard", + }, + "production": { + "build_image_major_version": 3, + "compatibility_date": "2026-03-03", + "fail_open": True, + "usage_model": "standard", + }, + }, + name="karaoke-gen", + production_branch="main") +pages_domain_gen_nomadkaraoke_com = cloudflare.PagesDomain("pages-domain-gen-nomadkaraoke-com", + account_id=ACCOUNT_ID, + name="gen.nomadkaraoke.com", + project_name="karaoke-gen") +worker_domain_nomadkaraoke_com = cloudflare.WorkersCustomDomain("worker-domain-nomadkaraoke-com", + account_id=ACCOUNT_ID, + environment="production", + hostname="nomadkaraoke.com", + service="nomadkaraoke-com-static", + zone_id=ZONE_IDS["nomadkaraoke.com"], + zone_name="nomadkaraoke.com") +worker_domain_www_nomadkaraoke_com = cloudflare.WorkersCustomDomain("worker-domain-www-nomadkaraoke-com", + account_id=ACCOUNT_ID, + environment="production", + hostname="www.nomadkaraoke.com", + service="nomadkaraoke-com-static", + zone_id=ZONE_IDS["nomadkaraoke.com"], + zone_name="nomadkaraoke.com") diff --git a/infrastructure/cloudflare/requirements.txt b/infrastructure/cloudflare/requirements.txt new file mode 100644 index 00000000..76b90dc1 --- /dev/null +++ b/infrastructure/cloudflare/requirements.txt @@ -0,0 +1,2 @@ +pulumi>=3.0.0,<4.0.0 +pulumi-cloudflare==6.22.1 diff --git a/infrastructure/cloudflare/rulesets.py b/infrastructure/cloudflare/rulesets.py new file mode 100644 index 00000000..5101ba94 --- /dev/null +++ b/infrastructure/cloudflare/rulesets.py @@ -0,0 +1,242 @@ +"""Zone ruleset entrypoints (one owner per zone+phase). nomadkaraoke.com's http_request_firewall_custom, +http_ratelimit and http_request_late_transform phases are owned by gen's GCP stack (modules/edge_security.py). + +Not managed here: karaokehunt.com's http_config_settings phase ("SSL for create.karaokehunt.com" and +"Disable challenge for create API" = set_config bic:false). pulumi-cloudflare 6.22.1 drops the `false`, +so refresh fails with "action parameters are required for the set_config action". Edit it in the dashboard. + +Adopted from the live account with `pulumi import` (2026-10-15); see README.md. +""" +import pulumi +import pulumi_cloudflare as cloudflare + +from ids import ACCOUNT_ID, ZONE_IDS + +ruleset_karaokehunt_com_request_dynamic_redirect = cloudflare.Ruleset("ruleset-karaokehunt-com-request-dynamic-redirect", + kind="zone", + name="default", + phase="http_request_dynamic_redirect", + rules=[ + { + "action": "redirect", + "action_parameters": { + "from_value": { + "status_code": 301, + "target_url": { + "value": "https://nomadkaraoke.com", + }, + }, + }, + "description": "Redirect all to nomadkaraoke.com", + "enabled": True, + "expression": "(http.host ne \"create.karaokehunt.com\")", + "ref": "379a4603c27e4acd9b259b83c4513e7c", + }, + { + "action": "redirect", + "action_parameters": { + "from_value": { + "status_code": 302, + "target_url": { + "value": "https://insigh.to/b/karaokehunt", + }, + }, + }, + "description": "Public roadmap", + "enabled": True, + "expression": "(http.host eq \"roadmap.karaokehunt.com\")", + "ref": "af4ff6bc30184e2ea8d85c97f075c6f5", + }, + ], + zone_id=ZONE_IDS["karaokehunt.com"]) +ruleset_karaokehunt_com_request_firewall_custom = cloudflare.Ruleset("ruleset-karaokehunt-com-request-firewall-custom", + kind="zone", + name="default", + phase="http_request_firewall_custom", + rules=[{ + "action": "block", + "description": "Block AI Scrapers and Crawlers rule", + "enabled": True, + "expression": "(cf.verified_bot_category eq \"AI Crawler\")", + "ref": "a3152fbf8921417caa5e70021fd37c9a", + }], + zone_id=ZONE_IDS["karaokehunt.com"]) +ruleset_kjbox_cc_request_dynamic_redirect = cloudflare.Ruleset("ruleset-kjbox-cc-request-dynamic-redirect", + description="kjbox.cc short links -> sing.nomadkaraoke.com", + kind="zone", + name="default", + phase="http_request_dynamic_redirect", + rules=[ + { + "action": "redirect", + "action_parameters": { + "from_value": { + "preserve_query_string": True, + "status_code": 302, + "target_url": { + "value": "https://sing.nomadkaraoke.com/", + }, + }, + }, + "description": "kjbox.cc/ -> singer code-entry page", + "enabled": True, + "expression": "(http.host in {\"kjbox.cc\" \"www.kjbox.cc\"} and http.request.uri.path eq \"/\")", + "ref": "62596d3873e04b2db1e802d92c966005", + }, + { + "action": "redirect", + "action_parameters": { + "from_value": { + "status_code": 302, + "target_url": { + "expression": "wildcard_replace(http.request.uri.path, r\"/*\", r\"https://sing.nomadkaraoke.com/?t=${1}\")", + }, + }, + }, + "description": "kjbox.cc/ -> sing.nomadkaraoke.com/?t=", + "enabled": True, + "expression": "(http.host in {\"kjbox.cc\" \"www.kjbox.cc\"} and http.request.uri.path ne \"/\")", + "ref": "1f2e8fb05f844449ae29e7c1237ffc5c", + }, + ], + zone_id=ZONE_IDS["kjbox.cc"]) +ruleset_kjtip_me_request_dynamic_redirect = cloudflare.Ruleset("ruleset-kjtip-me-request-dynamic-redirect", + kind="zone", + name="default", + phase="http_request_dynamic_redirect", + rules=[{ + "action": "redirect", + "action_parameters": { + "from_value": { + "status_code": 301, + "target_url": { + "value": "https://nomadkaraoke.com/tip", + }, + }, + }, + "description": "kjtip.me → nomadkaraoke.com/tip (KJ tip shortlink)", + "enabled": True, + "expression": "true", + "ref": "8835998667c947fea41d01c3c7721a24", + }], + zone_id=ZONE_IDS["kjtip.me"]) +ruleset_nomadkaraoke_com_request_dynamic_redirect = cloudflare.Ruleset("ruleset-nomadkaraoke-com-request-dynamic-redirect", + kind="zone", + name="default", + phase="http_request_dynamic_redirect", + rules=[ + { + "action": "redirect", + "action_parameters": { + "from_value": { + "status_code": 301, + "target_url": { + "expression": "wildcard_replace(http.request.full_uri, r\"http://*\", r\"https://${1}\")", + }, + }, + }, + "description": "Redirect from HTTP to HTTPS [Template]", + "enabled": True, + "expression": "(http.request.full_uri wildcard r\"http://*\")", + "ref": "2cd5ecabdaaa41b49820841a0fef485f", + }, + { + "action": "redirect", + "action_parameters": { + "from_value": { + "status_code": 301, + "target_url": { + "value": "https://discord.gg/FkrKrSmZEg", + }, + }, + }, + "description": "Discord Invite Redirect", + "enabled": True, + "expression": "(http.request.full_uri wildcard r\"*discord.nomadkaraoke.com*\")", + "ref": "4ee3e9d72fc3433e8164a4cacad8a7fd", + }, + { + "action": "redirect", + "action_parameters": { + "from_value": { + "status_code": 301, + "target_url": { + "value": "https://buy.stripe.com/00geUZgfHdhx6TS001", + }, + }, + }, + "description": "Stripe Pay Redirect", + "enabled": True, + "expression": "(http.host eq \"pay.nomadkaraoke.com\")", + "ref": "763ba6175ef94a2faae1c1840eaf5145", + }, + { + "action": "redirect", + "action_parameters": { + "from_value": { + "status_code": 302, + "target_url": { + "value": "https://gen.nomadkaraoke.com/en/requests", + }, + }, + }, + "description": "Requests Voting Board Redirect", + "enabled": True, + "expression": "(http.host eq \"requests.nomadkaraoke.com\")", + "ref": "69cb3e389b064f3792d79765a1dc1a41", + }, + ], + zone_id=ZONE_IDS["nomadkaraoke.com"]) +ruleset_nomadkaraoke_com_config_settings = cloudflare.Ruleset("ruleset-nomadkaraoke-com-config-settings", + kind="zone", + name="default", + phase="http_config_settings", + rules=[{ + "action": "set_config", + "action_parameters": { + "ssl": "flexible", + }, + "description": "Flacfetch Origin Flexible SSL", + "enabled": True, + "expression": "(http.host eq \"flacfetch.nomadkaraoke.com\")", + "ref": "7e856f00815a49ec8abb35266fad134d", + }], + zone_id=ZONE_IDS["nomadkaraoke.com"]) +ruleset_nomadkaraoke_com_request_origin = cloudflare.Ruleset("ruleset-nomadkaraoke-com-request-origin", + kind="zone", + name="default", + phase="http_request_origin", + rules=[{ + "action": "route", + "action_parameters": { + "origin": { + "port": 8080, + }, + }, + "description": "Flacfetch Protecc Port 8080", + "enabled": True, + "expression": "(http.host eq \"flacfetch.nomadkaraoke.com\")", + "ref": "95cbc9906fc747ee8bfbd1a57f4e55ca", + }], + zone_id=ZONE_IDS["nomadkaraoke.com"]) +ruleset_nomadkaroke_com_request_dynamic_redirect = cloudflare.Ruleset("ruleset-nomadkaroke-com-request-dynamic-redirect", + kind="zone", + name="default", + phase="http_request_dynamic_redirect", + rules=[{ + "action": "redirect", + "action_parameters": { + "from_value": { + "preserve_query_string": True, + "status_code": 301, + "target_url": { + "value": "https://nomadkaraoke.com", + }, + }, + }, + "description": "Redirect to correct domain", + "enabled": True, + "expression": "true", + "ref": "21a789b686fe4bbd91966ac505cd479c", + }], + zone_id=ZONE_IDS["nomadkaroke.com"]) diff --git a/infrastructure/cloudflare/scripts/build_import_list.py b/infrastructure/cloudflare/scripts/build_import_list.py new file mode 100644 index 00000000..6a09e00d --- /dev/null +++ b/infrastructure/cloudflare/scripts/build_import_list.py @@ -0,0 +1,163 @@ +#!/usr/bin/env python3 +"""Build a `pulumi import --file` list of the Nomad Karaoke Cloudflare account's resources. + +Used once to adopt the hand-made config into this stack (2026-10), and reusable to adopt +anything created outside Pulumi later. Reads the live account with CLOUDFLARE_API_TOKEN / +CLOUDFLARE_ACCOUNT_ID and prints JSON to stdout: + + python scripts/build_import_list.py > /tmp/import.json + pulumi import --file /tmp/import.json --out /tmp/generated.py + +Resources managed elsewhere are skipped on purpose (see EXCLUDED_* below and README.md). +""" +import json +import os +import re +import sys +import urllib.error +import urllib.request + +API = "https://api.cloudflare.com/client/v4" +TOKEN = os.environ["CLOUDFLARE_API_TOKEN"] +ACCOUNT = os.environ["CLOUDFLARE_ACCOUNT_ID"] + +# Owned by karaoke-gen's GCP platform stack (infrastructure/modules/edge_security.py). +EXCLUDED_DNS = {"api.nomadkaraoke.com", "api-edge-test.nomadkaraoke.com"} +EXCLUDED_RULESET_PHASES = { + "nomadkaraoke.com": {"http_request_firewall_custom", "http_ratelimit", "http_request_late_transform"}, + # pulumi-cloudflare 6.22.1 drops set_config bic:false, so refresh fails on this one (see rulesets.py). + "karaokehunt.com": {"http_config_settings"}, +} +# Created/deleted at runtime by gen's backend (backend/services/tenant_domain_service.py): +# every CNAME pointing at the tenant Pages project, and that project's custom domains. +TENANT_PAGES_PROJECT = "karaoke-gen-tenant" +# Owned by karaoke-decide's Pulumi stack. +EXCLUDED_WORKER_ROUTES = {"decide.nomadkaraoke.com/api/*"} +# Settings we pin explicitly (everything else stays at Cloudflare's defaults). +MANAGED_ZONE_SETTINGS = ["ssl"] + + +def _get(path): + req = urllib.request.Request(API + path, headers={"Authorization": f"Bearer {TOKEN}"}) + try: + body = json.load(urllib.request.urlopen(req)) + except urllib.error.HTTPError as e: + body = json.loads(e.read()) + if not body.get("success", True): + sys.exit(f"{path}: {body.get('errors')}") + return body + + +def cf(path): + """GET a Cloudflare API path; list results are followed across every page.""" + body = _get(path) + result = body["result"] + info = body.get("result_info") or {} + total_pages = info.get("total_pages") or 1 + if isinstance(result, list) and total_pages > 1: + sep = "&" if "?" in path else "?" + for page in range(2, total_pages + 1): + result = result + _get(f"{path}{sep}page={page}")["result"] + return result + + +def slug(*parts): + s = "-".join(str(p) for p in parts if p not in (None, "")) + return re.sub(r"[^a-zA-Z0-9-]+", "-", s.lower()).strip("-") + + +def main(): + out, seen = [], set() + + def add(typ, name, rid): + n, i = name, 2 + while n in seen: # duplicate names (e.g. several MX/TXT at the apex) get a suffix + n, i = f"{name}-{i}", i + 1 + seen.add(n) + out.append({"type": f"cloudflare:index/{typ}", "name": n, "id": rid}) + + zones = cf(f"/zones?account.id={ACCOUNT}&per_page=50") + tenant_target = None + for p in cf(f"/accounts/{ACCOUNT}/pages/projects"): + if p["name"] == TENANT_PAGES_PROJECT: + tenant_target = p["subdomain"] + + for z in sorted(zones, key=lambda z: z["name"]): + zn, zid = z["name"], z["id"] + zs = slug(zn) + add("zone:Zone", f"zone-{zs}", zid) + for s in MANAGED_ZONE_SETTINGS: + add("zoneSetting:ZoneSetting", f"setting-{zs}-{s}", f"{zid}/{s}") + + for r in sorted(cf(f"/zones/{zid}/dns_records?per_page=500"), + key=lambda r: (r["name"], r["type"], str(r.get("content")))): + if (r.get("meta") or {}).get("read_only"): + continue # owned by Email Routing / Workers custom domains + if r["name"] in EXCLUDED_DNS: + continue + if tenant_target and r["type"] == "CNAME" and r.get("content") == tenant_target: + continue + label = r["name"][: -len(zn)].rstrip(".") or "apex" + add("dnsRecord:DnsRecord", f"dns-{zs}-{slug(label)}-{r['type'].lower()}", f"{zid}/{r['id']}") + + for rs in cf(f"/zones/{zid}/rulesets"): + if rs.get("kind") != "zone" or rs["phase"] in EXCLUDED_RULESET_PHASES.get(zn, set()): + continue + add("ruleset:Ruleset", f"ruleset-{zs}-{slug(rs['phase'].removeprefix('http_'))}", + f"zones/{zid}/{rs['id']}") + + routing = cf(f"/zones/{zid}/email/routing") + if routing.get("enabled"): + add("emailRoutingSettings:EmailRoutingSettings", f"email-routing-{zs}", zid) + add("emailRoutingCatchAll:EmailRoutingCatchAll", f"email-catchall-{zs}", zid) + for rule in cf(f"/zones/{zid}/email/routing/rules"): + if any(m.get("type") == "all" for m in rule.get("matchers", [])): + continue # the catch-all, handled above + to = next((m.get("value") for m in rule["matchers"] if m.get("field") == "to"), rule["tag"]) + add("emailRoutingRule:EmailRoutingRule", f"email-rule-{slug(to)}", f"{zid}/{rule['tag']}") + + for route in cf(f"/zones/{zid}/workers/routes"): + if route["pattern"] in EXCLUDED_WORKER_ROUTES: + continue + add("workersRoute:WorkersRoute", f"worker-route-{slug(route['pattern'])}", f"{zid}/{route['id']}") + + for a in cf(f"/accounts/{ACCOUNT}/email/routing/addresses"): + add("emailRoutingAddress:EmailRoutingAddress", f"email-dest-{slug(a['email'])}", f"{ACCOUNT}/{a['id']}") + + for t in cf(f"/accounts/{ACCOUNT}/cfd_tunnel?is_deleted=false"): + add("zeroTrustTunnelCloudflared:ZeroTrustTunnelCloudflared", f"tunnel-{slug(t['name'])}", f"{ACCOUNT}/{t['id']}") + add("zeroTrustTunnelCloudflaredConfig:ZeroTrustTunnelCloudflaredConfig", + f"tunnel-config-{slug(t['name'])}", f"{ACCOUNT}/{t['id']}") + + add("zeroTrustOrganization:ZeroTrustOrganization", "access-organization", ACCOUNT) + for idp in cf(f"/accounts/{ACCOUNT}/access/identity_providers"): + if idp["type"] == "cloudflare": + continue # built-in, not user-managed + add("zeroTrustAccessIdentityProvider:ZeroTrustAccessIdentityProvider", + f"access-idp-{slug(idp['type'])}", f"accounts/{ACCOUNT}/{idp['id']}") + for tok in cf(f"/accounts/{ACCOUNT}/access/service_tokens"): + add("zeroTrustAccessServiceToken:ZeroTrustAccessServiceToken", + f"access-service-token-{slug(tok['name'])}", f"accounts/{ACCOUNT}/{tok['id']}") + for pol in cf(f"/accounts/{ACCOUNT}/access/policies"): + add("zeroTrustAccessPolicy:ZeroTrustAccessPolicy", f"access-policy-{slug(pol['name'])}", f"{ACCOUNT}/{pol['id']}") + for app in cf(f"/accounts/{ACCOUNT}/access/apps"): + add("zeroTrustAccessApplication:ZeroTrustAccessApplication", + f"access-app-{slug(app['domain'])}", f"accounts/{ACCOUNT}/{app['id']}") + + for p in cf(f"/accounts/{ACCOUNT}/pages/projects"): + add("pagesProject:PagesProject", f"pages-{slug(p['name'])}", f"{ACCOUNT}/{p['name']}") + if p["name"] == TENANT_PAGES_PROJECT: + continue # tenant custom domains are managed at runtime by gen's backend + for d in p.get("domains", []): + if d.endswith(".pages.dev"): + continue + add("pagesDomain:PagesDomain", f"pages-domain-{slug(d)}", f"{ACCOUNT}/{p['name']}/{d}") + + for d in cf(f"/accounts/{ACCOUNT}/workers/domains"): + add("workersCustomDomain:WorkersCustomDomain", f"worker-domain-{slug(d['hostname'])}", f"{ACCOUNT}/{d['id']}") + + json.dump({"resources": out}, sys.stdout, indent=1) + + +if __name__ == "__main__": + main() diff --git a/infrastructure/cloudflare/tests/test_build_import_list.py b/infrastructure/cloudflare/tests/test_build_import_list.py new file mode 100644 index 00000000..2ed60688 --- /dev/null +++ b/infrastructure/cloudflare/tests/test_build_import_list.py @@ -0,0 +1,114 @@ +"""Unit tests for scripts/build_import_list.py: the ownership exclusions must hold, or a re-import +would make this stack fight gen's edge stack, gen's runtime tenant domains or decide's stack.""" +import importlib.util +import io +import json +import pathlib +from contextlib import redirect_stdout + +import pytest + +SCRIPT = pathlib.Path(__file__).resolve().parents[1] / "scripts" / "build_import_list.py" +ACCOUNT, ZONE = "acct", "zone1" + + +@pytest.fixture +def run(monkeypatch): + monkeypatch.setenv("CLOUDFLARE_API_TOKEN", "tok") + monkeypatch.setenv("CLOUDFLARE_ACCOUNT_ID", ACCOUNT) + spec = importlib.util.spec_from_file_location("build_import_list", SCRIPT) + mod = importlib.util.module_from_spec(spec) + spec.loader.exec_module(mod) + + def _run(api): + monkeypatch.setattr(mod, "cf", lambda path: api.get(path.split("?")[0], [])) + buf = io.StringIO() + with redirect_stdout(buf): + mod.main() + return {r["name"]: r for r in json.loads(buf.getvalue())["resources"]} + + return _run + + +def fake_api(**over): + api = { + f"/zones": [{"name": "nomadkaraoke.com", "id": ZONE}], + f"/accounts/{ACCOUNT}/pages/projects": [ + {"name": "karaoke-gen", "subdomain": "karaoke-gen-9k4.pages.dev", + "domains": ["karaoke-gen-9k4.pages.dev", "gen.nomadkaraoke.com"]}, + {"name": "karaoke-gen-tenant", "subdomain": "karaoke-gen-tenant-x0h.pages.dev", + "domains": ["singa.nomadkaraoke.com"]}, + ], + f"/zones/{ZONE}/dns_records": [ + {"id": "r1", "type": "CNAME", "name": "gen.nomadkaraoke.com", "content": "karaoke-gen-9k4.pages.dev"}, + {"id": "r2", "type": "CNAME", "name": "api.nomadkaraoke.com", "content": "ghs.googlehosted.com"}, + {"id": "r3", "type": "CNAME", "name": "singa.nomadkaraoke.com", "content": "karaoke-gen-tenant-x0h.pages.dev"}, + {"id": "r4", "type": "MX", "name": "nomadkaraoke.com", "content": "route1.mx.cloudflare.net", + "meta": {"read_only": True, "email_routing": True}}, + {"id": "r5", "type": "TXT", "name": "nomadkaraoke.com", "content": "v=spf1"}, + {"id": "r6", "type": "TXT", "name": "nomadkaraoke.com", "content": "google-site-verification=x"}, + ], + f"/zones/{ZONE}/rulesets": [ + {"id": "rs1", "kind": "zone", "phase": "http_request_dynamic_redirect"}, + {"id": "rs2", "kind": "zone", "phase": "http_ratelimit"}, + {"id": "rs3", "kind": "managed", "phase": "ddos_l7"}, + ], + f"/zones/{ZONE}/email/routing": {"enabled": False}, + f"/zones/{ZONE}/workers/routes": [ + {"id": "w1", "pattern": "decide.nomadkaraoke.com/api/*"}, + {"id": "w2", "pattern": "create.karaokehunt.com/*"}, + ], + f"/accounts/{ACCOUNT}/access/identity_providers": [ + {"id": "i1", "type": "cloudflare"}, {"id": "i2", "type": "onetimepin"}], + } + api.update(over) + return api + + +def test_excludes_resources_owned_elsewhere(run): + names = run(fake_api()) + dns_ids = {r["id"] for r in names.values() if "dnsRecord" in r["type"]} + assert f"{ZONE}/r1" in dns_ids # gen consumer Pages CNAME is ours + assert f"{ZONE}/r2" not in dns_ids # api: gen edge stack + assert f"{ZONE}/r3" not in dns_ids # tenant CNAME: gen backend at runtime + assert f"{ZONE}/r4" not in dns_ids # read-only, owned by Email Routing + rulesets = [r["id"] for r in names.values() if "ruleset" in r["type"]] + assert rulesets == [f"zones/{ZONE}/rs1"] # gen owns ratelimit; managed rulesets skipped + routes = [r["id"] for r in names.values() if "workersRoute" in r["type"]] + assert routes == [f"{ZONE}/w2"] # decide's route stays in decide's stack + idps = [r["id"] for r in names.values() if "IdentityProvider" in r["type"]] + assert idps == [f"accounts/{ACCOUNT}/i2"] # built-in "cloudflare" IdP skipped + + +def test_pages_domains_skip_tenant_project_and_pages_dev(run): + names = run(fake_api()) + domains = [r["id"] for r in names.values() if "pagesDomain" in r["type"]] + assert domains == [f"{ACCOUNT}/karaoke-gen/gen.nomadkaraoke.com"] + + +def test_duplicate_logical_names_get_suffixes(run): + names = run(fake_api()) + txt = sorted(n for n in names if n.startswith("dns-nomadkaraoke-com-apex-txt")) + assert txt == ["dns-nomadkaraoke-com-apex-txt", "dns-nomadkaraoke-com-apex-txt-2"] + assert len(names) == len({r["name"] for r in names.values()}) + + +def test_cf_follows_every_page(monkeypatch): + monkeypatch.setenv("CLOUDFLARE_API_TOKEN", "tok") + monkeypatch.setenv("CLOUDFLARE_ACCOUNT_ID", ACCOUNT) + spec = importlib.util.spec_from_file_location("build_import_list_pages", SCRIPT) + mod = importlib.util.module_from_spec(spec) + spec.loader.exec_module(mod) + calls = [] + + def fake_get(path): + calls.append(path) + page = int(path.rsplit("&page=", 1)[1]) if "&page=" in path else 1 + return {"success": True, "result": [f"r{page}"], "result_info": {"page": page, "total_pages": 3}} + + monkeypatch.setattr(mod, "_get", fake_get) + assert mod.cf("/zones/z/dns_records?per_page=500") == ["r1", "r2", "r3"] + assert calls[1:] == ["/zones/z/dns_records?per_page=500&page=2", "/zones/z/dns_records?per_page=500&page=3"] + # Non-list results (e.g. a single settings object) are returned as-is. + monkeypatch.setattr(mod, "_get", lambda path: {"success": True, "result": {"enabled": True}}) + assert mod.cf("/zones/z/email/routing") == {"enabled": True} diff --git a/infrastructure/cloudflare/tunnels.py b/infrastructure/cloudflare/tunnels.py new file mode 100644 index 00000000..8eec738b --- /dev/null +++ b/infrastructure/cloudflare/tunnels.py @@ -0,0 +1,68 @@ +"""Remote-managed cloudflared tunnels and their ingress. Connectors: NomadPC systemd `cloudflared-nomad` +(nomad-kjbox) and hf2 `~/nomad-tunnel` compose (nomad-hf2); connector tokens are not managed here. + +Adopted from the live account with `pulumi import` (2026-10-15); see README.md. +""" +import pulumi +import pulumi_cloudflare as cloudflare + +from ids import ACCOUNT_ID, ZONE_IDS + +tunnel_nomad_hf2 = cloudflare.ZeroTrustTunnelCloudflared("tunnel-nomad-hf2", + account_id=ACCOUNT_ID, + config_src="cloudflare", + name="nomad-hf2", + opts=pulumi.ResourceOptions(protect=True)) +tunnel_config_nomad_hf2 = cloudflare.ZeroTrustTunnelCloudflaredConfig("tunnel-config-nomad-hf2", + account_id=ACCOUNT_ID, + config={ + "ingresses": [ + { + "hostname": "fiverrbot.nomadkaraoke.com", + "service": "http://fiverrbot:6080", + }, + { + "service": "http_status:404", + }, + ], + }, + source="cloudflare", + tunnel_id="531403b1-bcfa-4f6e-912e-a10bd8e5ebd5") +tunnel_nomad_kjbox = cloudflare.ZeroTrustTunnelCloudflared("tunnel-nomad-kjbox", + account_id=ACCOUNT_ID, + config_src="cloudflare", + name="nomad-kjbox", + opts=pulumi.ResourceOptions(protect=True)) +tunnel_config_nomad_kjbox = cloudflare.ZeroTrustTunnelCloudflaredConfig("tunnel-config-nomad-kjbox", + account_id=ACCOUNT_ID, + config={ + "ingresses": [ + { + "hostname": "kjssh.nomadkaraoke.com", + "service": "ssh://localhost:22", + }, + { + "hostname": "kjvnc.nomadkaraoke.com", + "service": "http://localhost:6080", + }, + { + "hostname": "kjbox.nomadkaraoke.com", + "origin_request": { + "no_tls_verify": True, + }, + "service": "https://localhost:443", + }, + { + "hostname": "sing.nomadkaraoke.com", + "origin_request": { + "no_tls_verify": True, + }, + "service": "https://localhost:443", + }, + { + "service": "http_status:404", + }, + ], + }, + source="cloudflare", + tunnel_id="04c88337-f076-45ed-bc19-4ac1222b4228") diff --git a/infrastructure/cloudflare/zones.py b/infrastructure/cloudflare/zones.py new file mode 100644 index 00000000..b4ac4a73 --- /dev/null +++ b/infrastructure/cloudflare/zones.py @@ -0,0 +1,64 @@ +"""Zones (protected) and the zone settings we pin explicitly. + +Adopted from the live account with `pulumi import` (2026-10-15); see README.md. +""" +import pulumi +import pulumi_cloudflare as cloudflare + +from ids import ACCOUNT_ID, ZONE_IDS + +zone_karaokehunt_com = cloudflare.Zone("zone-karaokehunt-com", + account={ + "id": ACCOUNT_ID, + }, + name="karaokehunt.com", + type="full", + opts=pulumi.ResourceOptions(protect=True)) +setting_karaokehunt_com_ssl = cloudflare.ZoneSetting("setting-karaokehunt-com-ssl", + setting_id="ssl", + value="strict", + zone_id=ZONE_IDS["karaokehunt.com"]) +zone_kjbox_cc = cloudflare.Zone("zone-kjbox-cc", + account={ + "id": ACCOUNT_ID, + }, + name="kjbox.cc", + type="full", + opts=pulumi.ResourceOptions(protect=True)) +setting_kjbox_cc_ssl = cloudflare.ZoneSetting("setting-kjbox-cc-ssl", + setting_id="ssl", + value="full", + zone_id=ZONE_IDS["kjbox.cc"]) +zone_kjtip_me = cloudflare.Zone("zone-kjtip-me", + account={ + "id": ACCOUNT_ID, + }, + name="kjtip.me", + type="full", + opts=pulumi.ResourceOptions(protect=True)) +setting_kjtip_me_ssl = cloudflare.ZoneSetting("setting-kjtip-me-ssl", + setting_id="ssl", + value="full", + zone_id=ZONE_IDS["kjtip.me"]) +zone_nomadkaraoke_com = cloudflare.Zone("zone-nomadkaraoke-com", + account={ + "id": ACCOUNT_ID, + }, + name="nomadkaraoke.com", + type="full", + opts=pulumi.ResourceOptions(protect=True)) +setting_nomadkaraoke_com_ssl = cloudflare.ZoneSetting("setting-nomadkaraoke-com-ssl", + setting_id="ssl", + value="full", + zone_id=ZONE_IDS["nomadkaraoke.com"]) +zone_nomadkaroke_com = cloudflare.Zone("zone-nomadkaroke-com", + account={ + "id": ACCOUNT_ID, + }, + name="nomadkaroke.com", + type="full", + opts=pulumi.ResourceOptions(protect=True)) +setting_nomadkaroke_com_ssl = cloudflare.ZoneSetting("setting-nomadkaroke-com-ssl", + setting_id="ssl", + value="flexible", + zone_id=ZONE_IDS["nomadkaroke.com"])