Skip to content

fix(sso): return clear errors and keep login working on misconfiguration - #37741

Merged
mohityadav766 merged 10 commits into
mainfrom
fix/21rt-sso-defects
Nov 16, 2026
Merged

mohityadav766 merged 10 commits into
mainfrom
fix/21rt-sso-defects

Conversation

@mohityadav766

@mohityadav766 mohityadav766 commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Describe your changes:

No OSS issue tracks these defects yet: they come from the SSO row of 2.1.0 release testing (codes below are that page's), found by the Sso*IT mock identity-provider suite. Refs #35799.

One commit per area:

  • OIDC sign-in errors (OC-07, OC-14, OC-17, ID-13): a provider that refuses the sign-in, a code exchange that fails or never answers (a wrong client secret included) and a user the deployment may not provision now return the browser to the sign-in page with a fixed reason code instead of a raw 500. The sign-in page shows a translated message and does not auto-redirect while it shows one. MCP sign-ins keep their error status.
  • Token signing (OP-13): changing tokenValidationAlgorithm no longer breaks bot, personal access and session tokens. The server signs its own tokens with RS256; the setting applies to the provider's tokens only.
  • Saving SSO settings (OC-15, SA-11, CF-02, CF-03, LD-12): a configuration the server cannot apply is put back and refused with 400 and the reason, instead of staying stored. A PUT refuses a client authentication method the server cannot perform and SAML signing without the SP keys. LDAPS without a trust store type fails with a readable reason. A PATCH can switch provider, and one that changes nothing is refused instead of answering 204.
  • SAML sign-in: two first sign-ins of one new user share one account instead of one getting a 500 (the race the page planned for the SAML phase). A post that is no SAML response gets a 400 (SA-17). SA-03 was already fixed by Fixes #37056: Sign the SAML configuration check and show the IdP's error reason #37436; this adds tests for it.

Out of scope:

  • SS-06 (a pod that has not reloaded yet ends a session the new provider issued): needs a design for how a stale pod answers, and the multi-node harness cannot switch providers yet.
  • The eight pending decisions (OC-16, OC-26, OP-05, RN-05, LD-08, RS-11, SC-13, SC-14). Unreachable discovery at save time (OC-16) is left as it is.

Needs a 2.1 backport after review.

Type of change:

  • Bug fix

High-level design:

The rules are recorded in docs/decisions/:

  • 2026-11-12-a-failed-sso-sign-in-returns-to-the-sign-in-page
  • 2026-11-12-openmetadata-signs-its-own-tokens-with-rs256
  • 2026-11-12-a-security-configuration-save-applies-in-full-or-is-refused

Tests:

Use cases covered

The codes above, each as an integration test against the in-JVM mock identity providers.

Unit tests

  • AuthenticationCodeFlowHandlerTest, JwtFilterTest, JWTTokenGeneratorTest, SamlAuthServletHandlerTest, ConcurrentFirstOidcLoginTest, new SystemRepositorySecurityConfigPatchTest and LdapUtilTest; UI: SignInPage.test.tsx.
  • Coverage not measured.

Backend integration tests

  • SsoOidcConfidentialLoginIT, SsoOidcPublicBearerIT, SsoSamlLoginIT, new SsoSecurityConfigApplyIT.
  • RED on the base commit: every new test failed for the reason release testing recorded, except SA-03, which already passed.
  • GREEN locally (MySQL + Elasticsearch): all seven Sso*IT classes, SystemResourceIT, McpOAuthIT, ConfigResourceIT and OpsRegenerateBotTokensIT (185 tests), then SsoSamlLoginIT and SsoSecurityConfigApplyIT again after the last change.

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Not run locally. The sign-in page change is covered by Jest.

Manual testing performed

None against a real identity provider; the release-testing plan covers that.

UI screen recording:

Not applicable — a bug fix that adds an error message to the sign-in page, covered by Jest.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation>
  • My PR is linked to a GitHub issue via Fixes #<issue-number> above.
  • I have commented on my code, particularly in hard-to-understand areas.
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.
  • Decision check: the rules this PR sets are recorded under docs/decisions/.
  • I have added a test that covers the exact scenario we are fixing.

🤖 Generated with Claude Code

Review follow-up (2026-11-14)

Preserve valid RS256, RS384 and RS512 bot tokens in stale-only regeneration using the same own-token verifier as request authentication. Unsigned and HMAC tokens are rejected. Added signed-token regressions. Focused unit run: 446 tests passed; sign-in UI: 18 tests passed.

Fresh MySQL + Elasticsearch integration run: 46 tests passed across SsoSecurityConfigApplyIT (5), SsoOidcPublicBearerIT (14), SsoSamlLoginIT (8), and SsoOidcConfidentialLoginIT (19). This is focused validation, not the full merge-gating suite.

RetriggerView in GreptileConfidence Score: 5/5

The follow-up appears safe to merge; all three previous findings are addressed.

Summary

This PR gives failed SSO sign-ins clear messages, keeps server-issued tokens independent of provider signing settings, and refuses security settings the server cannot apply.

  • Failed OIDC sign-ins return to a sign-in page with a clear reason.
  • Security-setting saves apply fully or return a clear refusal.
  • OpenMetadata-issued tokens use RS256 regardless of the provider's algorithm.
  • MCP OAuth discovery stays inside the configured base path.
  • SAML sign-ins share new accounts and reject unreadable responses clearly.

Review checks were based on source and test inspection; no tests were run during this review.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Admin saves security settings] --> B[Check settings]
  B --> C[Write only if stored rows still match]
  C -->|Another save won| D[Keep newer save and return 412]
  C --> E[Reload authentication]
  E -->|Success| F[Return success]
  E -->|Failure| G[Restore previous rows only if they still match this save]
  G -->|Restored| H[Return 400 with reason]
  G -->|Another save won| D
  G -->|Restore failed| I[Return 500 with warning]
Loading

Reviews (2) · Last reviewed commit: "docs(adr): amend MCP discovery to advert..." · Reviewed by Greptile

…eason

The confidential OIDC callback answered a provider that refused the
sign-in, a code exchange that failed or never answered (a wrong client
secret among them) and a user the deployment may not provision with a
raw 500 page. It now redirects to /signin?error=<code> with one of three
fixed codes, and the reported detail stays in the server log. The
sign-in page shows a translated message for the code and does not
auto-redirect to the provider while it shows one. A sign-in started by
an MCP client keeps the error status its callback reads.

Release testing, SSO row: OC-07, OC-14, OC-17, ID-13.
ADR:2026-11-12-a-failed-sso-sign-in-returns-to-the-sign-in-page
…thm changes

tokenValidationAlgorithm names the identity provider's signing
algorithm, but the server also signed and verified its own bot,
personal access, session and MCP tokens with it, so changing it (to
RS512, say) made all of them fail at once. The server now signs its
own tokens with RS256 and verifies them with the RSA algorithm they
name; the setting applies to the provider's tokens only. MCP discovery
advertises RS256 for the tokens the server issues.

Release testing, SSO row: OP-13.
ADR:2026-11-12-openmetadata-signs-its-own-tokens-with-rs256
- A configuration the server cannot apply (a failing LDAP bind, a
  keystore it cannot read, LDAPS without a trust store) is put back to
  the previous one and refused with 400 and the reason, instead of
  staying stored behind a 500 or a 401.
- A PUT also refuses, without contacting the provider, a client
  authentication method the server cannot perform, and SAML request or
  metadata signing without the SP certificate and key. Full validation
  also checks the method against the provider's discovery document.
- LDAPS without a trust store type fails with a readable reason.
- A PATCH is filtered by the provider it leaves in place, so it can
  switch provider, and a PATCH that only sets values the provider does
  not use is refused instead of answering 204.

Release testing, SSO row: OC-15, SA-11, CF-02, CF-03, LD-12.
ADR:2026-11-12-a-security-configuration-save-applies-in-full-or-is-refused
… SAML response

Two first SAML sign-ins of one new user raced to create the account and
the loser got a 500. It now signs in to the account the winner created,
as the OIDC sign-in already does, through a helper both now share in
UserUtil. A post to the assertion consumer service that is no SAML
response is refused with 400 instead of a 500.

Release testing, SSO row: the SAML first-login race and SA-17. Adds
tests for SA-03, which #37436 already fixed.
@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

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

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

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.

AuthProvider provider = authConfig == null ? null : authConfig.getProvider();
FieldError error = null;
if (provider == AuthProvider.SAML && authConfig.getSamlConfiguration() != null) {
error = SamlValidator.validateSecurityConfiguration(authConfig.getSamlConfiguration());

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.

A PUT now refuses SAML request signing that uses a keystore. SamlValidator.validateSecurityConfiguration requires sp.spX509Certificate and sp.spPrivateKey whenever sendSignedAuthRequest or signSpMetadata is true. But the sign-in code, SamlSettingsHolder.putSpCredentials, accepts either those PEM values or keyStoreFilePath + keyStoreAlias + keyStorePassword, and conf/openmetadata.yaml documents that route through SAML_KEYSTORE_*.

To hit it: take a deployment that signs SAML requests with a JKS keystore and has no PEM values. Do a GET and then a PUT of /v1/system/security/config, even one that only changes adminPrincipals. It now answers 400 "SP X509 certificate is required when request signing is enabled", where before this PR it succeeded. Every PUT stays blocked until the deployment moves to PEM credentials.

PATCH already ran this validator before this PR, so the UI had the gap already. This change extends it to PUT, which was the only path still working for these deployments.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in e63dbea. SamlValidator.validateSecurityConfiguration now asks SamlSettingsHolder.readsSpCredentialsFromKeyStore, the same check putSpCredentials uses to pick the keystore. Request signing with keystore path + alias + password and no PEM values now passes on PUT and PATCH. PEM values are still required where sign-in reads no keystore: an incomplete keystore, or metadata signing on its own.

Guard: SsoSamlLoginIT#requestSigningWithAKeyStoreIsSavedAndReadBack. It PUTs with a real JKS, GETs, PUTs again with an adminPrincipals change, then checks the sign-in request carries a Signature. It was RED on the previous head (400 "SP X509 certificate is required when request signing is enabled") and is GREEN now. Unit: SamlValidatorTest#validateSecurityConfigurationAcceptsSignedRequestsWithAKeyStore and #validateSecurityConfigurationNeedsPemCredentialsWhereSignInReadsNoKeyStore.

Comment on lines +151 to +162
void samlConfigurationThatCannotBeLoadedIsNotSaved() {
SecurityConfiguration broken = securityConfig.baselineCopy();
broken
.getAuthenticationConfiguration()
.getSamlConfiguration()
.getSecurity()
.withSendSignedAuthRequest(true)
.withKeyStoreFilePath("/nonexistent/om-sso-it-keystore.jks")
.withKeyStoreAlias("sp")
.withKeyStorePassword("keystore-password");

assertRefusedAndNothingSaved(broken);

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.

This test does not reach the rollback it is named for. The baseline from SsoConfigs.saml(...) has no SP certificate or key. So turning on sendSignedAuthRequest with a keystore path gets refused by the new pre-write check (requireApplicable, see the comment on SystemRepository.java:1996) before anything is written. The 400 and "nothing saved" assertions pass, but the store, reload and restore path never runs.

The ADR lists this test as a guard for "a keystore it cannot read". As written, only the two LDAP cases (CF-03 bind failure and LD-12) cover the rollback.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Rewritten in eb36e49. The case now points at a file that exists but is not a keystore. With e63dbea it passes the pre-write check, is stored, and fails when the reload loads the keystore.

It asserts that the 400 says the configuration could not be applied, so it got past requireApplicable, and that the stored, running and GET-read configurations are the previous ones. With the put-back call removed it fails on "the refused save was stored", together with both LDAP cases. With the put-back in place it passes.

Comment on lines +1298 to +1308
private void restoreSecurityConfiguration(SecurityConfiguration configuration) {
systemRepository.createOrUpdate(
new Settings()
.withConfigType(AUTHENTICATION_CONFIGURATION)
.withConfigValue(configuration.getAuthenticationConfiguration()));
systemRepository.createOrUpdate(
new Settings()
.withConfigType(AUTHORIZER_CONFIGURATION)
.withConfigValue(configuration.getAuthorizerConfiguration()));
SettingsCache.invalidateSettings(AUTHENTICATION_CONFIGURATION.toString());
SettingsCache.invalidateSettings(AUTHORIZER_CONFIGURATION.toString());

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.

The restore does not check whether its writes worked. SystemRepository.createOrUpdate catches most write errors and returns a 500 Response rather than throwing, and both return values are ignored here.

If either restore write fails after the reload failed, the caller gets 400 "it was not saved", but the rejected configuration stays in the database. Other servers and the next restart then load it, which is the situation the new ADR is meant to rule out.

Separately, the restore writes the snapshot read at the start of the request without checking whether the rows changed since. The PATCH write is guarded by updateSecurityConfigurationIfCurrent, but the restore is not. A save made by another admin while this request waits on a slow LDAP bind is overwritten, even though that admin was told it succeeded.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 8a5d9a6.

  • The put-back is now updateSecurityConfigurationIfCurrent(previous, written), where written is the exact JSON this request stored (the write now returns it). So it only replaces this save. A save that landed meanwhile is kept, and the refused save is answered 412.
  • A put-back that throws is logged at ERROR and answered 500: "...putting the previous one back failed, so the refused configuration may still be stored...". It no longer reports 400 "not saved".
  • PUT now writes with the same compare-and-set as PATCH, against the rows it read, so what it puts back is what it replaced. A PUT racing another save gets 412, like PATCH. Its writes throw instead of returning an ignored 500 Response.
  • After a 412 the server applies what is stored through reloadIfStoredChanged. A failure there is logged, so the caller still gets the 412.

Guards:

  • SsoSecurityConfigApplyIT#aSaveMadeWhileARefusedOneWaitsOnTheDirectoryIsKept holds the LDAP bind while another server's save lands. It was RED as 400 with that save undone, and is GREEN as 412 with the save kept.
  • SystemResourceSecurityConfigApplyTest covers a failed put-back write (500) and a save made meanwhile (412). Both were RED as 400 before.

so tokens issued by earlier releases under another setting keep working. Any other algorithm on
a token carrying the server's key id is refused.
- `tokenValidationAlgorithm` applies only to the identity provider's tokens.
- The MCP OpenID discovery document advertises RS256 for the tokens the server issues.

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.

This contradicts docs/decisions/2026-10-19-mcp-oauth-discovery-stays-inside-the-base-path.md, which is still Accepted and says at line 30 that id_token_signing_alg_values_supported is the configured tokenValidationAlgorithm. Neither record says it supersedes the other, so the tree now holds two Accepted decisions that disagree on the same discovery field.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Checked the code. Discovery advertises JWTTokenGenerator.SIGNING_ALGORITHM (RS256), and every token the server issues is signed with it, MCP access tokens included; MCP issues no ID tokens. So the code matches the 2026-11-12 record, and only the older record was stale.

287d5eb adds a v2 amendment to the 2026-10-19 record (a Revisions entry and ## Amendment — 2026-11-16) that replaces that clause. The RS256 record now points at it.

Guard: OAuthHttpStatelessServerTransportProviderTest#openIdDiscoveryAdvertisesTheAlgorithmOfTheTokensTheServerIssues, with the provider on RS512. It is RED when discovery follows tokenValidationAlgorithm (RS512 advertised, RS256 tokens) and GREEN now. check_decision_records.py is clean.

A PUT, and a PATCH before it, refused SAML request signing whose SP key
and certificate come from a keystore (keyStoreFilePath, keyStoreAlias
and keyStorePassword, the SAML_KEYSTORE_* route in conf/openmetadata.yaml)
with "SP X509 certificate is required when request signing is enabled",
although sign-in signs with that keystore. A GET and then a PUT of such a
deployment's configuration answered 400.

The save check now asks SamlSettingsHolder.readsSpCredentialsFromKeyStore,
which sign-in uses to choose its credentials, and needs the PEM values
only where sign-in reads no keystore: an incomplete keystore, or metadata
signing on its own.
The case set request signing with a keystore on a configuration without
SP PEM values, so the check made before anything is written refused it
and the store, apply and put-back path never ran.

It now names a file that exists but is not a keystore. The save passes
the check, is stored, and fails when the server loads the keystore. The
case checks that the 400 says the configuration could not be applied,
and that the stored, running and read configurations are the previous
ones. With the put-back removed it fails on "the refused save was
stored".
…rt a failed put-back

When the server could not apply a saved security configuration, it wrote
the previous one back with createOrUpdate, which answers a failed write
with a 500 Response that was ignored, and it wrote it whatever the rows
held by then.

- Putting the previous configuration back is a compare-and-set against
  the JSON the refused save wrote, which the write now returns. A save
  made meanwhile, for example by another admin while this one waited on
  a slow LDAP bind, is kept and the refused save is answered 412.
- A put-back that fails is logged and answered 500, saying the refused
  configuration may still be stored, instead of 400 "it was not saved".
- PUT writes with the same compare-and-set as PATCH, over the rows it
  read, so what it puts back is what it replaced; a PUT racing another
  save is answered 412, as a PATCH is. Its writes throw instead of
  returning an ignored error response.
- After a 412 the server applies what is stored with
  reloadIfStoredChanged; if that fails it is logged, so the caller still
  gets the 412.
…algorithm

The 2026-10-19 MCP discovery record said id_token_signing_alg_values_supported
is the configured tokenValidationAlgorithm, while the 2026-11-12 RS256 record
says the server signs its own tokens with RS256 whatever that setting is, and
discovery advertises RS256. The code already does the latter: discovery
advertises JWTTokenGenerator.SIGNING_ALGORITHM, which every token the server
issues, MCP access tokens included, is signed with.

The older record gets a v2 amendment that replaces that clause, and the RS256
record points at it. A unit test checks that discovery advertises the
algorithm of the tokens the server issues while the provider is on RS512.
@gitar-bot

gitar-bot Bot commented Nov 16, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 🔴 High risk 2 closed / 2 findings

Changing SSO authentication, JWT verification, and security-configuration rollback could reject valid users or leave administrators with unintended access settings.

Makes SSO failures recoverable: failed OIDC sign-ins return to the sign-in page with a reason, security-setting saves that the server cannot apply are refused with 400, OpenMetadata-issued tokens are signed with RS256 independent of the provider algorithm, and concurrent first SAML sign-ins share one account. Stale-token bot regeneration now treats legacy RS384/RS512 tokens as stale, and the accepted MCP discovery ADR was updated to match the server's own signing algorithm. No open issues found.

✅ 2 closed
✅ Bug: Stale-token bot regeneration treats legacy RS384/RS512 tokens as stale

📄 openmetadata-service/src/main/java/org/openmetadata/service/security/jwt/JWTTokenGenerator.java:97-101 📄 openmetadata-service/src/main/java/org/openmetadata/service/security/jwt/JWTTokenGenerator.java:124-138
internalVerificationAlgorithm() is now pinned to RS256 (JWTTokenGenerator.java:124-127). BotTokenRegenerator.isCurrent still verifies stored bot tokens with it (JWT.require(generator.internalVerificationAlgorithm())). On a deployment whose earlier releases signed bot tokens with RS384 or RS512, those tokens no longer verify there. OpenMetadataOperations' regenerate command with skipCurrent (Scope.STALE) then reissues every one of them. The bot tokens that external ingestion pipelines hold stop working, even though JwtFilter (through ownTokenVerificationAlgorithm) and the ADR say tokens from earlier releases stay valid.

Fix: in isCurrent, decode the token first, then verify it with JWTTokenGenerator.ownTokenVerificationAlgorithm(decoded.getAlgorithm(), generator.getPublicKey()). Treat the AuthenticationException that call throws for an unsupported algorithm as not current. This uses the same set of accepted algorithms as the request filter.

✅ Quality: Accepted MCP discovery ADR still says alg = tokenValidationAlgorithm

📄 openmetadata-mcp/src/main/java/org/openmetadata/mcp/server/transport/OAuthHttpStatelessServerTransportProvider.java:510-517 📄 docs/decisions/2026-11-12-openmetadata-signs-its-own-tokens-with-rs256.md:1-15
The Accepted record [docs/decisions/2026-10-19-mcp-oauth-discovery-stays-inside-the-base-path.md] says that id_token_signing_alg_values_supported is the configured tokenValidationAlgorithm. This PR changes addOpenIdDiscoveryFields so it always advertises JWTTokenGenerator.SIGNING_ALGORITHM (RS256). The new record 2026-11-12-openmetadata-signs-its-own-tokens-with-rs256 makes that rule ("The MCP OpenID discovery document advertises RS256 for the tokens the server issues"), but it does not say it supersedes the older record. The older record's Status is also still Accepted, so the tree now holds two Accepted records that contradict each other on the same discovery field.

Fix: in the 2026-10-19 record, set Status to Superseded by 2026-11-12-openmetadata-signs-its-own-tokens-with-rs256 for this point, or revise that bullet. Also add a Supersedes line to the new record.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

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

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.

3 participants