Repository navigation
fix(auth): end streams and connections when their credentials expire (#2817) - #2900
Merged
Merged
Conversation
…2817) Every token now ends what it opened at its exp plus the leeway it was accepted under, through the same Revocable end time lease tokens already used, so every waiter on revocation (control and uni streams, subscriptions, replays, cache watches, MQTT, Kafka) ends at expiry with no new timers per stream. A client certificate's notAfter caps that end time in authenticate_peer and authenticate_forwarded, and a stream opened on a connection whose certificate has already expired is refused. The QUIC client accept loop closes the connection at the certificate's notAfter (close code 2, "credential expired"), and both sides of an internal peer connection close it when the other side's certificate expires (close code 5), so the next dial presents the renewed one. Spec-Unaffected: authentication and connection lifetime; no TLA spec models credentials.
Stream ends wait on the wall clock (re-checked), like the connection closes, so a suspended host or a stepped clock cannot move them. The QUIC test checks the connection close code on a bare connection, so each certificate bound is guarded alone; a unit test covers the stream cap. Wider timing windows in the new tests. Kafka reports an expired client certificate as a refusal, not a transient failure. The auth doc notes MQTT ends at the bare exp. Spec-Unaffected: authentication and connection lifetime; no TLA spec models credentials.
Performance comparison (fast subset)✅ No statistically significant performance regressionsWelch's t-test, p < 0.05, minimum practical effect 3.0%. A worse change of 10.0% or more that is not significant is inconclusive: rerun the cell with more trials before trusting it. Baseline and candidate trials alternated on the same runner instance in this job, with the side that goes first flipping each round, to control for ambient noise. This check is advisory only and does not block merging.
|
…er closes (#2817) A chain's end is now the leaf and the intermediates on the path webpki builds to a trust anchor; the anchor and stray certificates no longer count. A leaf that does not parse refuses the credential. Peer connections close at a random time in the last 30 s before notAfter. MQTT waits on the wall clock, and Kafka closes idle and long-polling connections when the credential ends.
A client that stops reading could keep a connection open past its credential's end while the queued answers waited to be written.
el-bri-ga
enabled auto-merge (squash)
November 21, 2026 16:11
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #2817
Invariant restored: no connection or long-lived stream outlives the earliest expiry of the credentials it was authorized with (token
exp+ its acceptance leeway, client certificate chainnotAfter).Mechanism
One end time per authenticated credential, not a timer per stream.
Revocablealready had an end time that only lease tokens set; every waiter on revocation already racesRevocable::revoked(). Now:BrokerAuth::authenticatesets the end time for every token:exp + 60 s(the verifier's leeway; lease tokens keep 2 s).authenticate_peerandauthenticate_forwardedcap it at the chain's end (Revocable::ending_atkeeps the minimum), and refuse a stream opened after the certificate expired.felix_common::tls::ChainExpiry: the leaf'snotAfterand the intermediates on the path webpki rebuilds to the configured roots (verify_for_usage). The trust anchor and certificates off the path never count. With no path now (an intermediate has since expired, or an unverified forwarded chain) it counts every presented cert that is neither self-signed nor an anchor, which can only close earlier. Never later than the leaf. A leaf x509-parser cannot read refuses the credential (QUIC/peer connections close at once).[notAfter - min(30 s, left/4), notAfter].Every end, stream or connection, waits through
sleep_until_unix, which re-checks the wall clock at least once a minute, so a host suspend or a stepped clock cannot keep anything open much past its end.Entry points
serving/quic/streams/control.rs:160,:1236; auth incontrol/session.rs:77authenticate_peerend time ->revokedarm sendsrevokedand closestests/revocation.rs(existing revoke tests use the same arm)serving/quic/streams/uni.rs:73,:148Revocablequic/handlers/subscribe/feeder.rs:65,92,107;subscribe/replay.rs:364Revocable, last framerevokeda_subscription_ends_when_its_token_expiresquic/handlers/cache_watch.rs:683Revocablea_watch_ends_when_its_credential_is_revokedcovers the armserving/quic/conn.rs:303(client_chain_ends)2; unreadable leaf closes at oncea_connection_closes_when_its_client_certificate_expires(checks close code2on a bare connection, 20 s cert)felix-common/src/tls/expiry.rs(ChainExpiry::not_after)tls::expiry::tests::*(expired root in chain, expired intermediate-as-anchor, stray expired cert, no-path fallback, unreadable leaf/extra)serving/auth.rs:154(bound_by_chain)a_client_certificate_ends_what_its_token_opens_when_it_expires_first,a_client_certificate_that_does_not_parse_is_refusedserving/mqtt.rs:84->felix-mqtt/src/service/connection.rs:88sleep_until_unix) ->Disconnect(NotAuthorized)connection_ends_when_the_token_expires(real time)serving/kafka.rs:133(Principal::with_end) ->felix-kafka/src/service/connection.rs:96,149api::tests::sasl::a_connection_closes_when_its_credential_endsserving/auth.rs:237(authenticate_forwarded)serving::lib tests (client_certs)felix-replication/src/peer/server.rs:4965peer::tests::mtls::a_connection_closes_when_a_certificate_on_it_expiresfelix-replication/src/peer/pool/connection.rs:196dialer_expires = false)Revert checks: with the token end time back to lease-only,
a_subscription_ends_when_its_token_expiresfails (8 s timeout). With the connection close removed,a_connection_closes_when_its_client_certificate_expiresfails;bound_by_certificatehas its own unit test. The peer test fails with either the listener-side or the dialer-side close removed alone. WithChainExpiry::not_afterback to the minimum over every presented cert, 5 of the 9tls::expirytests fail (expired root, stray cert, intermediate-as-anchor, fallback, on-path intermediate).Design calls
revokedfor expiry rather than add a new error code; it is what lease-token expiry already sends, and a new code needs negotiation. Docs say it covers expiry.2(credential expired) for the client connection, and5on the internal port (0-4 were taken).exp + 60 s, the same leeway the verifier accepts it under, so the broker never ends a stream on a token it would still accept. Certificates get no leeway (rustls checksnotAfterwithout one).Auth; refresh means a new connection. Docs say so.spread_beforedraws fromfelix_common::jitter(seeded under the simulator), up to 30 s and at most a quarter of the time left, so a connection made on a nearly expired cert is not closed instantly. Never afternotAfter. Docs say to rotate node certs beforenotAfter; the Raft peer transport's reload is Raft peer TLS: re-read the certificate and key without a restart #2815.Principal::with_endhands the connectionRevocable::revoked(), which also fires on revocation, so a revoked idle Kafka connection closes too.Spec-Unaffected: authentication and connection lifetime; no TLA spec models credentials.