Repository navigation
feat(config)!: tagged [cache.origin] table replaces flat origin_url/origin_path (#437 PR1) - #463
Conversation
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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-pathCLI flags (and env vars) so origin selection is config-only. - Add
SecretStringfor S3 static credentials (redactedDebug, hashedSerialize) 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.
…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 Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
LOC breakdown for this PRDiff vs
Roughly 62% test code by added lines (1,237 / 1,993). Totals match Method: each |
…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]>
8790424 to
9d1886f
Compare
Coverage reportTotal: 86.55% (was 85.88%, ▲ +0.67%) — 9934/11478 lines
History
|
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-s3and the test mocks are wired in.cache.origin_url/cache.origin_path/cache.decompressfields are replaced with a tagged[cache.origin] kind = "http"|"fs"|"s3"table.CacheConfigandOriginConfigcarry#[serde(deny_unknown_fields)]so legacy configs and typos likedecompres = "auto"fail at config load with a clear "unknown field" error instead of silently no-opping.--origin-url/--origin-pathflags (and theirDECDN_*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.s3variant is recognised by the schema today (sodecdn config validatelints it);build_cacherejects 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/ResolvedS3Credentialsare new resolved types (mirror theOriginUrlprecedent). No public field-by-field constructor —resolve_s3_originis the only path. PR 2's runtime cannot reach an unvalidated config.SecretStringnewtype wrapsaccess_key_id/secret_access_key/session_token.Debugalways prints"***";Serializeemits a deterministic-per-process hash soruntime::reload::FileSectionSnapshotstill 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: parsesendpoint_urlintodecdn_cache::OriginUrl(PR 2 hands one canonical form to the SDK), collapsespath_style: Option<bool>tobool, normalizesprefix(auto-trailing-slash; rejects control chars and whitespace).Migration
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-prbefore 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 thedeny_unknown_fieldsgap onOriginConfig, the missing leading/trailing-hyphen check on bucket names, theSecretStringredaction wrapper for credentials, theResolvedS3Confignewtype on the resolved side, and ~40 new tests covering every validator branch and everyexpand_envS3 field.Test plan
cargo build --workspacecargo 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 warningscargo fmt -- --check— cleancargo doc --no-deps— no broken intra-doc linkscargo deny check— advisories / bans / licenses / sources OKdecdn config validaterejects legacyorigin_urlfield with a clear "unknown field" errordecdn config validateaccepts each new variant (HTTP, FS, S3) — S3 succeeds at validate time and bails at daemon startup with the placeholderBAD_UPPERCASE_NAMEwith a helpful error🤖 Generated with Claude Code