Skip to content

Check team grants, placement and membership against the resulting state, and tighten DomainOnlyAccessPolicy - #36695

Merged
sonika-shah merged 17 commits into
mainfrom
fix/team-edit-checks
Nov 4, 2026
Merged

sonika-shah merged 17 commits into
mainfrom
fix/team-edit-checks

Conversation

@sonika-shah

@sonika-shah sonika-shah commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Aligns team and domain-only authorization with the rules already applied to user roles: team grants, team placement and team membership are checked against the state a write produces, and DomainOnlyAccessPolicy covers administration resources.

What changed

  • Team roles and policies: adding a default role or policy to a team needs an admin, on POST, PUT, PATCH and team CSV import, as assigning a role to a user does. Removing one, or resending the ones a team already has, is unchanged, so an exported CSV still re-imports. Impersonated requests follow the same rule as for user privileges.
  • Team parents: adding a parent to a team needs the same permission as editing that parent, on REST and in team CSV import. The organization is exempt.
  • Closed teams: a user PATCH is judged on the teams it leaves the user in, so every patch operation gets the same admin check.
  • DomainOnlyAccessPolicy: keeps its allow and deny rules and gains two deny rules: creating, editing, deleting or deploying policies, roles, bots and apps in any domain, and creating, editing or deleting teams and users in no domain and bot users (noDomain() || isBotUser()). Running an app as configured, such as AutoPilot for a service, stays allowed. Assets in no domain stay fully editable. A 2.1.0 migration adds the rules to stored policies, customised ones included.

Behaviour changes

  • Adding roles or policies to a team, or placing a team under a parent, now needs an admin or edit permission on that parent, including for team owners and bots.
  • Team CSV import is not available to impersonated requests.
  • Domain-only users need another role to change policies, roles, apps or bots in any domain, or teams and users in no domain; a deny wins over that role. Their access inside their domains and to assets in no domain is unchanged. A domain-only user with no domain needs another role to edit their own profile, and a domain-only owner of a team in no domain to manage it.
  • Sign-in team claims (SSO/SAML), self sign-up, SCIM and seeded sample data write through the repository or as admin and are unchanged.
  • A deny takes precedence over other roles, so users holding DomainOnlyAccessRole cannot change policies, roles, bots or apps even when another role allows it. Deployments that delegate these to domain-scoped users need to adjust DomainOnlyAccessPolicy; the upgrade adds each new rule once.
  • The upgrade does not change team roles, policies, parents or memberships that are already set; admins may want to review them.

Tests

  • New tests in TeamResourceIT, UserResourceIT, BotImpersonationIT, DomainIsolationIT (including a table in no domain staying editable) and DomainOnlyAccessPolicySqlMigrationTest (MySQL and Postgres) fail without the change and pass with it.
  • Affected IT classes pass locally (MySQL): Team, User, BotImpersonation, DomainIsolation, TestCaseCsvDomainIsolation, FeedAccessAuthz, Activity, Conversation, AIContextKnowledgeAuthorization, TestDefinition, Task, Lineage, QueryVisibilityPolicy, Policy, Apps.
  • Upgrade end to end on MySQL and Postgres: released 2.0.7 stack, this branch's migrate, then this branch's server. The stored policy gains the new rule and the schema moves to 2.1.0; the API checks for the changes above behave as described after the upgrade.
Implementation notes
  • TeamResource uses the existing authorizeCreateOrUpdate / prepareCreateOrUpdateAuthorization hooks for create, PUT and bulk PUT, and overrides patchInternal to apply the patch and compare the result, following QueryResource.
  • TeamRepository.TeamCsv loads the stored team once per row (non-admins only) and checks added roles, policies and parents; parents the team already has, the import root and teams created by the same file are skipped.
  • UserResource.patch keeps validateTeamAddition for add operations and moves the closed-team check after the loop, reusing joinsClosedTeam.
  • The DomainOnlyAccessPolicy rules list resource types and cover no view operation, so search filtering is unchanged. The migration appends each rule where no rule of that name exists and sits with the other 2.1.0 policy updates.
  • Decision records: docs/decisions/2026-10-30-only-admins-add-roles-or-policies-to-a-team.md, docs/decisions/2026-11-02-domain-only-access-cannot-change-administration-resources-in-no-domain.md.

Team edits that add default roles or policies now need an admin, on PATCH,
PUT and CSV import alike, matching how roles are assigned to users. Placing
a team under a parent needs the same permission as editing that parent.

A user PATCH that changes team membership is judged on the teams the patch
leaves the user in, so every way of writing the change is checked the same.
@sonika-shah
sonika-shah requested a review from a team as a code owner October 30, 2026 12:29
@sonika-shah
sonika-shah requested a review from yan-3005 October 30, 2026 12:29
@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.

@github-actions github-actions Bot added backend safe to test Add this label to run secure Github workflows on PRs labels Oct 30, 2026
# Conflicts:
#	openmetadata-service/src/main/java/org/openmetadata/service/resources/teams/UserResource.java
A newly added parent needs EDIT_ALL on it, checked as the importing user;
parents the team already has, the import root and teams created by the
same file are skipped.
The allow rule now uses a new inUserDomains() function (own-domain
resources, plus listings and bulk requests that are filtered per item),
and a view rule keeps domainless resources readable. The 2.1.0 migration
updates the stored policy only while it still has the shipped rules.
@sonika-shah sonika-shah changed the title Check team grants and membership changes against the resulting state Fix team, membership and domain-only privilege escalations Nov 2, 2026
Copilot AI balanced review requested due to automatic review settings November 2, 2026 04:26

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.

🟡 Changes recommended

Unresolved authorization bypasses allow unauthorized logical-suite edits and impersonated-bot privilege escalation, while the security migration skips repository-saved policies because of its rule-order guard.

5 open issues
What changed in this PR

This PR tightens OpenMetadata authorization around team grants, parent relationships, closed-team membership, and domain-only access. It also updates existing installations while preserving customized policies.

Changes:

  • Adds authorization checks for team role, policy, and parent additions through REST and CSV import.
  • Checks resulting user memberships after PATCH and narrows domain-only grants on domainless resources.
  • Adds security regressions, guarded MySQL/PostgreSQL migrations, and decision records.
File Description
openmetadata-service/​src/​test/​java/​org/​openmetadata/​service/​security/​policyevaluator/​DomainAccessTest.java Tests domain, domainless, and listing behavior.
openmetadata-service/​src/​main/​resources/​json/​data/​policy/​DomainAccessPolicy.json Separates domain-scoped access from viewing grants.
openmetadata-service/​src/​main/​java/​org/​openmetadata/​service/​security/​policyevaluator/​RuleEvaluator.java Adds the inUserDomains() policy function.
openmetadata-service/​src/​main/​java/​org/​openmetadata/​service/​security/​policyevaluator/​ExpressionValidator.java Registers the new policy function.
openmetadata-service/​src/​main/​java/​org/​openmetadata/​service/​resources/​teams/​UserResource.java Checks closed-team membership after applying patches.
openmetadata-service/​src/​main/​java/​org/​openmetadata/​service/​resources/​teams/​TeamResource.java Authorizes team grant and parent additions.
openmetadata-service/​src/​main/​java/​org/​openmetadata/​service/​jdbi3/​TeamRepository.java Adds grant and parent checks to CSV imports.
openmetadata-integration-tests/​src/​test/​java/​org/​openmetadata/​it/​tests/​UserResourceIT.java Tests membership replacement for open and closed teams.
openmetadata-integration-tests/​src/​test/​java/​org/​openmetadata/​it/​tests/​TeamResourceIT.java Tests REST and CSV authorization restrictions.
openmetadata-integration-tests/​src/​test/​java/​org/​openmetadata/​it/​tests/​DomainIsolationIT.java Tests domainless write restrictions and retained in-domain access.
docs/​decisions/​2026-11-02-domain-only-access-grants-full-access-only-inside-the-users-domains.md Records domain-only policy semantics and migration behavior.
docs/​decisions/​2026-10-30-only-admins-add-roles-or-policies-to-a-team.md Records team grant, parent, and membership authorization rules.
bootstrap/​sql/​migrations/​native/​2.1.0/​postgres/​schemaChanges.sql Adds a guarded PostgreSQL policy rewrite.
bootstrap/​sql/​migrations/​native/​2.1.0/​mysql/​schemaChanges.sql Adds the corresponding MySQL policy rewrite.

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 2, 2026 04:34

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.

The repository stores rules sorted by name (allow before deny), so the
exact deny-then-allow comparison skipped installs whose policy was seeded
or edited through the API, leaving them unmigrated. Compare the two rules
by name, effect, resources, operations and condition instead, and cover
both dialects with a database-backed migration test.
A dry run gives a parent named by an earlier row a placeholder id, so a
non-admin re-importing an unchanged nested export had rows rejected for
parents they already have.
Team grants follow the same rule for impersonated callers as user
privileges in UserResource, and team CSV import is not available to them.
Copilot AI balanced review requested due to automatic review settings November 2, 2026 04:51

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.

🔵 Needs a closer look

Missing search translation for inUserDomains() can bypass domain restrictions, while team PATCH processing before authorization leaks protected relationship information.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

Medium severity Authorize PATCH requests before applying patches

openmetadata-service/​src/​main/​java/​org/​openmetadata/​service/​resources/​teams/​TeamResource.java:186

Both PATCH overloads apply the patch before authorizing access to the target team, so an unauthorized caller can distinguish matching relationship values or valid array indexes (403) from failed test operations or invalid indexes (patch errors). This reveals protected role and parent relationships. Run the canonical PATCH authorization before applying the patch in the shared helper, and add regressions showing that matching and nonmatching probes are both rejected with 403.

6 resolved since last review

Review effort: Balanced

Untranslated functions are dropped from the search filter, so a policy
using inUserDomains() was filtered as if the clause were absent. It maps
to the hasDomain() query without the clause that keeps documents in no
domain; a user with no domains matches nothing.
Copilot AI balanced review requested due to automatic review settings November 2, 2026 05:03

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

Restore the original allow rule and add a deny rule for creating,
editing or deleting policies, roles, teams, users and bots in no domain,
and bots in any domain. This drops inUserDomains() and its search
translation; the deny covers no view operation, so search is unchanged.
The migration appends the rule to every stored policy that lacks it.
Copilot AI balanced review requested due to automatic review settings November 2, 2026 05:24

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@sonika-shah
sonika-shah added this pull request to the merge queue Nov 2, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 2, 2026
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — failed_checks (2026-11-02T23:09:26Z)

Blocked the queue: integration-tests-mysql-elasticsearch

@sonika-shah
sonika-shah added this pull request to the merge queue Nov 3, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 3, 2026
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — failed_checks (2026-11-03T05:03:55Z)

Blocked the queue: playwright-summary

Failed Playwright tests:

  • Pages/AIProfile/ProfileMembers.spec.ts › Should navigate from the admins page to a team detail

Copilot AI balanced review requested due to automatic review settings November 3, 2026 05:57
@sonika-shah
sonika-shah enabled auto-merge November 3, 2026 05:57

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@sonika-shah
sonika-shah added this pull request to the merge queue Nov 3, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 3, 2026
@github-actions github-actions Bot added the merge conflict Conflicts with the latest main; removed from the merge queue label Nov 3, 2026
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — merge_conflict (2026-11-03T16:11:50Z)

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

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

# Conflicts:
#	openmetadata-service/src/main/java/org/openmetadata/service/resources/teams/UserResource.java
Copilot AI balanced review requested due to automatic review settings November 4, 2026 03:59
@github-actions github-actions Bot removed the merge conflict Conflicts with the latest main; removed from the merge queue label Nov 4, 2026

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@gitar-bot

gitar-bot Bot commented Nov 4, 2026

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

🔴 High risk · Tightening team-grant and domain-only authorization plus migrating stored policies could deny legitimate administration by domain-scoped users or team owners.

Tightens team and domain-only authorization so team grants, parents and membership are checked against the resulting state, and extends DomainOnlyAccessPolicy to administration resources. Resolved the inUserDomains() handling of entity-less write contexts, which now treats them as writes rather than listings. No open issues remain.

✅ 2 closed
✅ Security: inUserDomains() treats any entity-less context as a listing, writes included

📄 openmetadata-service/src/main/java/org/openmetadata/service/security/policyevaluator/RuleEvaluator.java:258-265 📄 openmetadata-service/src/main/resources/json/data/policy/DomainAccessPolicy.json:19-25 📄 docs/decisions/2026-11-02-domain-only-access-grants-full-access-only-inside-the-users-domains.md:17-19
inUserDomains() returns true whenever resourceContext.getEntity() is null. The comment says this is for listings that are filtered per item, but plenty of write paths also authorize against an entity-less new ResourceContext<>(type), and none of them filter per item. Examples: EntityResource.deleteStaleEntities (DELETE, then bulkDeleteStaleEntities runs with no per-item check), OpenLineageResource.postLineage (EDIT_LINEAGE on ResourceContext<>(TABLE)), and AIGovernanceFrameworkResource.authorizeFork (CREATE). A user whose only grant is DomainOnlyAccessRole therefore keeps All operations there and can delete or edit resources outside their domains. That contradicts the new ADR, which says changing anything in no domain now needs another role. Fix: have the All rule match only single resources inside the user's domains (return false when the entity is null) and let the ViewAll/hasDomain() rule cover listings. If entity-less writes must keep working, scope the exemption by operation instead.

Closed: Bug: CSV parent check doesn't exempt the Organization, unlike REST and ADR

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TeamRepository.java:1473-1482 📄 docs/decisions/2026-10-30-only-admins-add-roles-or-policies-to-a-team.md:22-23
The REST check in TeamResource skips the edit check when the added parent is ORGANIZATION_NAME, and the updated ADR says the organization is exempt in team CSV import too. rejectParentsNotEditable only exempts the import root, parents the team already has, and teams created in the same file. So when a non-admin team owner imports a row that places a team (new or existing) directly under Organization, canEditParent is called on the Organization and the row is rejected with "which you cannot edit", while the same change over REST succeeds. Fix: add ORGANIZATION_NAME.equals(parent.getName()) to alreadyAllowed.

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

@sonika-shah
sonika-shah enabled auto-merge (squash) November 4, 2026 04:02
@sonika-shah
sonika-shah merged commit bed6fa8 into main Nov 4, 2026
62 of 65 checks passed
@sonika-shah
sonika-shah deleted the fix/team-edit-checks branch November 4, 2026 04:03
@sonarqubecloud

sonarqubecloud Bot commented Nov 4, 2026

Copy link
Copy Markdown

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.

5 participants