Repository navigation
fix(identitybroker): count a session's hard expiry one clock skew early - #2658
Merged
Merged
Conversation
The broker closed a session only when its refresh token's expiry had passed by the broker's clock. A broker clock behind AS-1's then presents a grant AS-1 has already expired and gets grant_invalid, an internal error. Count the hard expiry as reached one clock skew early, as the design's step (6) check 2 requires, so skew fails closed and the user reopens on the next request. The echo check stays exact. Part of #2607. Co-authored-by: Mecatl <[email protected]>
This was referenced Nov 3, 2026
jhrozek
approved these changes
Nov 3, 2026
Merged
2 tasks
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Part of #2607.
Summary
The broker now treats a session's hard expiry as reached one clock skew before the held refresh token's expiry. This is design step (6), check 2, settled in the review of #2657.
Before this change, a session closed only once its refresh token's expiry had passed by the broker's own clock. A broker clock running behind AS-1's could therefore present a grant AS-1 had already expired. AS-1 answers that with
grant_invalid, which the broker maps to an internal error. Counting the expiry one skew early means skew always fails closed: the session ends a little early, and the user's next request reopens it.sessionTable.pastHardExpiry(internal/identitybroker/sessions.go) holds the rule. BothexpireLocked, which every lookup calls, andHoldsRefreshTokenuse it.credentialClockSkew(30 seconds); its comment now covers this use. Keys and gateway entries for the identity broker #2538 replaces it with one clock-skew setting.expires_atare both absolute times from the broker's own request, so no allowance is needed.Testing
TestSessionHardExpiryCountsOneSkewEarly: one second before the skew margin, the session is open and holds its refresh token. At the margin, which is still before the token's own expiry, lookups find it closed and the token is dropped. With the old comparison the test fails.go testpasses for./internal/identitybroker/...,./internal/testutil/identityharness/...and./cmd/mecak8s/, and for./internal/appand./internal/adapter/serverfiltered to identity-broker tests. The harness test (TestIdentityBrokerAgainstOfflineHarness) covers the end-to-end hard-expiry reopen.golangci-lint run ./internal/identitybroker/...: 0 issues.go test -raceon the identity packages passes.TestLoadACPSessionOwnsExactBindingUntilOverrideLifecycleEndsininternal/adapter/serverfails in this macOS checkout, and fails the same way without this change.go run ./cmd/mecademoshows a tool call, a permission ask and approval, and the result.CI runs the full suite.
API compatibility
Assessed per wire API compatibility. No contract change: the reasons and statuses are unchanged. A session that holds a refresh token now reports
session_closedup to 30 seconds earlier than before. Clients already reopen onsession_closed, so no client change is needed.