Skip to content

fix(security): batch of backend security-hardening fixes - #36156

Merged
mohityadav766 merged 30 commits into
mainfrom
fix/security-hardening-oct
Oct 29, 2026
Merged

mohityadav766 merged 30 commits into
mainfrom
fix/security-hardening-oct

Conversation

@mohityadav766

@mohityadav766 mohityadav766 commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Summary

A batch of backend security-hardening fixes from an internal review, grouped by area into one commit each:

  • Identity and account integrity (user-name comparison, credential handling, bot seeding).
  • Login and SSO token validation (OIDC, SAML, LDAP).
  • Secret handling on versions, history, follower and connection write paths.
  • Authorization consistency (deny-rule precedence, service/query/app/workflow checks).
  • Search RBAC and reindex integrity.
  • Request-filter, search-preview and CSV-import hardening.
  • Learning-resource URL scheme validation.

Each commit carries its own regression tests. Details are tracked internally.

Labelled skip-pr-checks.

Tracking: open-metadata/openmetadata-collate#7797

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge based on this follow-up review.

Summary

This PR hardens account checks, sign-in, secret handling, permissions, and search access.

  • Sign-in checks match the real account and identity provider.
  • Permission checks follow the real target and explicit deny rules.
  • Masked connection secrets stay tied to the original endpoint.
  • Apps and bots check their accounts and requested actions.
  • Search keeps access rules attached to indexed results.
  • Requests, imports, and learning links use stricter checks.

Reviews (16) · Last reviewed commit: "refactor: import types instead of naming..." · Reviewed by Greptile

…ntials intact

- Add SecurityUtil.sameIdentifier, which compares names, emails and email
  domains by their Locale.ROOT lower-case forms, the normalization stored
  names get. String.equalsIgnoreCase also compares upper-case forms and so
  equates distinct names. Use it for the self checks in UserResource and
  ActivityResource, the admin-name checks, session binding, adminEmails and
  the email-domain allow-lists. Normalize user names and emails with
  Locale.ROOT.
- POST /users/generateToken mints tokens for bot users only; people use
  personal access tokens, which can be revoked.
- A PUT or CSV row that carries no authentication mechanism keeps the stored
  one instead of dropping it.
- Bot seeding and app bot creation refuse an existing account of the same
  name that is not a bot.
- A bot can no longer be created for a soft-deleted user who is not a bot.
- Self sign-up requires the email the caller's token carries.
- Impersonation evaluates the target user with its domains loaded.
…ment

- Legacy claim flow: a provider-issued token must carry an email in
  allowedEmailDomains when that list is set, and the email must be the one
  stored on the account the user name resolves to. A provider token never
  signs in to a bot account.
- SAML: every response must be current and issued to this service provider
  (Conditions and SubjectConfirmationData NotOnOrAfter, SessionNotOnOrAfter,
  audience, Destination against the configured ACS URL), whatever strictMode
  is set to. Test Login applies the same rule. A rejected response is a 401.
- Public Entra ID clients accept tokens only from the tenant the authority
  names; multi-tenant authorities are unchanged.
- Basic auth: a self-registered account with a confirmation still pending
  cannot sign in, including through the MCP login form. The registration
  domain allow-list compares domains with sameIdentifier.
- LDAP: a wrong password is counted towards the login lockout (UnboundID
  reports a rejected bind by throwing), and a successful bind clears the
  count.
…nd off new endpoints

- Version and history endpoints redact the stored snapshot the way the
  entity's own reads do: EntityResource gains a snapshotRedaction hook that
  User (drops authenticationMechanism), every ServiceEntityResource (masks
  the connection), IngestionPipeline and Workflow override. The service
  follower, PATCH, delete and restore responses, and their follower change
  events, are masked too.
- A connection keeps its stored secret only while it points where it did:
  ConnectionSecretsGuard refuses a PATCH, PUT or test-connection workflow
  that changes an endpoint field while leaving a secret masked, encrypted or
  equal to the stored one. Admins and bots are unaffected.
- getSettingByName resolves the setting name to a SettingsType before the
  access checks, and refuses a row whose type is not the one requested, so an
  accent-insensitive DB collation cannot return the auth configuration.
- Settings reject a secret sent already Fernet-encrypted unless it is the one
  the setting holds, so a setting cannot decrypt another's token.
authorizeRequests(ANY) tried each request and passed as soon as one allowed
access, swallowing the AuthorizationException the others threw. An explicit
Deny rule threw the same exception as "no rule allowed it", so a Deny on one
request was ignored when a sibling request allowed access — for example query
listing checks ViewBasic on the query and ViewQueries on the parent table,
and a table Deny on ViewQueries was overridden.

CompiledRule.evaluateDenyRule now throws PolicyDeniedException, a subclass the
ANY loop rethrows while it still skips a plain "not allowed" to the next
request.
…d workflows

- A service's pipelines field listed pipelines a deny rule hides; it is now
  filtered to the ones the caller may view (admins and bots see all).
- Attaching or detaching a query to an asset, through /usage or queryUsedIn on
  create and PUT, checks EditQueries on each asset, so a query cannot be moved
  into another domain's asset without that permission.
- A tag-based deny rule now sees inherited tags: the authorization
  ResourceContext runs tag inheritance after loading the entity's own tags.
- A team no longer stores its parents' domains as its own, so they do not
  survive the parent's domain being removed.
- A description-only app PATCH no longer reinstalls or unschedules the app;
  rescheduling needs EditAll. An app trigger with a config override needs
  EditAll, not just Trigger.
- The reverse-ingestion trigger resolves the service from the store and
  requires a service entity type. The Spark-engine trigger confirms the stored
  request is a Spark request before applying the lighter create check.
…ces and lineage

- Query cost records are now subject to the query's search RBAC: they are a
  child of the query for RBAC, and their document carries the query's owners,
  tags and domains at the top level, so a deny on the query hides them. The
  query-cost-by-service aggregation drops groups whose query the caller cannot
  view.
- LLM model and MCP server search documents get their service's domain, so a
  service domain change propagates instead of leaving them domainless.
- The OpenSearch RBAC query cache key includes a policy generation that bumps
  whenever the policy caches are dropped, so a policy-rule or role-policy edit
  is not served stale for the cache TTL.
- MCP root_cause_analysis authorizes the real entity by FQN and runs the
  lineage view filter over its upstream producers, so an inherited-domain node
  is not returned to a caller denied it.
- Moving a Context Center page rewrites a descendant FQN only at a real "."
  boundary, so a sibling that merely shares a prefix is left alone.
- A SearchIndex reindex keeps its field-level tags.
…import

- The audit/change-event filter matched excluded endpoints with a substring
  check, so a write whose path embeds one (through a matrix parameter or an
  encoded separator) skipped auditing. It now shares JwtFilter.isExcludedEndpoint,
  which matches the resource path exactly after dropping matrix parameters.
- Search preview runs with caller-supplied settings that can stall the cluster;
  it now requires admin, like the settings write it previews.
- Table CSV import validated the whole table on every row, which made a large
  import quadratic in its column count; it validates once after applying the
  rows. A row naming a missing parent column no longer dereferences null.
A javascript: or data: URL in a learning resource runs in the product's
origin when the UI frames or links it. The backend restricted the scheme for
Link and PDF only, so Storylane, Video and Article accepted any scheme.

- LearningResourceRepository requires an http or https URL for every type.
- The Storylane, Video and Article players pass the URL through getSafeHttpUrl
  before framing or linking it, so a stored unsafe URL is dropped rather than
  executed.
@mohityadav766
mohityadav766 requested review from a team as code owners October 24, 2026 05:29
@mohityadav766 mohityadav766 added skip-pr-checks Bypass PR metadata validation check safe to test Add this label to run secure Github workflows on PRs labels Oct 24, 2026
@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.

The Entra authority version segment, the email separator and the
connection field name were raw literals in equals/contains calls.
The bot-name check was covered by a unit test that mocked three
repositories and the entity registry. An integration test now installs
an app whose bot name a person already holds, and checks that the saved
account is unchanged and that neither the bot nor the app is created.
A refused install now answers 400 instead of an unhandled 500.
The SAML response validator spelled out javax.servlet.http.HttpServletRequest,
and two JwtFilterTest lines called Mockito.mockStatic by its full name
although it is statically imported.
@github-actions

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — failed_checks (2026-10-28T07:29:53Z)

Blocked the queue: integration-tests-mysql-elasticsearch

@github-actions

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — merge_conflict (2026-10-28T10:36:03Z)

The entry left the queue before it was built, so no checks ran against it.

Conflicts with the latest main — rebase, then re-queue.

…g-oct

# Conflicts:
#	openmetadata-service/src/test/java/org/openmetadata/service/security/auth/LdapDirectoryValidationTest.java
Main's msal-mock fixture now signs its ID token with the mock IdP, and
that token carried no tid claim. The fixture's authority names a tenant,
and a public Entra client accepts only tokens from the tenant its
authority names, so every scenario failed with "Token tenant 'null' is
not the tenant configured for sign-in". The mock's /test/id-token takes
an optional tenantId and signs it as tid, as Entra ID does, and the
fixture passes its own tenant.
@gitar-bot

gitar-bot Bot commented Oct 28, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 9 closed / 9 findings

🔴 High risk · Sign-in, authorization, and connection-secret changes could enable account takeover, unauthorized writes, or credential exposure if checks are flawed.

Security-hardening batch covering authorization deny-rule precedence, secret handling on write paths, login and SSO token validation, and bot account checks. Resolved this session: ANY-mode Deny precedence depending on request order, retarget guard missing secret: references under an external SM, root-replace app patch rescheduling the app, endpoint token allowlist gaps for Oracle TNS and Domo instanceDomain, trigger-only users setting unset config keys, no-email provider tokens skipping bot-account and domain checks, and per-query relationship reads in bulk query PUT. No open issues found.

✅ 9 closed
✅ Security: ANY-mode Deny precedence depends on request order

📄 openmetadata-service/src/main/java/org/openmetadata/service/security/DefaultAuthorizer.java:186-200 📄 openmetadata-service/src/main/java/org/openmetadata/service/security/PolicyDeniedException.java:16-26 📄 openmetadata-service/src/test/java/org/openmetadata/service/security/DefaultAuthorizerTest.java:570-584
authorizeRequests with AuthorizationLogic.ANY still breaks on the first request that passes. A PolicyDeniedException on a later request is never evaluated, so [allowed, denied] passes while [denied, allowed] is refused. The rule this commit adds ("a Deny on any of the tried resources refuses the whole request", in PolicyDeniedException's Javadoc) only holds when the denied resource happens to come first. The new test only covers the denied-first order. Fix: evaluate every request, remember whether any one passed, rethrow a PolicyDeniedException as soon as one appears, and add a test for the allowed-first order.

✅ Security: Retarget guard misses secret: references under an external SM

📄 openmetadata-service/src/main/java/org/openmetadata/service/secrets/masker/ConnectionSecretsGuard.java:86-93
keepsStoredSecret only counts a secret as kept when it is the mask, a Fernet token, or exactly the stored value. With an external secrets manager, the stored values are secret:/<prefix>/<serviceType>/<service>/<field> references, and the naming is predictable. ExternalSecretsManager.storeValue passes any value that already starts with secret: through untouched. A non-admin can point the connection at a host they control and send another service's reference as the password. The guard accepts it, and ingestion or a test connection then resolves that secret and sends it to the new host. That is exactly what the guard exists to stop. Fix: treat a value where SecretsManager.isSecret(value) is true as kept/borrowed, the same way Fernet tokens are.

✅ Bug: Root-replace app patch no longer reschedules the app

📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/apps/AppResource.java:988-996 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/apps/AppResource.java:1012-1016 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/apps/AppResource.java:1054-1062
touchesScheduleOrConfig relies on JsonUtils.extractPatchedFields, which skips a / path. A whole-document replace therefore returns an empty set, and reschedules is false. Before this change every patch to a scheduled app deleted and reinstalled its schedule. Now a root replace that changes appSchedule or appConfiguration is saved to the database, but the scheduler keeps running the old schedule and config. It also skips the new EditAll gate. ServiceEntityResource.mayRetargetConnection in this same PR already treats an empty field set on a non-empty patch as "may touch everything". Fix: apply the same rule here.

✅ Quality: New authorization and secret rules have no decision record

📄 openmetadata-service/src/main/java/org/openmetadata/service/security/PolicyDeniedException.java:16-22 📄 openmetadata-service/src/main/java/org/openmetadata/service/secrets/masker/ConnectionSecretsGuard.java:27-36 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/teams/UserResource.java:981-986 📄 openmetadata-service/src/main/java/org/openmetadata/service/security/JwtFilter.java:678-692
This PR adds cross-cutting rules that other components and future changes have to respect, and docs/decisions/ records none of them. Two examples are the new PolicyDeniedException and ConnectionSecretsGuard. (1) "In an ANY-mode authorization, an explicit Deny on any requested resource refuses the whole request." (2) "A caller who is not an admin or a bot must re-enter a connection's secrets whenever any non-secret connection setting changes, on service PATCH/PUT and test-connection workflows." (3) "/users/generateToken mints tokens for bot users only; people use personal access tokens." (4) "A public-client Entra ID deployment accepts provider tokens only from the tenant ID its authority names." The PR description says "Details are tracked internally", so these rules exist nowhere in the tree. Fix: add records stating these rules, or point to existing ones.

✅ Security: Endpoint token allowlist misses Oracle TNS string and Domo instanceDomain

📄 openmetadata-service/src/main/java/org/openmetadata/service/secrets/masker/ConnectionSecretsGuard.java:64 📄 openmetadata-service/src/main/java/org/openmetadata/service/secrets/masker/ConnectionSecretsGuard.java:74-75 📄 openmetadata-service/src/main/java/org/openmetadata/service/secrets/masker/ConnectionSecretsGuard.java:96-102 📄 docs/decisions/2026-10-24-a-masked-connection-secret-is-kept-only-while-the-endpoint-is-unchanged.md:18-22
This commit replaces the old check (refuse if anything differs) with a name match on host, url, uri, endpoint, account, server, address, port. Some fields that decide where a connection goes don't match any of those tokens. One is Oracle's oracleConnectionType.oracleTNSConnection, which holds the whole (DESCRIPTION=(ADDRESS=(HOST=..)(PORT=..))) string. Another is Domo's instanceDomain (format uri). A caller who can edit the service but only sees the password masked can point the TNS string at a host they control and leave password as *********. endpointChanged returns false, the masker puts the stored password back, and the runner sends it to the attacker. That is the same leak the guard was added to stop. An allowlist of field names fails open here. A safer fix is to keep the old "any masked difference blocks" rule and exempt a short list of known-safe fields (filter patterns, supports* flags, descriptions). If you keep the allowlist, add tns, domain, dsn and connection, and add a test for the Oracle TNS case.

...and 4 more closed from earlier reviews

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

@github-actions

Copy link
Copy Markdown
Contributor

❌ UI Checkstyle Failed

❌ Bundle Runtime Check

A route chunk loads but one of its chunks still exports undefined: a chunking change broke module initialisation. Run yarn build && yarn bundle:runtime locally.


Fix locally (fast - only checks files changed in this branch):

make ui-checkstyle-changed

@sonarqubecloud

Copy link
Copy Markdown

@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — failed_checks (2026-10-28T20:48:59Z)

Blocked the queue: integration-tests-postgres-opensearch

@github-actions

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — manual (2026-10-29T08:04:25Z)

No required check failed — the entry may have timed out, or been dequeued while a required check was still pending.

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 skip-pr-checks Bypass PR metadata validation check

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants