Skip to content

Address review on derive grant checks - #7044

Merged
jhrozek merged 1 commit into
mainfrom
exchange-derive-grants
Nov 4, 2026
Merged

jhrozek merged 1 commit into
mainfrom
exchange-derive-grants

Conversation

@jhrozek

@jhrozek jhrozek commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Follow-up to "Derive child exchange grants from refresh tokens" (#7007). It fixes the four review findings on that PR that were held back so the approved head stayed as reviewed.

  • A refresh-only config looked valid, but no derive could ever succeed. A derived child allows ID-JAGs and is capped by id_jag_max_lifetime. With only refresh_token_max_lifetime set, the client got top-level grants it could never derive from, and every derive failed with token_type_not_permitted. Validation now rejects refresh_token_max_lifetime without id_jag_max_lifetime at startup.
  • A grant with under one whole second left could get different answers. The whole-second expiry check ran after the liveness checks. So a revoked grant with under a second left got revoked, and a child got not_issuable, instead of grant_invalid as the docs promise. The check now runs right after the client check, before any other refusal. The test uses a fixed clock, so it pins the order on every run, not about half the time.
  • The zero-lifetime boundary rows were missing from TestValidateChildEntry. They were removed with the old parent_expired reason. They are back, now expecting invalid_expires_at.
  • "Parent" meant two different grants in the derive path. The presented grant is now called the source, and parent means only a grant's own parent (as in parent_revoked). This is a rename in code, tests and docs; behaviour is unchanged.
  • docs/arch/17-token-exchange-delegation.md: the check-order list gets the whole-second step, and the note about token_type_not_permitted after a config change is corrected (a configured client can no longer reach the missing-cap case).

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other (describe):

Test plan

  • Unit tests (task test)
  • E2E tests (task test-e2e)
  • Linting (task lint-fix)
  • Manual testing (describe below)

Ran go build ./pkg/authserver/... and go test -race on pkg/authserver/server/tokenexchange and pkg/authserver/server/registration against the final tree. Both pass. The full suite and lint run in CI.

Does this introduce a user-facing change?

Yes, for auth server configuration:

  • Before: a delegate client with token_exchange.exchange_refresh_tokens set to only refresh_token_max_lifetime started normally. Every derive from its grants was then refused with token_type_not_permitted.
  • After: that configuration fails at startup with token_exchange.exchange_refresh_tokens.refresh_token_max_lifetime requires id_jag_max_lifetime, because a derived child refresh token is capped by it. Setting id_jag_max_lifetime alone, or both caps, works as before.

The field exists only in the RunConfig (there is no CRD for it yet), so no migration is needed.

Also, a presented grant with under one whole second left now always gets grant_invalid. Before, it could get revoked, parent_revoked or not_issuable, depending on what else was wrong with it.

Special notes for reviewers

  • The storage.ErrExpired branch in checkPresentedGrant can no longer be reached, because the whole-second check refuses every expired grant first. It is kept on purpose as a guard in case that order changes, and its comment says so.
  • TestDeriveChildTypeNotConfiguredFallback (renamed from TestDeriveChildTypeMustBeConfigured) uses a refresh-only policy that startup now rejects. It is kept on purpose: it pins the refusal for a handler built without config validation.

Refuse a refresh-only exchange_refresh_tokens config at startup: a
derived child is capped by id_jag_max_lifetime, so without it every
derive is refused. Restore the zero-lifetime boundary rows in
TestValidateChildEntry. Check whole-second expiry for the presented
grant before any other refusal, so an under-one-second grant always
gets grant_invalid. Rename the presented grant from parent to source,
keeping parent for the grant's own parent.

Co-authored-by: Mecatl <[email protected]>
@github-actions github-actions Bot added the size/M Medium PR: 300-599 lines changed label Nov 3, 2026
@codecov

codecov Bot commented Nov 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.54%. Comparing base (f87c47a) to head (0de2da8).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7044      +/-   ##
==========================================
+ Coverage   80.53%   80.54%   +0.01%     
==========================================
  Files         853      853              
  Lines       87221    87225       +4     
==========================================
+ Hits        70243    70256      +13     
+ Misses      16973    16964       -9     
  Partials        5        5              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rdimitrov rdimitrov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The whole-second check now runs before the liveness refusals, and the ErrExpired guard is a strict subset of it, so the order is consistent. The new startup rejection only affects refresh-only configs, which could never derive anyway, and #7007 is not in a release yet (v0.61.0 predates it), so no existing users break.

@jhrozek
jhrozek merged commit 8e99604 into main Nov 4, 2026
47 checks passed
@jhrozek
jhrozek deleted the exchange-derive-grants branch November 4, 2026 13:23
@github-actions github-actions Bot mentioned this pull request Nov 4, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Medium PR: 300-599 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants