Skip to content

Fixes #37056: Rewrite the stored SAML IdP certificate as standard PEM in the 2.0.10 migration - #38315

Merged
manerow merged 11 commits into
mainfrom
fix/saml-idp-certificate-pem-migration
Nov 23, 2026
Merged

manerow merged 11 commits into
mainfrom
fix/saml-idp-certificate-pem-migration

Conversation

@manerow

@manerow manerow commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

Fixes #37056

#38197, #38219 and #38302 read the IdP certificate strictly: one on a single line, or with spaces for line breaks, stops the server at startup. We keep it; the database must hold only certificates it accepts:

  1. Existing data. A 2.0.10 migration rewrites samlConfiguration.idp.idpX509Certificate as standard PEM; an unreadable value stays, with a warning.
  2. New values, one check. Every settings write (security PUT and PATCH, settings API, update-security-config, seeds, reconcile) passes SystemRepository.prepareSettingForUpdate. That step now gets the decrypted stored value and runs SamlValidator.validateIdpCertificate, the UI save rule, only on a new or changed certificate: an unchanged expired one is never refused. A refusal stores nothing and surfaces as before: 400, exit 1, a stopped first or ENV start, or a kept value and error log in AUTO/DB. SettingsWriteFunnelTest fails if a new method writes a setting past that step. Undoing a security save the server cannot apply puts back the rows it replaced as they were read, without the check, so a stored certificate that has since expired comes back.

Upgrade note: ENV mode applies the deployment value on every start, so a single-line SAML_IDP_CERTIFICATE is refused on the first start after upgrading, though the migration fixed the stored copy. Fix the variable: standard PEM, or the base64 body alone. AUTO keeps the migrated value.

Backports: #38318, #38317.

Type of change:

  • Bug fix

High-level design:

None.

Tests:

Unit tests

  • Migration: IdpCertificatePemTest, SamlIdpCertificateMigrationTest (MySQL 8.3, PostgreSQL 16).
  • Each write path, bad, good and unchanged expired: SystemRepositorySecuritySettingsTest; what update-security-config stores: OpenMetadataOperationsSecurityConfigTest; undoing a refused save over an expired certificate: SystemResourceSecurityConfigApplyTest; also DeploymentConfigReconcilerTest, SettingsWriteFunnelTest.

Backend integration tests

  • SsoSamlIdpCertificateIT: PUT and PATCH refuse a bad certificate (400, nothing stored), store a good one, keep a stored expired one, and put it back unchanged when a save cannot be applied. Also green: SsoSecurityConfigApplyIT; on the previous head, SamlSecurityConfigIT, ConfigSourceIT and two more.

Local Java test run: PASSED

  • Commit: 0ac9686dc3df (base origin/main)
  • Finished: 2026-11-23 10:17 UTC · 4.1 min
  • Scope: focused; merge readiness is not established. Broader steps deferred: 8 (run --scope full).
Step Scope Classes Tests Failed Skipped Min Result
unit openmetadata-service (11 classes) 11 201 0 0 1.5 passed
integration mysql-elasticsearch · isolated 1 8 0 0 2.6 passed
  • Impacted, not run locally: 2 classes (listed in the details)

Manual testing performed

Real runs (MySQL, PostgreSQL): a bad certificate stops a fresh install and ENV; AUTO keeps the row; update-security-config exits 1 and writes nothing.

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.
  • Self-review: I reviewed the final diff against REVIEW.md; no 🔴 finding.
  • Decision check: updates docs/decisions/2026-11-20-the-stored-saml-idp-certificate-is-standard-pem.md.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no new blocking issue was found.

Summary

Rewrites stored SAML IdP certificates as standard PEM during the 2.0.10 migration.

  • The 2.0.10 upgrade rewrites readable stored SAML certificates as standard PEM.
  • Settings writes check new or changed SAML certificates before saving them.
  • A refused security save restores the settings rows it replaced as they were read.

No new actionable issues found. Previous threads are unnumbered and were not reposted. No tests were run during this review.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Existing stored certificate] --> B[2.0.10 migration]
  B --> C[Rewrite readable values as PEM]
  D[Settings write] --> E{Certificate new or changed?}
  E -->|Yes| F[Check certificate]
  F -->|Accepted| G[Store settings]
  F -->|Refused| H[Leave stored settings unchanged]
  E -->|No| G
  G --> I{Security save applies?}
  I -->|No| J[Restore original rows if still current]
