Repository navigation
fix: host-aware domain routes, bare-word in:, bounded shutdown, JWT revocation, and boot-time service bindings - #12
Conversation
A route declared under Router::domain answered every host: dispatch kept only
the first route per method+path, so a domain route shadowed the catch-all for
all requests and the catch-all was unreachable.
Routes sharing a method+path are now grouped. A group with domain routes is
served by a host dispatcher that picks the first route whose domain matches
the Host header (or the URI authority), case-insensitively and without the
port, where a {name} label matches one DNS label, and falls back to the route
without a domain. With no match and no catch-all the answer is 404.
The existing domain test asserted the old behaviour (a request with no Host
reaching the domain route); it now checks both hosts.
Each list item was parsed as JSON and items that did not parse were dropped, so in:admin,editor produced an empty allow-list and rejected every value; only numbers or quoted strings worked. Items are now read the way contains: reads its needle: JSON when it parses (1 is a number, "1" a string), otherwise the raw text. Matching stays strict on type and value.
graceful(timeout) ignored its timeout: it resolved on SIGTERM/SIGINT and the server then drained with no limit, so one stuck request or connection could hold shutdown open indefinitely. After the signal, graceful now starts a deadline that exits the process with status 1 if it is still running once the timeout elapses. Callers keep the same API: Application::shutdown (30 s) is still the graceful-shutdown signal, so the runnable app and generated apps get the bound without changes. Checked against the runnable app: with an unfinished request held open, the process exits 31 s after SIGTERM; with no requests in flight it exits at once.
JwtGuard::logout returned Ok(()) without doing anything, so a logged-out token stayed valid until it expired, and a refresh token could be replayed any number of times. Each login now issues its access/refresh pair with a shared session id (sid claim, omitted when empty so older tokens still decode). logout revokes the pair by recording the sid in a cache Store until the refresh token would expire; parse and refresh reject a revoked pair. refresh revokes the old pair with an atomic put_if_absent before issuing the new one, so a refresh token works once even under concurrent use. Tokens issued before sid existed are revoked individually by a hash of the token. An unreadable store fails closed with StoreUnavailable. The default store is per-process memory; with_revocation_store takes a shared store (Redis) so every process honours a logout. The claims contract lists the new field.
No provider put the database, the cache, or the queue in the container, so each feature that needed one built its own from config. rustasea::services adds three providers that read the boot-time config: DatabaseServiceProvider binds an orm::ConnectionResolver (connects lazily, on first resolve), CacheServiceProvider binds a cache::CacheManager, and QueueServiceProvider registers the queue connections that need no database (sync, and redis with its feature) and binds the parsed QueueConfig. A missing table falls back to the defaults; a table that does not parse is left unbound and reported, without stopping boot. A database queue connection needs a live pool, which a synchronous provider cannot open, so connect_database_queues registers those after boot through the bound resolver.
The runnable app registers the database, cache, and queue providers ahead of its own, and connects the database queue connections right after boot. Started against the shipped config, it logs that the database connections were registered and serves as before.
docs/milestones.md: M0 gains the database, cache, and queue bindings and the bounded shutdown drain; M1 the host-aware domain routing; M3 JWT revocation and bare-word in: lists. The matching open items are removed, and the next M0 action becomes registering the service providers in the scaffold templates. Citations into the router dispatcher, the umbrella crate, and the app's main are repointed: this branch moved them, and the into_axum_router and resolve citations were already off on master. .agents module docs: F-M0-CFG-03, F-M0-BOOT-04, F-M1-RTE-02, F-M3-VAL-02, and F-M3-AUTH-01 are Done (60 done, 48 partial, 2 not started). The JWT claims contract lists the new sid claim (in the auth commit). CHANGELOG entries for each change.
Review: fix/foundation-and-correctness (PR #12)Reviewed head Must fix before merge
Should fix
Verified good
Nits
DecisionNEEDS_FIX on the expired-token logout path and the two missing auth tests; the rest are follow-ups. The host-routing, validation, boot-wiring, and shutdown changes are otherwise solid. |
Review of rustasea#12: logout returned Ok on an expired access token without reading its sid, so the pair's refresh token, valid for up to a day more, survived a "successful" logout. logout now verifies the signature, issuer, and audience without the exp check, then revokes the pair; a malformed or forged token is still rejected. A pair's revocation is now kept for one full refresh TTL from the moment of revoking. It was derived from the presented token's iat, which could end a second before the refresh half expires because the two halves are stamped by separate clock reads. Tests added for the two properties that were only asserted sequentially: two concurrent refreshes with one token succeed exactly once, and an unreadable revocation store fails closed with StoreUnavailable on parse, refresh, and logout. The revocation tests move to jwt/revoke/tests.rs.
|
Thanks for the review. Every item is addressed in new commits on top of
Checked on rustc 1.100.0: |
Review of rustasea#12: connect_database_queues resolved the default database connection and handed that one pool to every database queue connection, so a queue connection naming another database (connection = "jobs") silently used the default one. Each database queue connection now resolves the database connection it names; no name, or "default", selects the default connection, as DatabaseSessionStore does. The drivers are registered directly, so the queue config is no longer registered a second time after boot (which also re-leaked the default connection name). The services test now uses two database connections and checks that both were opened. Its sync-driver assertion was tautological (the registry seeds sync) and is replaced by a check of the recorded default connection.
Review of rustasea#12: the matching domain route was picked in registration order, so a {tenant}.example.com route registered before admin.example.com shadowed the exact host. Exact domains are now tried before {placeholder} domains; registration order decides within each group. Also from the review: - A trailing dot (api.example.com.) names the same host and is stripped. - A domain registered twice in a different case (API.example.com and api.example.com) keeps the first route, as an exact duplicate already did. - Tests for hosts that are empty, have empty labels, merely share a prefix, are punycode, or are not visible ASCII: all fall back to the catch-all.
Review of rustasea#12: the deadline graceful() spawns after the signal could not be cancelled, so a process that kept running after a successful drain would still be exited with status 1 when the timeout elapsed. The runnable app was safe only because main returns right after serving. graceful() now records the deadline, and drain_complete() cancels it; a second signal replaces the first deadline instead of stacking another.
|
@vheins every item from your review is addressed in the new commits (mapping in the comment above), and CI is green on |
- Logout decodes with exp disabled so an expired access token still revokes its live refresh half. - Revocation retention gains a 60s margin so it outlives both halves. - Add concurrent-refresh (atomic single-use) and store-outage (fail closed) tests.
- Specificity ranking in host selection: exact domains outrank placeholder patterns - Trailing-dot normalization so `api.example.com.` matches `api.example.com` - Case-folded domain registration so patterns differing only in case dedup - Tests for wildcard/exact ordering, trailing dot, and malformed Host values
- Resolve each database-backed queue connection by its declared name - Fall back to the default connection when the name is unset - Replace the tautological boot assertion with a provider-only registration
4c10684 to
c58901f
Compare
#12 merged with different review follow-ups than the ones its docs commit described, and that docs commit was not part of the merge, so citations into the dispatcher, host dispatch, the JWT guard, the shutdown module, and services.rs pointed at the wrong lines (two in README.md as well). They are repointed, and the descriptions now match the merged code: exact domains before {name} domains, logout revoking from an expired access token, and the GracefulShutdown guard. M0 records DATABASE_URL support in the bound resolver, the app's pools going through it, and generated apps registering the providers, and drops those items from Partial, Missing, and Next actions. M3 notes why the scaffold's database user provider item is still open: generated apps have no login flow to wire it into yet. Changelog entries for both.
Summary
Fixes four places where an existing feature behaved wrongly, and adds the database, cache, and queue bindings that M0 listed as missing. Ordered bottom-up so later milestones can build on them: the M4 scheduler needs the queue binding to dispatch, and the scaffold work in M3 needs the database one.
Seven commits, one per scope. Each commit message has the detail; this description covers what the commits cannot say on their own.
Changes
fix(router): match domain routes against the request hostRouter::domainanswered every host and made the catch-all on the same method+path unreachable. Requests are now routed byHost.fix(validation): accept bare words in in: and in_array: listsin:admin,editorrejected every value.fix(foundation): bound the shutdown drain by its timeoutgraceful(timeout)ignored its timeout, so a stuck request could hold shutdown open forever.fix(auth): revoke JWT pairs on logout and make refresh tokens single-useJwtGuard::logoutdid nothing, and a refresh token could be replayed.feat(rustasea): bind database, cache, and queue services at bootrustasea::servicesproviders bind aConnectionResolver, aCacheManager, and the queue connections.feat(app): register the framework service providers at bootdocs: record the foundation and correctness fixesdocs/milestones.md,docs/laravel-parity.md, the module task rows, and the changelog.Behaviour changes
404if there is none. Matching ignores case and the port; a{name}label matches one DNS label, but its value is not exposed as a route parameter. The existing test intests/dispatch.rsasserted the old behaviour and was updated.Application::shutdown), the process exits with status 1. Callers keep the same API, so generated apps get this too.sidclaim shared by an access/refresh pair.logoutrevokes the pair;refreshrevokes the old pair atomically before issuing the new one, so a client that retries a refresh with the same token now getsInvalidToken. Revocations are kept in a cacheStore, per-process memory by default;JwtGuard::with_revocation_storetakes a shared store for multi-process deployments. An unreadable store fails closed withStoreUnavailable. Tokens issued beforesidexisted still verify and are revoked individually.in:/in_array:: each item is read as JSON when it parses and as text otherwise. Bare numbers stay numbers, so matching is still strict on type.QueueServiceProviderrecords the configured default queue connection; with an empty[queue]table it registers nothing, as before.Testing
Run on rustc 1.100.0, the toolchain CI uses:
cargo xtask cipasses.cargo test --workspace --no-fail-fastpasses (190 suites, 1977 tests), as doescargo test -p rustasea-storage --features aws,sftp.Cargo.lockis unchanged andcargo metadata --lockedpasses.crates/rustasea-router/tests/host_dispatch.rsand unit tests inhost.rs), bare-wordin:, the shutdown deadline, five JWT revocation cases, and three service-provider cases (crates/rustasea/tests/services.rs).GET /with 200.Not covered
@vheins, could you review this?