Skip to content

fix(identitybroker): count a session's hard expiry one clock skew early - #2658

Merged
ChrisJBurns merged 1 commit into
mainfrom
fix/identitybroker-hard-expiry-skew
Nov 3, 2026
Merged

ChrisJBurns merged 1 commit into
mainfrom
fix/identitybroker-hard-expiry-skew

Conversation

@ChrisJBurns

Copy link
Copy Markdown
Contributor

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. Both expireLocked, which every lookup calls, and HoldsRefreshToken use it.
  • The skew is the existing interim 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.
  • The echo check at session open stays exact. The requested and echoed expires_at are both absolute times from the broker's own request, so no allowance is needed.

Testing

  • New 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 test passes for ./internal/identitybroker/..., ./internal/testutil/identityharness/... and ./cmd/mecak8s/, and for ./internal/app and ./internal/adapter/server filtered 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 -race on the identity packages passes. TestLoadACPSessionOwnsExactBindingUntilOverrideLifecycleEnds in internal/adapter/server fails in this macOS checkout, and fails the same way without this change.
  • go run ./cmd/mecademo shows 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_closed up to 30 seconds earlier than before. Clients already reopen on session_closed, so no client change is needed.

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]>
@ChrisJBurns
ChrisJBurns merged commit 40a8e5e into main Nov 3, 2026
42 checks passed
@ChrisJBurns
ChrisJBurns deleted the fix/identitybroker-hard-expiry-skew branch November 3, 2026 17:57
@toolhive-release-app toolhive-release-app Bot mentioned this pull request Nov 18, 2026
2 tasks
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.

2 participants