Loading

Reviews (15) · Last reviewed commit: "Mark unchanged parameters and locals fin..." · Reviewed by Greptile

@manerow
manerow requested a review from a team as a code owner November 20, 2026 14:25
@manerow
manerow requested a review from IceS2 November 20, 2026 14:25
@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR checks passed

The linked issue has a description and all required Shipping project fields set. Thanks!

@gitar-bot

gitar-bot Bot commented Nov 23, 2026

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

The migration rewrites stored SAML IdP certificates and gates security-setting writes; certificate handling could disrupt SAML login or block server startup.

Rewrites the stored SAML IdP certificate as standard PEM in the 2.0.10 migration and checks new or changed certificates on every settings write, so single-line or space-separated values are refused before storage. Resolved the finding that the gate's lenient save check let old-layout certificates into the database.

✅ 1 closed
✅ Bug: Gate's lenient save check lets old-layout certificates into the database

📄 openmetadata-service/src/main/java/org/openmetadata/service/security/auth/validator/SamlIdpCertificateGate.java:48-60 📄 openmetadata-service/src/main/java/org/openmetadata/service/security/auth/validator/SamlValidator.java:236-250 📄 openmetadata-service/src/test/java/org/openmetadata/service/config/source/DeploymentConfigReconcilerTest.java:281-295 📄 docs/decisions/2026-11-20-the-stored-saml-idp-certificate-is-standard-pem.md:39-53
SamlIdpCertificateGate.requireUsable calls SamlValidator.validateIdpCertificate, which goes to validateX509Certificate. That method strips the BEGIN/END markers and runs replaceAll("\s+", "") before decoding (SamlValidator.java:495-516). So it accepts the layouts the ADR says the strict JDK reader rejects: a certificate on one line, spaces where the line breaks belong, or spaces before BEGIN. The ADR's own Context says the save check reads the certificate the lenient way.

Here is how that goes wrong. In ENV or AUTO, an operator sets SAML_IDP_CERTIFICATE to a different value in the old single-line layout. The gate passes it, and storeMerged / prepareSeed writes it to the row. Once the strict reader (#38219) is in place, the server then cannot read that certificate at startup. In AUTO there is no good stored value left to fall back to. This contradicts ADR decision 5 / Consequences ("no deployment value can put a bad one back") and the PR claim "In ENV an old-layout variable stops the start". No test covers it: the IDP_SINGLE_LINE cases only reconcile an unchanged variable, so the gate never runs.

Fix: have the gate check the value with the same strict parsing the server uses at startup, e.g. CertificateFactory.generateCertificates on the raw text, or the strict reader from #38219, alongside the expiry check. Add a reconciler or gate test where a changed single-line variable is refused.

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

@yan-3005 yan-3005 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.

Could we add this to the 2.0.10 release notes, so customers on ENV config mode know before they upgrade?

SAML IdP certificate (2.0.10): OpenMetadata now reads the SAML identity provider certificate more strictly. A certificate saved in the database is reformatted automatically during the upgrade, so nothing to do there. If you set it through the SAML_IDP_CERTIFICATE environment variable and it is written on a single line together with the -----BEGIN CERTIFICATE----- and -----END CERTIFICATE----- lines, the server will not start after the upgrade. Use standard PEM, with the BEGIN and END lines each on their own line, or put only the base64 body on one line without those lines.

@manerow

manerow commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@yan-3005 thanks for the review. One correction for 2.0.10: 2.0 has no ENV mode, and SAML_IDP_CERTIFICATE only seeds an empty database there, so upgrading with a single-line value still works (the migration rewrites the stored copy). Only a new 2.0.10 install with a single-line value stops. The ENV warning applies to the next 2.1 patch. I added the release notes to PR #38317 (2.0.10) and PR #38318 (2.1) so they are picked up when the patch notes are written.

@manerow
manerow merged commit 6fb28f5 into main Nov 23, 2026
70 checks passed
@manerow
manerow deleted the fix/saml-idp-certificate-pem-migration branch November 23, 2026 11:49
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.

SAML config: “SSO URL returned error (HTTP 400)” on Entra IdP SSO Login URL when signed-request options are enabled

2 participants