Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
# Only an admin adds roles or policies to a team

- **Status:** Accepted
- **Revisions:** v1 2026-10-30 (initial) · v2 2026-11-13 (MCP `create_entity` applies the same check) · v3 2026-11-26 (user CSV import applies the closed-team rule)
- **Revisions:** v1 2026-10-30 (initial) · v2 2026-11-13 (MCP `create_entity` applies the same check) · v3 2026-11-26 (user CSV import applies the closed-team rule) · v4 2026-12-03 (Guard adds the tests for leaving a closed team)
- **Deciders:** Sonika Shah
- **Guard:** `TeamResourceIT` (`test_ownerCannotAddRolesOrPoliciesToOwnTeam`,
`test_ownerCannotAddRolesToOwnTeamThroughPut`, `test_ownerCanOnlyMoveOwnTeamUnderTeamTheyCanEdit`,
`test_importCsv_ownerCannotAddRolesToTeams`, `test_importCsv_ownerCannotPlaceTeamUnderTeamTheyCannotEdit`,
`test_importCsv_ownerDryRunReimportsNestedHierarchy`),
`BotImpersonationIT.test_impersonatedAdmin_cannotAddTeamRolesOrImportTeams`,
`UserResourceIT`
(`test_patchUser_joinClosedTeamWithReplace_forbiddenForNonAdmin`),
(`test_patchUser_joinClosedTeamWithReplace_forbiddenForNonAdmin`,
`test_nonAdmin_cannotLeaveClosedTeam`),
`UserTeamAssignmentPrivilegeIT` (`test_selfUpdate_cannotLeaveClosedTeam`,
`test_selfUpdate_canLeaveOpenTeam`, `test_adminRemoval_fromClosedTeam_stillWorks`),
`CreateEntityToolTest#aNonAdminCannotCreateATeamWithDefaultRoles`,
`UserImportPrivilegeEscalationIT` (closed-team cases)

Expand Down Expand Up @@ -50,3 +53,8 @@ User CSV import, direct and `importAsync`, applies the same closed-team check as
in, as a `PATCH` is. The check lives in `UserRepository.changesClosedTeamMembership`, which
`UserResource` and the user importer both call, so the two cannot drift. A dry run reports the
same rejection as a real run.

## Amendment: Guard adds the tests for leaving a closed team (v4)

No rule changes. The Guard list adds the tests that cover a user leaving a team that is
not joinable.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import java.util.List;
import java.util.UUID;
import org.junit.jupiter.api.Test;
Expand All @@ -28,9 +29,8 @@
/**
* Members of a team hold the team's {@code defaultRoles} as inherited roles and are governed by the
* team's policies, so adding a user to a team that is not open to everyone grants privileges the
* same way naming a role does. {@code PATCH /v1/users/{id}} has always required an administrator for
* it; these tests pin the same rule onto {@code POST /v1/users} and {@code PUT /v1/users}, which
* carry the membership in the request body instead of a JSON patch.
* same way naming a role does, and leaving one sheds them the way dropping a role does. These tests
* pin that rule onto {@code POST /v1/users}, {@code PUT /v1/users} and {@code PATCH /v1/users/{id}}.
*
* <p>The negative controls matter as much as the rejections: the guard is delta-based, so joinable
* teams, unchanged membership and administrators all have to keep working.
Expand Down Expand Up @@ -174,6 +174,76 @@ void test_adminAssignment_toClosedTeam_stillWorks(TestNamespace ns) {
"An admin must still be able to move a user into a closed team");
}

@Test
void test_selfUpdate_cannotLeaveClosedTeam(TestNamespace ns) throws Exception {
// Swapping the closed team for an open one leaves it as surely as removing it outright.
Team closedTeam = createTeam(ns, "leaveclosed", false, dataStewardRoleId());
Team openTeam = createTeam(ns, "leaveswap", true, null);
Joiner joiner = createJoiner(ns, "leaver", closedTeam.getId());

OpenMetadataException byPut =
assertThrows(OpenMetadataException.class, () -> joiner.putTeams(List.of(openTeam.getId())));
assertEquals(403, byPut.getStatusCode(), "Leaving a closed team by PUT: " + byPut.getMessage());
OpenMetadataException byPatch =
assertThrows(OpenMetadataException.class, () -> joiner.patchTeams(List.of(openTeam)));
assertEquals(
403, byPatch.getStatusCode(), "Leaving a closed team by PATCH: " + byPatch.getMessage());

User stored = fetchMembership(joiner.user());
assertTrue(teamIds(stored).contains(closedTeam.getId()), "The user must stay in the team");
assertFalse(teamIds(stored).contains(openTeam.getId()), "The swap must not half-apply");
assertTrue(
roleNames(stored).contains(DATA_STEWARD), "The team's default role must stay in force");
}

@Test
void test_selfUpdate_canLeaveOpenTeam(TestNamespace ns) {
Team firstTeam = createTeam(ns, "leaveopen1", true, null);
Team secondTeam = createTeam(ns, "leaveopen2", true, null);
Joiner joiner = createJoiner(ns, "openleaver", firstTeam.getId());

joiner.putTeams(List.of(secondTeam.getId()));
List<UUID> afterPut = teamIds(fetchMembership(joiner.user()));
assertFalse(afterPut.contains(firstTeam.getId()), "Leaving an open team by PUT stays allowed");
assertTrue(afterPut.contains(secondTeam.getId()));

joiner
.client()
.getHttpClient()
.executeForString(HttpMethod.PATCH, usersPath(joiner.user()), removeFirstTeam());
assertFalse(
teamIds(fetchMembership(joiner.user())).contains(secondTeam.getId()),
"Leaving an open team by PATCH stays allowed");
}

@Test
void test_adminRemoval_fromClosedTeam_stillWorks(TestNamespace ns) {
Team closedTeam = createTeam(ns, "adminrm", false, null);
Team otherClosedTeam = createTeam(ns, "adminrm2", false, null);
OpenMetadataClient admin = SdkClients.adminClient();

Joiner patched = createJoiner(ns, "adminrmpatch", closedTeam.getId());
admin
.getHttpClient()
.executeForString(HttpMethod.PATCH, usersPath(patched.user()), removeFirstTeam());
assertFalse(
teamIds(fetchMembership(patched.user())).contains(closedTeam.getId()),
"An admin must still be able to remove a user from a closed team by PATCH");

Joiner moved = createJoiner(ns, "adminrmput", closedTeam.getId());
admin
.getHttpClient()
.executeForString(
HttpMethod.PUT,
"/v1/users",
body(moved.user().getName(), moved.user().getEmail(), otherClosedTeam.getId()));
List<UUID> afterPut = teamIds(fetchMembership(moved.user()));
assertFalse(
afterPut.contains(closedTeam.getId()),
"An admin must still be able to move a user out of a closed team by PUT");
assertTrue(afterPut.contains(otherClosedTeam.getId()));
}

@Test
void test_selfUpdate_cannotReachAdminThroughRolesOrBots(TestNamespace ns) throws Exception {
// The whole escalation walk in one place: neither the direct role grant nor the bot create is
Expand Down Expand Up @@ -225,6 +295,15 @@ void putRoles(List<String> roleIds) {
put("\"roles\":" + jsonIds(roleIds));
}

void patchTeams(List<Team> teams) {
ArrayNode references = MAPPER.createArrayNode();
teams.forEach(
team -> references.addObject().put("id", team.getId().toString()).put("type", "team"));
ArrayNode patch = MAPPER.createArrayNode();
patch.addObject().put("op", "replace").put("path", "/teams").set("value", references);
client.getHttpClient().executeForString(HttpMethod.PATCH, usersPath(user), patch);
}

private void put(String privilegedField) {
client
.getHttpClient()
Expand Down Expand Up @@ -292,6 +371,17 @@ private String body(String name, String email, UUID teamId) {
return "{\"name\":\"" + name + "\",\"email\":\"" + email + "\",\"teams\":[\"" + teamId + "\"]}";
}

private static String usersPath(User user) {
return "/v1/users/" + user.getId();
}

/** Removes the user's only team, so the index is unambiguous. */
private static ArrayNode removeFirstTeam() {
ArrayNode patch = MAPPER.createArrayNode();
patch.addObject().put("op", "remove").put("path", "/teams/0");
return patch;
}

