Skip to content

fix(udp-core): [#2458] inject the UDP connection-cookie cipher - #2470

Merged
josecelano merged 32 commits into
torrust:developfrom
josecelano:2458-inject-udp-cookie-cipher
Oct 8, 2026
Merged

josecelano merged 32 commits into
torrust:developfrom
josecelano:2458-inject-udp-cookie-cipher

Conversation

@josecelano

@josecelano josecelano commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

Summary

Replaces the global, cfg(test)-switched UDP connection-cookie cipher with one key created at startup and injected into everything that issues or validates connection IDs. A production build can no longer select the public all-zero test key, and the startup check_seed(), which compared an unused seed instead of the cipher, is gone. Design: ADR docs/adrs/20261007085634_inject_the_udp_connection_cookie_cipher.md. Spec and evidence: docs/issues/open/2458-inject-udp-cookie-cipher/.

Closes #2458

Changes

  • udp-core: new CookieCipher (crypto/cookie_cipher.rs): built only from a cryptographically secure RNG in production, a fixed key only under #[cfg(test)], redacted Debug (CookieCipher([REDACTED])), no key accessor, key schedule wiped on drop through blowfish's zeroize feature, and the raw key bytes held in a zeroize::Zeroizing buffer filled in place, so they are wiped once the cipher is built. zeroize 1.9.1 (latest stable) is a new direct udp-core dependency with default features off; it was already in the graph through secrecy, so no new crate is added and the lock file only moves it from 1.9.0. connection_cookie::make and check take the cipher explicitly and every instrumented function skips it. UdpTrackerCoreServices creates one Arc<CookieCipher>, and the connect, announce, and scrape services take it as a required constructor argument. AnnounceService::authenticate and ScrapeService::authenticate are now public.
  • Removed: crypto::keys (the Keeper trait, Current/Instance facades, cfg aliases), crypto::ephemeral_instance_keys (seed and cipher statics), check_seed(), and torrust_tracker_udp_core::initialize_static() with its callers in the tracker bootstrap and the udp-server and axum-rest-api-server servers and test environments.
  • udp-server: never holds the key. The disabled-validation observability path calls the services' authenticate. Handler tests share one test-only key through test_cookie_cipher() and issue connection IDs through connection_id_issued_to.
  • Benchmarks: new connection_cookie_benchmark (make, check); repaired connect_once, which passed an async fn to b.iter without awaiting it and measured only the creation of a future.
  • Docs: corrected the udp-server crate docs (they described connection IDs as a hash with a secret seed), the bootstrap docs, src/AGENTS.md, and the Spam and abuse resistance #2411 EPIC's citations of the deleted key file.

Design changes approved by the maintainer at the design-review checkpoint (after the first vertical slice): the key stays inside udp-core's services instead of being exposed to udp-server, and the udp-server tests share one test-only key. The ADR records both.

Validation

  • Regression tests, each seen red against a reintroduced bug (mutate-then-restore, recorded in manual-verification-evidence.md): R1 random keys differ from the test key and from each other; R2 a compile_fail,E0599 doctest that production code cannot name the test key (red on develop before the fix); R3 a connection ID issued by a container's connect service is accepted by its announce and scrape services; R4 Debug is redacted. R2's error code is checked only by nightly rustdoc, which the CI unit job runs.
  • Manual checks against the running tracker: normal connect and announce (M1); an announce with a connection ID forged with the all-zero key is rejected while the tracker's own ID is accepted, and a production build cannot select the test key (M2b, the like-for-like recheck of the pre-fix reproduction); a trace-level log of connect, announce, and scrape contains no key material (M3). The disposable examples used for M2b are not part of this PR; their code is recorded verbatim in the evidence.
  • Performance (performance-evidence.md), baseline measured before any production change, same machine and settings, one-sided pass rule:
Measurement Before After Limit
aquatic_udp_load_test mean responses/s 152198 154261 not below 142155
make median 43.67 ns 44.77 ns not above 49.93 ns
check median 46.88 ns 46.99 ns not above 48.30 ns
connect_once median 58.71 ns 59.05 ns not above 59.10 ns
  • linter all, the pre-commit gate on every commit, and the pre-push checks (nightly fmt, check, docs, and the full stable test suite) pass.
  • Independent Task Reviewer: REVIEW PASSED, AC1-AC8 pass; its should-fix and a nit are applied (agent-review-reports.md).

Benchmarking Documentation (Separate Commits)

At the maintainer's request this PR also updates what the work showed was missing, each in its own commit: docs/benchmarking.md now catalogs every benchmark level and tool, how to choose one, how to record before-and-after evidence, and how to check that a benchmark measures anything; a new run-benchmarks skill (.github/skills/dev/benchmarking/) points to it; run-benches.sh uses current package names; and the write-unit-test skill explains how compile_fail regression doctests are checked.

Notes for Reviewers

  • Commits are small and in plan order (ADR, red run, benchmark, baseline, key type, wiring, removal, verification, docs). A transitional static existed between the key-type and removal commits so each commit compiles.
  • The commit docs(issues): [#2458] record the post-fix manual verification and acceptance review also contains a three-line ADR frontmatter link fix that its message does not mention: a failed pre-commit left it staged. History is not rewritten.
  • The Task Reviewer's nit N1 (also wipe the raw 32-byte key array in CookieCipher::random()) was accepted by the maintainer after the PR opened and is in the fix(udp-core): [#2458] wipe the raw cookie key bytes after building the cipher commit. The wipe cannot be tested without undefined behavior; R1 guards that the buffer is actually filled.
  • Follow-up not in this PR: the http-core announce benchmark has the same unawaited-future defect; it is listed under Known Defects in docs/benchmarking.md.
  • Issue Overhaul Packages Testing: Add tests for udp-tracker-core package #1348 is paused until this merges; its author adapts the udp-core tests that call make/check or construct the services.

@josecelano
josecelano requested a review from a team as a code owner October 7, 2026 10:53
Copilot AI balanced review requested due to automatic review settings October 7, 2026 10:53
@josecelano josecelano self-assigned this Oct 7, 2026
@josecelano
josecelano requested a review from da2ce7 October 7, 2026 10:54
josecelano added a commit to josecelano/torrust-tracker that referenced this pull request Oct 7, 2026
Sets related-pr to torrust#2470 and the status to in-review, ticks the automatic-verification checkpoint after the pre-push checks passed, and logs the two rebases.

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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

Review effort: Lite
Findings: 1 High severity · 1 Medium severity

Open (2)
What changed in this PR

This PR removes the global, cfg-switched UDP connection-cookie key and replaces it with a single CookieCipher created at startup (per composition root) and injected into the UDP services that issue/validate connection IDs, eliminating the possibility of selecting the all-zero test key in production.

Changes:

  • Introduces CookieCipher and wires it through connection_cookie::{make,check} and UDP connect/announce/scrape services.
  • Removes the old global key/seed statics and startup check_seed()/initialize_static() hooks across application/bootstrap and test environments.
  • Adds/fixes benchmarks and updates docs/specs/skills to record performance evidence and benchmarking guidance.
File Description
src/​bootstrap/​app.rs Removes check_seed() and UDP-core static initialization; updates bootstrap docs comment.
src/​AGENTS.md Removes checklist guidance referencing check_seed().
share/​default/​config/​tracker.udp.benchmarking.toml Adds a skill-link comment for benchmarking workflow.
project-words.txt Adds “doctests” to project dictionary.
packages/​udp-server/​src/​testing/​environment.rs Removes UDP-core static initialization from test environment.
packages/​udp-server/​src/​server/​mod.rs Removes UDP-core static initialization from UDP server tests.
packages/​udp-server/​src/​server/​launcher.rs Removes UDP-core static initialization from launcher tests.
packages/​udp-server/​src/​lib.rs Updates crate docs to describe connection ID as encryption with a startup key (not a hash/seed).
packages/​udp-server/​src/​handlers/​scrape.rs Uses ScrapeService::authenticate for disabled-validation observability; updates tests to use shared test key helper.
packages/​udp-server/​src/​handlers/​mod.rs Adds shared test CookieCipher and helper to issue connection IDs consistently across handler tests.
packages/​udp-server/​src/​handlers/​connect.rs Injects test cipher into ConnectService in handler tests; expected IDs come from shared helper.
packages/​udp-server/​src/​handlers/​announce.rs Uses AnnounceService::authenticate for disabled-validation observability; updates tests to use shared helper and injected cipher.
packages/​udp-server/​benches/​udp_tracker_server_benchmark.rs Injects a CookieCipher into benchmark context and uses new make(&cipher, ...) signature.
packages/​udp-core/​src/​services/​scrape.rs Stores injected CookieCipher; makes authenticate public and uses it in handle_scrape.
packages/​udp-core/​src/​services/​connect.rs Stores injected CookieCipher; make now receives cipher; updates unit tests accordingly.
packages/​udp-core/​src/​services/​announce.rs Stores injected CookieCipher; makes authenticate public and uses it in handle_announce.
packages/​udp-core/​src/​lib.rs Removes UDP-core initialize_static() and old ephemeral key wiring.
packages/​udp-core/​src/​crypto/​mod.rs Replaces old keys/ephemeral_instance_keys modules with cookie_cipher.
packages/​udp-core/​src/​crypto/​keys.rs Deletes old keeper/facade-based key management module.
packages/​udp-core/​src/​crypto/​ephemeral_instance_keys.rs Deletes old global seed/cipher statics (including zeroed test cipher).
packages/​udp-core/​src/​crypto/​cookie_cipher.rs Adds CookieCipher with redacted Debug, test-only fixed key, and encrypt/decrypt API.
packages/​udp-core/​src/​container.rs Creates one shared Arc<CookieCipher> in core services and injects into connect/announce/scrape; adds collaboration tests.
packages/​udp-core/​src/​connection_cookie.rs Updates cookie algorithm implementation to require explicit &CookieCipher for make/check.
packages/​udp-core/​benches/​udp_tracker_core_benchmark.rs Fixes connect_once benchmark to actually await work via Criterion async executor.
packages/​udp-core/​benches/​helpers/​sync.rs Removes prior helper that benchmarked only future creation / non-awaited work.
packages/​udp-core/​benches/​helpers/​mod.rs Switches helpers module from sync to connect.
packages/​udp-core/​benches/​helpers/​connect.rs Adds benchmark context that builds services once and exposes an awaited connect call.
packages/​udp-core/​benches/​connection_cookie_benchmark.rs Adds new Criterion benchmark for connection_cookie::{make,check}.
packages/​udp-core/​Cargo.toml Enables blowfish zeroize feature and adds new benchmark target.
packages/​axum-rest-api-server/​src/​testing/​environment.rs Removes UDP-core static initialization from REST API server test environment.
packages/​axum-rest-api-server/​src/​server.rs Removes UDP-core static initialization from REST API server tests.
docs/​issues/​open/​2458-inject-udp-cookie-cipher/​performance-evidence.md Adds detailed before/after performance evidence for cookie cipher injection.
docs/​issues/​open/​2458-inject-udp-cookie-cipher/​manual-verification-evidence.md Updates manual verification evidence including post-fix forged-cookie rejection checks.
docs/​issues/​open/​2458-inject-udp-cookie-cipher/​implementation-retrospective.md Adds implementation retrospective and process notes.
docs/​issues/​open/​2458-inject-udp-cookie-cipher/​agent-review-reports.md Adds independent task reviewer report.
docs/​issues/​open/​2458-inject-udp-cookie-cipher/​ISSUE.md Updates issue status/progress log/acceptance criteria and adds performance considerations/tasks.
docs/​issues/​open/​2411-spam-and-abuse-resistance/​EPIC.md Updates EPIC references to point at new key/cipher implementation locations.
docs/​benchmarking.md Expands benchmarking catalog/selection/evidence guidance; documents known benchmark defects and correct config field name.
docs/​adrs/​index.md Adds ADR entry for cookie-cipher injection design.
docs/​adrs/​20261007085634_inject_the_udp_connection_cookie_cipher.md Adds ADR describing design and rationale for injected cookie cipher.
contrib/​dev-tools/​benches/​run-benches.sh Updates package name and expands script to run udp-server benches; adds skill-link.
.github/​skills/​dev/​testing/​write-unit-test/​SKILL.md Documents nightly-only enforcement of compile_fail error codes for doctests.
.github/​skills/​dev/​benchmarking/​run-benchmarks/​SKILL.md Adds new skill describing how to choose/run/record benchmarks and evidence.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/udp-core/src/container.rs Resolved

@da2ce7 da2ce7 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed at 1a462d8fea2f752aff4dd1715ed28693b7a0762f (round 1). Recomputed from the bytes at this head, against develop at 24bf4746a.

This PR implements the issue's specification: one CookieCipher per composition root replaces the cfg(test)-switched global cookie statics, make/check take the cipher explicitly, the public all-zero key and check_seed() are removed, and the PR adds a cookie benchmark, repairs connect_once, and documents benchmarking (guide and run-benchmarks skill). 21 commits, 44 files, +1,943/−455.

Fix vs spec and ADR. random() draws [u8; 32] from rand::rng() (cookie_cipher.rs:49-51); fixed_for_testing() is #[cfg(test)] pub(crate) (:56-57) and is named only in udp-core test modules and the compile_fail doctest; encrypt/decrypt are pub(crate), Debug is hand-redacted (:74-77), and there is no Clone or accessor. Every #[instrument] that receives the cipher skips it (connection_cookie.rs:131,159,243,250). The tracker builds UdpTrackerCoreServices once (src/container.rs:102) and every UDP instance reuses it (:220), so the binary has one key; the REST API container that builds its own is reached only from test modules. udp-server names CookieCipher only in its test helpers. No code reference to the removed statics, facades, check_seed or udp_core::initialize_static remains. The secrecy deviation is stated with reasons.

Regression tests. R1 (cookie_cipher.rs:91,108), R4 (:125), R2 (doctest :38) and R3 (container.rs:258,281) exist and assert what the strategy says, and each recorded mutation is one its test catches. An independent Blowfish recomputation gives [69, 151, 249, 78, 120, 221, 152, 97] for the zero block under 32 zero bytes, exactly M-R1's recorded output, and reproduces the pinned constant at connection_cookie.rs:276, so the format is unchanged (AC6). R2's pre-fix red run (reported) used the E0432 predecessor doctest; the committed E0599 doctest is shown red by M-R2b/M-R2c, as the spec planned. Recorded test counts (45, 47, 219) match the tree.

Manual verification and records. V1/V3 record the toolchain, commands, verbatim disposable sources and output; V3's rejection bound matches its log timestamp. M3 greps type and placeholder names; key bytes are excluded by construction (R4, skips). No merged document cites a branch commit id. status: in-review with T8 awaiting the maintainer's review matches the log; branch and related-pr match the PR. The Task Reviewer's S1 and N3 are applied.

Performance. Recomputed: P1 mean 152197.78, lowest run 142155.29, highest medians 49.93/48.30/59.10 ns; P2 mean 154260.85, medians 44.77/46.99/59.05 ns. All four limits follow the one stated rule (lowest P1 run; highest P1 median), written into the evidence before P2 ran; all pass (connect_once by 0.05 ns). Benchmark code changes between P1 and P2 only for the new parameters, and develop changed only docs since the measured base. The to_async(&runtime).iter repair fits criterion's async_tokio; the http-core defect listed in docs/benchmarking.md is real at the base; every catalog path and package name exists.

Manifests and hygiene. blowfish gains zeroize; the new [[bench]] uses harness = false like its siblings; the lockfile keeps 584 packages with three new edges to the existing zeroize 1.9.0 and block-buffer 0.12.1; deny.toml is untouched. 21 Conventional subjects with [#2458], author = committer, author times ascending, no trailers. Builds, tests and zeroize behaviour are reported.

Security reading. No path selects the fixed key outside cfg(test); no service or container implements Debug; the key never crosses a process or log boundary; benchmarks use random(). N1 stays the maintainer's open decision.

Findings

  • F1 [Minor] src/AGENTS.md:32 still says global-services initialization sets up a crypto seed. Blocking only because it leaves a false statement in the tree.
  • F2 [Nit] write-unit-test: "ignores the code" reads as "ignores the doctest".
  • F3 [Suggestion] UdpTrackerCoreServices::cookie_cipher could be pub(crate).

Checked, no finding

  • The EPIC row's new citations (connection_cookie.rs:160, cookie_cipher.rs:49, container.rs:171) resolve at this head.
  • bbb790a95's ADR frontmatter edit is the same link swap its body describes for the spec.
  • 36c0bc2a2 fixes a script whose old package name no longer exists; the new skill follows add-new-skill and the marker convention.
  • The design checkpoint names the maintainer as reviewer; the approval is logged before the next code commit.
  • The PR body's closing keyword fits an implementation PR (open-pull-request); the open decision and the follow-up are stated.

Checks

On the loop's compute hub at this head, base develop 24bf4746a (receipts server-gates-krkavec-147 and -148): pre-commit profile gate exit 0 (74 s), clippy-allow-reasons --base-ref 24bf4746a exit 0, tree clean after the gate; linter markdown, linter cspell, linter lychee exit 0; frontmatter-validator --all: 19 errors / 4 warnings at this head and 19 / 4 at develop 24bf4746a re-measured, so no new frontmatter finding; whole-workspace cargo +stable test --all-targets --all-features: 3016 passed, 0 failed (71 s; the base's count was 3017, the difference being the tests removed with the deleted key module); cargo +nightly clippy --workspace --all-targets --all-features -- -D warnings: exit 0, 0 diagnostics (12 s). GitHub checks at this head at posting time: "23 checks: Publish (Development) completed/skipped; Publish (Release) completed/skipped; Docker E2E completed/skipped". At posting, develop is 24bf4746a, this head's base.

Comment thread src/AGENTS.md Resolved
Comment thread packages/udp-core/src/container.rs Resolved
@josecelano
josecelano force-pushed the 2458-inject-udp-cookie-cipher branch from 1a462d8 to e7a9c83 Compare October 7, 2026 13:24
josecelano added a commit to josecelano/torrust-tracker that referenced this pull request Oct 7, 2026
Sets related-pr to torrust#2470 and the status to in-review, ticks the automatic-verification checkpoint after the pre-push checks passed, and logs the two rebases.

@da2ce7 da2ce7 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed at e7a9c83ec639e0e9730a24c953850925a36d6b0f (round 2). Recomputed from the bytes at this head, against develop at c7cb2b3fa.

This push rebases the 21 round-1 commits onto c7cb2b3fa and adds the raw-key wipe (fab0df957) with its ADR update (14d3e1139) and records (e7a9c83ec).

Carried commits. The range-diff shows all 21 round-1 commits unchanged (=). develop's delta since 24bf4746a touches none of the PR's 44 files, and those files equal the round-1 tip's except for the three new commits. The round-1 reading of the fix, the regression tests, the records, the performance evidence, the manifests and the security reading therefore stands.

The wipe. cookie_cipher.rs:56-58 creates Zeroizing::new([0; KEY_LEN]), fills it in place with rand::rng().fill(&mut *key), and passes &key. The lockfile pins rand 0.9.5, whose Rng::fill fills the whole [u8; 32]. &key deref-coerces to from_key's &[u8; KEY_LEN] (:68), and new_from_slice borrows it, so no by-value copy of the raw key is made on the way to the cipher. Zeroizing's drop wipes the buffer when random() returns, as :51-53 says. The expanded schedule still holds the key for the cipher's lifetime and is wiped on drop. The new doc comment (:26-27) and the ADR state that copies the compiler or the operating system make elsewhere are out of the wipe's reach, and that the wipe cannot be tested.

Cargo.toml:40 adds zeroize = { version = "1.9.1", default-features = false }. The lockfile delta is exactly zeroize 1.9.0 → 1.9.1 plus the new udp-core edge, with 584 packages on both sides. That Zeroizing<[u8; 32]> needs no default feature cannot be checked offline here; the build is reported green. The ADR's Memory decision (ADR:102-107) matches the code.

The new evidence section (manual-verification-evidence.md:521-549) records green runs whose 42 unit tests match the tree, and mutation M-R1-fill, whose red output (1 passed, 2 failed, 39 filtered out) is consistent. M-R1-fill shows the key is not left all-zero; that every byte is filled rests on Rng::fill. The spec log (ISSUE.md:389) and both last-updated-utc stamps read 13:19. The reason for not re-measuring performance holds: make and check are unchanged, and random() runs once per composition root. implementation-retrospective.md is untouched.

F1–F3. src/AGENTS.md, write-unit-test/SKILL.md and container.rs are byte-identical to the round-1 tip, so all three findings stand and are re-raised inline at the same anchors. F1 still blocks. F3 makes the same point as the open Copilot thread at container.rs:146.

Hygiene. All 24 subjects are Conventional with [#2458], and the three new ones match their diffs. Author = committer throughout. The new author times (13:18:47Z, 13:20:23Z, 13:20:48Z) are in order, and all committer times (13:21:22Z–13:21:31Z) fall after develop moved at 12:50Z. There are no trailers and no banned token, project-words.txt gains only Zeroizing, and no merged document cites a branch commit id. No round-1 thread had a reply at capture.

Findings

  • F1 [Minor] (re-raise) src/AGENTS.md:32 still says the global-services step sets up a crypto seed. Blocking.
  • F2 [Nit] (re-raise) write-unit-test/SKILL.md:151 "ignores the code".
  • F3 [Suggestion] (re-raise) UdpTrackerCoreServices::cookie_cipher could be pub(crate).
  • No new finding from the wipe.

Checked, no finding

  • The open Copilot thread at cookie_cipher.rs:59 (raw key array not wiped) is addressed at the bytes by fab0df957.
  • fab0df957's message records why the crate is needed, its latest-stable version and its feature choice, as add-rust-dependency asks.
  • The PR body now records N1 as accepted rather than open.

Checks

On the loop's compute hub at this head, base develop c7cb2b3fa (receipts server-gates-krkavec-154 and -155): pre-commit profile gate exit 0 (165 s code, 152 s documents), clippy-allow-reasons --base-ref c7cb2b3fa exit 0, tree clean after the gate; linter markdown, linter cspell, linter lychee exit 0; frontmatter-validator --all: 19 errors / 4 warnings at this head and 19 / 4 at develop c7cb2b3fa re-measured, so no new frontmatter finding; whole-workspace cargo +stable test --all-targets --all-features: 3016 passed, 0 failed (97 s; as at the round-1 head); cargo +nightly clippy --workspace --all-targets --all-features -- -D warnings: exit 0, 0 diagnostics (13 s). GitHub checks at this head at posting time: "23 check runs, 20 success (Publish (Release) skipped; Publish (Development) skipped; Context success; Package Coverage Regression success; Package Coverage (torrust-tracker-udp-core) success; Package Coverage (torrust-tracker-axum-rest-api-server) success; Package Coverage (torrust-tracker) success; Package Coverage (torrust-tracker-udp-server) success; Discover Package Coverage success; Generate Coverage Report success; Docker E2E skipped; Unit (stable) success; Build on windows-latest (stable) success; Build on macos-latest (nightly) success; Unit (nightly) success; Layer Boundary Bans success; Build on ubuntu-latest (stable) success; Build on ubuntu-latest (nightly) success; Build on macos-latest (stable) success; Documented Clippy Allows success; Test (Docker) (release) success; Build on windows-latest (nightly) success; Docs Lint success)". At posting, develop is a43bebea9 (the merge of #2469, which edits docs/issues/open/2411-spam-and-abuse-resistance/EPIC.md, a file this PR also edits), and git merge-tree of this head onto it reports a content conflict in that file, so the branch needs a rebase before it can merge; the gate figures above were measured at this head's base c7cb2b3fa.

Comment thread src/AGENTS.md Resolved
Comment thread packages/udp-core/src/container.rs Resolved
@josecelano
josecelano force-pushed the 2458-inject-udp-cookie-cipher branch from e7a9c83 to 169b175 Compare October 7, 2026 15:19
josecelano added a commit to josecelano/torrust-tracker that referenced this pull request Oct 7, 2026
Sets related-pr to torrust#2470 and the status to in-review, ticks the automatic-verification checkpoint after the pre-push checks passed, and logs the two rebases.
josecelano added a commit to josecelano/torrust-tracker that referenced this pull request Oct 7, 2026
UdpTrackerCoreServices::cookie_cipher is now pub(crate). Nothing outside udp-core read it, but as a public field any holder of the services, such as the application container, could clone the key and pass it to the public make and check. A compile_fail doctest (E0616) with a compiling companion pins that code outside the crate cannot read it, so the ADR's statement that udp-server never holds the key is enforced by the compiler. Review findings F1 and F5 on PR torrust#2470 (Copilot, and da2ce7's F3).
josecelano added a commit to josecelano/torrust-tracker that referenced this pull request Oct 7, 2026
…rap flow

initialize_global_services() now sets up only logging and the clock; the UDP connection-cookie key is created by AppContainer::initialize. The bootstrap diagram in src/AGENTS.md still said the global-services step set up a crypto seed. Review finding F3 on PR torrust#2470 (da2ce7's F1).
josecelano added a commit to josecelano/torrust-tracker that referenced this pull request Oct 7, 2026
…ile_fail doctest to fail

The write-unit-test note said stable rustdoc 'ignores the code', which reads as ignoring the doctest. Stable still fails a compile_fail doctest that compiles; it only does not check the pinned error code. Review finding F4 on PR torrust#2470 (da2ce7's F2).
josecelano added a commit to josecelano/torrust-tracker that referenced this pull request Oct 7, 2026
…ey in udp-core

Records that UdpTrackerCoreServices::cookie_cipher is pub(crate) and pinned by a compile_fail doctest, following review findings F1 and F5 on PR torrust#2470.
josecelano added a commit to josecelano/torrust-tracker that referenced this pull request Oct 7, 2026
Records the rebase, the pub(crate) key field with its compile_fail doctest and the mutation that made it red, and the documentation corrections, and notes why the dated coupling report on develop stays unchanged.
@josecelano
josecelano requested a review from da2ce7 October 7, 2026 15:19
@josecelano

Copy link
Copy Markdown
Member Author

Review response for Copilot review 5441412069 and @da2ce7's reviews 5441582812 (round 1) and 5443352831 (round 2). The audit is docs/pr-reviews/pr-2470-review/PR-REVIEW.md (audit IDs; Cameron's own IDs in parentheses).

Finding Source Disposition Resolution reference
F1 Copilot 5441412069, container.rs:146 FIXED fix(udp-core): [#2458] keep the cookie key private to udp-core
F2 Copilot 5441412069, cookie_cipher.rs:59 FIXED fix(udp-core): [#2458] wipe the raw cookie key bytes after building the cipher
F3 (F1) 5441582812, src/AGENTS.md:32 FIXED docs(src): [#2458] stop describing a crypto seed in the bootstrap flow
F4 (F2) 5441582812, write-unit-test FIXED docs(skills): [#2458] say stable rustdoc still requires a compile_fail doctest to fail
F5 (F3) 5441582812, container.rs:145 NO_ACTION, re-raise of F1 Superseded by F1
F6 (F1) 5443352831, re-raise NO_ACTION, re-raise of F3 Superseded by F3
F7 (F2) 5443352831, re-raise NO_ACTION, re-raise of F4 Superseded by F4
F8 (F3) 5443352831, re-raise NO_ACTION, re-raise of F5 Superseded by F1
F9 5443352831 body: the branch conflicts with develop FIXED This comment

F9: the branch is rebased onto develop a64d1497e. Two conflicts, both resolved by keeping both sides: the #2411 EPIC's last-updated-utc stamp (now the time of this branch's edit) and docs/adrs/index.md, where #2468's ADR row and this PR's row are both kept, in timestamp order. The branch is 0 commits behind develop, linter all and the pre-push checks pass, and all commits are signed. The generated 2026-10-06 workspace coupling report on develop still lists crypto::keys and udp_core::initialize_static; it is a dated snapshot, so it stays unchanged.

For F1, the field is now pub(crate) and a compile_fail,E0616 doctest, with a compiling companion, pins that code outside udp-core cannot read the key; making the field pub again turns the doctest red. The ADR and the issue evidence record this.

josecelano added a commit to josecelano/torrust-tracker that referenced this pull request Oct 7, 2026
Audits Copilot review 5441412069 and da2ce7 reviews 5441582812 and 5443352831: F1-F4 fixed, F5-F8 re-raises superseded, and F9 (the rebase the round-2 body asked for) fixed. The audit validator reports 9 rows and 0 failures.
@josecelano

Copy link
Copy Markdown
Member Author

ACK 4b9155f

@da2ce7 da2ce7 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed at 4b9155f57a2689caeb82a626b50052e0563f1d4a (round 3). Recomputed from the bytes at this head, against develop at a64d1497e.

The two pushes rebase the 24 round-2 commits onto a64d1497e, with two conflicts resolved (the 2411 EPIC stamp and the ADR index row). They also add the three fixes, the pub(crate) doctest, the records and the audit.

Carried commits. Both range-diffs recompute byte-identical to the captures: 22 = and two !.

  • Commit 1 (dc2fbf006) differs only in context: its index row now follows #2468's row, in timestamp order.
  • Commit 20 (f72706264) differs only in the EPIC stamp hunk (12:55 → 14:59). The citation row is unchanged and #2469's edits are intact.
  • The PR's other files equal the round-2 head's apart from the six new commits, so the scope items verified in rounds 1–2 stand.

F1. src/AGENTS.md:32 now reads ← logging, clock and :33 reads ← builds all containers and the UDP cookie key. That matches initialize_global_services() (src/bootstrap/app.rs:76-78, clock-only initialize_static() at :90-91), and the key is created through src/container.rs:102 at packages/udp-core/src/container.rs:192. Fixed.

F2. write-unit-test/SKILL.md:150-151 now says stable rustdoc "still requires the doctest to fail to compile but accepts any error; only nightly checks the pinned error code". That is what the issue's M-R2b stable run shows. Fixed.

F3 and the doctest. container.rs:166 is pub(crate).

  • The compile_fail,E0616 doctest (:145-151) reads services.cookie_cipher from outside the crate; E0616 is the private-field error.
  • The companion (:155-161) uses the same import and shape on the public event_bus, so a wrong path cannot make the guard pass.
  • Stable fails a compile_fail doctest that compiles, so the guard holds on stable; nightly also checks the error code.
  • Only container.rs:109,119,129 read the field; udp-server and the benchmarks never did.
  • The recorded mutation (field pub again: "Test compiled successfully, but it's marked compile_fail") and its filter counts match the crate's 5 mergeable and 2 compile_fail doctests. Fixed.

Records. The ADR (:89-91) states the pub(crate) field and its doctest. The spec log entry (ISSUE.md:390) and both last-updated-utc stamps read 15:03. The evidence section is stamped 15:00, before the fix commit. implementation-retrospective.md is untouched.

Audit. The record has nine rows, each with a matching detail entry. Its Ownership, Status Values and Completion Rules blocks equal the template at the base. The cells I checked:

  • Each Source review ID owns its source comment, and each thread row cites exactly one reply, on its own thread.
  • Every FIXED subject is on the branch.
  • Severities equal the posted brackets; Copilot's High and Medium are marked inferred.
  • Reviewer finding ID carries this loop's F1–F3.
  • F5–F8 are RE_RAISE_OF and NO_ACTION/SUPERSEDED, with reply URLs and Superseded by … replies.
  • F9 is NON_RESOLVABLE, with the review URL as source and the response comment as its reference. That is admissible under process-pr-review/SKILL.md:232-234, since a rebase has no subject of its own.
  • The Processing Log is chronological and no later than the record commit, and the response comment's nine rows match.

The validator script was not run here. A re-implementation of its checks over the captured comments passes.

Hygiene. All 30 subjects are Conventional with [#2458] and true to their diffs, and author = committer throughout. The five fixes were authored 15:01:32Z–15:04:12Z, just before develop's 15:04:14Z merge, and committed in the 15:05:15Z–15:05:26Z rebase. The audit commit (15:22:34Z) follows the replies. Cargo.lock and project-words.txt are unchanged since round 2; there is no banned token and no branch id cited. Git's trailer parser reads e770f2c4e's one-paragraph body, which starts UdpTrackerCoreServices::cookie_cipher, as a pseudo-trailer.

Findings

  • F4 [Minor] EPIC.md:92 cites cookie_cipher.rs:49 and container.rs:171, which no longer point at the key's creation. Blocking.
  • F1, F2, F3: fixed at the bytes.

Checked, no finding

  • Both conflict resolutions keep both sides.
  • The dated coupling report on develop stays unchanged, as the records say.

Checks

On the loop's compute hub at this head, base develop a64d1497e (receipts server-gates-krkavec-163 and -164): pre-commit profile gate exit 0 (78 s code, 78 s documents), clippy-allow-reasons --base-ref a64d1497e exit 0, tree clean after the gate; linter markdown, linter cspell, linter lychee exit 0; frontmatter-validator --all: 19 errors / 4 warnings at this head and 19 / 4 at develop a64d1497e re-measured, so no new frontmatter finding; validate-audit-record.py --pr-number 2470 over the live review comments: 9 rows, 2 log entries, 0 failures; whole-workspace cargo +stable test --all-targets --all-features: 3016 passed, 0 failed (73 s); cargo +nightly clippy --workspace --all-targets --all-features -- -D warnings: exit 0, 0 diagnostics (88 s). GitHub checks at this head at posting time: "23 check runs, 20 success (Publish (Development) skipped; Publish (Release) skipped; Context success; Package Coverage Regression success; Docker E2E skipped; Unit (nightly) success; Layer Boundary Bans success; Documented Clippy Allows success; Unit (stable) success; Test (Docker) (release) success; Package Coverage (torrust-tracker) success; Package Coverage (torrust-tracker-udp-core) success; Package Coverage (torrust-tracker-axum-rest-api-server) success; Package Coverage (torrust-tracker-udp-server) success; Build on macos-latest (nightly) success; Build on windows-latest (stable) success; Build on ubuntu-latest (stable) success; Build on macos-latest (stable) success; Build on windows-latest (nightly) success; Docs Lint success; Build on ubuntu-latest (nightly) success; Discover Package Coverage success; Generate Coverage Report success)". At posting, develop is a64d1497e, this head's base, and the merge of this head onto it is clean by git merge-tree.

josecelano added a commit to josecelano/torrust-tracker that referenced this pull request Oct 7, 2026
…n by symbol

The connection-ID row of the torrust#2411 EPIC cited cookie_cipher.rs:49 and container.rs:171, which later commits in this branch moved, and connection_cookie.rs:160, which departs from the EPIC's review basis (7970cdf, where check is at :159). Restore :159 and name the key's creation by symbol, CookieCipher::random and UdpTrackerCoreServices::initialize_from, which do not drift; the basis note now says why that row uses symbols. Review finding F10 on PR torrust#2470 (da2ce7's F4).
…and acceptance review

Records V2-V4 on the last production change: the normal connect-and-announce flow works (M1); the running tracker rejects an announce with a connection ID forged with the all-zero key, the same forged cookie is rejected in process, and a production build cannot name the test key (M2b); and a trace-level log of connect, announce, and scrape contains no key material (M3). Marks T6, T7, and B3 done, reviews AC1-AC7 against the evidence, logs the maintainer's checkpoint approval, and replaces the related-artifact links to the deleted key modules with crypto/cookie_cipher.rs.
…es.sh

The script benchmarked torrust-tracker-torrent-repository, which was renamed torrust-tracker-torrent-repository-benchmarking, and skipped the udp-server benchmark. Found while surveying the benchmarks for the issue's performance evidence.
…ent before-and-after evidence

Adds what implementing torrust#2458 showed was missing: a table of every benchmark level and tool with what it measures and its command (including the udp-core, udp-server, and http-core Criterion benchmarks, the persistence benchmark, and the workflow timing scripts), criteria for choosing one, the procedure for recording before-and-after evidence with a one-sided pass rule, and how to check that a benchmark measures anything. Records the http-core announce benchmark's unawaited-future defect as a known defect.

Also corrects the torrent-repository benchmark package name, the logging key (trace_filter, not threshold), and the related-artifact path of the aquatic guide.
Adds .github/skills/dev/benchmarking/run-benchmarks, the agent workflow for docs/benchmarking.md: when a change needs performance evidence, how to choose instruments, check that they measure something, write a one-sided pass rule, measure before and after, and record the result in issue-local performance-evidence.md. Links the guide to the skill and adds skill-link markers to the script and the load-test configuration the skill depends on.
…ests are checked

Implementing torrust#2458 showed that stable rustdoc accepts any compile error for a compile_fail doctest and checks the pinned error code only on nightly. The write-unit-test skill now asks for a companion doctest, for running the mutations on both toolchains, and for relying on the nightly CI job to enforce the code.
…mpletion review

Marks D1 and AC8 done, ticks the completed checkpoints and criteria, links the new evidence and retrospective from the frontmatter, and adds implementation-retrospective.md: the design change that keeps the key out of udp-server, the empty T6, the late performance planning, the nightly-only compile_fail check, the broken benchmarks, and the evidence-time and staging mistakes, with reusable improvements.
Records the independent Task Reviewer's report (REVIEW PASSED, AC1-AC8 pass) in agent-review-reports.md. Fixes S1: AC6 and the Regression Test Strategy cited a round-trip quickcheck property that exists only on the torrust#1348 branch; they now cite it_should_validate_a_valid_cookie, with a correction note. Fixes N3 by removing a leftover template instruction, and ticks the reviewer checkpoints.
…n-ID citations

Issue torrust#2458 deletes crypto/ephemeral_instance_keys.rs, which the torrust#2411 abuse-case inventory cited for the key being generated at startup, and shifts connection_cookie::check by one line. Point the row to CookieCipher::random and to where UdpTrackerCoreServices creates the one key; the row's wording stays true.
Sets related-pr to torrust#2470 and the status to in-review, ticks the automatic-verification checkpoint after the pre-push checks passed, and logs the two rebases.
…lding the cipher

CookieCipher::random now fills a zeroize::Zeroizing buffer in place and builds the cipher from it, so the raw 32-byte key is wiped when the function returns; previously only the expanded key schedule was wiped (through blowfish's zeroize feature). Filling in place avoids a moved copy of the array. The maintainer accepted the Task Reviewer's nit N1.

zeroize is already in the dependency graph through secrecy and blowfish; this adds it as a direct udp-core dependency at the latest stable version, 1.9.1 (the lock file moves from 1.9.0), with default features off because Zeroizing over a byte array needs none. Adds Zeroizing to the dictionary. A test cannot observe the wipe without undefined behavior, so it is not tested; R1 still guards the key: filling a different buffer leaves the all-zero key and fails both R1 tests.
The Memory decision now also covers the raw key bytes, held in a zeroize::Zeroizing buffer filled in place, the direct zeroize dependency, and that wiping is best effort and cannot be tested.
Logs the maintainer's acceptance of nit N1 and records the green runs and the new mutation (filling a throwaway buffer leaves the all-zero key and fails both R1 tests). Explains why the wipe is untested and why performance is not re-measured.
UdpTrackerCoreServices::cookie_cipher is now pub(crate). Nothing outside udp-core read it, but as a public field any holder of the services, such as the application container, could clone the key and pass it to the public make and check. A compile_fail doctest (E0616) with a compiling companion pins that code outside the crate cannot read it, so the ADR's statement that udp-server never holds the key is enforced by the compiler. Review findings F1 and F5 on PR torrust#2470 (Copilot, and da2ce7's F3).
…rap flow

initialize_global_services() now sets up only logging and the clock; the UDP connection-cookie key is created by AppContainer::initialize. The bootstrap diagram in src/AGENTS.md still said the global-services step set up a crypto seed. Review finding F3 on PR torrust#2470 (da2ce7's F1).
…ile_fail doctest to fail

The write-unit-test note said stable rustdoc 'ignores the code', which reads as ignoring the doctest. Stable still fails a compile_fail doctest that compiles; it only does not check the pinned error code. Review finding F4 on PR torrust#2470 (da2ce7's F2).
…ey in udp-core

Records that UdpTrackerCoreServices::cookie_cipher is pub(crate) and pinned by a compile_fail doctest, following review findings F1 and F5 on PR torrust#2470.
Records the rebase, the pub(crate) key field with its compile_fail doctest and the mutation that made it red, and the documentation corrections, and notes why the dated coupling report on develop stays unchanged.
Audits Copilot review 5441412069 and da2ce7 reviews 5441582812 and 5443352831: F1-F4 fixed, F5-F8 re-raises superseded, and F9 (the rebase the round-2 body asked for) fixed. The audit validator reports 9 rows and 0 failures.
…n by symbol

The connection-ID row of the torrust#2411 EPIC cited cookie_cipher.rs:49 and container.rs:171, which later commits in this branch moved, and connection_cookie.rs:160, which departs from the EPIC's review basis (7970cdf, where check is at :159). Restore :159 and name the key's creation by symbol, CookieCipher::random and UdpTrackerCoreServices::initialize_from, which do not drift; the basis note now says why that row uses symbols. Review finding F10 on PR torrust#2470 (da2ce7's F4).
…inding F10

Adds da2ce7 review 5444749296: F10 (the torrust#2411 EPIC's moved cookie-key citations) is fixed, and the round-3 note about a pseudo-trailer is logged. The audit validator reports 10 rows and 0 failures.
@josecelano
josecelano force-pushed the 2458-inject-udp-cookie-cipher branch from c4e1265 to 7b7c277 Compare October 7, 2026 16:31
@josecelano
josecelano requested a review from da2ce7 October 7, 2026 16:32
@josecelano

Copy link
Copy Markdown
Member Author

ACK 7b7c277

@josecelano
josecelano merged commit 44a280c into torrust:develop Oct 8, 2026
23 checks passed
josecelano added a commit to josecelano/torrust-tracker that referenced this pull request Oct 8, 2026
…closed

Move the cookie-cipher spec folder to docs/issues/closed/ after PR torrust#2470 merged and torrust#2458 closed. Mark the spec done (T8 and the last two checkpoints), log the merge, and point every live reference at the new path: the ADR, docs/benchmarking.md, the run-benchmarks skill, and the PR torrust#2461 and torrust#2470 audit records. The progress-log entry that records the old path stays as history.
josecelano added a commit that referenced this pull request Oct 8, 2026
…ssues/closed

3ab1bd3 chore(issues): archive closed issue #2458 spec to docs/issues/closed (Jose Celano)

Pull request description:

  Archives the specification for issue #2458 (closed on GitHub when PR #2470 merged) from `docs/issues/open/` to `docs/issues/closed/`.

  Related to #2458

  - Verified issue #2458 is `CLOSED` on GitHub; it was the only closed issue with a spec under `docs/issues/open/`, and no draft is already linked to a GitHub issue.
  - Moved the whole folder (`ISSUE.md`, `agent-review-reports.md`, `implementation-retrospective.md`, `manual-verification-evidence.md`, `performance-evidence.md`) and updated its frontmatter: `status: done`, `spec-path`, `last-updated-utc`, and the paths in `related-artifacts` and `issue-spec`.
  - Marked T8 done, ticked the last two workflow checkpoints, and logged the merge and the archive.
  - Pointed every live reference at the new path: the cookie-cipher ADR, `docs/benchmarking.md`, the `run-benchmarks` skill, and the PR #2461 and #2470 audit records (frontmatter, as the #2448 archive did). One progress-log entry still records the old path; it is history and stays.
  - `linter markdown`, `linter lychee`, `linter cspell`, and the pre-commit and pre-push hooks passed.

ACKs for top commit:
  josecelano:
    ACK 3ab1bd3

Tree-SHA512: 9632a76dbd4ae800b4062a1623e3404af01dd5d1468cbd5e997403650d29e5fdec4fc618791715474750e97c8c3c81977e60dde753a9aa2b5b44d512f9510d5a
@da2ce7

da2ce7 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Post-merge note: this pull request requested a review from this account and was closed without one at its final head. A post-merge review will not be done: This account approved the final head of this pull request; the open review request is a stale re-request.

This branch was previously deployed

1 inactive deployment
coverage — 7b7c2773 Deployed Oct 7, 2026 by josecelano via Generate Coverage Report #2482
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.

fix(udp-core): inject the UDP connection-cookie cipher

3 participants