Skip to content

fix(auth): OIDC login-loop hardening — interactive fallback on login_required, preserve pending logins - #31181

Merged
mohityadav766 merged 5 commits into
mainfrom
okta-offline-access-issues
Aug 11, 2026
Merged

mohityadav766 merged 5 commits into
mainfrom
okta-offline-access-issues

Conversation

@mohityadav766

@mohityadav766 mohityadav766 commented Aug 7, 2026 •

Copy link
Copy Markdown
Member

Fixes #30304 (Okta confidential client login loop — this PR is the server-side half).

Root cause (reproduced end-to-end)

On a confidential OIDC deployment, the login loop is server-side session loss amplified by error handling:

  1. /api/v1/auth/login writes the session cookie immediately, but the session only becomes usable at /callback. A concurrent /refresh (another tab's expiry timer, shared cookie) landing in that window broke the pending login — the user completes Okta/WebAuthn and their own callback then fails.
  2. login_required & friends (the IdP's spec-defined "silent auth not possible" replies, e.g. prompt=none with no IdP session) returned HTTP 500 with no recovery path.
  3. A stale/consumed session cookie at /callback also returned 500.

Reproduced deterministically against server:1.13.1 + the repo's mock OIDC provider (confidential client, offline_access): the exact sequence login → concurrent refresh → complete Okta → callback failed into a loop. The same defects exist on main in the new SessionService architecture (verified by code path).

Changes

  • handleCallback: login_required/interaction_required/consent_required/account_selection_required → 302 to /signin (interactive) instead of 500.
  • handleCallback: missing pending session → 302 to /signin (stale cookie already cleared) instead of 500.
  • SessionService.acquireRefreshLease: PENDING (in-flight) login → return empty (401) without clearing the session cookie — a concurrent refresh no longer breaks the login round-trip.

Testing

  • New unit test acquireRefreshLease_pendingLogin_returnsEmptyWithoutClearingCookieOrSession (fails without the fix).
  • New regression tests: login_required at /callback redirects to /signin; non-silent errors keep the 500; no-pending-session callback asserts the redirect.
  • SessionServiceTest: 32/32 green; AuthenticationCodeFlowHandlerTest: 33/33 green.
  • Behavior matrix verified on the 1.13 reproduction rig (mock IdP; same sequences): loop sequence now ends logged-in; login_required → interactive signin; healthy login+refresh unchanged.

Sibling PRs: 2.0 (cherry-pick of this commit) and 1.13 (equivalent hotfix for the in-memory HttpSession architecture).

🤖 Generated with Claude Code

… pending logins (#30304)

- /callback with login_required/interaction_required/consent_required/
  account_selection_required: redirect to interactive /signin instead of 500.
  These are the IdP's spec-defined 'silent auth not possible' replies
  (e.g. prompt=none with no IdP session); a 500 loops the frontend.
- /callback with no pending session (stale/consumed cookie): redirect to
  /signin instead of 500 — the stale cookie is already cleared.
- acquireRefreshLease on a PENDING (in-flight) login: return empty (401)
  WITHOUT clearing the session cookie — a concurrent tab's refresh timer
  must not break the login round-trip at the IdP.

Root cause reproduced end-to-end on 1.13.1 + mock OIDC provider (issue #30304,
Okta confidential + offline_access): login -> concurrent refresh -> user
completes Okta -> callback fails -> loop. Test added for the pending-lease race.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@mohityadav766
mohityadav766 requested a review from a team as a code owner August 7, 2026 11:57
Copilot AI lite review requested due to automatic review settings August 7, 2026 11:57
@github-actions

github-actions Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens the OIDC authentication code flow to prevent server-side login loops in confidential-client deployments (e.g., Okta with offline_access) by (1) providing an interactive fallback for spec-defined “silent auth not possible” errors and stale pending sessions, and (2) ensuring concurrent refresh attempts don’t invalidate an in-flight login.

Changes:

  • Add interactive fallback redirect (/signin) from /callback when the IdP returns login_required / interaction_required / related silent-auth errors.
  • Redirect to /signin (instead of 500) when the callback cookie references no live pending session.
  • Prevent /refresh from clearing cookies or mutating sessions when the session is PENDING (login in-flight), plus add a regression unit test.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
openmetadata-service/src/main/java/org/openmetadata/service/security/session/SessionService.java Avoids clearing session cookie / mutating state when refresh races with an unexpired PENDING login session.
openmetadata-service/src/main/java/org/openmetadata/service/security/AuthenticationCodeFlowHandler.java Redirects to interactive signin for missing pending session and for spec-defined silent-auth error codes instead of returning 500.
openmetadata-service/src/test/java/org/openmetadata/service/security/session/SessionServiceTest.java Adds unit coverage ensuring PENDING sessions don’t get their cookie cleared or session mutated during refresh lease acquisition.

Comment on lines 480 to 491
if (response instanceof AuthenticationErrorResponse authenticationErrorResponse) {
LOG.error(
"Bad authentication response, error={}", authenticationErrorResponse.getErrorObject());
// login_required & friends are the IdP's spec-defined "silent auth not possible"
// replies (e.g. prompt=none with no IdP session). Fall back to interactive signin
// instead of a 500 the frontend cannot recover from.
if (SILENT_AUTH_ERRORS.contains(authenticationErrorResponse.getErrorObject().getCode())) {
resp.sendRedirect(serverUrl + "/signin");
return;
}
throw new TechnicalException("Bad authentication response");
}
@github-actions

github-actions Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

✅ Playwright Results — workflow succeeded

Validated commit 9771e9a4535215519acebe86d3bf739abeb22d4d in Playwright run 31396542459, attempt 1.

✅ 796 passed · ❌ 0 failed · 🟡 0 flaky · ⏭️ 0 skipped · 🧰 0 lifecycle flaky

Performance

Blocking targets: ✅ met · Optimization targets: 🟡 in progress

Shard-job maxima below are not the full workflow wall time; the linked run includes build, fixture, planning, and reporting.

🕒 Full workflow signal wall (to summary) 1h 1m 38s

⏱️ Max setup 3m 2s · max shard execution 20m 56s · max shard-job elapsed before upload 24m 29s · reporting 6s

🌐 215.24 requests/attempt · 2.67 app boots/UI scenario · 15.13% common-shard skew

Optimization targets still in progress:

  • Common shard skew was 15.13% (convergence target: at most 15%).
  • Browser traffic was 215.24 requests per attempt (convergence target: fewer than 200).
  • Application boot ratio was 2.67 per UI scenario (2497 boots / 936 scenarios; convergence target: at most 1).
Shard Passed Failed Flaky Skipped Lifecycle failed Lifecycle flaky
✅ Shard chromium-01 138 0 0 0 0 0
✅ Shard chromium-02 167 0 0 0 0 0
✅ Shard chromium-03 148 0 0 0 0 0
✅ Shard chromium-04 175 0 0 0 0 0
✅ Shard data-asset-rules-01 61 0 0 0 0 0
✅ Shard domain-isolation-01 14 0 0 0 0 0
✅ Shard global-state-01 34 0 0 0 0 0
✅ Shard import-export-01 17 0 0 0 0 0
✅ Shard ingestion-01 1 0 0 0 0 0
✅ Shard reindex-01 2 0 0 0 0 0
✅ Shard search-01 10 0 0 0 0 0
✅ Shard search-rbac-01 29 0 0 0 0 0

📦 Download artifacts

How to debug locally
# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip    # view trace

Copilot AI review requested due to automatic review settings August 7, 2026 14:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Suppressed comments (2)

openmetadata-service/src/main/java/org/openmetadata/service/security/AuthenticationCodeFlowHandler.java:490

  • login_required/silent-auth errors are being logged at ERROR before you short-circuit to an interactive redirect. Since these errors are expected in the silent-auth flow, this will generate noisy/false-positive ERROR logs in normal operation. Consider checking the error code first and logging at DEBUG/INFO for the silent-auth fallback, reserving ERROR for truly unexpected authentication errors.
      if (response instanceof AuthenticationErrorResponse authenticationErrorResponse) {
        LOG.error(
            "Bad authentication response, error={}", authenticationErrorResponse.getErrorObject());
        // login_required & friends are the IdP's spec-defined "silent auth not possible"
        // replies (e.g. prompt=none with no IdP session). Fall back to interactive signin
        // instead of a 500 the frontend cannot recover from.
        if (SILENT_AUTH_ERRORS.contains(authenticationErrorResponse.getErrorObject().getCode())) {
          resp.sendRedirect(serverUrl + "/signin");
          return;
        }
        throw new TechnicalException("Bad authentication response");

openmetadata-service/src/main/java/org/openmetadata/service/security/AuthenticationCodeFlowHandler.java:468

  • This behavior change (no pending session at callback now redirects to /signin instead of returning a 500) likely breaks the existing unit test AuthenticationCodeFlowHandlerTest#handleCallback_noPendingSession_writesErrorResponse, which currently asserts a 500 + body containing "No pending session found for callback". The PR should update that test (and any similar ones) to assert the redirect behavior.
      Optional<UserSession> maybePendingSession = sessionService.getPendingSession(req, resp);
      if (maybePendingSession.isEmpty()) {
        // The cookie points at no live pending session (invalidated, restarted, or already
        // consumed). A 500 here strands the browser in a login loop; getPendingSession has
        // already cleared the stale cookie, so route the user to interactive signin instead.
        LOG.warn("No pending session found for callback, redirecting to signin");
        resp.sendRedirect(serverUrl + "/signin");
        return;

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings August 10, 2026 14:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@gitar-bot

gitar-bot Bot commented Aug 11, 2026

Copy link
Copy Markdown
Code Review ✅ Approved

Hardens OIDC login flow to prevent server-side session loss during concurrent refreshes and redirects silent-auth errors to interactive sign-in. No issues found.

Options

Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

User login fails after adding the configuration offline_access in scope for SSO OKTA

4 participants