Skip to content

refactor(cp): first-class Env type for installation identity#281

Merged
posix4e merged 1 commit into
mainfrom
refactor/env-type
Jun 2, 2026
Merged

refactor(cp): first-class Env type for installation identity#281
posix4e merged 1 commit into
mainfrom
refactor/env-type

Conversation

@posix4e
Copy link
Copy Markdown
Member

@posix4e posix4e commented Jun 2, 2026

First step of the unified prod+PR management / CF-reconcile arc (groundwork; no behaviour change).

Why

env_label was a free-form String: threaded through config, compared with == "production" in scattered spots, and any DD_ENV value — including typos or junk like invalid name {uuid} — was accepted and baked straight into Cloudflare resource names (dd-{env}-cp-*), silently breaking collector discovery for the real env.

What

  • src/env.rs (new): Env parses + validates DD_ENV as a lowercase DNS label (^[a-z0-9][a-z0-9-]*$, ≤40 chars), classifies well-known kinds (production/staging/dev/pr-N) with a Named fallback so legitimately-named installs (bot, dogfood, future envs) are not rejected — only malformed labels are. Env-intrinsic behaviour as methods: requires_intel_ita() (replaces the == "production" || == "staging" ITA gate, identical semantics) and is_ephemeral() (for later lifecycle/GC policy). Unit tests included.
  • config.rs: Common.env_label: Stringenv: Env (single source of truth); Ita::from_env takes &Env.
  • cp.rs: call sites read the label via env.label().

No wire or behaviour change — CF names and /health's env field are byte-identical; this is type-safety + boot-time validation. cf_snapshot/collector still take &str (threaded to &Env in the next PR).

Validation

  • cargo fmt clean; compiles locally (only the unrelated pre-existing macOS-target sessiond.rs errors remain — CI builds musl).
  • CI build job runs Env::parse unit tests (accept production/staging/dev/pr-7/bot, reject uppercase/whitespace/too-long).
  • Preview deploy must come up green with identical tunnel names + /health env.

Part of the arc: Env type → degraded-aware snapshot → register env-binding → drift logging → reconcile plan → reconcile apply → cleanup wiring.

🤖 Generated with Claude Code

env_label was a free-form String threaded through config and compared
with `== "production"` in scattered places, and any DD_ENV value (incl.
typos / junk like "invalid name {uuid}") was accepted and silently baked
into Cloudflare resource names, breaking collector discovery.

Introduce `Env` (src/env.rs): parse+validate DD_ENV as a lowercase DNS
label, classify the well-known kinds (production/staging/dev/pr-N) with a
`Named` fallback so legitimately-named installs (bot, dogfood, future
envs) are never rejected — only malformed labels are. Env-intrinsic
behaviour becomes methods: `requires_intel_ita()` (replaces the
`== "production" || == "staging"` ITA-mode gate, same semantics) and
`is_ephemeral()` (for later lifecycle/GC policy).

`config::Common.env_label: String` → `env: Env` (single source of truth);
`Ita::from_env` takes `&Env`. All call sites read the string via
`env.label()`. No wire/behaviour change — CF names and /health env are
identical; this is type-safety + boot-time validation groundwork for the
CF drift/reconcile work. cf_snapshot/collector still take `&str` (threaded
to `&Env` in a follow-up).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 2, 2026

DD preview ready

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

Browser login: visit https://pr-281.devopsdefender.com — DD redirects you to
the GitHub App auth broker. A DD session cookie scoped
to .devopsdefender.com lets the preview, fleet, and
shell hosts share the same login.

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-281.devopsdefender.com/register
(authenticated by ITA attestation).

@posix4e posix4e merged commit 7f6a643 into main Jun 2, 2026
3 checks passed
@posix4e posix4e deleted the refactor/env-type branch June 2, 2026 22:56
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