diff --git a/docs/decisions/2026-10-30-only-admins-add-roles-or-policies-to-a-team.md b/docs/decisions/2026-10-30-only-admins-add-roles-or-policies-to-a-team.md index 887a4cad5474..bb8225d33acb 100644 --- a/docs/decisions/2026-10-30-only-admins-add-roles-or-policies-to-a-team.md +++ b/docs/decisions/2026-10-30-only-admins-add-roles-or-policies-to-a-team.md @@ -1,7 +1,7 @@ # 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`, @@ -9,7 +9,10 @@ `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) @@ -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. diff --git a/openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/UserTeamAssignmentPrivilegeIT.java b/openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/UserTeamAssignmentPrivilegeIT.java index 3ac84189fdd7..21a32f6adf51 100644 --- a/openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/UserTeamAssignmentPrivilegeIT.java +++ b/openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/UserTeamAssignmentPrivilegeIT.java @@ -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; @@ -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}}. * *

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. @@ -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 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 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 @@ -225,6 +295,15 @@ void putRoles(List roleIds) { put("\"roles\":" + jsonIds(roleIds)); } + void patchTeams(List 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() @@ -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); } diff --git a/openmetadata-spec/src/main/resources/json/schema/api/teams/createTeam.json b/openmetadata-spec/src/main/resources/json/schema/api/teams/createTeam.json index 9bf97ffbb4c3..239c885d39b2 100644 --- a/openmetadata-spec/src/main/resources/json/schema/api/teams/createTeam.json +++ b/openmetadata-spec/src/main/resources/json/schema/api/teams/createTeam.json @@ -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 }, diff --git a/openmetadata-spec/src/main/resources/json/schema/entity/teams/team.json b/openmetadata-spec/src/main/resources/json/schema/entity/teams/team.json index 6c8aa3b28ada..f5858d5b3259 100644 --- a/openmetadata-spec/src/main/resources/json/schema/entity/teams/team.json +++ b/openmetadata-spec/src/main/resources/json/schema/entity/teams/team.json @@ -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 }, diff --git a/openmetadata-spec/src/main/resources/json/schema/entity/teams/teamHierarchy.json b/openmetadata-spec/src/main/resources/json/schema/entity/teams/teamHierarchy.json index 019fc75dd78d..49b61809d93c 100644 --- a/openmetadata-spec/src/main/resources/json/schema/entity/teams/teamHierarchy.json +++ b/openmetadata-spec/src/main/resources/json/schema/entity/teams/teamHierarchy.json @@ -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 } diff --git a/openmetadata-spec/src/main/resources/rdf/ontology/openmetadata.ttl b/openmetadata-spec/src/main/resources/rdf/ontology/openmetadata.ttl index 9eec0f82163e..fce1df45edeb 100644 --- a/openmetadata-spec/src/main/resources/rdf/ontology/openmetadata.ttl +++ b/openmetadata-spec/src/main/resources/rdf/ontology/openmetadata.ttl @@ -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 . diff --git a/openmetadata-ui/src/main/resources/ui/src/generated/api/teams/createTeam.ts b/openmetadata-ui/src/main/resources/ui/src/generated/api/teams/createTeam.ts index ec9356378754..251bdca422bf 100644 --- a/openmetadata-ui/src/main/resources/ui/src/generated/api/teams/createTeam.ts +++ b/openmetadata-ui/src/main/resources/ui/src/generated/api/teams/createTeam.ts @@ -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; diff --git a/openmetadata-ui/src/main/resources/ui/src/generated/entity/teams/team.ts b/openmetadata-ui/src/main/resources/ui/src/generated/entity/teams/team.ts index afa1e39dd7d2..fb015d59e787 100644 --- a/openmetadata-ui/src/main/resources/ui/src/generated/entity/teams/team.ts +++ b/openmetadata-ui/src/main/resources/ui/src/generated/entity/teams/team.ts @@ -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; /** diff --git a/openmetadata-ui/src/main/resources/ui/src/generated/entity/teams/teamHierarchy.ts b/openmetadata-ui/src/main/resources/ui/src/generated/entity/teams/teamHierarchy.ts index f9278f6bb33b..2a49cff38c01 100644 --- a/openmetadata-ui/src/main/resources/ui/src/generated/entity/teams/teamHierarchy.ts +++ b/openmetadata-ui/src/main/resources/ui/src/generated/entity/teams/teamHierarchy.ts @@ -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; /** @@ -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; /**