Repository navigation
test(identitybroker): test session open against the real AS-1 - #2743
Conversation
ChrisJBurns
left a comment
There was a problem hiding this comment.
-
medium · correctness — Unconsumed queued faults are silently ignored and can leak into later subtests (
internal/identitybroker/adapter/as1server/as1servertest/faults.go:1280)FailNextExchange, DropNextExchange, LoseNextExchangeResponse and ReplaceNextExchangeEcho push onto a queue that nothing checks at the end of a test. If the code under test stops sending the exchange (for example, the broker refuses earlier), the fault is never applied and the test may still pass for the wrong reason. Several tests share one AS1 across subtests, for example TestFailNextExchangeAnswersWithoutAS1 and TestSignInSelectsUserScopeAndClient. In those, a leftover fault from a failed subtest is applied to the next subtest's exchange and causes misleading cascading failures.
Recommendation: In Start, register a t.Cleanup that fails the test (t.Errorf) when
len(f.queue) != 0, naming the pending fault kinds. Optionally add aPending() intaccessor so shared-fixture subtests can check that the queue is empty. -
low · security — SignIn does not check that the selected user actually signed in, and the one-shot selector is a shared FIFO not bound to a request (
internal/identitybroker/adapter/as1server/as1servertest/as1servertest.go:745)as1servertest.SignInqueuesIdP.SignInNextAs(req.User)and then returns the access token without checking the token'ssub_id.IdP.signInUser(internal/testutil/identityharness/idp.go) uses the first queued name for whichever authorization reaches the IdP next. A selection that is never used stays queued. That happens when authorization fails before reaching the IdP, or when a subtest on a shared fixture fails. Two concurrent sign-ins on one harness can also swap users. In each case a later sign-in silently gets the wrong identity. The ownership tests (owner mismatch, `ReasonSessionOwneRecommendation: In
SignIn, parse the returned access token'ssub_id.sub(assignedInUseralready does in as1servertest_test.go) andt.Fatalfif it differs fromreq.Userwhen one was given. Also document thatSignInNextAsis unsafe for concurrent sign-ins on one IdP, or clear the queue when authorization fails. -
low · security — Client-assertion expiry no longer checked at the skew boundary (
internal/identitybroker/adapter/authserverclient/client_test.go:1827)The "expired" case used to send an assertion one second past exp plus the allowed clock skew. It now sends one dated 10 minutes in the past (exp is 9 minutes old), and "replay inside the skew" is gone. An AS-1 that accepted assertions expired by up to several minutes would still pass these tests. The issue accepts dropping the in-skew replay case, but the expired case could have kept a tighter boundary without needing a server clock.
Recommendation: Date the expired assertion just past the real AS-1's documented leeway, e.g.
time.Now().Add(-MaxClientAssertionLifetime - <AS-1 leeway> - few seconds), so the test still catches a too-lenient expiry check. If ToolHive's leeway is unknown, add a comment saying the boundary is deliberately not checked.
jhrozek
left a comment
There was a problem hiding this comment.
One thing for the rebase onto #2733: main's TestSessionHardExpiryClosesTheSession has a VerifyCredentialForOwner row in the old two-field shape (internal/identitybroker/sessionopen_test.go:514 on main). This PR changes the rows to {name, converts, lookup}, so that row will conflict. Please carry it over with converts: false. If it is dropped while fixing the conflict, nothing fails, and #2733's path silently loses its expiry test.
Move the identity broker's session-open tests from the offline harness's AS-1 to ToolHive's AS-1 in process, behind a fault-injecting transport. The harness keeps only its conversion, as the grant fixture for ID-JAG tests, and revocation, each naming the ToolHive issue that retires it. Closes #2677 Co-authored-by: Mecatl <[email protected]>
- Record a request whose AS-1 response body fails to read. - Close the fixture listener when setup fails before the server starts. - Name the dropped-request case for what it injects, and assert the remembered-token refusal never reaches AS-1. - Say that the first-call hard-expiry case uses a made-up echo. - Do not print the error when it discloses an access token. Co-authored-by: Mecatl <[email protected]>
- Fail a test that leaves injected faults queued. - Check that a sign-in gets the user it selected, and clear an unused selection when authorization fails. - Test an expired client assertion just past its expiry: AS-1 allows no leeway. - Split the test-only IdentityBrokerAS1 clock into the broker clock and the client-assertion clock, so the real-AS-1 test signs on wall time. - Bound the shared AS-1 client to ten seconds per request. - Keep #2733's VerifyCredentialForOwner row in the hard-expiry table. Co-authored-by: Mecatl <[email protected]>
d9f088b to
688aa0f
Compare
Closes #2677
Summary
The identity broker's session-open tests now run against the real AS-1 (ToolHive's embedded authorization server, in process) instead of the offline harness's AS-1, so refusal reasons and behaviour come from the server production uses.
internal/identitybroker/adapter/as1server/as1servertest: starts a real AS-1 with the harness IdP upstream and a broker delegate client, signs users in, signs expired tokens with a test-owned key, and aFaultTransportin front of AS-1 that injects 429/5xx, dropped requests, lost responses, altered or missing echoed grants, and any OAuth error/reason body, and records requests and client assertions.internal/identitybroker/sessionopen_test.go,authserverclientandinternal/appsession-open tests move to it. Broker clock is wall time plus a test offset; assertion clock is wall time. Hard expiry: advance the offset, observe the close without reaching AS-1, reset, reopen.TestIdentityBrokerAgainstRealAS1(mecak8s): session close and hard-expiry reopen through real startup wiring against a real AS-1.as1server's in-package tests (TestSessionOpenWithATokenForAnotherAudience), so no audience option is exported.IdP.SignInNextAs,RegisterAS1Upstream,ResignAccessToken; its AS-1 fault injection, emulated subject-token refusal tests, and session-open introspection (ExchangeRefusals,ReceivedClientAssertions,ExpireGrant) are deleted.GrantandGrantsIssuedstay for the tests still on the harness.internal/app: the test-onlyIdentityBrokerAS1.Nowseam is split intoNow(broker clock) andAssertionNow(client assertions), so the real-AS-1 test keeps assertions on wall time. Production leaves both nil.VerifyCredentialForOwnerrow is kept inTestSessionHardExpiryClosesTheSession..golangci.yml: a narrow depguard rule foras1servertest, and a deny so productioninternal/appcode cannot import it.Still on the harness's AS-1, and what retires it
TestIdentityBrokerAgainstOfflineHarness(cmd/mecak8s)TestRevocationAuthenticates,TestFormMustNotCarryClientCredentials(authserverclient)Dropped: assertion replay inside the clock skew (needs an AS-1 clock no ToolHive issue tracks); plain replay moved to the real AS-1.
Real AS-1 behaviour that differs from the old harness
client_idwith 400invalid_request, not 401invalid_client.sub_id, so the broker refuses it at check 1 before AS-1 is called; thesubject_token_audiencemapping is proven with a re-signed token.Test plan
task lint: root and engine modules 0 issues (the existing gosec G703 inenvironment/microvm/launch_ownership_darwin.gois unrelated).go test -raceon identityharness,internal/identitybroker/...,cmd/mecak8s,internal/adapter/clientauth, and theinternal/appidentity broker tests.go test -race ./...: remaining failures matchorigin/mainin this environment (shell/git setup), none in touched packages.go run ./cmd/mecademo: tool call, permission ask/approval, result.API compatibility
None: tests, test support and lint configuration only; no remote-observable change.