diff --git a/docs/adrs/094-project-permission-model.md b/docs/adrs/094-project-permission-model.md new file mode 100644 index 0000000000..5041b7bd11 --- /dev/null +++ b/docs/adrs/094-project-permission-model.md @@ -0,0 +1,731 @@ +# ADR 094: Projects Carry the Permission Model, the Platform Is Its Root + +> **Status:** Proposed +> **Date:** 2026-12-02 +> **Amends:** [ADR 075](075-platform-operators.md) §6 and its rejected +> alternative "A separate listing and a capability read for operators" (an +> operator listing), [ADR 036](036-api-credential-planes.md) (which operations +> take a person's credential), [ADR 054](054-customer-collaboration-grants.md) +> §9 (the shape of effective access, with the operator path among its sources), +> [ADR 092](092-mcp-server.md) §4 and §6 (which operations are tools, and who +> is asked), [ADR 082](082-oauth-and-oidc-server.md) §3 (who skips consent on +> the platform issuer) +> **Related:** [ADR 033](033-internal-permission-management.md), +> [ADR 053](053-cross-project-principals.md) §9, +> [ADR 082](082-oauth-and-oidc-server.md) §3, +> [ADR 086](086-invitations.md), +> [ADR 092](092-mcp-server.md) §4 and §8, +> [Console ADR 0004](../../apps/console/docs/adrs/0004-console-deployment-modes.md) §5, +> [#3470](https://github.com/zitadel/nextgen/issues/3470) + +## Context + +Zitadel's workload lives in projects: each one holds its own users, teams, +sessions, applications, sign-in configuration, releases and deployments. The +deployment's platform is the root above them and its back office. Its project +holds the hosted cloud's customer accounts, the teams that own customer +projects (ADR 054), the Console's sign-in and the platform issuer. Its +operators (ADR 075) administer every project. + +The catalog already reads this way. `platform.operator` closes to +`project.admin` on every project through the implied `project.platform` +tupleset (ADR 075 §1). The API does not. It shows no platform. It presents +the platform project as one more project. And it answers some questions about +a project only to a project secret, so the people who run a project, and the +operators above them, cannot ask them. + +On 2026-12-01 a person connected an MCP client to the hosted cloud as its +bootstrap admin, an operator, and had it investigate: + +- **"Who is admin here?" was empty.** `listProjectMembers` lists owning teams + and grants. An operator holds neither, so the platform project's list was + empty, with nothing to say why. +- **The agent could not tell the platform project from a customer's.** Its + users are every customer's account, not one customer's users. +- **An operator was refused what the check allows.** About thirty operations + accept only a project secret, so every person is refused before the check + runs, an operator included. Among them are `querySessions` and `getSession`, + whose sessions record the IP and user agent each began with: the one-call + answer to "where did this person sign in from". The agent pieced it together + from events instead, in 19 calls. +- **A person's agent cannot find its own projects.** The `/users/me` reads, + `listMyProjects` among them, accept only a session cookie. + +Three gaps sit under those symptoms. Each is a gap in the project model, not +in the platform: + +1. **Nothing below a project has relations of its own.** Every gate asks + `viewer`, `editor` or `admin` on a project, so a session is read by + everyone who can view its project and by nobody else, its own user + included. +2. **Which credential an operation takes was decided operation by operation** + (ADR 036), and recorded in `userBoundSessionOperations`, a list kept for + another purpose (zitadel/nextgen#3538). +3. **A write to a user does not look at what the user holds.** Today the + project-secret-only plane keeps a platform-project editor from setting an + operator's password (the gate contract's `openCredentialTier`). That + protects the platform project only by accident, and it fails as soon as a + person's credential is admitted. + +## Decision + +### 1. The shape: a root, projects, and objects below a project + +- **One permission model, per project.** Every project, the platform + project included, has the same types, relations and gates. Nothing in the + model names the platform project. +- **The platform enters the model at one point:** `operator from platform` + on `project.admin`. An operator holds `admin` on every project through that + edge, and every role closes from `admin`. Nothing else reaches across + projects, except the cross-project grants of ADR 053. +- **The platform project is a project with back-office contents.** Its users + are customer accounts, its teams own customer projects, and its sign-in is + the Console's. Two rules hold for it because of those contents, and both are + stated in project terms so they apply anywhere the same contents appear: + - the configuration that signs people in to it is written by its admins + only (`requirePlatformConfigurationAdmin`, Console ADR 0004 §1); + - a write to a user is checked against what that user holds on other + projects (§4). On the platform project that protects the customers' + projects and the operators. +- **Objects below a project get relations of their own** when their access + differs from their project's roles. Sessions are the first (§3). Their + parent and their owner are implied from their own row, never stored as + tuples. + +### 2. The catalog + +The seeded catalog after this ADR, in the OpenFGA form the earlier ADRs use. +The first five types are unchanged. `session` is new. + +```text +type user + +type team + relations + define member: [user] + +type platform + relations + define operator: [user] # issued by configuration only (ADR 075 §4) + +type project + relations + define platform: [platform] # implied: the deployment's one platform + define team: [team] # the owning team (ADR 054 §2) + define admin: [user, team#member] or member from team or operator from platform + define editor: [user, team#member] or admin + define viewer: [user, team#member] or editor + +type session + relations + define project: [project] # implied: sessions.project_id + define user: [user] # implied: sessions.user_id + define reader: user or admin from project + define revoker: user or admin from project +``` + +**Implied tuplesets.** A relation whose comment says "implied" holds no rows. +Its tuple is a fact about the object, read from where the object is stored: + +| Tupleset | Read from | Resolved by | +|---|---|---| +| `project.platform` | the deployment: every project | SQL, the operator path (`writePlatformOperatorExists`), as today | +| `session.project` | `resource_scope_index` (`resource_kind = 'session'`), which already holds every session's project | the resolver: it asks `admin` on that project with a full Check | +| `session.user` | `sessions.user_id`, with the session's project | the resolver: it compares the caller, a user homed in the session's project, with the session's user, and asks nothing | + +- **The resolver, not SQL, follows `session.project`.** A Check of + `session#reader` becomes two questions: is the caller the session's user, + and does the caller hold `admin` on the session's project. The second is + the Check the gates already ask, so it already includes owning teams, + grants, team grants and the operator path. Nothing in + `writePlatformOperatorExists` changes: its edge filter takes only tupleset + `platform`, so the session's edges never match it. +- **Nothing writes a session tuple.** `ValidateAssignment` refuses any + assignment whose `object_type` is `session`, as it refuses a malformed + platform one (`ErrPlatformAssignmentShape`). A relation that only the row + decides cannot be granted around the row. +- **Lists need no new predicate.** `querySessions` gates project-wide on + `admin`: an admin's list is every session of the project, and anyone else + is refused. A person lists their own sessions with `listMySessions` (§6), + whose filter is `user_id`, not a resolver predicate. `resource_scope_index` + gains no column. +- **Migrations, one per dialect** (Postgres, SQLite, Spanner, each at its + next number), additive like `platform_operator`: + - `authz_relations`: `(session, project)`, `(session, user)`, + `(session, reader)`, `(session, revoker)`; + - `authz_relation_references`: `session.project → project`, + `session.user → user`; + - `authz_expression_edges`, for each of `reader` and `revoker`: a + `computed_userset` on `session.user` at position 0, and a + `tuple_to_userset` with source `project.admin` and tupleset + `session.project` at position 1; + - `authz_relation_closure`: the reflexive rows, and the two the compiler + derives from the computed usersets, `session.user` to `session.reader` + and to `session.revoker` (`compiler.go`, `directImplications`). No + existing closure changes. Nothing can match them, since no assignment + names `session` (below). + - The `Down` deletes exactly these rows, as `platform_operator`'s does. +- **The compiler and the oracle learn the implied set.** `domain` gains + `AuthzImpliedTuplesets`, `{project.platform, session.project, session.user}`. + The compiler refuses an implied tupleset that is not in that set, so a new + one is a decision. The oracle (`resolver/oracle.go`) mirrors the resolver + for `session`, and its property tests cover the session's user, a + project admin, an operator, a viewer and a stranger. + +### 3. Sessions + +Decided on 2026-12-02. A session is read and revoked by its own user, by an +administrator of its project ("a project owner" means `admin`), and by +operators. Viewers and editors no longer read sessions. + +| Operation | Today | After | +|---|---|---| +| `getSession` | `viewer` on the project, project secret only | `session#reader` | +| `revokeSession` | `admin` on the project, project secret only | `session#revoker` | +| `querySessions` | `viewer` on the project, project secret only | `admin` on the project | +| `listMySessions` (new, §6) | none | the caller's own sessions | + +- `admin from project` includes the owning team's members (ADR 054 §3), + everyone granted `admin`, and the operators. A project secret holds + `project.admin`, so nothing changes for it. +- On the platform project, a customer reads and ends their own Console + sessions. An admin of the platform project reads every customer's, and an + admin of a workload project reads that project's sessions. That is the + "owners and operators" rule, stated per project. +- A session read never answers the session's token. `getSession` and + `querySessions` keep no `x-zitadel-returns-secret`, and a test holds it + (§5). +- The permission catalog's `project_viewer` bundle drops `session.read`. + +### 4. Writes to a user are checked against what the user holds + +Decided on 2026-12-02: an administrator of the user's project, or an +operator, may set another person's password. The draft added that only an +operator sets an operator's password. This section states that rule as a +property of every project. + +Decided on 2026-12-02: the cover check applies on every project. + +**The rule.** A write that can take over or lock out a user needs `admin` on +the user's project, and the caller must cover the target. The caller covers +the target when, for every role the target holds on any project, the caller +holds at least that role there, and, when the target holds +`platform.operator`, the caller holds it too. + +- **Where it applies:** + - the credential tier: `setUserPassword`, `createUserPasskeyRegistration`, + `completeUserPasskeyRegistration`, and any later factor reset + (`credentialTierPath`); + - minting or rotating a credential that acts as another principal: a + principal client's secret or key, and a PAT owned by someone else + (identity model). Each is account takeover by another name; + - `deleteUser` (lockout); + - `updateUser` when it changes an attribute a sign-in identifies by (the + email or the username). Decided on 2026-12-02: such a change asks + `admin`, raised from `editor`, on every project, since it is a takeover + path. The catalog's `user.write` row already warns that an editor + changing identifiers is safe only while no sign-in trusts the email + alone; this closes it before `magic_link` or `otp` arrive. +- **How it is computed.** The target's roles are what `listMyProjects` would + answer for the target: their direct grants, their team grants and their + owning-team memberships, with the role each gives. The caller must hold at + least that role on each of those projects. Each is one `CheckProjects` + call, which is already one statement for the grants and at most one for + the operator path. +- **It is a later check, not a relation.** "Holds everything the target + holds" compares two principals' whole grant sets, which no OpenFGA relation + expresses. It runs after the gate, like `requirePlatformConfigurationAdmin`, + and its rows go in `authz_later_checks_internal_test.go`. A refusal answers + the operation's `permission_denied` with its own reason, + `target_holds_more`, so an agent can say why. It does not name the + project or role the caller lacks, which would tell them what the target + holds. +- **It holds only at the moment of the write.** A credential set for a user + who holds nothing yet stays when that user later gains a role. On a + workload project that is the project's own business. On the platform + project, where every account can come to own customer projects, it is + not, so there the credential tier, identifier changes and deletion of + another user are **operators' only** (decided on 2026-12-02: those are + customer accounts, so an admin setting one would be an account takeover). +- **What it does on each kind of project:** + - On a workload project, whose users hold no role elsewhere, it is just + `admin`. + - On the platform project, writes to another user's credentials or + identifiers are operators' only, as above. The cover check still runs, + so an operator cannot take over another operator's account unnoticed: + the target's `operator` is a role the caller must also hold, and the + event records both. + - It answers the draft's second open question ("how is 'the user holds + operator' checked"): the operator is one of the roles covered. +- **`openCredentialTier` closes.** The three credential-tier rows move to + `admin`. `TestCredentialTierOperationsRefuseTheSessionCookie` becomes a test + that every credential-tier operation asks `admin` and runs the cover check, + whichever of a project secret, a Console cookie or a person's token calls + it. After that, the cookie may call them too. + +### 5. Which credential an operation takes: one rule + +Decided by the user on 2026-12-02: "We want to have an agent-native IAM so +all operations should be able to go through the MCP but either its a user +through consent OR a PAT or a machine identity (or agent)." And: "MCP is for +managing resources and debuging and building the login UI." + +ADR 036 split the planes. This replaces the per-operation list +(`userBoundSessionOperations`) with three classes the spec carries and a +test holds. + +| Class | Operations | Project secret | Console session | Person's token (consent) | PAT | Machine identity | MCP tool | +|---|---|---|---|---|---|---|---| +| **Management** | everything not below | yes | yes | yes | yes | yes | yes | +| **Application sign-in** | the nine marked `x-zitadel-plane: app`: `createSession`, `exchangeHandoff`, `createAuthAttempt`, `getAuthAttempt`, `createAuthAttemptHandoff`, `createAuthAttemptChallenge`, `verifyAuthAttemptChallenge`, `createUserPasskeyRegistration`, `completeUserPasskeyRegistration` | yes | no | no | no | no | no | +| **Public** | `createFlow`, `getFlowStep`, `submitFlowStep`, `getLive`, `getReady` | anonymous | — | — | — | — | no | + +- **In the management class, the credential's scopes and the principal's + permissions decide, and nothing else.** An operator passes because the + check allows them, not because the plane names them. A person's token, a + PAT and a machine identity are each capped by their scopes. +- **What a PAT and a machine identity hold.** A PAT acts as its owner, + capped by its scopes. A principal client acting for its owner never holds + more than the owner; a client acting as itself holds its own grants, which + stay when the owner loses a role (identity model). ADR 053 §9 makes + platform-homed automation wait for that principal's own record. Decided + on 2026-12-02: this ADR admits a person's token and a Console session; + PATs and machine identities are admitted only once their own ADR (ADR + 036's PAT conditions, the identity model's principal client) is accepted. + Staff automation never holds `operator`. +- **Nothing is hidden for what it returns or takes.** ADR 092 §4's rule that + an operation answering with a credential is never a tool is withdrawn, and + `x-zitadel-takes-secret` hides nothing. Both marks stay, as warnings: + - a scope that reaches a marked operation is never preselected on the + consent screen; + - the operation's event records the mark, the principal and the + `client_id`; + - the tool's description says what the answer or the argument holds. +- **Asking the person before a marked or destructive call (ADR 092 §6).** + Decided on 2026-12-02: the consented scope is the gate, the endpoint asks + only where the client can answer, and a machine is never asked. In two + stages: + - **Until scope choice ships** (PR 3543): consent on main grants all + requested scopes or none (`flowengine/auth_request.go`), and most + marked operations share a scope with harmless ones (`createDeployment` + and `rollbackDeployment` share `deployment.write`; `createInvitation` + shares `project.write`). So the scope is no gate yet. A marked or + destructive call through the endpoint from a client that cannot answer + the question (protocol revision before `2026-07-28`) is **refused**, as + ADR 092 §6 has it today. + - **Once a person can choose scopes, and each marked operation has a scope + of its own** (`user.set_password`, `session.delete`, a new + `deployment.deploy`, `invitation.create`, `application.publish`, + `variable.write`): the scope a person ticked on purpose is the gate. The + endpoint still asks where the client can answer; a client that cannot is + served if its token carries that operation's own scope. + - A machine identity is never asked: its grants are the decision. + - **Today, PR 3542** offers the three operations that answer with a + credential (`publishApplication`, `createProjectClaim`, + `createInvitation`) as tools and asks about none of them: the + `x-zitadel-returns-secret` mark only words the tool's description. That + is consistent with the decision only while those three are not + destructive; marking any of them destructive brings it under the first + stage. +- **What stays with a person's own session.** `getMySession`, + `revokeMySession` and `getMySessionCsrfToken` describe the browser session + that calls them, so they stay cookie-only. The other session-cookie-only + operations are a person's own and take a person's token: the `/users/me` + reads (§6), `updateMyUser`, `completeProjectClaim`, and `lookupInvitation`, + `acceptInvitation`, `rejectInvitation`. +- **`createProjectClaim` keeps the project secret.** A claim is bound to the + hash of the secret that started it (`secretHashOperations`, `claim.go`), + and the secret is what proves the project is the claimant's. A signed-in + person or machine has no project to claim: it creates one under its team + (next item). +- **Two operations take no credential today:** `createProject` and + `getProjectClaimWindow`. `createProject` is management. It takes a + person's token, a PAT or a machine identity and creates the project under + a team the caller may create projects for (ADR 054 §7), with no anonymous + create-then-claim link. Its anonymous form stays for the cloud's sign-up. + `getProjectClaimWindow` belongs to that anonymous flow and stays public. +- **Scopes.** Every management operation names a scope + (`TestEveryOperationAPersonsTokenReachesNamesAScope`). This ADR adds: + - `session.read` and `session.delete`, which the catalog already declares; + - `user.set_password` for the credential tier, the catalog's own split + (the spec names `user.write` there today, which the catalog lists as + drift); + - `platform.read` for `listPlatformOperators` (§9). +- **The tests:** + - `TestEveryOperationTakesTheCredentialsItsClassAdmits` replaces + `userBoundSessionOperations` as the authority. The map stays only for + what it was made for, which operations skip an anonymous building cookie. + - zitadel/nextgen#3538's `TestAPersonsTokenReachesWhatASessionReaches` + holds the same equality from the other side. + - `TestNoOperationAnswersASecretUnmarked` checks every response schema + against `x-zitadel-returns-secret`, and every request schema against + `x-zitadel-takes-secret`. + +What this opens to a person, a PAT and a machine identity, each at its gate: + +| Operation | Gate | Marks | +|---|---|---| +| `querySessions`, `getSession`, `revokeSession` | §3 | `revokeSession` destructive | +| `listIdpRevisions`, `listProjectPreviews`, `listDeploymentVariables` | `viewer` | — | +| `publishBranding`, `publishFlowDefinition`, `publishIdp`, `publishPolicy`, `publishSchema`, `createRelease`, `buildRelease` | `editor`; on the platform project, operators only (below) | — | +| `removeProjectPreview` | `editor` (`whyPreviewRemoval`) | destructive | +| `setVariables`, `deleteVariable` | `editor` | takes a secret | +| `publishApplication` | `editor`; on the platform project, operators only (below) | returns a secret | +| `createInvitation` | `admin` (ADR 086) | returns a secret | +| `setUserPassword` | `admin` and the cover check (§4); on the platform project, operators only | takes a secret, destructive | +| `deactivateTeam` | `admin` and §7's rule | destructive | + +- The last two rows wait for §4 and §7: neither admits a person's credential + before the cover check is enforced. +- The passkey registrations stay on the application plane, out of MCP, + with the other application sign-in calls (decided on 2026-12-02). +- **The platform project's sign-in configuration is operators' only.** Today + its identity providers, flows, schemas, policies, applications and + releases take only a project secret, and the platform project mints none + (ADR 053 §9), so nobody but configuration changes them. Opening them at + `admin` would let an administrator of the platform project, who is not an + operator, publish an identity provider connection and sign in as any user + linked to it, operators included (links resolve by connection and + subject, `flow_sso_identity_resolver.go`). So on the platform project + `requirePlatformConfigurationAdmin` asks `platform#operator` for every + configuration write a person's credential newly reaches (decided on + 2026-12-02: operators only). The writes a Console session already makes + there (origins, deployments) keep today's `admin`. + +### 6. A person's own reads take their token + +- `getMyUser`, `listMyProjects`, `listMyTeams`, `getMyUserSchema`, + `listMyPasskeys`, `listMyIdentityLinks` and `getMyPasswordState` take a + person's token as well as their session. Each names the scope of what it + reads: `user.read`, `project.read`, `team.read` or `schema.read`. +- **New: `listMySessions`** (`GET /users/me/sessions`, `session.read`) + lists the caller's sessions in their home project with the IP and user + agent each began with. It is §2's `session.user` arm as a list. +- **The MCP endpoint's instructions** tell an agent signed in as a person to + start with `getMyUser`, then `listMyProjects`, which answers each project + with its access (§10). + +### 7. Team membership that confers a project role + +#3470: `createTeamMembership` asks `admin` on the team's project, and +`createUser` with `team_id` asks `editor`. On an owning team, that lets an +admin of the platform project, or an editor through `createUser`, make +anyone an admin of a customer's project. + +- **The rule is §4's, applied to the role the membership confers.** Adding a + member to a team needs, on every project the team holds a role on (as + owner or through a team grant), at least that role. Both operations ask + it. +- **Who passes it.** The gate today is `admin` on the team's project, the + platform project for an owning team. With the cover rule on top, only an + operator passes both, and a customer still cannot add a co-owner, which + #3470 asks for. Decided on 2026-12-02: an active member of the team that + owns the project may add a member (they already hold its `admin`), the + gate asks team membership instead of `admin` on the platform project, an + operator may always add one, and an admin of the platform project adds + one only under the recovery path below. +- ADR 054 §8's recovery path stays: an admin of the platform project may add + an owner to an owning team that has no active member. That is the one + exception, it is logged with `authorization.path`, and an operator may + always add one. +- `deactivateTeam` takes a person's credential once this rule lands, under + the same check, since deactivating an owning team ends its owners' access. + +### 8. Who decides that a client skips consent + +The draft kept credential-returning operations to clients the deployment +pins as first-party. The user decided otherwise on 2026-12-02, asked whether +only the CLI should receive secrets: "but an mcp client can already do that +and we do not want to limit what MCP clients can be used as a saas offer, +right?" Every management operation now takes any client the person +consented to (§5). + +What remains of the finding is consent itself: + +- A client metadata document can never claim `first_party`: + `ParseClientDocument` builds the client without it. +- A stored application can. `first_party` is a field of its client + document, written by `publishApplication`, which on the platform project + an admin of the platform project may call. A first-party client of the + platform issuer is asked no consent (ADR 082 §3), so its tokens carry + every scope it asks for, for every customer who signs in to it. +- **Decided on 2026-12-02:** on the platform issuer, the deployment's configuration + names the clients that skip consent (`oauth.first_party_clients`: the + Console, the CLI). The document's flag still decides consent on every + other project's issuer, where the project's own admins are the right + people to decide it. + +### 9. The platform as a resource + +Decided on 2026-12-02. + +- **`getPlatform`** (`GET /platform`) answers the platform project's + `project_id` and, when OAuth is on, the platform issuer, as the Console's + runtime document already does. Any authenticated caller may read it. A + deployment without a platform project answers `404`. +- **`listPlatformOperators`** (`GET /platform/operators`) lists the users who + hold `operator`, each with when the assignment was made and its grantor + (`config`, ADR 075 §4). + - Its gate is `operator` on the platform. Only operators read it. An admin + of the platform project does not. + - Its scope is `platform.read`. A project secret's `project.write` stands + in for every scope (`scopeGranted`, `authz.go`), but a secret still + cannot call it: the gate is `platform#operator`, which only a user + homed in the platform project can hold. + - There is no write. Issuing operators stays configuration. +- **A project says what it is.** The project resource gains `kind`: + `platform` for the platform project, `standard` for any other. It shows to + whoever may read that project. +- **`listProjectMembers` keeps its meaning:** roles held on one project. On + the platform project, its description and its agent note point to + `listPlatformOperators`. + +### 10. Effective access: how a person holds a project + +ADR 054 §9 and Console ADR 0004 §5 planned this. ADR 075 §6 rejected a +capability read ("am I an operator"). This is per project, read from the +check, and is not that read. + +```json +{ + "project_id": "proj_…", + "kind": "standard", + "access": { + "role": "admin", + "sources": [ + { "kind": "owning_team", "team_id": "team_…", "role": "admin" }, + { "kind": "grant", "grant_id": "grant_…", "role": "editor" }, + { "kind": "team_grant", "team_id": "team_…", "grant_id": "grant_…", "role": "viewer" }, + { "kind": "platform_operator", "role": "admin" } + ] + } +} +``` + +- **Where it appears:** `getProject` and every item of `listMyProjects`. + `access` is the caller's, never anyone else's. +- **`role`** is `StrongestProjectRole`. +- **`sources`** lists every path that grants a role, not only the first one + that allowed (decided on 2026-12-02: otherwise removing the strongest + grant leaves access nobody saw). The resolver today stops at the first allow (`CheckPath`), so + this needs one more statement: the caller's active assignments that close + to a project role, plus the operator path. +- **What it answers:** + - An agent learns it runs the deployment from a `platform_operator` source + on any project. + - "Who is admin here", for an operator on the platform project, becomes + `listProjectMembers` (empty, with its note) plus `listPlatformOperators`. +- **The Console replaces its probe.** `readPlatformAccess` + (`apps/console/src/features/platform/access.ts`) reads + `GET /projects/{platform_project_id}` and treats `403` or `404` as "not + yours". It reads `access.role` from the same response instead, and a person + without access still gets the `404`. Each surface still derives itself from + its own target (ADR 054 §10). No screen branches on `platform_operator`. + +### 11. Where the records disagree, and which wins + +| Topic | Permission catalog | Gate contract (`authz_contract_internal_test.go`) | This ADR | +|---|---|---|---| +| Session reads | `project_viewer` bundle holds `session.read` | `QuerySessions`, `GetSession` ask `viewer` | **Decision wins.** `admin` or the session's user; the catalog and the contract both change. | +| Setting a password | `user.set_password` is admin-only and credential-tier (lines 85, 178) | asks `editor`, marked `openCredentialTier` | **The catalog wins**, plus the cover check (§4), and operators only on the platform project; `open` is removed. | +| Passkey registration for another user | under `user.set_password` | asks `editor`, marked `openCredentialTier` | Same as setting a password. | +| A password's scope | `user.set_password` | the spec names `user.write` (catalog drift note) | **The catalog wins**: the scope becomes `user.set_password`. | +| Changing a user's identifiers | `user.write` at `editor`, safe only until email-trusting sign-in | `UpdateUser` asks `editor` | **Decided:** `admin` and the cover check on every project (§4); on the platform project, operators only. | +| Removing a preview | write never implies delete (line 53) | asks `editor`, `whyPreviewRemoval`, marked `openWriteIsNotDelete` | **The contract wins** for previews: removing one ends a preview early and keeps its history. The `open` note stays for `deleteVariable` and `revokeRelease`, which this ADR does not decide. | +| Invitation reads | folded into `team_membership.read`, which viewers hold | ADR 086 asks `admin`, marked `openInvitationRead` | Not decided here. A person's token keeps ADR 086's `admin`. | +| Operators as a role on the platform project | `platform.operator` is not a role on the platform project (line 246) | — | Unchanged: `listPlatformOperators` gates on `platform#operator`, not on `project#admin`. | +| A capability read for operators | — | — | ADR 075 §6 stands for "am I an operator". Effective access per project (§10) amends its "no listing" with `listPlatformOperators`. | + +### 12. Sequence + +Each step must leave the system no less safe than the step before, on its +own. So the checks land before the operations they bound. + +1. **§6:** a person's own reads take their token, and `listMySessions`. This + changes nobody's access to anyone else. +2. **§2 and §3:** the session type in all three dialects, the resolver and + oracle, then the session gates, each with its contract row. +3. **§8:** on the platform issuer, configuration names the clients that + skip consent. Before this, no step may let a person publish an + application on the platform project. +4. **§4 and §7:** the cover check, the credential tier at `admin`, the + operator-only rule for the platform project, and #3470. +5. **§5:** the class rule and its tests, then the operations it opens, with + the platform project's configuration at `platform#operator`, and ADR 092 + §4's amendment. Marked and destructive calls from clients that cannot + answer stay refused until scope choice and per-operation scopes ship. + `createProject` for a signed-in caller follows. +6. **§9 and §10:** the platform resource, `kind`, and effective access; the + Console drops its probe. +7. PATs and machine identities, once their own record is accepted. + +## Escalation paths, and how this closes each + +| # | Path | Today | Closed by | +|---|---|---|---| +| 1 | An admin of the platform project acts deployment-wide | Kept apart by the catalog (ADR 075 §1); nothing lists who is an operator | `platform#operator` stays the only cross-project relation; `listPlatformOperators` gates on it (§9) | +| 2 | An admin or editor of the platform project sets a customer's or an operator's password, or registers a passkey for them, including before the account owns anything | Only the project-secret plane prevents it (`openCredentialTier`) | On the platform project, operators only; elsewhere `admin` plus the cover check (§4). The test holds every credential-tier operation, whichever credential calls it | +| 3 | An editor changes an operator's or a customer's email, then signs in by email | Safe only while no sign-in trusts the email alone (catalog `user.write`) | The cover check on identifier changes (§4) | +| 4 | An admin of the platform project deletes or deactivates an operator's user (lockout) | `deleteUser` asks `admin` | The cover check on `deleteUser` (§4) | +| 5 | An admin of the platform project adds a member to a customer's owning team | Open (#3470): `createTeamMembership` asks `admin`, `createUser` with `team_id` asks `editor` | The membership must not confer more than the caller holds (§7); ADR 054 §8 recovery is the one exception | +| 6 | A viewer reads every session's IP, user agent and `metadata` | The catalog's viewer bundle; events also show a request's `ip` and `user_agent` to viewers | `session#reader` (§3) for sessions. **For events:** `listEvents` and `getEvent` ask `viewer` and answer the request metadata today. Decided on 2026-12-02: `ip` and `user_agent` are answered only to `admin`, as sessions are | +| 7 | Someone grants themselves `session#reader` on another user's session | Not possible yet: no session type | `ValidateAssignment` refuses every `session` assignment (§2) | +| 8 | A credential lands in an outside app's context | No person's token reaches one (#3538 before 049c3080b) | Accepted by the user's decision (§5). Bounded by the operation's scope, never preselected on consent; its event names the principal and `client_id`; the endpoint asks where the client can answer | +| 9 | An admin of the platform project marks an application `first_party`, so the platform issuer asks customers no consent for it | Not possible today: a person cannot publish an application (`security.go`, ADR 092 §4) | On the platform issuer, configuration names the clients that skip consent (§8), landing before any person may publish an application there (§12); and the platform project's configuration is operators' only (§5) | +| 10 | An agent's token, or an admin of the platform project, publishes sign-in configuration for the whole cloud, such as an identity provider that signs in as an operator | Not possible: only a project secret publishes, and the platform project mints none | On the platform project, configuration writes ask `platform#operator` (§5). A deployment through the endpoint is refused for a client that cannot answer the question until per-operation scopes ship (§5) | +| 11 | A variable's secret value, or a password being set, passes through a model's context | Both writes are project-secret-only | Accepted by the user's decision (§5). `x-zitadel-takes-secret` keeps the scope off the consent screen's defaults and records the mark in events | +| 12 | A team secret (`sk_team_`) reaches sessions | — | `session.*` stays off the `sk_team_` allowlist; its Checks answer `NotFound` | + +## Consequences + +### Positive + +- One model per project. The platform adds one edge and one listing, so what + holds for a customer's project holds for the platform project and the other + way round. +- An agent signed in as a person finds its projects, how it holds each one, + who runs the deployment, and where a person signed in, each in one call. +- Account takeover is closed by a rule about what the target holds, not by + which credential plane the caller used. +- Which credential an operation takes is a class in the spec, held by tests. + +### Negative / Risks + +- `session` is the catalog's first type below a project, and the resolver + learns two implied tuplesets. The oracle and its property tests must grow + with it. +- The cover check adds one `CheckProjects` per write to a user. It is cheap + on a workload project and proportional to a customer's projects on the + platform project. +- Viewers lose session reads, and editors lose `setUserPassword`. +- About twenty-five operations change their security in the spec. The SDKs, + the API mock and the CLI follow. +- A person's token, held by an agent, may publish configuration and build + releases. Serving one stays a deployment, which the MCP endpoint asks + before. + +## Related decisions of 2026-12-02 + +Recorded here for the roles ADR, which is not written yet: + +- **Roles.** Viewer, editor and admin stay the only ladder (ADR 054 §5). + There is no `user_manager` role and no `supporter` level. A help-desk + person is a viewer who is granted the single permissions they need; a + named bundle can follow. Staff support is an operator giving one staff + member a viewer grant on one project, with an expiry. +- **The project secret** shrinks to an application's sign-in calls and local + development once PATs and service accounts exist. No date is set, and it + keeps working until people have moved. +- **Invitations** take the grant scopes (`grant.create`, `grant.read`, + `grant.delete`), which answers the permission catalog's open question 8 + (zitadel/nextgen#3538). + `createInvitation` with `replaces_invitation_id` deletes the original, so + it also asks `grant.delete`, and `grant.read` when it carries the + original's metadata over. +- **`cancelInvitation`** is not asked about before it runs: cancelling is + how a leaked invitation link is ended, and a client that cannot answer + the endpoint's question must be able to end one (zitadel/nextgen#3542). +- **A leaked client secret** is replaced through a dedicated rotate + operation, in its own change; today only a retry with the request's + `Idempotency-Key` replaces it, which a tool cannot send. +- **`search`** asks each result type's own read scope of a person's token. +- **The roles ADR** waits until someone builds help-desk permissions; the + decisions above are its record until then. + +## Open questions + +None. Decided on 2026-12-02 and folded in: +- every management operation goes through the MCP endpoint (§5); +- asking before a call, in two stages (§5); +- who skips consent on the platform issuer (§8); +- the cover check on every project (§4); +- the platform project's sign-in configuration is operators' only (§5); +- passkey registration stays on the application plane (§5); +- identifier changes ask `admin` (§4); +- another platform-project user's credentials and deletion are operators' + only (§4); +- who adds a member to an owning team (§7); +- PATs and machine identities wait for their own ADR (§5); +- request `ip` and `user_agent` in events go to admins only; +- effective access lists every source (§10). + +## Rejected alternatives + +### Taking the platform out of the project machinery + +A platform stored apart from projects would need its own users, teams, +sign-in, issuer and release. The project machinery provides each one, and +the API can present the platform as its own resource without moving it. + +### Rules that name the platform project + +"Only an operator sets an operator's password", or "an admin of the platform +project may not touch customer accounts", would each be an exception keyed on +the platform project. The cover check (§4) gives the same answer there and +the right one on every other project. + +### Listing operators as members of every project + +Every customer would see the deployment's staff in their member list. ADR +075 §5 shows customers what operators change, not who could. + +### An "am I an operator" read + +It would be the capability read ADR 075 rejected, and the Console would +branch on it, which ADR 054 §10 forbids. Effective access with its sources +answers the same question per project, from the check. + +### Letting operators alone past the credential plane + +Admitting an operator's credential on the project-secret-only operations, +and no one else's, makes operators a special case of a question every person +asks. Opening them by class and letting the gate decide gives operators the +same result through the same path. + +### Session tuples written at sign-in + +They would double every sign-in's writes, and could disagree with the +session they describe (ADR 033 §2). The session's row already says whose it +is and where it lives. + +### Keeping session reads at `viewer` + +It shows every viewer the IP, user agent and `metadata` of everyone's +sessions, and still leaves a person unable to read their own. + +### Keeping credential-returning operations from outside clients + +The first draft admitted them only for clients the deployment pins, never +through MCP. The user rejected that on 2026-12-02: an agent-native IAM offers +every management operation to every client a person consents to, and a SaaS +offer cannot pick which MCP clients its customers use. + +### Hiding operations that take or return a secret from MCP tools + +ADR 092 §4 did this for answers; the draft extended it to requests. It would +leave an agent unable to register an application, claim a project, invite a +person or set a variable. The marks now warn instead of hiding (§5). + +## Documentation impact + +- ADR 075 §6: the operator listing is §9 of this ADR; operators appear as an + effective-access source (§10). +- ADR 054 §9: the effective-access shape; §8: the cover rule for + owning-team membership (§7). +- ADR 036: the credential classes (§5) replace the per-operation list. +- ADR 092 §4: an operation that returns a credential is a tool; the marks + warn instead (§5). §6: who is asked, and when (§5). +- `docs/design/api/system-permission-catalog.md`: the `session` type, + `session.read` out of `project_viewer`, `user.set_password` as the spec's + scope, `platform.read`, and the cover check under the credential tier. +- `apps/api/api/openapi/AGENTS.md`: `x-zitadel-takes-secret` and the class + rule. +- ADR 082 §3: on the platform issuer, configuration names the clients that + skip consent (§8). +- `apps/api/internal/storage/AGENTS.md`: implied tuplesets are never + assignments. +- The API reference and the agent notes (ADR 092 §3) for the new and changed + operations; the MCP endpoint's instructions (§6). +- The CLI's commands, `zitadel login` publishing, and `SKILL.md`. +- `apps/docs/content/docs/guides/investigate-with-events.mdx`: where a person + signed in, from `listMySessions` and `querySessions`. diff --git a/docs/adrs/README.md b/docs/adrs/README.md index 113aebef19..9bee4b8c9a 100644 --- a/docs/adrs/README.md +++ b/docs/adrs/README.md @@ -99,3 +99,4 @@ This directory contains architecture decision records (ADRs) for nextgen. | [091](091-release-pinning.md) | Release Pinning | Proposed | The app sends the release it was built against in `X-Zitadel-Release` when it starts a sign-in. Each deployment keeps a pin list per target, the earlier deployments a pin may still use, taken only from the previous deployment and its list up to the release's `.zitadel/pinning/pinning.json` `keep` (default 0), so `keep: 0` is a permanent cut. A pin outside the list gets the newest release; the response's `X-Zitadel-Release` names the release that served and a `flow.pin_not_served` event records the miss. `setUserPassword` takes no pin. Amends ADR 085 §2. | | [092](092-mcp-server.md) | MCP — the API as Tools on the Server, and the MCP Servers Zitadel Protects | Proposed | Zitadel's MCP server is an endpoint of the Go server, `/api/v1/mcp`, on unless `mcp.enabled` turns it off, so a local server, a self-hosted one and the cloud serve the same one. A tool is one operation read from the embedded OpenAPI document, and a call is that operation's own request to the API's handler with the caller's credential: a project secret today, a person's token once the OAuth pieces exist. The spec marks which operations only read (`x-zitadel-read-only`), belong to applications (`x-zitadel-plane: app`) or return a credential (`x-zitadel-returns-secret`). A client is shown the tools its credential's scopes cover, and a destructive call is sent only after the person at the client confirmed that call. Customers' MCP servers, which Zitadel protects, follow on the same OAuth pieces, and Agent Skills over MCP's Skills extension are wanted on the same endpoint. | | [093](093-policy-decision-events.md) | Policy Decision Events | Proposed | A policy gate records each evaluation as a wide event, `policy.evaluate.denied` or `policy.evaluate.allowed`, naming the policy, the revision and the failed rules. The gate writes it when it decides, best-effort and outside the operation's transaction, so the events get a category of their own, `policy`. The server setting `events.policy.decisions` (`none`, `deny` by default, `all`) selects what is recorded. Amends ADR 048 and ADR 066. | +| [094](094-project-permission-model.md) | Projects Carry the Permission Model, the Platform Is Its Root | Proposed | One permission model per project; the platform enters only as `operator from platform` on `project.admin`. Sessions become a catalog type whose project and user are implied from the row: read and revoked by their user and the project's admins, operators included. Writes that can take over or lock out a user need `admin` and must cover every role the target holds (the credential tier, identifier changes, deletion, owning-team membership). Every management operation takes a person's token (consent), a PAT or a machine identity and is an MCP tool, decided by scopes and permissions; only application sign-in and the public flow stay out, and secret-bearing operations are marked, never hidden. `getPlatform`, `listPlatformOperators` (operators only) and a project's `kind`; effective access with its sources replaces the Console's probe. Amends ADR 075 §6, ADR 054 §9, ADR 036, ADR 092 §4 and §6, and ADR 082 §3. |