Repository navigation
feat(api)!: check a write to a user against what the user holds - #3562
Conversation
ADR 094 §2, step 2 of its sequence: the catalog's first type below a project. A session's project and user are facts of its row, never tuples: - migrations in all three dialects add session.project, session.user, session.reader and session.revoker, with reader and revoker closing from the session's user and from admin on its project; - domain.AuthzImpliedTuplesets names the relations no assignment holds, the compiler refuses any other relation that can hold none, and ValidateAssignment refuses every assignment naming a session or an implied tupleset; - CheckSessionUser reads the implied session.user tuple by primary key, and the resolver answers a session relation as the session's own user first, then as admin on its project through the full project Check; - the oracle mirrors it, and a cross-dialect test holds the resolver and its foothold to the oracle for the session's user, another user, an admin, an owning team's member, an editor, a viewer, an operator, the project secret and a stranger. No gate asks a session relation yet; the next commit moves them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmTQoT7kemXw7jcdBJ3
ADR 094 §3, the gates of step 2 of its sequence: - getSession asks session#reader and revokeSession session#revoker: the session's own user, an admin of its project (an owning team's member included) and operators. A by-id gate of a resource with relations of its own (resourceAccess.object) asks that relation of the resource. - querySessions asks admin on the project: each session records the IP and user agent its user signed in from. - listEvents and getEvent answer a request's metadata.client.ip and user_agent only to an admin of the project, the events half of the ADR's escalation path 6; the admin question runs after the gate allowed, through the gate's resolver. The gate contract names the session relations and the reason the list asks admin; the permission catalog drops session.read from project_viewer; the ADR marks step 2 built. Only a project secret reaches the session operations today, and it administers its own project, so nothing changes for them until a person's credential is admitted; the events change is what viewers notice, and the changeset says so. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmTQoT7kemXw7jcdBJ3
ListActiveAuthzAssignmentsByPrincipal answers what a team holds across projects, which ADR 094 §7's team rule needs to know before a membership confers it. It reads the principal index in each dialect, skips revoked grants and leaves expiry to the caller, with a parity test on all three. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmTQoT7kemXw7jcdBJ3 (cherry picked from commit f190acc)
ADR 094 §4 and §7, step 4 of its sequence. A write that can take over or lock out a user needs the caller to hold, on every project, at least each role the user holds there, and platform#operator when the user does: - setUserPassword and both passkey registrations ask admin, not the project-secret plane alone, and run the cover check; the Console cookie stays off them until step 5 opens the plane by class. - deleteUser runs the cover check after its admin gate. - updateUser asks admin and the cover check when the patch changes the schema's x-identifier attribute or moves the user to a schema that designates another; a dry run answers the same. - On the reserved platform project these are operators' only for another user's account. A membership confers the team's roles (#3470): createTeamMembership and createUser with team_id ask the caller to hold each of them; to a team that owns a project only an active member of it or an operator adds one, and deactivateTeam on a team holding grants elsewhere asks the same. Refusals answer the operation's permission_denied with details.details.reason (target_holds_more, operators_only, owning_team_members_only) and never name what the target holds. The check costs one ListAuthorizedProjects page for a target who holds nothing elsewhere and at most a handful of CheckProjects otherwise. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmTQoT7kemXw7jcdBJ3 (cherry picked from commit cce80dc)
…operator Until #1261 brings ADR 054 §8's recovery path, the team rule leaves an owning team with no active member to the deployment's operators, whom platform.operators names wherever owning teams exist. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmTQoT7kemXw7jcdBJ3 (cherry picked from commit 3158ce2)
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 73be250 The changes in this PR will be included in the next version bump. This PR includes changesets to release 27 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The cover check counted every role a target held anywhere. On a deployment without a platform project any project's secret may grant a role to any user, so an outsider could stop a project from deleting, resetting or re-identifying its own user by granting that user something (review of step 4, finding 1). The check now counts what a target holds only for a user or team of the platform project, the case ADR 094 §4 is about. Elsewhere the home project's admin decides: a project that grants a role to another project's principal trusts that project with the principal's identity and roster, as it already does with its status (ADR 053 §4). ADR 094 §4 says so. TestCoverCheckLeavesAProjectItsOwnUsers runs the reviewer's scenario end to end on a harness without a platform project, which the integration harness can now build; TestCredentialTierCoversTheTarget holds path 2 for a secret of the platform project. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmTQoT7kemXw7jcdBJ3 (cherry picked from commit 61d0643)
The check sent every project the target is listed on to one CheckProjects statement, one UNION ALL arm per project. The review of step 4 measured 73 s and a 5.9 GB backend at 840 projects on Postgres 16, and a 500 at 501 on SQLite (finding 2). Now an operator covers every target and an active member of a team covers what it confers, so neither is walked; the walk asks ten projects a statement, the caller first, and stops at the first project the caller does not cover; and it decides at most 200 of a target's projects, refusing a target who holds roles on more with operators_only. TestCoverCheckIsBounded holds it with a target on 1,200 projects (refused in 15 ms on Postgres, 62 ms on SQLite; an operator passes in 11 ms) and the deepest walk over 200 (0.35 to 0.95 s on Postgres, 1.3 s on SQLite). On the Spanner emulator the same cases take 87 to 96 s, nearly all of it in the listing statement listMyProjects shares. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmTQoT7kemXw7jcdBJ3 (cherry picked from commit d7a154d)
ADR 094 asked for an operator to write another platform user's credentials, identifiers or deletion, and left an owning team without an active member to operators. A deployment may name none (platform.operators is empty, as on zitadel start), and there nobody could (review of step 4, finding 3). Where no operator is named, the platform project's admins stand in, under the cover check, and may add a member to an owning team that has no active member: ADR 054 §8's recovery path, marked in the request's events with the new authorization.path owning_team_recovery. Where one is named, both stay the operator's. HasActiveTeamMember, in all three dialects with a parity test, tells an ownerless team. zitadel start's bootstrap admin holds no role on the platform project, so there nobody writes another user's credentials, before ADR 094 or after; TestCoverCheckWithoutAnOperator runs a deployment as it makes one, shows that, and that an admin of the platform project does these writes, recovers an ownerless team, and loses both once an operator is named. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmTQoT7kemXw7jcdBJ3 (cherry picked from commit 7174ff9)
deleteTeamMembership asked only admin on the team's project, so an admin of the platform project who is no operator removed any but the last owner from a customer's owning team, locking them out of the customer's projects (review of step 4, finding 4; also so on main). Removing a member ends the roles the team gave them, so it takes the rule adding one does (ADR 094 §7): for a team of the platform project, the caller holds each role the team confers, and from an owning team only its active members or an operator remove one. TestCoverCheck holds it end to end; the last-owner and membership tests remove as the operator. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmTQoT7kemXw7jcdBJ3 (cherry picked from commit 3715287)
The gate contract cited TestTeamMembershipRule, which did not exist, and nothing tested requireTeamDeactivation or the half of ADR 094 §7 about a team's grants on other projects (review of step 4, finding 5). TestTeamRuleHoldsWhatTheTeamConfers holds both: a caller who holds less than a grant of the team is refused on adding, removing and deactivating, one who holds as much passes, an active member is not asked, and deactivating a team that owns a project is left to the service. The operators-only rule on the reserved platform project is now held end to end by TestCoverCheckWithoutAnOperator. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmTQoT7kemXw7jcdBJ3 (cherry picked from commit 980e780)
The bounded walk asked the caller first and the target only where the caller held less, at the same role. A project the target is listed on but holds no role on now, as a deactivated user's direct grant, then passed as soon as the caller held any role there, though ADR 094 §4 counts it as admin: the grant comes back with the user. A viewer of a customer project re-identified and deleted a deactivated admin of it (second review of step 4, item 1). Where the caller holds less than admin, the walk now first asks whether the target holds a role there at all, and refuses if not. Still at most six statements a chunk of ten. TestCoverCheckCountsAnInactiveTargetAsAdmin fails without the change; TestCoverWalkIsChunkedAndStopsEarly asserts the chunks and the early stop the bound test only logged. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmTQoT7kemXw7jcdBJ3 (cherry picked from commit 8639153)
The reserved platform project's id is fixed, so on a database that outlives a test run, as a local Postgres does, the next run found the last run's project with keys an earlier master key encrypts, and minting a session for it failed. The harness now deletes such a project before creating its own. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmTQoT7kemXw7jcdBJ3 (cherry picked from commit 960bcf4)
Deactivating a team cascades to the users whose lifecycle it owns (ADR 024) and drops their memberships, with no proj.last_owner refusal. Deactivating the lifecycle team of an owning team's only member emptied the owning team without refusal, and a platform admin then recovered it and read the customer's project (second review of step 4, item 2). - TeamService.Delete records, before the cascade, the owning teams the lifecycle-owned users are active members of, and refuses with proj.last_owner when the cascade leaves one without an active member: ADR 054 §8's amendment calls team deactivation administration, so it may no more end a last owner than a removal may. - On the platform project, deactivating a team that owns the lifecycle of an active account is an operator's alone, since it deactivates customer accounts. No production code sets a lifecycle owner yet. ADR 094 §7 records both and the open question of who may deactivate such a team once lifecycle owners ship. The reviewer's scenario runs end to end in TestCoverCheckWithoutAnOperator and fails without the change. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmTQoT7kemXw7jcdBJ3 (cherry picked from commit ae807b8)
ADR 054 §8's recovery lets an admin of the platform project add an owner to an owning team without an active member, where no operator is named. The gate it sits in is shared by adding and removing a member, so the recovery admitted removals from such a team too (second review of step 4, item 5). It now admits additions only; TestCoverCheckWithoutAnOperator shows a removal refused with owning_team_members_only and fails without the change. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmTQoT7kemXw7jcdBJ3 (cherry picked from commit 81c80cf)
The platform admins' stand-in asked whether any platform#operator grant was live. That is also false when platform.operators lists an operator whose user is not seeded yet, or after the last operator's account is deleted, so a deployment that names an operator could hand its platform admins the stand-in (second review of step 4, item 4). The handler now records, from the configuration, whether platform.operators names anyone (WithPlatformOperatorsNamed), and the stand-in asks that: the configuration is the root of trust (ADR 075 §4), and it takes no statement. The harness names operators by default, as the hosted cloud does; the reserved harness names none, as zitadel start does. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmTQoT7kemXw7jcdBJ3 (cherry picked from commit 23597c2)
A target on more than 200 projects is refused with operators_only, which an operator alone passes. On a deployment that names no operator nobody passes it, and the refusal did not say what to do (second review of step 4, item 3). It now says to list one in platform.operators: the bound stays an operator's, since the walk it stops is what can take a database down, and naming an operator is the configuration's call. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmTQoT7kemXw7jcdBJ3 (cherry picked from commit ba67286)
- The reset in TestCoverCheckWithoutAnOperator went through a session cookie, which the credential tier does not take yet, so it answered 401 and the test only asserted "not 403" (item 6). It now resets with a secret of the platform project and asserts the service's own answer, past every permission check. - TestTeamRuleHoldsWhatTheTeamConfers now adds and removes a member through requireTeamMembershipChange, the real gate, and not only through the cover functions behind it. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmTQoT7kemXw7jcdBJ3 (cherry picked from commit c86747e)
The second review asked whether createUser's team_id is a way into a team the cover check never sees. It is not: a membership's team is one of the user's own project, a foreign key in every dialect, so an admin of another project cannot create a user into a team of the platform project. The refusal answered 500 internal, though, as did any team_id that names no team of the project. It now answers 400 user.invalid, read after the transaction because Spanner can report the key at commit. TestCoverCheck creates a user of a customer project into a platform owning team and asserts the 400 on SQLite, Postgres and Spanner. ADR 094 §7 lists the ways to a membership: an invitation grants a role on the inviting project and joins no team. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmTQoT7kemXw7jcdBJ3 (cherry picked from commit 62e7a61)
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Whether an operator is named is read from platform.operators, not from a live platform#operator grant, yet the one test that named an operator also seeded its grant, so a check that went back to reading grants would have passed it (review of PR #3562 at 8bc9715). TestCoverCheckWithoutAnOperator now names an operator in configuration, asserts no operator's grant is live, and shows an admin of the platform project refused both the deletion of another account (operators_only) and the recovery of an ownerless owning team (owning_team_members_only). With operatorNamed reading live grants instead, this subtest fails and no other does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmTQoT7kemXw7jcdBJ3
A Handler whose platformOperatorsNamed was never set read it as "no operator named", which hands the platform project's admins the operator's stand-in. Only cmd/server sets it today, so a future constructor that forgot it would quietly widen access (review of PR #3562 at 8bc9715). An unset flag now counts as named: only a configuration that names no operator grants the stand-in. TestPlatformProjectUsersAreOperatorsOnly shows a handler built without it refusing the admin with operators_only and admitting no recovery, and fails without the change; the stand-in case now says its configuration names none. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmTQoT7kemXw7jcdBJ3
Whether an operator is named is read from platform.operators, not from a live platform#operator grant, yet the one test that named an operator also seeded its grant, so a check that went back to reading grants would have passed it (review of PR #3562 at 8bc9715). TestCoverCheckWithoutAnOperator now names an operator in configuration, asserts no operator's grant is live, and shows an admin of the platform project refused both the deletion of another account (operators_only) and the recovery of an ownerless owning team (owning_team_members_only). With operatorNamed reading live grants instead, this subtest fails and no other does. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmTQoT7kemXw7jcdBJ3
A Handler whose platformOperatorsNamed was never set read it as "no operator named", which hands the platform project's admins the operator's stand-in. Only cmd/server sets it today, so a future constructor that forgot it would quietly widen access (review of PR #3562 at 8bc9715). An unset flag now counts as named: only a configuration that names no operator grants the stand-in. TestPlatformProjectUsersAreOperatorsOnly shows a handler built without it refusing the admin with operators_only and admitting no recovery, and fails without the change; the stand-in case now says its configuration names none. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmTQoT7kemXw7jcdBJ3
The review of PR #3562 at 8bc9715 left four hardening items that matter only once a lifecycle owner exists on the platform project, which no production code sets yet. ADR 094 §7 now lists them beside the open question on lifecycle-team deactivation, as conditions for that feature: the stand-in that deactivation deliberately gives no one, the unbounded read of a team's lifecycle users, the missing project-row lock in ensureOwningTeamsKeepAMember, and the ownership read the handler leaves to the service. The stand-in bullet now names that exception and says that a server never told about operators counts one as named. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmTQoT7kemXw7jcdBJ3
main holds this branch's base as one squash commit (#3551). Its tree is the base's final head merged with the main before it, which this branch already holds, so the squash is recorded as merged and nothing changes. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
main gained a person's own sessions (#3560), which the permission catalog lists beside this branch's session relations: both stay on the session.read row. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
…check main gained personal access tokens (#3563) beside everything this branch's base already held. The server and the test harness wire both the operators' flag and the token service. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
A personal access token acts as its owner, so the cover check holds it as it holds the owner's session: on a deployment that names no operator, an admin of the platform project's token writes a user its owner covers and is refused one who holds more, on an update and on a delete, for the same reason. The harness's token service takes the platform project the harness has, so a harness without one stays without one. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
main holds this branch's base, the session gates, as one squash commit (#3552). Its tree is the base's final head merged with the main before it, which this branch already holds, so the squash is recorded as merged and nothing changes. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
There was a problem hiding this comment.
🟡 Changes recommended
Concurrent recovery requests can bypass healthy-team membership restrictions, while credential admission rules block legitimate deactivation of platform-homed teams with foreign-project grants.
3 open issues
What changed in this PR
Implements ADR 094’s authorization checks for sensitive user writes and team membership changes, protecting platform accounts based on the roles they hold.
Changes:
- Requires admin access and role coverage for credential, identifier and deletion operations.
- Adds owning-team membership rules, recovery checks and deactivation safeguards.
- Updates storage queries, tests, API contracts, generated code and release guidance.
| File | Description |
|---|---|
packages/go/api/oas_validators_gen.go |
Validates recovery authorization metadata. |
packages/go/api/oas_schemas_gen.go |
Adds recovery metadata and last-owner errors. |
packages/go/api/oas_json_gen.go |
Updates generated JSON handling. |
docs/design/api/system-permission-catalog.md |
Documents revised permission requirements. |
docs/adrs/094-project-permission-model.md |
Records implementation decisions and limits. |
apps/cli/skills/zitadel-cli/SKILL.md |
Explains role-coverage refusals. |
apps/api/internal/storage/stmttest/authz_test.go |
Tests cross-project assignment queries. |
apps/api/internal/storage/stmttest/authz_membership_edge_test.go |
Tests active-member detection. |
apps/api/internal/storage/dialect/sqlite/authz_membership_edge.go |
Adds SQLite active-member lookup. |
apps/api/internal/storage/dialect/sqlite/authz_assignment.go |
Adds SQLite principal-grant lookup. |
apps/api/internal/storage/dialect/spanner/authz_membership_edge.go |
Adds Spanner active-member lookup. |
apps/api/internal/storage/dialect/spanner/authz_assignment.go |
Adds Spanner principal-grant lookup. |
apps/api/internal/storage/dialect/postgres/authz_membership_edge.go |
Adds PostgreSQL active-member lookup. |
apps/api/internal/storage/dialect/postgres/authz_assignment.go |
Adds PostgreSQL principal-grant lookup. |
apps/api/internal/service/user.go |
Checks identifier changes and maps invalid teams. |
apps/api/internal/service/team.go |
Guards against last-owner deactivation cascades. |
apps/api/internal/service/team_test.go |
Tests deactivation cascade safeguards. |
apps/api/internal/service/statement.go |
Declares new authorization queries. |
apps/api/internal/service/mocks/service.mock.go |
Regenerates statement mocks. |
apps/api/internal/domain/schema_designation.go |
Detects identifier changes. |
apps/api/internal/domain/schema_designation_test.go |
Tests identifier-change detection. |
apps/api/internal/domain/event.go |
Defines recovery audit metadata. |
apps/api/internal/domain/authz.go |
Defines authorization refusal reasons. |
apps/api/internal/api/user.go |
Applies sensitive-write and membership checks. |
apps/api/internal/api/user_passkey_registration.go |
Applies credential-tier authorization. |
apps/api/internal/api/team.go |
Applies team authorization checks. |
apps/api/internal/api/integration_test/team_membership_test.go |
Uses operators for owning-team mutations. |
apps/api/internal/api/integration_test/last_owner_test.go |
Updates last-owner authorization fixtures. |
apps/api/internal/api/integration_test/helpers/token.go |
Supports optional platform projects. |
apps/api/internal/api/integration_test/helpers/server.go |
Configures deployment authorization variants. |
apps/api/internal/api/integration_test/helpers/project.go |
Supports reserved and absent platform projects. |
apps/api/internal/api/integration_test/helpers/invitation.go |
Supports standalone invitation fixtures. |
apps/api/internal/api/integration_test/helpers/harness.go |
Adds deployment configuration variants. |
apps/api/internal/api/integration_test/helpers/grant.go |
Supports standalone grant fixtures. |
apps/api/internal/api/integration_test/helpers/event.go |
Supports standalone event fixtures. |
apps/api/internal/api/integration_test/grant_test.go |
Uses operator authorization for deletion. |
apps/api/internal/api/integration_test/cover_test.go |
Tests user and team role coverage. |
apps/api/internal/api/integration_test/cover_standalone_test.go |
Tests home-project authority without a platform. |
apps/api/internal/api/integration_test/cover_reserved_test.go |
Tests operator fallback and team recovery. |
apps/api/internal/api/integration_test/cover_bound_test.go |
Exercises coverage limits and timing. |
apps/api/internal/api/handler.go |
Tracks configured operator presence. |
apps/api/internal/api/generated/oas_validators_gen.go |
Validates recovery metadata. |
apps/api/internal/api/generated/oas_unimplemented_gen.go |
Refreshes generated operation documentation. |
apps/api/internal/api/generated/oas_server_gen.go |
Refreshes generated handler documentation. |
apps/api/internal/api/generated/oas_schemas_gen.go |
Adds recovery metadata and error types. |
apps/api/internal/api/generated/oas_json_gen.go |
Updates generated JSON handling. |
apps/api/internal/api/generated/oas_handlers_gen.go |
Refreshes generated endpoint documentation. |
apps/api/internal/api/cover_internal_test.go |
Tests coverage rules and bounds. |
apps/api/internal/api/authz.go |
Adds admin-write and membership authorization. |
apps/api/internal/api/authz_later_checks_internal_test.go |
Documents coverage-test locations. |
apps/api/internal/api/authz_contract_internal_test.go |
Updates credential and membership contracts. |
apps/api/cmd/server/server.go |
Supplies configured operator presence. |
apps/api/api/openapi/endpoints/users/methods.yaml |
Documents membership rules and invalid teams. |
apps/api/api/openapi/endpoints/users/by_id/password/methods.yaml |
Documents password-write authorization. |
apps/api/api/openapi/endpoints/users/by_id/passkeys/registrations/methods.yaml |
Documents registration-start authorization. |
apps/api/api/openapi/endpoints/users/by_id/passkeys/registrations/by_id/methods.yaml |
Documents registration-completion authorization. |
apps/api/api/openapi/endpoints/users/by_id/methods.yaml |
Documents identifier and deletion checks. |
apps/api/api/openapi/endpoints/teams/by_id/methods.yaml |
Documents deactivation safeguards. |
apps/api/api/openapi/endpoints/teams/by_id/memberships/methods.yaml |
Documents membership and recovery rules. |
apps/api/api/openapi/endpoints/teams/by_id/memberships/by_id/methods.yaml |
Documents membership-removal authorization. |
apps/api/api/openapi/endpoints/teams/by_id/deactivateTeam-error-response.yaml |
Adds the last-owner error response. |
apps/api/api/openapi/components/schemas/event-metadata.yaml |
Adds recovery authorization metadata. |
apps/api/api/openapi/bundled/openapi.json |
Refreshes the bundled API contract. |
.changeset/create-user-unknown-team.md |
Announces invalid-team error correction. |
.changeset/cover-check.md |
Announces breaking authorization changes. |
Review effort: Balanced
| if len(owned) == 0 && gateErr != nil { | ||
| return "", gateErr | ||
| } | ||
| if err := h.requireTeamHeld(ctx, teamAccess, projectID, teamID, held, owned, gateErr == nil && adding); err != nil { |
| return nil, err | ||
| } | ||
| // Deactivating a team ends what its members hold through it (ADR 094 §7). | ||
| if err := h.requireTeamDeactivation(ctx, projectID, string(params.TeamID)); err != nil { |
|
|
||
| if teamID != nil { | ||
| // A membership in the team confers its roles (ADR 094 §7). | ||
| if err := h.requireTeamCover(ctx, userAccess, string(params.ProjectID), *teamID); err != nil { |
…onsent Brings in main at eaced99 (#3552, #3562, #3564). The CLI's api-coverage test keeps only the two consent operations as not called: the personal access token commands now call theirs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137eGmUEzNb3SNs7Rj5USYf


Context
Step 4 of ADR 094's sequence (§4 and §7), closing its escalation paths 2 to 5: a write that can take over or lock out a user, and a team membership that confers a project role, did not look at what the user holds or would gain. Stacked on the session gates (#3552); it does not depend on step 3 (#3553).
Summary
internal/api/cover.go). After the gate allows, the caller must hold, on every project, at least each role the target holds there, andplatform#operatorwhen the target holds it. The target's roles are whatlistMyProjectswould answer for them: oneListAuthorizedProjectspage, thenCheckProjectsfromadmindown. A refusal answers the operation'spermission_deniedwithdetails.details.reason(target_holds_more,operators_only,owning_team_members_only) and never names what the target holds.admin:setUserPassword,createUserPasskeyRegistrationandcompleteUserPasskeyRegistrationaskadminon the user's project and run the cover check.openCredentialTieris gone;TestCredentialTierOperationsAskAdminpins the relation. The Console cookie stays off them until step 5 opens the plane by class.deleteUserruns the cover check after itsadmingate.updateUserasksadminand the cover check when the patch changes the attribute the schema designates withx-identifier, or moves the user to a schema that designates another (domain.IdentifierChanged); a dry run answers the same.operators_only). The cover check still runs, so an operator does not touch another operator's account unnoticed.createTeamMembershipandcreateUserwithteam_idask the caller to hold each of them. To a team that owns a project, only an active member of that team or an operator adds one; the gate asks that membership instead ofadminon the platform project, so a customer can add a co-owner.deactivateTeamon a team holding grants elsewhere asks the same; a team that owns a project is still refused withteam.owns_project.ListActiveAuthzAssignmentsByPrincipal(all three dialects, parity test) reads what a team holds across projects.Validation
Run by the session that wrote the change, in its cloud container, on its working branch:
go test -tags {sqlite,postgres}_integration ./internal/...pass.TestCoverCheck,TestCredentialTierCoversTheTargetand the last-owner, team-membership, grant and user integration tests;stmttest -run TestAuthz(the new parity test included). All pass.spanner.ymlruns weekly on main and on dispatch, not on a pull request. It needs dispatching on this branch before this is trusted on Spanner.go test ./...inapps/apipasses, apart from threecmd/servermux tests that need the Console'sdist, which the container does not build.TestCoverCheckholds paths 3, 4 and 5 and the owner, operator and ownerless-team cases;TestCredentialTierCoversTheTargetholds path 2 for a project secret. Unit:TestCredentialTierOperationsRunTheCoverCheck,TestPlatformProjectUsersAreOperatorsOnly,TestCredentialTierOperationsAskAdmin,TestIdentifierChanged,TestAuthzAssignmentStatements_ListActiveByPrincipal.go generatechanges only descriptions; the error sets and the Go client's API are unchanged. The OpenAPI lint reports 0 errors.Run again by the coordinating session, on all sixteen commits cherry-picked onto
claude/authz-session-gates(three for the change, five and eight for the two rounds of fixes). The branch differs from the writing session's last head only by step 3's files, which are #3553's:go build ./...inapps/apigo test ./internal/api/ ./internal/domain/ ./internal/service/ ./internal/authz/...go test -tags sqlite_integration ./internal/api/integration_test/(the whole package) and./internal/storage/stmttest/ -run 'Authz|Team'node scripts/check-pr-title.mjs --title "…"Release notes / changeset
.changeset/cover-check.md(@zitadel/serverminor with a Breaking note;@zitadel/clipatch for the skill)..changeset/create-user-unknown-team.md(@zitadel/serverpatch):createUserwith ateam_idthat names no team of the project answers 400 instead of 500.Notes
Reviewed three times. The first independent review found five problems (listed below with their fixes). A second verified those fixes, found two closed and two new holes opened; a third round of commits answered each. A third reviewer then read the whole change as an attacker at
8bc971579, removed each third-round fix in a scratch worktree and reran the tests. Its verdict: safe to merge as it is. It found no path by which someone who is neither an operator nor covers the target sets their password, registers a passkey, changes their identifier, deletes them or gains a role through a team; no error path that allows a write; and the change no less safe than its base for a project secret, a Console session, a person's token and an operator. The second review's holes are closed, each held by a test that fails without its fix.The second review's findings and their fixes:
viewercould re-identify and delete a deactivated user who holdsadmin. It counts asadminagain.TestCoverCheckCountsAnInactiveTargetAsAdminholds it, andTestCoverWalkIsChunkedAndStopsEarlynow asserts the chunking and the early stop.409 proj.last_owner, as a removal would be, and on the platform project only an operator deactivates a team that owns the lifecycle of an active account. This needed a decision ADR 094 does not make; the stricter behaviour is built and the question is written into §7. The reviewer's scenario runs end to end inTestCoverCheckWithoutAnOperator.platform.operators), not from live assignments, which were also empty when a listed operator had not been seeded or their account had been deleted.platform.operators.createUserwith ateam_idof another project answered500; it now answers400 user.invalid(second changeset,.changeset/create-user-unknown-team.md). The membership's team must belong to the user's own project, by a foreign key in all three dialects, so this is not a way into another project's team. Invitations grant a project role and never a team membership.Security review, and what it changed. An independent review ran the built server and measured. It found no way around the check (a
null, a schema move and a dry run are covered), no error path that allows the write, and nothing a refusal reveals. It raised five points, each fixed here in a commit of its own and held by a test:TestCoverCheckLeavesAProjectItsOwnUsersruns the reviewer's exact scenario over HTTP. The hosted cloud was not exposed, since grants there need a principal homed in the platform project.operators_onlyand a message, never a 500. Worst case: about 120CheckProjectsstatements, one listing and two operator checks.TestCoverCheckIsBoundedmeasures it (table below).metadata.authorization.pathowning_team_recovery, a new enum value). Where an operator is named, both stay the operator's.TestCoverCheckWithoutAnOperatorruns on a server set up aszitadel startsets it up.deleteTeamMembershipnow takes the same rule as adding one.operators_onlyon the reserved platform project is exercised end to end.A corrected premise. On a server as
zitadel startmakes it, nobody holds a role on the platform project: the bootstrap import makes a user and a team membership and grants nothing. So these writes were impossible there before this change as well. This change had only taken them from deployments that have a platform admin and no operator, which point 3 gives back.Measured by
TestCoverCheckIsBounded:The emulator's time is nearly all in
ListAuthorizedProjects, whichlistMyProjectsshares; it has not been measured on real Spanner.Who notices. An editor no longer changes a user's email or other
x-identifierattribute; the Console's user profile card shows the server's refusal message on save. An admin of the platform project no longer deletes, sets the password of or changes the identifier of another account there, nor adds members to a customer's owning team; an operator does. A project secret is refused for a user who also holds a role on another project, sozitadel user deleteandzitadel api setUserPasswordcan now answertarget_holds_more(the skill says so). No SDK or API-mock caller needed a change.Cost in the common case. A target who is not homed in the platform project: nothing is counted. A platform-homed target who holds nothing elsewhere: one
ListAuthorizedProjectsstatement. The walk rarely runs: on the reserved platform project a non-operator is refused before it unless no operator is named, and operators and owning-team members skip it.Ownerless owning teams (Implement ownerless-team recovery (ADR 054 §8: last-owner refusal, needs_owner, platform-admin rescue) #1261). Until Implement ownerless-team recovery (ADR 054 §8: last-owner refusal, needs_owner, platform-admin rescue) #1261 brings ADR 054 §8's recovery path, an owning team with no active member gets a member from an operator only;
TestCoverCheckholds it. Owning teams exist only on a platform project, andplatform.operatorsnames an operator wherever there is one, so a deployment can always recover.Decisions taken for review:
zitadel startname its bootstrap admin an operator? Not built. It would be oneNEXTGEN_PLATFORM_OPERATORSentry in the launchers, would give the local admin authority over every project on the local server, and would change what the local Console lists.x-identifier. The alternative is a fixed list of attributes (email,username).admin, since the write would outlast a reactivation.Left open, recorded in ADR 094: a schema move that keeps the identifier's designation needs only
editorand could break a user's sign-in (a lockout, not a takeover); anddeactivateTeammust run the user check for each team-owned user once lifecycle owners ship, which no production code sets today.Related work: [BE] Remove a passkey and end the user's other sessions #3484 and [BE] Issue a passkey enrollment link for a user #3485 add credential-tier operations, which
credentialTierPathwill flag forcredentialTierOperations. feat(console): add a Users tab to the team page with lifecycle owners and Add user #2332 (Console team Users tab with Add user) will meet the owning-team rule.Written in the session https://claude.ai/code/session_0137eGmTQoT7kemXw7jcdBJ3; the commits were cherry-picked onto the session-gates branch and the draft opened by the coordinating session below.
https://claude.ai/code/session_0137eGmVSt2DgYJj2CjZbi1U
Generated by Claude Code