Skip to content

chore(cf): reap orphan Access apps on CP startup#146

Closed
posix4e wants to merge 1 commit into
mainfrom
chore/cf-access-reap
Closed

chore(cf): reap orphan Access apps on CP startup#146
posix4e wants to merge 1 commit into
mainfrom
chore/cf-access-reap

Conversation

@posix4e
Copy link
Copy Markdown
Member

@posix4e posix4e commented Apr 19, 2026

Summary

The CF Access dashboard fills up with dead `dd-*` apps whenever a tunnel gets torn down outside the collector's orphan-GC path — force-deleted preview VMs, apps from older naming schemes, the tail of long preview cycles.

New `cf::reap_orphan_access_apps(env)` in `src/cf.rs`: lists every `dd-{env}-*` Access app, resolves each one's `domain` to the CNAME's target cfd tunnel id, deletes anything whose tunnel isn't in the live set (or whose CNAME no longer exists). CP's `run()` spawns it 10 s after startup so a slow CF API call doesn't delay the collector or agent registration. CNAME lookups cache per base hostname to keep the round-trip count bounded. Best-effort: delete failures log and continue.

Every CP deploy is a cleanup pass. Stacks on main (independent of PR #145's vanity-claim work).

Test plan

  • `cargo build --release` / `cargo clippy -D warnings` / `cargo test` — 21 tests pass.
  • Redeploy a CP; confirm serial log shows `cp: reaped N orphan CF Access apps` (N should be large on the first deploy after this lands).
  • Redeploy again on the same env; N should be 0.

🤖 Generated with Claude Code

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 19, 2026

DD preview ready

URL: https://pr-146.devopsdefender.com

Browser login: visit https://pr-146.devopsdefender.com — Cloudflare Access routes you
through GitHub OAuth. Membership (public) in the DD GitHub
org grants access; the DD_ACCESS_ADMIN_EMAIL is the
break-glass fallback.

Machine-to-machine: GitHub Actions workflows in the
DD_OWNER org pass their per-job OIDC JWT as
Authorization: Bearer … (audience dd-agent).

Register endpoint for a local agent: https://pr-146.devopsdefender.com/register
(CF-Access-bypassed; authenticated by ITA attestation).

CF Access apps accumulate in the account whenever an agent/CP tunnel
gets torn down outside the collector's orphan-GC path — a PR preview
VM force-deleted in GCP, apps from an older naming scheme, or the
tail of a long preview cycle. The dashboard ends up with a huge pile
of `dd-*` self-hosted apps nobody's looking at.

New `cf::reap_orphan_access_apps(env)` lists every `dd-{env}-*`
Access app, resolves each domain's CNAME to its target cfd tunnel
id, and deletes the app if the tunnel isn't in the live set. CP's
`run()` fires it 10s after startup as a spawned task so a slow CF
API call doesn't block the collector or agent registration. CNAME
lookups cache per base hostname to keep the round-trip count
bounded. Best-effort: delete failures log and continue.

Every new CP deploy is also a cleanup pass. No separate workflow.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@posix4e posix4e force-pushed the chore/cf-access-reap branch from 970b157 to cf0403d Compare April 19, 2026 22:03
@posix4e posix4e changed the title chore(cf): reap orphan Access apps on startup + manual workflow chore(cf): reap orphan Access apps on CP startup Apr 19, 2026
@posix4e
Copy link
Copy Markdown
Member Author

posix4e commented Apr 19, 2026

Closing — parked in #149 for later. Not pursuing right now.

@posix4e posix4e closed this Apr 19, 2026
@posix4e posix4e deleted the chore/cf-access-reap branch April 19, 2026 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant