Skip to content

Fixes #35840: only admins can change a user's domains (backport 2.0 #35845) - #35846

Merged
manerow merged 2 commits into
2.0from
fix/35840-user-own-domains-2.0
Oct 21, 2026
Merged

manerow merged 2 commits into
2.0from
fix/35840-user-own-domains-2.0

Conversation

@manerow

@manerow manerow commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Backport of PR #35845 to 2.0, for 2.0.6. The commit is a clean cherry-pick: the change is the same as on main (identical git patch-id --stable), only its line numbers differ.

Problem

Any user could add a domain to their own profile, with PATCH /v1/users/{id} or PUT /v1/users, and hasDomain() then treated them as a member of that domain. With a rule such as "allow EditAll when hasDomain()" they could edit that domain's assets and move them into their own domain, which gets around the fix for #33420 (PR #35798 on this branch). Through PUT this also worked for users with the built-in DomainOnlyAccessRole, and a non-admin allowed to edit other users could give them any domain the same way.

What this PR changes

Domains join the admin-only checks UserResource already applies to roles, isAdmin, isBot and closed teams:

  • PATCH: any operation on /domains needs an admin.
  • PUT: adding a domain the user does not already hold as their own needs an admin. Sending the domains they already have, or none, works as before.
  • POST and self sign-up: a create request that names domains needs an admin.

What users will notice

Only admins can change a user's domains, as on main. Every other self-edit keeps working, and the user profile page already shows the domain control to admins only.

How it was tested

  • The seven new tests in UserResourceIT pass on this branch, on Postgres and MySQL. On untouched 2.0 the four that change behavior fail, on both databases.
  • The live checks against running servers were done on main (PR Fixes #35840: only admins can change a user's domains #35845); the code they exercise is the same here.

Fixes #35840

RetriggerView in GreptileConfidence Score: 4/5

The repository's Java style requirements still need to be satisfied before merging.

Findings

  1. P2 Domain tests are too long ▶
  2. P2 New parameters miss required final ▶
  3. P2 Tests repeat shared strings ▶

Summary

Adds admin-only checks for assigning domains to users.

  • Only admins can add or change a user's domains.

Reviews (2) · Last reviewed commit: "Test that a team's domain cannot be clai..." · Reviewed by Greptile

@manerow
manerow requested a review from a team as a code owner October 21, 2026 08:23
@manerow
manerow requested review from mohityadav766 and removed request for a team October 21, 2026 08:23
@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.

@manerow
manerow requested a review from sonika-shah October 21, 2026 08:23
@github-actions github-actions Bot added backend safe to test Add this label to run secure Github workflows on PRs labels Oct 21, 2026
// ===================================================================

@Test
void test_patchUser_ownDomains_forbiddenForNonAdmin(TestNamespace ns) {

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.

P2 New parameters miss required final

The seven new tests leave ns non-final, although CLAUDE.md requires final on parameters that do not change. Add final to these new TestNamespace parameters to satisfy the repository requirement before merging.

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

HttpMethod.PATCH,
"/v1/users/" + patched.getId(),
addDomainsOp(testDomain().getEntityReference()));
admin.getHttpClient().executeForString(HttpMethod.PUT, "/v1/users", userBodyWithDomain(put));

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.

P2 Tests repeat shared strings

The new tests repeat "/v1/users" and "domains" as literals. CLAUDE.md requires a named constant when a string appears more than once. Reuse or define constants for these values to satisfy the repository requirement before merging.

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

}

@Test
void test_putUser_keepsOwnDomainButCannotClaimTeamDomain(TestNamespace ns) {

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.

P2 Domain tests are too long

test_putUser_keepsOwnDomainButCannotClaimTeamDomain combines team creation, user creation, two requests, and stored-state checks in one long method. CLAUDE.md requires small, focused methods and says to aim for 15 lines or fewer. Extract the setup and request checks into named helpers before merging. The new self-signup test has the same problem.

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@gitar-bot

gitar-bot Bot commented Oct 21, 2026

Copy link
Copy Markdown
Code Review ✅ Approved

🔴 High risk · Making domain assignments admin-only changes authorization and could deny legitimate users domain access, while blocking self-granted access to protected assets.

Restricts user domain changes to admins in UserResource, covering PATCH on /domains, PUT adding unheld domains, and POST/self sign-up requests that name domains, which closes the self-assignment path around the #33420 fix. No issues found.

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

@sonarqubecloud

Copy link
Copy Markdown

@manerow
manerow merged commit 08a02e5 into 2.0 Oct 21, 2026
75 of 78 checks passed
@manerow
manerow deleted the fix/35840-user-own-domains-2.0 branch October 21, 2026 12:14

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.

2 participants