Skip to content

feat(config)!: tagged [cache.origin] table replaces flat origin_url/origin_path (#437 PR1) - #463

Merged
thiras merged 4 commits into
mainfrom
feat/origin-config-enum
May 8, 2026
Merged

thiras merged 4 commits into
mainfrom
feat/origin-config-enum

Conversation

@thiras

@thiras thiras commented May 7, 2026

Copy link
Copy Markdown
Contributor

Summary

PR 1 of 2 for #437 (S3-compatible origin backend). This PR ships only the config schema; the S3 runtime backend lands in PR 2 once aws-sdk-s3 and the test mocks are wired in.

  • The flat cache.origin_url / cache.origin_path / cache.decompress fields are replaced with a tagged [cache.origin] kind = "http"|"fs"|"s3" table. CacheConfig and OriginConfig carry #[serde(deny_unknown_fields)] so legacy configs and typos like decompres = "auto" fail at config load with a clear "unknown field" error instead of silently no-opping.
  • --origin-url / --origin-path flags (and their DECDN_* env vars) are removed. Origin selection is config-only — the upcoming S3 backend has too many fields (bucket, region, endpoint, credentials) to fit cleanly on a command line.
  • The s3 variant is recognised by the schema today (so decdn config validate lints it); build_cache rejects it at startup with an operator-greppable placeholder error pointing at PR 2. A // TODO(#437-PR2) marker locks the cleanup.

Resolution-side guarantees

  • ResolvedS3Config / ResolvedS3Credentials are new resolved types (mirror the OriginUrl precedent). No public field-by-field constructor — resolve_s3_origin is the only path. PR 2's runtime cannot reach an unvalidated config.
  • SecretString newtype wraps access_key_id / secret_access_key / session_token. Debug always prints "***"; Serialize emits a deterministic-per-process hash so runtime::reload::FileSectionSnapshot still distinguishes rotated credentials without exposing cleartext.
  • validate_s3_bucket_name: 3–63 chars, lowercase [a-z0-9.-], no leading/trailing dot or hyphen (per AWS doc rule), no consecutive dots, no IPv4-literal form.
  • resolve_s3_origin: parses endpoint_url into decdn_cache::OriginUrl (PR 2 hands one canonical form to the SDK), collapses path_style: Option<bool> to bool, normalizes prefix (auto-trailing-slash; rejects control chars and whitespace).

Migration

# before
[cache]
origin_url = "https://origin.example/"
decompress = "auto"

# after
[cache.origin]
kind = "http"
url = "https://origin.example/"
decompress = "auto"          # optional; defaults to "auto"
# before
[cache]
origin_path = "/var/lib/decdn/origin"

# after
[cache.origin]
kind = "fs"
path = "/var/lib/decdn/origin"

The same table accepts kind = "s3" (with bucket / region / endpoint_url / path_style / prefix / credentials sub-fields) — runtime support arrives in PR 2.

Review history

This PR went through /pr-review-toolkit:review-pr before being opened. Five specialized agents (code-reviewer, pr-test-analyzer, comment-analyzer, silent-failure-hunter, type-design-analyzer) ran in parallel; all 16 surfaced findings were addressed before opening — including the deny_unknown_fields gap on OriginConfig, the missing leading/trailing-hyphen check on bucket names, the SecretString redaction wrapper for credentials, the ResolvedS3Config newtype on the resolved side, and ~40 new tests covering every validator branch and every expand_env S3 field.

Test plan

  • cargo build --workspace
  • cargo nextest run --workspace — 536 tests pass (up from 493 pre-Implement an S3-compatible origin backend (S3/R2/B2/MinIO) as a first-class Origin impl #437; 43 new tests added by this PR)
  • cargo clippy --workspace --all-targets — no warnings
  • cargo fmt -- --check — clean
  • cargo doc --no-deps — no broken intra-doc links
  • cargo deny check — advisories / bans / licenses / sources OK
  • Manual: decdn config validate rejects legacy origin_url field with a clear "unknown field" error
  • Manual: decdn config validate accepts each new variant (HTTP, FS, S3) — S3 succeeds at validate time and bails at daemon startup with the placeholder
  • Manual: bucket-name validator rejects BAD_UPPERCASE_NAME with a helpful error

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings May 7, 2026 16:17

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the cache origin configuration by moving backend selection (HTTP, filesystem, S3) into a tagged [cache.origin] table. It removes deprecated flat configuration fields and enforces stricter validation using #[serde(deny_unknown_fields)] to ensure users receive clear errors for outdated configuration shapes. Additionally, it introduces a SecretString type to redact sensitive credentials in logs and updates configuration resolution and tests to support the new schema. I have no feedback to provide.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR delivers PR1 of #437 by introducing a breaking cache-origin config schema: the legacy flat cache.origin_url / cache.origin_path / cache.decompress fields are replaced with a tagged [cache.origin] table (kind = "http" | "fs" | "s3"), with resolution-time validation and environment/tilde expansion. The runtime is updated to consume the new resolved origin type, while the s3 variant is intentionally rejected at startup with a placeholder error until PR2 wires the AWS SDK.

Changes:

  • Replace legacy cache-origin fields with a tagged [cache.origin] schema (deny-unknown-fields) plus resolution/validation, expansion, and extensive tests.
  • Remove --origin-url / --origin-path CLI flags (and env vars) so origin selection is config-only.
  • Add SecretString for S3 static credentials (redacted Debug, hashed Serialize) and update runtime/cache wiring and logging accordingly.

Reviewed changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
crates/node/tests/sighup_signal.rs Update resolved-config fixtures to the new cache.origin field.
crates/node/src/runtime/reload.rs Update reload test fixtures to the new resolved cache origin shape.
crates/node/src/runtime/mod.rs Switch runtime wiring to ResolvedOrigin; add origin-kind startup logging; add S3 placeholder rejection + test.
crates/common/src/config/types.rs Introduce tagged [cache.origin] schema, S3 wire types, and deny_unknown_fields protections.
crates/common/src/config/secret.rs Add SecretString wrapper for secrets with redacted Debug and hashed Serialize (for reload diffing).
crates/common/src/config/resolved.rs Add ResolvedOrigin and resolved S3 config/credentials types.
crates/common/src/config/mod.rs Implement origin resolution (resolve_origin/resolve_s3_origin), S3 validators, and origin-specific env expansion.
crates/common/src/cli/run.rs Remove origin CLI flags; document config-only origin selection.
crates/common/Cargo.toml Add serde_json dev-dependency for SecretString serialization tests.
crates/cli/tests/config_validate.rs Update config validation test fixtures to use cache.origin.
crates/cache/src/origin/fs.rs Update filesystem-origin error strings to match new config key names (cache.origin.path).
CHANGELOG.md Document breaking config migration and CLI flag removals.
Cargo.lock Lockfile update for new dev-dependency usage.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/common/src/config/types.rs Resolved
Comment thread crates/common/src/config/resolved.rs Resolved
Comment thread crates/common/src/config/secret.rs Resolved
Comment thread crates/common/src/config/mod.rs Resolved
thiras added a commit that referenced this pull request May 7, 2026
…437 PR1 review)

Four doc-only fixes from Copilot's PR1 review (PR #463), all
technically correct:

- `S3Credentials` doc claimed `SecretString` "is not Serialize"; in
  fact `SecretString` does implement Serialize, emitting a hashed
  placeholder. Doc rotted between iterations — corrected to describe
  the actual behaviour and refer readers to the SecretString module
  doc for the full contract.
- `ResolvedOrigin` doc claimed `ResolvedS3Config` had non-public
  fields and a validator-only constructor; the fields are in fact
  `pub` (matching every other `Resolved*` type in the crate). Doc
  rephrased: `resolve_origin` is the **intended** construction path
  the runtime consumes, but Rust visibility doesn't enforce the
  contract for in-crate code — that's a code convention, not a
  type-level invariant.
- `ResolvedS3Config` type doc carried the same overreach; same
  correction applied.
- `secret` module doc and the `Serialize` impl comment claimed the
  hash is "DefaultHasher (per-process keyed)". `DefaultHasher::new()`
  in fact uses fixed `(0, 0)` SipHash-1-3 keys, so the digest is
  deterministic across processes. Wording corrected to
  "deterministic across processes; non-cryptographic" with the
  `~2^-64` collision bound called out explicitly.

`resolve_s3_origin` doc carried the same "only path" overstatement
as the `ResolvedOrigin` one — softened to "the **intended** path …
the only producer the resolution layer feeds into the runtime".

No code changes; build / clippy / fmt / nextest / cargo deny / cargo
doc all pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@codecov

codecov Bot commented May 7, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.25173% with 58 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/common/src/config/mod.rs 96.41% 30 Missing ⚠️
crates/node/src/runtime/mod.rs 78.49% 20 Missing ⚠️
crates/cache/src/origin/fs.rs 44.44% 5 Missing ⚠️
crates/common/src/config/secret.rs 95.58% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

@thiras

thiras commented May 7, 2026

Copy link
Copy Markdown
Contributor Author

LOC breakdown for this PR

Diff vs main (merge-base bb44c82), crates/**/*.rs only:

Bucket Added Removed Net
Production (src outside #[cfg(test)]) +756 −117 +639
Tests (all) +1,237 −193 +1,044
  – unit (#[cfg(test)] blocks in src) — — —
  – integration (crates/*/tests/) — — —
Total +1,993 −310 +1,683

Roughly 62% test code by added lines (1,237 / 1,993). Totals match git diff --shortstat (1992/309) within one line.

Method: each +/− line in the diff is classified by whether it falls inside a #[cfg(test)] block in the corresponding pre/post blob; everything under crates/*/tests/ counts as test.

thiras and others added 4 commits May 8, 2026 11:39
…rigin_path (#437)

The pre-existing flat `cache.origin_url`, `cache.origin_path`, and
`cache.decompress` fields are replaced with a tagged
`[cache.origin] kind = "http"|"fs"|"s3"` table. `CacheConfig` and
`OriginConfig` (and each variant payload) carry
`#[serde(deny_unknown_fields)]` so legacy configs and typos like
`decompres = "auto"` fail at config load with a clear "unknown
field" error instead of silently no-opping or surfacing as a "no
origin configured" surprise on the first cache miss.

`--origin-url` / `--origin-path` flags and their env vars are
removed. Origin selection is now config-only — the upcoming S3
backend has too many fields (bucket, region, endpoint, credentials)
to fit cleanly on a command line, and keeping all three backends
file-only avoids CLI-vs-TOML mismatch picking the wrong backend
silently.

The `s3` variant (with bucket / region / endpoint_url / path_style /
prefix / credentials) is recognised by the schema today; the
runtime backend wiring lands in the follow-up PR for #437. The S3
variant is rejected at startup by `build_cache` with an explicit
placeholder message (operator-greppable: names the variant + the
issue) so the schema can bake without exposing a half-implemented
backend.

Resolution introduces:
* `ResolvedS3Config` / `ResolvedS3Credentials` (in `resolved.rs`):
  the runtime form that `ResolvedOrigin::S3` holds. Mirrors the
  `OriginUrl` precedent — there is no public field-by-field
  constructor; the only path is through `resolve_s3_origin`. PR2's
  S3 backend cannot reach an unvalidated config.
* `SecretString` newtype (`config::secret`): wraps
  `access_key_id` / `secret_access_key` / `session_token`. `Debug`
  always prints `"***"`; `Serialize` emits a deterministic-per-
  process hash so SIGHUP-time diff detection in
  `runtime::reload::FileSectionSnapshot` still distinguishes
  rotated credentials without ever exposing cleartext.
* `validate_s3_bucket_name`: 3-63 chars, lowercase `[a-z0-9.-]`,
  no leading/trailing dot or hyphen (per AWS doc rule), no
  consecutive dots, no IPv4-literal form. Caught at config load.
* `resolve_s3_origin`: validates bucket/region/endpoint/prefix
  shape, parses `endpoint_url` into a `decdn_cache::OriginUrl`
  (so PR2 hands a single canonical form to the SDK regardless of
  whether the operator wrote `http://minio:9000` or `.../`),
  collapses `path_style: Option<bool>` to `bool` (None -> false =
  SDK default), normalizes `prefix` (auto-trailing-slash; rejects
  control chars and whitespace).

Test coverage adds:
* per-branch tests for `validate_s3_bucket_name` (boundaries,
  uppercase, underscore, leading/trailing dot or hyphen,
  consecutive dots, IPv4 literal);
* per-branch tests for `resolve_s3_origin` (empty region,
  whitespace-only region, empty endpoint, non-http endpoint,
  prefix `/`, prefix `..`, prefix `\`, prefix control-char,
  prefix whitespace);
* `OriginConfig::Http` and `Fs` typo rejection via
  `deny_unknown_fields`;
* `expand_env` env-var substitution on every S3 field
  (bucket/region/endpoint/prefix/credentials) including
  proof that a missing-`${VAR}` error inside a secret field
  does not echo any cleartext from the secret value;
* legacy `decompress` rejection (sibling of legacy
  `origin_url`/`origin_path` rejection tests);
* `build_cache` S3 placeholder message contract;
* regression lock that `decdn config validate` succeeds for an
  S3 TOML today (so PR2 doesn't accidentally invert that).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…437 PR1 review)

Four doc-only fixes from Copilot's PR1 review (PR #463), all
technically correct:

- `S3Credentials` doc claimed `SecretString` "is not Serialize"; in
  fact `SecretString` does implement Serialize, emitting a hashed
  placeholder. Doc rotted between iterations — corrected to describe
  the actual behaviour and refer readers to the SecretString module
  doc for the full contract.
- `ResolvedOrigin` doc claimed `ResolvedS3Config` had non-public
  fields and a validator-only constructor; the fields are in fact
  `pub` (matching every other `Resolved*` type in the crate). Doc
  rephrased: `resolve_origin` is the **intended** construction path
  the runtime consumes, but Rust visibility doesn't enforce the
  contract for in-crate code — that's a code convention, not a
  type-level invariant.
- `ResolvedS3Config` type doc carried the same overreach; same
  correction applied.
- `secret` module doc and the `Serialize` impl comment claimed the
  hash is "DefaultHasher (per-process keyed)". `DefaultHasher::new()`
  in fact uses fixed `(0, 0)` SipHash-1-3 keys, so the digest is
  deterministic across processes. Wording corrected to
  "deterministic across processes; non-cryptographic" with the
  `~2^-64` collision bound called out explicitly.

`resolve_s3_origin` doc carried the same "only path" overstatement
as the `ResolvedOrigin` one — softened to "the **intended** path …
the only producer the resolution layer feeds into the runtime".

No code changes; build / clippy / fmt / nextest / cargo deny / cargo
doc all pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…t claims

Three follow-up phrasing precisions on the doc-only fixes from
23bd93f. Pure comment edits, no behavior change.

- secret.rs: hedge the DefaultHasher claim against std-internals
  drift. The previous wording pinned the keys at "fixed (0,0)
  SipHash-1-3"; that is correct today but is a std-internal detail.
  std's public DefaultHasher::new() doc only commits to "the same
  output for all DefaultHasher instances in a build of the
  standard library", so anchor on that contract instead. The
  cross-process determinism we rely on for in-process snapshot
  diffing follows from the std contract directly.
- secret.rs: replace the "2^-64 birthday-bound" qualifier with
  "single-pair collision probability ~2^-64 for a 64-bit output".
  The birthday-bound shorthand mixes two distinct quantities
  (per-pair collision vs. ~2^32 birthday-paradox threshold) — for
  this use case (compare exactly two snapshots per credential
  field) the per-pair number is the right one.
- mod.rs: align the resolve_s3_origin doc's hedge wording with the
  cleaner phrasing on ResolvedOrigin / ResolvedS3Config so a fresh
  reader gets the same caveat once and does not see two slightly
  different formulations on cross-link.

cargo doc / build / clippy / nextest (188 tests in decdn-common)
all clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Adds 13 tests covering the ADD: items the PR1 test analyzer flagged
as Important and that weren't yet locked down by named tests:

- expand_env_substitutes_cache_origin_fs_path: positive ${VAR}
  substitution for the FS origin path. Sibling of the existing
  expand_env_substitutes_cache_origin_url; matches the pattern of
  one positive substitution test per URL/path-shaped field.
- resolve_cache_origin_fs_expands_tilde_in_path: tilde expansion
  inside resolve_origin (~/origin -> <home>/origin) for the FS
  variant. Pins the contract that ~ expansion runs at resolution,
  not in expand_env.
- resolve_cache_rejects_empty_http_origin_url: the explicit
  ensure!(!url.is_empty(), ...) branch in resolve_origin (separate
  from parse_origin_url's scheme/format checks).
- resolve_cache_rejects_empty_fs_origin_path: sibling of the above
  for the FS variant's emptiness check.

serde-tagged-enum invariants (six tests) — locks the
deny_unknown_fields and missing-required-field error shapes
operators see at config load:

- origin_rejects_missing_kind_tag
- origin_rejects_unknown_kind_value (e.g. kind = "httpx")
- http_origin_rejects_missing_url_field
- fs_origin_rejects_missing_path_field
- s3_origin_rejects_missing_bucket_field
- s3_origin_rejects_missing_region_field

S3 credentials end-to-end (three tests):

- resolve_cache_origin_s3_static_credentials_round_trip: Static
  creds round-trip through resolve_cache into
  ResolvedS3Credentials::Static with values preserved as
  SecretStrings.
- resolve_cache_origin_s3_default_chain_no_profile: DefaultChain
  with profile = None resolves cleanly (the most common shape
  for AWS operators using IAM roles or AWS_PROFILE).
- resolve_cache_origin_s3_no_credentials_resolves_to_none: absent
  [cache.origin.credentials] table resolves to None — pins the
  default so a future refactor of resolve_s3_origin can't
  synthesize a DefaultChain placeholder.

Helper:
- assert_origin_toml_rejects: shared fragment-matcher for the
  serde-rejection tests.

201 tests in decdn-common (was 188); 549 across the workspace.
clippy / fmt / cargo doc / cargo deny all clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@thiras
thiras force-pushed the feat/origin-config-enum branch from 8790424 to 9d1886f Compare May 8, 2026 08:39
@github-actions

github-actions Bot commented May 8, 2026

Copy link
Copy Markdown

Coverage report

Total: 86.55% (was 85.88%, ▲ +0.67%) — 9934/11478 lines

File Coverage Lines Δ
crates/cache/src/origin/fs.rs 74.67% 168/225 ● 0.00%
crates/common/src/config/mod.rs 96.25% 2951/3066 ▼ 0.45%
crates/common/src/config/secret.rs 95.59% 65/68 new
crates/node/src/runtime/mod.rs 40.96% 222/542 ▲ +10.52%
crates/node/src/runtime/reload.rs 95.15% 1177/1237 ▼ 0.02%
History
Commit Total Δ vs base
9d1886f (HEAD) 86.55% ▲ +0.67%

@thiras
thiras merged commit ccbe7fa into main May 8, 2026
12 checks passed
@thiras
thiras deleted the feat/origin-config-enum branch May 8, 2026 11: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.

2 participants