private User fetchMembership(User user) {
return SdkClients.adminClient().users().get(user.getId().toString(), MEMBERSHIP_FIELDS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"default": null
},
"isJoinable": {
"description": "Can any user join this team during sign up? Value of true indicates yes, and false no.",
"description": "Can users join or leave this team on their own? When false, only an admin (by editing the user) or someone allowed to edit the team's users (by editing the team) can add or remove members.",
"type": "boolean",
"default": true
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
"default": null
},
"isJoinable": {
"description": "Can any user join this team during sign up? Value of true indicates yes, and false no.",
"description": "Can users join or leave this team on their own? When false, only an admin (by editing the user) or someone allowed to edit the team's users (by editing the team) can add or remove members.",
"type": "boolean",
"default": true
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"$ref" : "#/definitions/teamHierarchyList"
},
"isJoinable": {
"description": "Can any user join this team during sign up? Value of true indicates yes, and false no.",
"description": "Can users join or leave this team on their own? When false, only an admin (by editing the user) or someone allowed to edit the team's users (by editing the team) can add or remove members.",
"type": "boolean",
"default": true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4783,7 +4783,7 @@ om:isHidden a rdf:Property ;
om:isJoinable a rdf:Property ;
om:projectionStatus om:Stored ;
rdfs:label "isJoinable" ;
rdfs:comment "Can any user join this team during sign up? Value of true indicates yes, and false no. Set on om:Team." ;
rdfs:comment "Can users join or leave this team on their own? When false, only an admin (by editing the user) or someone allowed to edit the team's users (by editing the team) can add or remove members. Set on om:Team." ;
rdfs:domain om:Team ;
rdfs:range xsd:boolean .

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ export interface CreateTeam {
*/
externalId?: string;
/**
* Can any user join this team during sign up? Value of true indicates yes, and false no.
* Can users join or leave this team on their own? When false, only an admin (by editing the
* user) or someone allowed to edit the team's users (by editing the team) can add or remove
* members.
*/
isJoinable?: boolean;
name: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ export interface Team {
*/
inheritedRoles?: EntityReference[];
/**
* Can any user join this team during sign up? Value of true indicates yes, and false no.
* Can users join or leave this team on their own? When false, only an admin (by editing the
* user) or someone allowed to edit the team's users (by editing the team) can add or remove
* members.
*/
isJoinable?: boolean;
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ export interface TeamHierarchy {
href?: string;
id: string;
/**
* Can any user join this team during sign up? Value of true indicates yes, and false no.
* Can users join or leave this team on their own? When false, only an admin (by editing the
* user) or someone allowed to edit the team's users (by editing the team) can add or remove
* members.
*/
isJoinable?: boolean;
/**
Expand Down Expand Up @@ -89,7 +91,9 @@ export interface ChildElement {
href?: string;
id: string;
/**
* Can any user join this team during sign up? Value of true indicates yes, and false no.
* Can users join or leave this team on their own? When false, only an admin (by editing the
* user) or someone allowed to edit the team's users (by editing the team) can add or remove
* members.
*/
isJoinable?: boolean;
/**
Expand Down
Loading