diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 300ac5a..fdfdfb9 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -15,8 +15,9 @@ once there are more than 20. > panel; a form with files is refused while Turnstile is misconfigured; a script that creates staff accounts > with a password under 12 characters fails; behind a proxy that hides the site's address and without > `serverURL` nobody can enter a 2FA code; a project's own staff collection without access rules gets rules; -> changing the SMTP server in the panel asks for the password again. No import-map change. One new field -> (`smtpRequireTls`): **Postgres / SQLite need a migration**, MongoDB nothing. +> changing the SMTP server in the panel asks for the password again; a slug in `access.staffCollections` that +> is not an auth collection stops the start. No import-map change, **no schema change and no migration** on any +> database. ### Security - **Stored secrets are write-only.** `smtpPassword` and `turnstileSecretKey` (Site integrations) were returned @@ -27,11 +28,10 @@ once there are more than 20. ([security.md](./security.md) "Stored secrets"). - **The SMTP password stays with the server it was saved for.** Hiding the value was not enough: an admin session could point the SMTP server at a machine of its own and have a test e-mail deliver the password. A - save in the panel or over the API that changes the server, the port, the user name or "Require encryption" - (or switches the transport to SMTP) while a password is stored must now send the password again, or remove - it (`secrets.reenterOnChange`). Server code with the Local API is not asked. -- **"Require encryption" for SMTP** (`smtpRequireTls` in Site integrations → E-mail sending, off by default): - with it the password is never sent over an unencrypted connection (a server without STARTTLS gets nothing). + save in the panel or over the API that changes the server, the port or the user name while a password is + stored must now send the password again, or remove it (`secrets.reenterOnChange`) — whatever the transport + says (the mail adapter falls back to SMTP when Microsoft Graph is not configured). Server code with the Local + API is not asked. - **Restoring a version of Site integrations** (only where a project turned versions on for that global) answered with the stored secrets; they are masked there too (`maskSecretsOnRestore`). - **Nobody creates an account for themselves, or takes one over.** (1) Payload's first-user route @@ -42,8 +42,11 @@ once there are more than 20. `delete` rules had Payload's default, "any logged-in user" — an account of any auth collection: a visitor account could create a staff account, or change a staff account's password and roles. Such a collection now gets rules for the operations it has none for: with the plugin's roles — an admin (update: or the account - itself); with role values of its own, or none — an account of that same collection, or a plugin admin. The - rules hold with 2FA on and off. Anonymous sign-up into the staff collection was already refused; the + itself); with role values of its own, or none — an account of that same collection, or a plugin admin. + `unlock` gets the admin rule and `read` "a staff account" (a visitor account could list the staff accounts + and lift their login lock). An account never changes its **own** roles: the collection's `roles` field, when + it has no field access of its own, is closed for that. The rules hold with 2FA on and off, and for a staff + collection that a plugin listed after ipalKit adds. Anonymous sign-up into the staff collection was already refused; the plugin's injected collection already had these rules. No known site has a second staff collection ([access.md](./access.md) "Account rules"). - **2FA verify and setup attempts only from the site's own origin.** A page on another origin that the browser @@ -68,20 +71,23 @@ once there are more than 20. and logs a notice once per start. It will be removed in a later release, named here in advance. ### Added -- Options: `accounts` (`panelRole`, `adminOnlyCreate`, `adminOnlyWrite`, `firstUserRoute`, `password`), - `secrets.writeOnly`, `secrets.reenterOnChange`, `forms.turnstileOnConfigError`, `twoFactor.sameOrigin`, - `twoFactor.verifyLimit.store`, `dashboardAlerts`. Panel: "Require encryption" (`smtpRequireTls`). +- Options: `accounts` (`panelRole`, `adminOnlyCreate`, `adminOnlyWrite`, `staffOnlyRead`, `firstUserRoute`, + `password`), `secrets.writeOnly`, `secrets.reenterOnChange`, `forms.turnstileOnConfigError`, + `twoFactor.sameOrigin`, `twoFactor.verifyLimit.store`, `dashboardAlerts`. - ipal-doctor rules: `access-missing` (no `access` option: every panel account is an admin), `csrf-empty` - (neither `serverURL` nor `csrf`), and with `--url`: `open-signup` (info), `staff-accounts-open` (error: a staff - collection an account of another collection may write to), `turnstile-degraded` (warning, error after 24 - hours), `turnstile-env-key`. The deep status gained `openSignUp`, `staffOpenToOthers`, `turnstile`, + (neither `serverURL` nor `csrf`), and with `--url`: `open-signup` (info), `staff-accounts-open` (error; warning + for `read`: a staff collection an account of another collection may write to, read or unlock), + `staff-own-roles` (warning: a staff collection with role values of its own and no rules), `turnstile-degraded` + (warning, error after 24 hours), `turnstile-env-key`. The deep status gained `openSignUp`, `staffOnOwnRoles`, + `staffOpenToOthers`, `turnstile`, `turnstileSecretFromEnv` (states and slugs, never a key). - Exports: `writeOnlySecret`, `writeOnlySecrets`, `SECRET_MASK`, `SECRET_CLEAR`, `maskSecretAfterRead`, `keepSecretBeforeValidate`, `buildKeepSecret`, `isSecretMask`, `INTEGRATION_SECRET_FIELDS`, `SMTP_PASSWORD_BOUND_TO`, `maskSecretsOnRestore`, `maskWriteOnlySecrets`; `panelAccess`, `applyPanelRole`, `resolvePanelRole`, `countBelowPanelRole`, `DEFAULT_PANEL_ROLE`; `staffCreateAccess`, `staffUpdateAccess`, - `sameStaffCollectionAccess`, `hasPluginRoles`, `applyStaffAccountAccess`, `buildFirstUserEndpoint`, - `applyFirstUserRoute`, `openSignUpCollections`, `staffCollectionsOpenToOthers`; `checkPassword`, + `staffReadAccess`, `sameStaffCollectionAccess`, `rolesByAdminOnly`, `rolesNotOwn`, `hasPluginRoles`, + `applyStaffAccountAccess`, `adoptLateAuthCollections`, `unknownStaffCollections`, `buildFirstUserEndpoint`, + `applyFirstUserRoute`, `openSignUpCollections`, `staffCollectionsOpenToOthers`, `staffCollectionsOnOwnRoles`; `checkPassword`, `buildPasswordRuleHook`, `applyPasswordRule`, `resolvePasswordRule`, `DEFAULT_PASSWORD_MIN_LENGTH`; `requestFromOwnOrigin`, `ownOrigins`, `reportRefusedOrigin`; `buildVerifyLimit`, `verifyLimitKey`, `clearVerifyLimits`; `turnstileSecretFromEnv`, `TURNSTILE_SECRET_ENV`; from `/server`: `passTurnstile`, `passSubmitGates`, @@ -89,9 +95,14 @@ once there are more than 20. - `MaskedField` says "A value is set" for a write-only field and offers "Remove the stored value". ### Requires project changes -- **Postgres / SQLite: a migration.** Site integrations has a new checkbox, `smtpRequireTls`: - `pnpm payload migrate:create`, commit, deploy it with the code ([deployment.md](./deployment.md) §4.3). Without - it the global cannot be read (no e-mail, no Turnstile check). MongoDB needs nothing. +- **No migration.** This release adds no field, column, table or collection of its own on any database. The + stored 2FA attempt count uses Payload's own `payload-kv` collection, which every schema of a Payload version + that has `payload.kv` already contains; where it cannot be reached the count stays in memory and the limit + still holds. +- **A slug in `access.staffCollections` (or `access.authCollection`) that is not an auth collection of the + config stops the start**: `[ipal] access names "…" as a staff collection, but this config has no auth + collection with that slug`. Fix the slug. (A plugin listed after ipalKit may add the collection; it gets the + account rules when the site starts.) - **Set `serverURL`** if it is not set. Behind a reverse proxy that rewrites `Host` and sends no `X-Forwarded-Host` (nginx's plain `proxy_pass`; Coolify / Traefik keep `Host`) the server does not know its own address, and the 2FA code page is refused as "another origin": **nobody can enter a code**. The log says @@ -110,13 +121,16 @@ once there are more than 20. `turnstile-env-key`). - **Forms with a File field:** make sure Turnstile works (`ipal-doctor --url` → no `turnstile-degraded`); while it does not, those forms are refused. To keep accepting them: `forms: { turnstileOnConfigError: { files: 'allow' } }`. -- **A project's own staff collection without `create` / `update` / `delete` rules** gets them. With the plugin's - roles (`access.authCollection`, or a `roles` select with only `user` / `editor` / `admin`): only an admin - creates and deletes accounts, and an account is changed by an admin or by itself — if non-admins did that on - your site, write the rule you want. With **role values of its own** (`superadmin`, …) or no roles: accounts - of that collection keep working as before, accounts of other collections are refused — nothing to do, but the - plugin does not know your roles, so write your own rules. Off: `accounts: { adminOnlyCreate: false, - adminOnlyWrite: false }`. `first-register` for other auth collections: `403` unless the collection allows +- **A project's own staff collection without `create` / `update` / `delete` / `unlock` / `read` rules** gets + them. With the plugin's roles (`access.authCollection`, or a `roles` select with only `user` / `editor` / + `admin`): only an admin creates, deletes and unlocks accounts and changes roles; an account is changed by an + admin or by itself — if non-admins did that on your site, write the rule you want. With **role values of its + own** (`superadmin`, …) or no roles: accounts of that collection keep working as before, except that an + account no longer changes its **own** roles; accounts of other collections are refused. The plugin does not + know your roles, so write your own rules (`ipal-doctor --url` → `staff-own-roles`). `read`: only staff + accounts read a staff collection — **a front end that shows staff accounts to logged-in visitors** (an author + box read with a customer's session) needs its own `read` rule or `accounts: { staffOnlyRead: false }`. Off: + `accounts: { adminOnlyCreate: false, adminOnlyWrite: false, staffOnlyRead: false }`. `first-register` for other auth collections: `403` unless the collection allows sign-up, or `accounts: { firstUserRoute: 'all' }`. - **`access.firstUserAdmin: false`** with `access.defaultRole` below `editor`: the panel role is not applied (a warning at start); with `accounts.panelRole` set the start fails — set `access.defaultRole: 'editor'` or @@ -130,19 +144,20 @@ once there are more than 20. Existing accounts with short passwords keep logging in. - **A panel or front end on another domain that posts to `/api/verify-totp`:** `twoFactor: { …, sameOrigin: { origins: ['https://…'] } }`. -- **Recommended, with the owner:** tick "Require encryption" in Site integrations → E-mail sending where the - mail server supports STARTTLS (type the password again when asked), then send a test e-mail. - `pnpm payload generate:types`, `pnpm ipal:skills`. ### Known limitations - Write-only protects the API and the panel, not the database: the two secrets are stored in plain text there and in backups (encryption at rest is not part of this release). A secret equal to `********` or `[[clear]]` cannot be stored. A session that may send e-mail can still use the mailbox through the site (send, not - read). "Require encryption" is off by default: until it is ticked, a server (or someone in between) that - offers no STARTTLS on a port other than 465 gets the password in clear text, as before. -- The account rules for a staff collection with role values of its own do not enforce those roles: inside the - collection every account may create, change and delete accounts, as before. `read` is not touched: a staff - collection of your own without a `read` rule is readable by any logged-in account (Payload's default). + read). On a port other than 465 the SMTP connection is encrypted only when the server offers STARTTLS, as + before; an option to require it is not part of this release. +- The account rules for a staff collection with role values of its own do not enforce those roles: an account + cannot change its own roles, but inside the collection every account may still create an account with any + role, and change or delete another account — the plugin cannot rank roles it does not know. Write the + collection's own rules; `staff-own-roles` in the doctor names such a collection. +- An account of a staff collection **without a `roles` field** is an admin to the plugin (unchanged): it may + manage accounts of the other staff collections too. Give every staff collection roles, or its own rules. - The panel role and the password rule need `access` (roles) resp. a staff collection with password login; a second staff collection without a `roles` field is not affected by `panelRole`. - The stored verify count uses Payload's `payload.kv`; on a Payload version without it the count is in memory diff --git a/docs/access.md b/docs/access.md index cb4c1c3..3664a54 100644 --- a/docs/access.md +++ b/docs/access.md @@ -234,7 +234,8 @@ ipalKit({ access: { authCollection: 'users' }, // accounts: { panelRole: 'user' }, // every account may open the panel (as before) // accounts: { adminOnlyCreate: false }, // Payload's default `create` on your own staff collection - // accounts: { adminOnlyWrite: false }, // Payload's default `update` / `delete` there + // accounts: { adminOnlyWrite: false }, // Payload's default `update` / `delete` / `unlock` there, roles field left alone + // accounts: { staffOnlyRead: false }, // Payload's default `read` there // accounts: { firstUserRoute: 'all' }, // Payload's first-user route for every empty auth collection // accounts: { firstUserRoute: ['users', 'partners'] }, // accounts: { password: { minLength: 16 } }, // or password: false @@ -260,15 +261,16 @@ at the second factor, so the 2FA screens stay reachable. - **Check:** log in to `/admin` as an account with the role `user` → "Unauthorized"; `GET /api/access` for it → `canAccessAdmin: false`; `GET /api/users/me` still answers. -### Nobody creates an account for themselves, or takes one over (`accounts.adminOnlyCreate`, `accounts.adminOnlyWrite`, `accounts.firstUserRoute`) +### Nobody creates an account for themselves, or takes one over (`accounts.adminOnlyCreate`, `accounts.adminOnlyWrite`, `accounts.staffOnlyRead`, `accounts.firstUserRoute`) By default only the first account of a site can be registered by a visitor, and it becomes admin (`access.firstUserAdmin`); every other account is made by an admin, and an account is changed by an admin or by its owner. -Payload's default for a collection without access rules is "any logged-in user" for `create`, `update` and -`delete` — an account of **any** auth collection. On a project's own staff collection a visitor account -(`customers`) could therefore create a staff account, or `PATCH` a staff account's password and roles. +Payload's default for a collection without access rules is "any logged-in user" for `create`, `read`, `update`, +`delete` and `unlock` — an account of **any** auth collection. On a project's own staff collection a visitor +account (`customers`) could therefore create a staff account, `PATCH` a staff account's password and roles, +list the staff accounts, and lift the lock after failed logins. | | Before | Now (default) | |---|---|---| @@ -277,6 +279,8 @@ Payload's default for a collection without access rules is "any logged-in user" | A signed-in editor or plain user creates an account in the plugin's injected collection | refused | refused | | …in **the project's own** staff collection that has no `create` rule | **allowed** (Payload's default) | refused — an admin, fully signed in | | A visitor account (`customers`) changes or deletes an account of the project's own staff collection that has no `update` / `delete` rule | **allowed** (Payload's default) | refused | +| A visitor account lists the accounts of such a collection, or unlocks one | **allowed** (Payload's default) | refused | +| An account of such a collection changes its **own** `roles` (the field has no access of its own) | **allowed** | refused — with the plugin's roles only an admin changes roles | | `POST /api//first-register` on another empty auth collection (`members`) | **200** | 403 | | …on an empty **second staff collection** (`access.staffCollections`) | **200, and that account was staff** | 403 — an admin of the panel's collection creates its first account | | A collection that allows sign-up (`customers` with `create: () => true`) | allowed | allowed, its first-user route too | @@ -284,21 +288,39 @@ Payload's default for a collection without access rules is "any logged-in user" **Which rule a staff collection gets** (the panel's login collection, `access.authCollection`, `access.staffCollections`) — only for an operation it has **no** rule for; a rule you wrote always stays: -| The collection | `create` | `update` | `delete` | -|---|---|---|---| -| carries **the plugin's roles**: it is `access.authCollection`, or has a `roles` select whose values are all `user` / `editor` / `admin` (`hasPluginRoles`) | an admin (`staffCreateAccess`) | an admin, or the account itself (`staffUpdateAccess(slug)`) | an admin | -| has **roles of its own** (`superadmin`, `writer`, …) or no `roles` field — the plugin cannot tell who its admins are | an account of that same collection, or a plugin admin of another staff collection (`sameStaffCollectionAccess(slug)`) | the same | the same | +| The collection | `create`, `delete`, `unlock` | `update` | the `roles` field (when it has no `access.update`) | `read` | +|---|---|---|---|---| +| carries **the plugin's roles**: it is `access.authCollection`, or has a `roles` select whose values are all `user` / `editor` / `admin` (`hasPluginRoles`) | an admin (`staffCreateAccess`) | an admin, or the account itself (`staffUpdateAccess(slug)`) | only an admin changes it (`rolesByAdminOnly`) | a staff account (`staffReadAccess`) | +| has **roles of its own** (`superadmin`, `writer`, …) or no `roles` field — the plugin cannot tell who its admins are | an account of that same collection, or a plugin admin of another staff collection (`sameStaffCollectionAccess(slug)`) | the same | an account never changes its **own** (`rolesNotOwn(slug)`) | a staff account | -Always "fully signed in": a session that still owes its second factor passes none of them. In the second row -your own roles are not enforced by the plugin — what was allowed inside the collection stays allowed; what -closes is the door for accounts of **other** collections. Write your own rules to say who inside may do what. +Always "fully signed in": a session that still owes its second factor passes none of them. -- `adminOnlyCreate: false` = Payload's default `create`; `adminOnlyWrite: false` = Payload's default `update` - and `delete`. The rules are put on the collections **before** the 2FA package wraps them, so they hold with - 2FA on and off. -- `read` is not touched: a staff collection of your own without a `read` rule is readable by any logged-in - account (Payload's default; the injected collection has "admin or self"). Write a `read` rule - (`adminOrSelfIn(slug)`). +**Roles of your own — what the plugin does and does not hold.** It cannot rank `superadmin` against `writer`, +so inside such a collection it enforces one thing only: an account does not change its own roles. Everything +else that was allowed inside the collection stays allowed — **every account of it may still create an account +with any role, and change or delete another account**. That is a hole only you can close: write the +collection's `create` / `update` / `delete` rules and the field access of its `roles` field from your roles. +`ipal-doctor --url` names such a collection (`staff-own-roles`, warning). What the plugin closes for you is the +door for accounts of **other** collections. + +**A staff collection without a `roles` field:** every account of it is an admin to the plugin (unchanged), so +it may also manage the accounts of the other staff collections. Give it the plugin's roles +(`buildRolesField`), or write its rules. + +**A staff collection that a plugin listed after ipalKit adds** gets the same rules, the password rule and the +first-user endpoint when the site starts (and on a dev reload); the log says `[ipal] Account rules also put on +auth collections added after ipalKit: …`. There the plugin tells "no rule" from "your rule" by Payload's own +default function, so a rule you wrote stays. A slug in `access.staffCollections` or `access.authCollection` +that is **not an auth collection of the config stops the start** with the slug and the list of auth +collections (`unknownStaffCollections`). + +- `adminOnlyCreate: false` = Payload's default `create`; `adminOnlyWrite: false` = Payload's default `update`, + `delete` and `unlock`, and the `roles` field is left alone; `staffOnlyRead: false` = Payload's default `read`. + The rules are put on the collections **before** the 2FA package wraps them, so they hold with 2FA on and off. +- `read` = "a fully signed-in account of a staff collection": staff sees staff (the panel needs it for + relationship fields and the account list), a visitor account sees nothing. The injected collection keeps its + stricter "admin or self". **A front end that shows staff accounts to logged-in visitors** needs its own `read` + rule on that collection (a rule you wrote wins), or `staffOnlyRead: false`. - `firstUserRoute`: `'panel'` (default) = the collection the panel logs in with; a list of slugs = those; `'all'` = Payload's behaviour. A collection whose own `create` rule lets an anonymous request through keeps its route. The plugin puts its own `POST /first-register` endpoint in front of Payload's on every auth @@ -314,15 +336,18 @@ closes is the door for accounts of **other** collections. Write your own rules t - **What an existing site sees:** nothing, unless its own staff collection relied on Payload's defaults (non-admins creating accounts in a collection with the plugin's roles; accounts of another collection writing to it) — then write the rule you want, or set `adminOnlyCreate: false` / `adminOnlyWrite: false`. -- `ipal-doctor --url`: `open-signup` (info) lists auth collections with open sign-up; `staff-accounts-open` - (error) names a staff collection an account of another collection may create in, update or delete from +- `ipal-doctor --url`: `open-signup` (info) lists auth collections with open sign-up; `staff-own-roles` (warning) + a staff collection with role values of its own on the default rules; `staff-accounts-open` + (error) names a staff collection an account of another collection may create in, read (a warning), update, delete from or unlock (the rules are off, or your own rule is wider). -- Building blocks: `staffCreateAccess`, `staffUpdateAccess`, `sameStaffCollectionAccess`, `hasPluginRoles`, - `applyStaffAccountAccess`, `buildFirstUserEndpoint`, `applyFirstUserRoute`, `openSignUpCollections`, - `staffCollectionsOpenToOthers`. +- Building blocks: `staffCreateAccess`, `staffUpdateAccess`, `staffReadAccess`, `sameStaffCollectionAccess`, + `rolesByAdminOnly`, `rolesNotOwn`, `hasPluginRoles`, `applyStaffAccountAccess`, `adoptLateAuthCollections`, + `unknownStaffCollections`, `buildFirstUserEndpoint`, `applyFirstUserRoute`, `openSignUpCollections`, + `staffCollectionsOpenToOthers`, `staffCollectionsOnOwnRoles`. - **Check:** `curl -X POST /api/members/first-register -H 'content-type: application/json' -d '{"email":"x@example.com","password":"a-long-password-1"}'` → `403`, also as `/First-Register`; the same for - `/api/users` → `403`. Logged in as a visitor account: `PATCH /api/users/` → `403`. + `/api/users` → `403`. Logged in as a visitor account: `PATCH /api/users/` and `GET /api/users` → `403`. As a + non-admin of a staff collection: `PATCH` your own account with `roles` → the roles do not change. ### Passwords (`accounts.password`, default 12 characters) @@ -347,7 +372,7 @@ characters."; texts `passwordTooShort`, `passwordIsEmail` in `i18n.translations. ## Turn off, override, extend - **Account rules:** `accounts: false`, or one by one — `panelRole`, `adminOnlyCreate`, `adminOnlyWrite`, - `firstUserRoute`, `password` (above). + `staffOnlyRead`, `firstUserRoute`, `password` (above). - **Turn off:** leave out `access` — no `roles` field, the auth collection keeps Payload's rules (or yours). `access.firstUserAdmin: false` stops giving admin to the first account. - **Override:** `access.staffCollections` (who is staff), `access.authAccess` (injected collection), your own auth collection (wins whole), diff --git a/docs/agent/AGENT.md b/docs/agent/AGENT.md index 84662ef..715b4bc 100644 --- a/docs/agent/AGENT.md +++ b/docs/agent/AGENT.md @@ -1170,9 +1170,9 @@ add missing hosts with flags / `extra`; (3) change `mode` to `'enforce'` in both | At most 5 verify attempts per account in 10 minutes (`POST /api/verify-totp` → `429`); the count is kept in memory and in the database (`payload.kv`), so a restart or a second instance does not reset it | `twoFactor.verifyLimit: false` | `verifyLimit: { max, windowMinutes, store: 'memory' }` | | 2FA verify and setup attempts only from the site's own origin: a request a browser marks as coming from elsewhere (`Origin`, `Sec-Fetch-Site`) gets `403` and is not counted. **Set `serverURL`**: behind a proxy that rewrites `Host` and sends no `X-Forwarded-Host` the site's own page is refused without it (logged once per origin: `[ipal] 2FA: a code from origin … was refused`) | `twoFactor.sameOrigin: false` | `sameOrigin: { origins: ['https://app.example.com'] }`; `requestFromOwnOrigin`, `reportRefusedOrigin` | | Stored secrets are write-only: `smtpPassword` and `turnstileSecretKey` come back as `'********'` over REST, GraphQL and in the panel; an empty save keeps the value, `'[[clear]]'` removes it; server code reads the real value with the Local API. **The panel is the source — never add an env variable for them** (`TURNSTILE_SECRET_KEY` is deprecated) | `secrets: { writeOnly: false }` | `writeOnlySecret(field)` / `writeOnlySecrets(fields, names)` for your own secret fields; with versions on the entity add `hooks.afterRead: [maskSecretsOnRestore]` | -| The SMTP password stays with its server: a save in the panel or over the API that changes the server, port, user name or "Require encryption" (or switches the transport to SMTP) without the password is refused (`400` "Enter the password again…") — otherwise an admin session points the server at its own machine and a test e-mail hands the password over. Seeds and scripts (Local API, access control off) are not asked. Site integrations → E-mail sending has **"Require encryption"** (`smtpRequireTls`, off by default; a new field — Postgres / SQLite need a migration): tick it where the server supports STARTTLS | `secrets: { reenterOnChange: false }` | `writeOnlySecret(field, { boundTo: [...] })`, `buildKeepSecret`, `SMTP_PASSWORD_BOUND_TO` | +| The SMTP password stays with its server: a save in the panel or over the API that changes the server, port or user name without the password is refused (`400` "Enter the password again…"), whatever the transport says — otherwise an admin session points the server at its own machine and a test e-mail hands the password over. A change of the transport alone asks for nothing. Seeds and scripts (Local API, access control off) are not asked | `secrets: { reenterOnChange: false }` | `writeOnlySecret(field, { boundTo: [...] })`, `buildKeepSecret`, `SMTP_PASSWORD_BOUND_TO` | | The admin panel opens for `editor` and above; an account with only `user` sees "Unauthorized" (the API is not touched). First start logs how many accounts are below the role | `accounts: { panelRole: 'user' }` (or `false`) | `panelRole: 'admin'`; your own `access.admin`; `panelAccess(role)` | -| Nobody creates an account for themselves, or takes one over. A staff collection (also the project's own) without a `create` / `update` / `delete` rule gets one: with the plugin's roles — create and delete: an admin; update: an admin or the account itself. With roles of its own, or none: an account of that same collection, or a plugin admin (accounts of other collections are refused; write your own rules for who inside may do what). Payload's first-user route answers only for the panel's login collection (the first account, which becomes admin), in any spelling of the URL. `access.firstUserAdmin: false` with a default role below the panel role: the default panel role is not applied (logged), an explicit one is refused at start | `accounts: { adminOnlyCreate: false, adminOnlyWrite: false, firstUserRoute: 'all' }` | your own rule wins; `firstUserRoute: ['users', 'partners']`; a collection with open sign-up keeps its routes; `staffCreateAccess`, `staffUpdateAccess(slug)`, `sameStaffCollectionAccess(slug)`, `hasPluginRoles`, `applyStaffAccountAccess`, `buildFirstUserEndpoint` | +| Nobody creates an account for themselves, or takes one over. A staff collection (also the project's own, also one a later plugin adds) without a `create` / `update` / `delete` / `unlock` / `read` rule gets one: with the plugin's roles — create, delete, unlock: an admin; update: an admin or the account itself; the `roles` field: only an admin. With roles of its own, or none: an account of that same collection, or a plugin admin, and an account never changes its own roles — **the plugin cannot rank a project's own roles: write that collection's rules** (`ipal-doctor` → `staff-own-roles`). `read`: a staff account. Payload's first-user route answers only for the panel's login collection (the first account, which becomes admin), in any spelling of the URL. `access.firstUserAdmin: false` with a default role below the panel role: the default panel role is not applied (logged), an explicit one is refused at start. A slug in `access.staffCollections` that is not an auth collection stops the start | `accounts: { adminOnlyCreate: false, adminOnlyWrite: false, staffOnlyRead: false, firstUserRoute: 'all' }` | your own rule wins; `firstUserRoute: ['users', 'partners']`; a collection with open sign-up keeps its routes; `staffCreateAccess`, `staffUpdateAccess(slug)`, `staffReadAccess`, `sameStaffCollectionAccess(slug)`, `rolesByAdminOnly`, `rolesNotOwn(slug)`, `hasPluginRoles`, `applyStaffAccountAccess`, `adoptLateAuthCollections`, `buildFirstUserEndpoint` | | A password set on a staff account has at least 12 characters and is not the e-mail address; existing passwords are not checked | `accounts: { password: false }` | `password: { minLength }`; `checkPassword`, `buildPasswordRuleHook` | | While Turnstile cannot check (wrong secret, Cloudflare down): a text form is accepted, a form with files is refused | `forms: { turnstileOnConfigError: 'allow' }` | `'reject'`, `{ text, files }`; `turnstileOnConfigError` at a call site wins | | Dashboard alerts by role: integration details for admins, a neutral line for editors, nothing for others; cookie alerts for editors and above. `'all'` checks nothing — no role, no second factor | `dashboardAlerts: { integrations: 'all', cookies: 'all' }` | `integrations: 'editor'`; the components' `details` / `audience` props | diff --git a/docs/agent/skills/ipal-debug/SKILL.md b/docs/agent/skills/ipal-debug/SKILL.md index 823af16..686ccc1 100644 --- a/docs/agent/skills/ipal-debug/SKILL.md +++ b/docs/agent/skills/ipal-debug/SKILL.md @@ -104,10 +104,11 @@ through this procedure. Ask only when you are missing something you cannot get y | `POST /api//first-register` answers `403` on an empty collection | `accounts.firstUserRoute`: only the panel's login collection may register its first account that way (the plugin's own endpoint sits in front of Payload's) | an admin creates the account; or the collection's own `create: () => true` (sign-up); or `accounts: { firstUserRoute: [''] }` | | an editor (or a script with its token) gets `403` creating an account in the project's own `users` | `accounts.adminOnlyCreate`: only admins create staff accounts where the roles are the plugin's | create as an admin; or write the collection's `create` rule; or `adminOnlyCreate: false` | | an account gets `403` changing or deleting ANOTHER account of a staff collection (it worked before) | `accounts.adminOnlyWrite`: an admin, or the account itself (update only); on a collection with roles of its own: accounts of that collection | do it as an admin; or write the collection's `update` / `delete` rule; or `adminOnlyWrite: false` | +| an account saves its own profile and its `roles` do not change (no error) | `accounts.adminOnlyWrite`: nobody changes its own roles; with the plugin's roles only an admin changes roles | an admin changes the role; or give the `roles` field its own `access.update` | +| a logged-in visitor (customer) gets `403` reading a staff collection — an author box went empty | `accounts.staffOnlyRead`: only staff accounts read a staff collection without a `read` rule | write that collection's `read` rule; or `staffOnlyRead: false` | +| the site does not start: `[ipal] access names "…" as a staff collection, but this config has no auth collection with that slug` | a slug in `access.staffCollections` / `access.authCollection` is not an auth collection (a typo, a removed collection) | fix the slug or add the collection | | a fresh site with `access.firstUserAdmin: false`: the first account sees "Unauthorized", or the start fails with `leaves a fresh site with nobody who can open the panel` | the first account gets the default role, below the panel role | `access.defaultRole: 'editor'`, or `accounts: { panelRole: false }`, or drop `firstUserAdmin: false` | -| saving Site integrations fails on the password field: "Enter the password again…" | the server, port, user name or "Require encryption" changed (or the transport switched to SMTP) and the stored SMTP password is kept only for the settings it was saved with | type the password again; or "Remove the stored value" for a server without one; a seed with the Local API is not asked; `secrets: { reenterOnChange: false }` | -| e-mail fails with `Error upgrading connection with STARTTLS` | "Require encryption" is ticked and the server offers no STARTTLS on that port | the right port (587, or 465); or untick it (the password then travels unencrypted) | -| SQL site after the upgrade: Site integrations cannot be read, `column "smtp_require_tls" does not exist` | the new checkbox needs a migration | `pnpm payload migrate:create`, commit, deploy (deployment.md §4.3) | +| saving Site integrations fails on the password field: "Enter the password again…" | the server, port or user name changed and the stored SMTP password is kept only for the settings it was saved with — also when the transport says Microsoft Graph | type the password again; or "Remove the stored value" for a server without one; a seed with the Local API is not asked; `secrets: { reenterOnChange: false }` | | creating an account / changing a password fails with "The password must have at least 12 characters." | `accounts.password` (applies to new passwords of staff accounts, in scripts too) | a longer password; `accounts: { password: { minLength } }` or `false` | | the API returns `"smtpPassword":"********"` / own code "lost" the SMTP password or Turnstile secret | write-only secrets: reads through access control never get the value | read on the server: `payload.findGlobal({ slug: 'site-integrations' })` (access control off); `secrets: { writeOnly: false }` restores the old behaviour | | the SMTP password "disappears" after saving Site integrations | it does not: the field shows "A value is set"; an empty save keeps it | to change it type a new one; to remove it press "Remove the stored value" (API: `'[[clear]]'`) | diff --git a/docs/agent/skills/ipal-reference/SKILL.md b/docs/agent/skills/ipal-reference/SKILL.md index ff3531e..7b03bab 100644 --- a/docs/agent/skills/ipal-reference/SKILL.md +++ b/docs/agent/skills/ipal-reference/SKILL.md @@ -34,11 +34,12 @@ description: Complete map of everything @intecion/ipal-kit provides — every ip | `accounts` | on (all rules) | rules for the accounts of the staff collection; each key below | `false` = none of them | | `accounts.panelRole` | `'editor'` | the lowest role that may open the admin panel (Payload's `access.admin` on the collection with the roles): an account with only `user` sees "Unauthorized"; the API is not touched; the role decides, not the second factor. First start logs `N account(s) … cannot open the admin panel` (an error when it is everyone). Needs `access` | `'user'` / `false` = everyone, as before; `'admin'`; your own `access.admin` / `access.authAccess.admin` wins | | `accounts.adminOnlyCreate` | on | a staff collection (panel login collection, `access.authCollection`, `access.staffCollections`) without a `create` rule gets one instead of Payload's "any logged-in user" — also the project's own collection. With the plugin's roles (`access.authCollection`, or a `roles` select with only `user` / `editor` / `admin`): an admin, fully signed in. With roles of its own, or none: an account of that same collection, or a plugin admin of another staff collection | `false` = Payload's default; a `create` rule you wrote always wins | -| `accounts.adminOnlyWrite` | on | the same for `update` and `delete`: with the plugin's roles — update: an admin or the account itself, delete: an admin; otherwise an account of that same collection, or a plugin admin. Closes Payload's default, under which a visitor account could change a staff account's password. `read` is not touched | `false` = Payload's default; rules you wrote always win | +| `accounts.adminOnlyWrite` | on | the same for `update`, `delete` and `unlock`: with the plugin's roles — update: an admin or the account itself; delete, unlock: an admin; otherwise an account of that same collection, or a plugin admin. With it the collection's `roles` field (when it has no `access.update`) is closed for self-promotion: with the plugin's roles only an admin changes roles; with role values of the project's own an account never changes its own (the plugin cannot rank them — write that collection's rules). Closes Payload's default, under which a visitor account could change a staff account's password | `false` = Payload's default, the `roles` field left alone; rules you wrote always win | +| `accounts.staffOnlyRead` | on | `read` on a staff collection without a `read` rule: a fully signed-in account of a staff collection (Payload's default let a visitor account list the staff accounts) | `false` = Payload's default; a `read` rule you wrote wins | | `accounts.firstUserRoute` | `'panel'` | which auth collections `POST /api//first-register` answers for while they are empty: only the one the panel logs in with (the first account of a site → admin). Others get `403`, a second staff collection included, in any spelling of the URL (the plugin's own endpoint sits in front of Payload's); a collection whose own `create` allows an anonymous request keeps its route. With `access.firstUserAdmin: false` and a default role below the panel role, the default `panelRole` is not applied (logged) and an explicit one is refused at start | a list of slugs; `'all'` = Payload's behaviour | | `accounts.password` | `{ minLength: 12 }` | when a password is SET on a staff collection (create, first-user screen, change, reset by e-mail; panel, API and Local API): at least `minLength` characters, not the account's e-mail address. Existing passwords are never checked — a shorter one keeps logging in | `{ minLength }`; `false` = Payload's rule (3 characters) | | `secrets.writeOnly` | on | `smtpPassword` and `turnstileSecretKey` (Site integrations) are never returned: REST, GraphQL and the panel get `'********'` when a value is stored; a save with nothing / empty / the mask keeps it, a new value replaces it, `'[[clear]]'` removes it; the Local API with access control off reads the real value. The panel is the source of these secrets — no env variable. A restore of a version is masked too | `false` = returned to whoever may read the global, as before | -| `secrets.reenterOnChange` | on | a save through access control that changes `smtpHost`, `smtpPort`, `smtpUser`, `smtpRequireTls`, or switches `emailTransport` to SMTP, while a password is stored, must send the password again or remove it (`400` on the field otherwise) — so an admin session cannot send the stored password to a server of its own. The Local API with access control off is not asked | `false` = the stored password follows the new server | +| `secrets.reenterOnChange` | on | a save through access control that changes `smtpHost`, `smtpPort` or `smtpUser` while a password is stored must send the password again or remove it (`400` on the field otherwise), whatever `emailTransport` says — so an admin session cannot send the stored password to a server of its own. A change of the transport alone, and the Local API with access control off, are not asked | `false` = the stored password follows the new server | | `dashboardAlerts` | `{ integrations: 'admin', cookies: 'editor' }` | who sees the plugin's dashboard alerts: integration details (error text, link) for `integrations` and above, a neutral "ask an administrator" for editors below it, nothing for others; the cookie crawl / approval alert for `cookies` and above. With a role, a session that owes its second factor sees none | `integrations: 'editor' | 'all'`, `cookies: 'all'` (`'all'` = as before: no role and no second factor is checked) | | `adminRoute` | `'/admin'` | `config.routes.admin`; stats link and views, `IntegrationAlerts` | the project moves `app/(payload)//` itself and adds the route to the proxy matcher (security.md) | | `twoFactor` | **none = error** | `@clocklimited/payload-2fa` with `forceSetup: true` (TOTP enforced, also checked in the API) | `twoFactor: false` (discouraged); omitting the option throws `[ipal] twoFactor.issuer is required` | diff --git a/docs/agent/skills/ipal-reference/resources/api.md b/docs/agent/skills/ipal-reference/resources/api.md index 33cc866..cd34c13 100644 --- a/docs/agent/skills/ipal-reference/resources/api.md +++ b/docs/agent/skills/ipal-reference/resources/api.md @@ -67,10 +67,10 @@ Admin panel components from `@intecion/ipal-kit/admin` — the project does NOT | `isAdmin(user, source?)` | `@intecion/ipal-kit`; in client components `@intecion/ipal-kit/client` | Predicate → `boolean`: staff account with the `admin` role (see `hasMinimumRole`). In hooks and endpoints: `isAdmin(req.user, req.payload)`; in a client component: `isAdmin(user, config)` from `/client` — the main entry does not build there with webpack (`'server-only' cannot be imported…`). | | `isEditor(user, source?)` | `@intecion/ipal-kit`; in client components `@intecion/ipal-kit/client` | Predicate → `boolean`: staff account with `editor` or higher. | | `panelAccess(minimum?)`, `applyPanelRole(config, slug, role)`, `resolvePanelRole(option)`, `countBelowPanelRole(payload, slug, role)`, `DEFAULT_PANEL_ROLE` | `@intecion/ipal-kit` | `accounts.panelRole`: an `access.admin` function ("holds at least `minimum`", default `'editor'`; role only, not the second factor); the applier (skips a collection that has its own `access.admin`); the option → role or `null` when off; `{ all, below }` counts for the start-up line; `'editor'`. | -| `staffCreateAccess`, `staffUpdateAccess(slug)`, `sameStaffCollectionAccess(slug)`, `hasPluginRoles(collection)`, `applyStaffAccountAccess(config, staffSlugs, { create?, write?, pluginRoles? })` | `@intecion/ipal-kit` | `accounts.adminOnlyCreate` / `adminOnlyWrite`: the access functions — "an admin, fully signed in" (create, delete); "an admin, or the account itself" (update; self = an account of THAT collection); "an account of this staff collection, or a plugin admin of another" (a collection whose roles are not the plugin's); whether a collection carries the plugin's roles (a top-level `roles` select with only `user` / `editor` / `admin`); the applier — puts the rules on the named staff collections for the operations that have none, `pluginRoles` = slugs whose roles field is injected later. Run it before any plugin that wraps access (the 2FA package). | -| `buildFirstUserEndpoint(option?)`, `applyFirstUserRoute(config, option?)`, `openSignUpCollections(payload)`, `staffCollectionsOpenToOthers(payload)` | `@intecion/ipal-kit` | `accounts.firstUserRoute`: the plugin's own `POST /first-register` collection endpoint, matched before Payload's — `403` unless the collection is the panel's login collection (`'panel'`), is in the list, or its own `create` lets an anonymous request through; otherwise it calls Payload's handler (and sets `req.context.ipalFirstRegister`); the applier (every auth collection; `'all'` adds nothing; `endpoints: false` is left alone). For the doctor: slugs of auth collections with open sign-up; `':'` for every staff collection an account of a non-staff collection may create in, update or delete from. | +| `staffCreateAccess`, `staffUpdateAccess(slug)`, `staffReadAccess`, `sameStaffCollectionAccess(slug)`, `rolesByAdminOnly`, `rolesNotOwn(slug)`, `hasPluginRoles(collection)`, `applyStaffAccountAccess(config, staffSlugs, { create?, write?, read?, pluginRoles? })` | `@intecion/ipal-kit` | `accounts.adminOnlyCreate` / `adminOnlyWrite` / `staffOnlyRead`: the access functions — "an admin, fully signed in" (create, delete, unlock); "an admin, or the account itself" (update; self = an account of THAT collection); "a fully signed-in account of a staff collection" (read); "an account of this staff collection, or a plugin admin of another" (a collection whose roles are not the plugin's); the two field-access functions for a `roles` field (`update`: only an admin / never the account itself); whether a collection carries the plugin's roles (a `roles` select at the top level of the data with only `user` / `editor` / `admin`); the applier — puts the rules on the named staff collections for the operations that have none and closes the `roles` field where the plugin's `update` rule is in force, `pluginRoles` = slugs whose roles field is injected later. Run it before any plugin that wraps access (the 2FA package). | +| `buildFirstUserEndpoint(option?)`, `applyFirstUserRoute(config, option?)`, `adoptLateAuthCollections(payload, staffSlugs, { access?, beforeOperation?, firstUserRoute? })`, `unknownStaffCollections(payload, staffSlugs)`, `openSignUpCollections(payload)`, `staffCollectionsOpenToOthers(payload)`, `staffCollectionsOnOwnRoles(payload)` | `@intecion/ipal-kit` | `accounts.firstUserRoute`: the plugin's own `POST /first-register` collection endpoint, matched before Payload's — `403` unless the collection is the panel's login collection (`'panel'`), is in the list, or its own `create` lets an anonymous request through; otherwise it calls Payload's handler (and sets `req.context.ipalFirstRegister`); the applier (every auth collection; `'all'` adds nothing; `endpoints: false` is left alone). For the doctor: slugs of auth collections with open sign-up; `':'` for every staff collection an account of a non-staff collection may create in, read, update, delete from or unlock; slugs of staff collections with role values of their own on the default rules. `adoptLateAuthCollections` gives auth collections that a plugin listed after ipalKit added the same rules on the live config (called by the plugin at start and on a dev reload; returns the slugs); `unknownStaffCollections` lists staff slugs that are not auth collections (the plugin stops the start on any). | | `checkPassword(password, { email?, minLength? })`, `buildPasswordRuleHook({ minLength? })`, `applyPasswordRule(config, slugs, rule)`, `resolvePasswordRule(option)`, `DEFAULT_PASSWORD_MIN_LENGTH` | `@intecion/ipal-kit` | `accounts.password`: `'short' \| 'email' \| null` for a new password (length in characters); the `beforeOperation` hook for `create` / `update` / `resetPassword` (throws Payload's `ValidationError` on `password`, text in the panel's language; the account's address is looked up by id, reset token or bulk query when the request carries none; a password that is not text is refused; login is never checked); the applier; the option → `{ minLength }` or `null`; `12`. | -| `writeOnlySecret(field, options?)`, `writeOnlySecrets(fields, names, optionsByName?)`, `maskSecretAfterRead`, `keepSecretBeforeValidate`, `buildKeepSecret(options?)`, `SECRET_MASK`, `SECRET_CLEAR`, `isSecretMask(value)`, `INTEGRATION_SECRET_FIELDS`, `SMTP_PASSWORD_BOUND_TO` | `@intecion/ipal-kit` | Write-only secret fields (`secrets.writeOnly`): the wrapper for one field and for named fields anywhere in a tree (tabs, rows, groups); the two field hooks (reads through access control get `'********'`, the Local API with access control off gets the value; a save with nothing / empty / the mask keeps the stored value, `'[[clear]]'` removes it); the hook builder with options — `{ boundTo: ['siblingField'], appliesWhen?: (siblingData) => boolean }`: a save through access control that changes a bound sibling field without sending the secret throws a `ValidationError` on the secret (`secrets.reenterOnChange`); the two constants; the plugin's own secret field names (`smtpPassword`, `turnstileSecretKey`); the fields the SMTP password is bound to (`emailTransport`, `smtpHost`, `smtpPort`, `smtpUser`, `smtpRequireTls`). | +| `writeOnlySecret(field, options?)`, `writeOnlySecrets(fields, names, optionsByName?)`, `maskSecretAfterRead`, `keepSecretBeforeValidate`, `buildKeepSecret(options?)`, `SECRET_MASK`, `SECRET_CLEAR`, `isSecretMask(value)`, `INTEGRATION_SECRET_FIELDS`, `SMTP_PASSWORD_BOUND_TO` | `@intecion/ipal-kit` | Write-only secret fields (`secrets.writeOnly`): the wrapper for one field and for named fields anywhere in a tree (tabs, rows, groups); the two field hooks (reads through access control get `'********'`, the Local API with access control off gets the value; a save with nothing / empty / the mask keeps the stored value, `'[[clear]]'` removes it); the hook builder with options — `{ boundTo: ['siblingField'], appliesWhen?: (siblingData) => boolean }`: a save through access control that changes a bound sibling field without sending the secret throws a `ValidationError` on the secret (`secrets.reenterOnChange`); the two constants; the plugin's own secret field names (`smtpPassword`, `turnstileSecretKey`); the fields the SMTP password is bound to (`smtpHost`, `smtpPort`, `smtpUser` — not the transport: the mail adapter may fall back to SMTP). | | `maskSecretsOnRestore`, `maskWriteOnlySecrets(data, fields)` | `@intecion/ipal-kit` | Versions and write-only secrets: the `afterRead` hook for a global or a collection (a restore answers with the version document, fields under `version`, where field hooks do not run — it masks them there for reads through access control); the walker it uses (masks every write-only field in `data`, following tabs, rows, groups, arrays and blocks). On Site integrations by default; add the hook to your own entity that has both. | | `requestFromOwnOrigin(req, extraOrigins?)`, `ownOrigins(req, extraOrigins?)`, `reportRefusedOrigin(req, extraOrigins?)` | `@intecion/ipal-kit` | `twoFactor.sameOrigin`: `false` when a browser marks the request as coming from another origin (`Origin` not among the request's host, `serverURL`, `csrf`, `cors`, the extras; a default port written out on the host is ignored; else `Sec-Fetch-Site` not `same-origin` / `none`); `true` without those headers. `ownOrigins` → `{ hosts, origins }`. `reportRefusedOrigin` writes one log line per refused origin and process (at most 50) with the ways to allow it, and returns whether it wrote. For your own state-changing endpoint. | | `buildVerifyLimit(collection, { max?, windowMinutes?, store? })`, `verifyLimitKey(collection, id)`, `clearVerifyLimits()` | `@intecion/ipal-kit` | `twoFactor.verifyLimit`: `async (req) => Response \| null` — counts an attempt of `req.user` in memory and, unless `store: 'memory'`, in `payload.kv`; a `429` with `Retry-After` past `max`. The kv key of an account's count; emptying the in-memory counts (tests). | @@ -81,7 +81,7 @@ Admin panel components from `@intecion/ipal-kit/admin` — the project does NOT | `buildRolesField(defaultRole?, { firstUserAdmin? })` | `@intecion/ipal-kit` | The `roles` select field the plugin injects (only admins set roles; `firstUserAdmin` default `true` = the account made on "Create first user" gets `admin`). The plugin wires it itself — use it only for an auth collection the plugin does not manage. | | `injectRoles(config, accessOption)` | `@intecion/ipal-kit` | Adds `roles` to `accessOption.authCollection` in a config. The plugin calls it itself with `access` — do not call. | -**Types:** `AccountsOptions` (`accounts`: `panelRole`, `adminOnlyCreate`, `adminOnlyWrite`, `firstUserRoute`, `password`), `WriteOnlySecretOptions` (`{ boundTo?, appliesWhen? }`), `PasswordRuleOptions` (`{ minLength? }`), `FirstUserRouteOption` (`'panel' \| 'all' \| string[]`), `TurnstileOnConfigError` / `TurnstileOnConfigErrorOption` / `TurnstileFormKind` (`@intecion/ipal-kit/server`), `VerifyLimitOptions` (`twoFactor.verifyLimit`: `{ max?, windowMinutes?, store? }`), `RequireSetupOptions` (`twoFactor.requireSetup`), `TwoFactorResetOptions`, `TwoFactorSetupState`, `SafeBackRule` / `SafeBackContext` (`twoFactor.safeBack` as a function: `(back, { adminRoute, origin? }) => string`), `TotpViewComponent` (a view component as registered: a path or `{ path, exportName?, clientProps?, serverProps? }`), `SafeTotpViewProps` (`@intecion/ipal-kit/admin`), `Role` (`'user' \| 'editor' \| 'admin'`), `AccessOption` (the plugin's `access` option: `authCollection`, `defaultRole`, `authAccess`, `firstUserAdmin`, `staffCollections`). +**Types:** `AccountsOptions` (`accounts`: `panelRole`, `adminOnlyCreate`, `adminOnlyWrite`, `staffOnlyRead`, `firstUserRoute`, `password`), `StaffAccountAccessOptions` (`{ create?, write?, read?, pluginRoles? }`), `StaffAccountRules` (what the plugin put on a staff collection, in `custom.ipalAccountRules`: `{ applied, ownRoles }`), `WriteOnlySecretOptions` (`{ boundTo?, appliesWhen? }`), `PasswordRuleOptions` (`{ minLength? }`), `FirstUserRouteOption` (`'panel' \| 'all' \| string[]`), `TurnstileOnConfigError` / `TurnstileOnConfigErrorOption` / `TurnstileFormKind` (`@intecion/ipal-kit/server`), `VerifyLimitOptions` (`twoFactor.verifyLimit`: `{ max?, windowMinutes?, store? }`), `RequireSetupOptions` (`twoFactor.requireSetup`), `TwoFactorResetOptions`, `TwoFactorSetupState`, `SafeBackRule` / `SafeBackContext` (`twoFactor.safeBack` as a function: `(back, { adminRoute, origin? }) => string`), `TotpViewComponent` (a view component as registered: a path or `{ path, exportName?, clientProps?, serverProps? }`), `SafeTotpViewProps` (`@intecion/ipal-kit/admin`), `Role` (`'user' \| 'editor' \| 'admin'`), `AccessOption` (the plugin's `access` option: `authCollection`, `defaultRole`, `authAccess`, `firstUserAdmin`, `staffCollections`). ## Accessibility — widget (`accessibility`) — details: `node_modules/@intecion/ipal-kit/docs/accessibility.md` diff --git a/docs/agent/skills/ipal-setup/SKILL.md b/docs/agent/skills/ipal-setup/SKILL.md index 8006ad5..3cf63a9 100644 --- a/docs/agent/skills/ipal-setup/SKILL.md +++ b/docs/agent/skills/ipal-setup/SKILL.md @@ -250,9 +250,14 @@ the panel shows Site settings, Site integrations, Cookies, Form messages, the Fo - **Account rules** (`accounts`, on by default; `false` or key by key to change): the panel opens for `editor` and above (`panelRole`; an account with only `user` sees "Unauthorized", the API is not touched — give panel users at least `editor`); only an admin creates staff accounts, and an account is changed by an admin or by - itself — also in the project's own staff collection (`adminOnlyCreate`, `adminOnlyWrite`; a staff collection - with role values of its own gets "an account of that collection, or a plugin admin" instead, so write its - `create` / `update` / `delete` / `read` rules yourself); Payload's first-user route answers only for the + itself, nobody changes its own roles, and only staff accounts read staff accounts — also in the project's own + staff collection and in one a later plugin adds (`adminOnlyCreate`, `adminOnlyWrite`, `staffOnlyRead`). **A + staff collection with role values of its own** (not `user` / `editor` / `admin`) gets only "an account of that + collection, or a plugin admin": the plugin cannot rank your roles, so inside it every account may create an + account with any role — **write its `create` / `update` / `delete` rules and the field access of its `roles` + field yourself** (`ipal-doctor --url` → `staff-own-roles`). Give every staff collection a `roles` field: without + one each of its accounts is an admin to the plugin. Every slug in `access.staffCollections` must be an auth + collection of the config, or the site does not start; Payload's first-user route answers only for the panel's login collection (`firstUserRoute`) — so **create the first account right after the first deploy**, it becomes the admin; a new password has at least 12 characters (`password`). A customer collection with sign-up: write its own `create: () => true`; the rules do not touch it. Do not combine @@ -266,8 +271,7 @@ the panel shows Site settings, Site integrations, Cookies, Form messages, the Fo them; `TURNSTILE_SECRET_KEY` is deprecated (local test keys in `.env` still work). Read them only on the server with the Local API. `secrets: { writeOnly: false }` turns it off. Changing the SMTP server, port or user name in the panel asks for the password again (`secrets.reenterOnChange`); a seed with the Local API is - not asked. Tick **Require encryption** in Site integrations → E-mail sending where the mail server supports - STARTTLS (off by default; the field `smtpRequireTls` needs a migration on Postgres / SQLite). + not asked. - **Forms with files** are refused while Turnstile cannot check (wrong keys, Cloudflare down); text forms are still accepted. `forms: { turnstileOnConfigError: … }` changes either. - A second auth collection (`customers`, a client zone): set `admin: { user: 'users' }` in `buildConfig`; its diff --git a/docs/agent/skills/ipal-upgrade/SKILL.md b/docs/agent/skills/ipal-upgrade/SKILL.md index fc9572d..90092a6 100644 --- a/docs/agent/skills/ipal-upgrade/SKILL.md +++ b/docs/agent/skills/ipal-upgrade/SKILL.md @@ -424,11 +424,10 @@ setup screen with "Set up two-step verification by …"; after the code it is in account → "Two-step verification: Set up." and the reset button; delete the account. **→ the release with `accounts` / `secrets` (CHANGELOG "Unreleased — hardening"; PROGRAMISTA §6, item 69) — read every point, most sites change nothing:** -1. Update the package, `pnpm install`, `pnpm ipal:skills`, `pnpm payload generate:types`. No import-map change. - **One new field**: `smtpRequireTls` (a checkbox) in Site integrations — MongoDB needs nothing; **Postgres / - SQLite: `pnpm payload migrate:create`, commit, deploy the migration with the code** (deployment.md §4.3), or - Site integrations cannot be read (no e-mail, no Turnstile). The verify count uses Payload's own `payload-kv` - collection. +1. Update the package, `pnpm install`, `pnpm ipal:skills`, `pnpm payload generate:types`. No import-map change, **no + schema change and no migration** on any database (the verify count uses Payload's own `payload-kv` + collection). `grep -n "staffCollections\|authCollection" src/payload.config.ts`: every slug there must be an + auth collection of the config — a wrong one now stops the start with the slug in the message. 2. **Panel access by role.** After the first start read the log: `[ipal] N account(s) of "users" are below the role "editor" and cannot open the admin panel`. Those accounts (role `user`, or no role) now see "Unauthorized" in the panel. Give the people who work in the panel `editor`, or set @@ -440,11 +439,9 @@ account → "Two-step verification: Set up." and the reset button; delete the ac them over REST / GraphQL as an admin, or with `overrideAccess: false`, now gets `'********'`: read them on the server with `payload.findGlobal({ slug: 'site-integrations' })`. A script that saves the whole global back keeps the secrets (the mask means "keep"). **New:** a save in the panel or over the API that changes the SMTP - server, port, user name or "Require encryption" must send the password again ("Enter the password again…"); - a script that does that over REST / GraphQL sends the password with it, a seed with the Local API is not - asked. `secrets: { reenterOnChange: false }` turns it off. With the owner, consider ticking **Require - encryption** (Site integrations → E-mail sending) where the server supports STARTTLS, then send a test - e-mail. During a rolling update a page opened under the new version and saved against the OLD one stores + server, port or user name must send the password again ("Enter the password again…"), also when the transport + is set to Microsoft Graph; a script that does that over REST / GraphQL sends the password with it, a seed + with the Local API is not asked. `secrets: { reenterOnChange: false }` turns it off. During a rolling update a page opened under the new version and saved against the OLD one stores `********` as the password: after the deploy, check that a test e-mail goes out. 4. **`TURNSTILE_SECRET_KEY` is deprecated** (it still works). If the log says `[ipal] Deprecated: the Turnstile secret key comes from the TURNSTILE_SECRET_KEY environment variable` or `ipal-doctor --url` reports @@ -455,18 +452,26 @@ account → "Two-step verification: Set up." and the reset button; delete the ac File field is now refused (text forms are accepted as before). Check `ipal-doctor --url` → no `turnstile-degraded`; to keep the old behaviour: `forms: { turnstileOnConfigError: { files: 'allow' } }`. 6. **Account creation and changes.** A project whose **own** staff collection has no `create` / `update` / - `delete` rule gets one (before: any signed-in account of any auth collection — a customer could change a - staff password): + `delete` / `unlock` / `read` rule gets one (before: any signed-in account of any auth collection — a customer + could change a staff password, list the staff accounts, lift a login lock): - the collection carries the plugin's roles (`access.authCollection`, or a `roles` select with only `user` / - `editor` / `admin`): create and delete — an admin; update — an admin or the account itself. **Check:** does - a non-admin create or edit other accounts there today? Then write the rule you want; + `editor` / `admin`): create, delete, unlock — an admin; update — an admin or the account itself; its + `roles` field — only an admin (when the field has no `access.update` of its own). **Check:** does a + non-admin create or edit other accounts, or change roles, there today? Then write the rule you want; - the collection has **role values of its own** (`superadmin`, …) or no roles: accounts of that collection - keep working as before; accounts of other collections are refused. Nothing to do, but write your own rules - — the plugin does not know your roles. + keep working as before, except that an account no longer changes its **own** roles; accounts of other + collections are refused. **Write your own rules** — the plugin does not know your roles, and inside the + collection every account can still create an account with any role (`ipal-doctor --url` → + `staff-own-roles`); + - `read`: only staff accounts read a staff collection. **Check:** does the front end show staff accounts + (an author box) to logged-in visitors with the visitor's session? Then write that collection's `read` rule, + or `accounts: { staffOnlyRead: false }`. Anonymous visitors never could. + A staff collection added by a plugin listed after ipalKit gets the same rules at start. `first-register` on any auth collection other than the panel's login collection answers `403` unless that collection allows sign-up. `access.firstUserAdmin: false` with a default role below `editor`: the panel role is not applied (a warning at start), or — with `accounts.panelRole` set — the start fails with the fix in the - message. Wanted otherwise: `accounts: { adminOnlyCreate: false, adminOnlyWrite: false, firstUserRoute: 'all' }`. + message. Wanted otherwise: `accounts: { adminOnlyCreate: false, adminOnlyWrite: false, staffOnlyRead: false, + firstUserRoute: 'all' }`. 7. **Passwords.** New passwords of staff accounts need 12 characters; **existing shorter passwords keep working** — nobody is logged out or asked to change. A script that creates staff accounts with a short password fails with a validation error: lengthen it, or `accounts: { password: { minLength: 8 } }`. @@ -482,7 +487,7 @@ account → "Two-step verification: Set up." and the reset button; delete the ac error text; accounts with only `user` see no alerts. `dashboardAlerts: { integrations: 'all' }` restores it (`'all'` checks no role and no second factor). **Check:** `pnpm exec ipal-doctor --url ` (new rules: `access-missing`, `csrf-empty`, `open-signup`, -`staff-accounts-open`, `turnstile-degraded`, `turnstile-env-key`); as an admin `GET /api/globals/site-integrations` shows +`staff-accounts-open`, `staff-own-roles`, `turnstile-degraded`, `turnstile-env-key`); as an admin `GET /api/globals/site-integrations` shows `"smtpPassword":"********"`; a test e-mail and a test form still work; an editor and an admin still log in. ## 2. Inventory (no code changes) diff --git a/docs/dev/PROGRAMISTA.md b/docs/dev/PROGRAMISTA.md index 489bc35..0a44bdb 100644 --- a/docs/dev/PROGRAMISTA.md +++ b/docs/dev/PROGRAMISTA.md @@ -676,7 +676,7 @@ Do one item at a time, build, check. Order by importance: | 66 | **1.16.4** — production `PAYLOAD_SECRET` shorter than 32 characters (the site would stop at `assertEnv`) | Before deploying 1.16.4, check the length in Coolify (`node -e 'console.log(process.env.PAYLOAD_SECRET.length)'`). Shorter: a random 32+ character secret (logs everyone out, asks for 2FA again, breaks stored API keys), or `ipalEnvRules({ secretMinLength: 0 })` for now | CHANGELOG 1.16.4, deployment.md "PAYLOAD_SECRET — length and changing it" | | 67 | **1.16.5 — security** — with 2FA on, `/admin/verify-totp?back=https%3A%2F%2Fexample.com%2F` sends the user to example.com after the code (and `back=javascript:…` runs script in the panel) | Upgrade and, **in ONE deploy**, `pnpm payload generate:importmap` (adds `@intecion/ipal-kit/admin#SafeTotpView`), commit `importMap.js`, `rm -rf .next`, redeploy on Coolify — with the old map the 2FA screens have no code form and nobody can sign in (run `pnpm exec ipal-doctor` before deploying; the start log says so too); check: the link above ends on `/admin`. `pnpm ipal:skills`. No option, env or migration; off / own rule: `twoFactor.safeBack` | CHANGELOG 1.16.5, security.md "The `back` link of the 2FA screens" | | 68 | **1.16.6 — 2FA setup required** (not a routine patch: a new default that can lock accounts out) — an account that has not set 2FA up still reads data over the API with its password; or after the upgrade an account "can do nothing" / is blocked | Before upgrading: `ipal-doctor --url` → accounts without 2FA set it up or are removed; one admin (better two) must have 2FA; deploy day agreed with the owner. Then, in ONE deploy: update, `generate:types`, `generate:importmap` (`TwoFactorStatusField`, `TwoFactorAlert`), **Postgres/SQLite: `migrate:create` and the migration applied in the same deploy when the new container starts — `prodMigrations` or `pnpm payload migrate && pnpm start`, never a pre-deployment command (deployment.md §4.3) — (column `totp_setup_from`); without it every login answers 500**, build, redeploy. Existing accounts get 72 h from the first start; blocked later → admin: account page → "Reopen setup". Password-login integrations: API key or `requireSetup.exempt`. `pnpm ipal:skills` | CHANGELOG 1.16.6, security.md "Setup required" | -| 69 | **Unreleased — hardening (M1)** — an account with only the role `user` sees "Unauthorized" in the panel; or the API returns `"smtpPassword":"********"`; or a form with a File field is refused while Turnstile is misconfigured; or "The password must have at least 12 characters."; or "Enter the password again…" on the SMTP password; or `403` "Not allowed from this origin." on the 2FA code | Update, `generate:types`, redeploy; no import map change. One new field (`smtpRequireTls`): Postgres / SQLite need a migration, MongoDB nothing. Set `serverURL` (a proxy that rewrites `Host` otherwise blocks the 2FA code; the log names the origin). Read the start log (`N account(s) … cannot open the admin panel`) and give panel users `editor`. Own code that read the two secrets over the API → Local API on the server. `TURNSTILE_SECRET_KEY` is deprecated: with the owner move the key into the panel. Own staff collection without `create` / `update` / `delete` rules: an admin (update: or the account itself) where the roles are the plugin's, accounts of that collection where they are the project's own. Existing short passwords keep working. Switches: `accounts`, `secrets`, `forms.turnstileOnConfigError`, `twoFactor.sameOrigin`, `dashboardAlerts`. `pnpm ipal:skills` | CHANGELOG "Unreleased — hardening", access.md "Account rules", security.md "Stored secrets", turnstile.md | +| 69 | **Unreleased — hardening (M1)** — an account with only the role `user` sees "Unauthorized" in the panel; or the API returns `"smtpPassword":"********"`; or a form with a File field is refused while Turnstile is misconfigured; or "The password must have at least 12 characters."; or "Enter the password again…" on the SMTP password; or `403` "Not allowed from this origin." on the 2FA code | Update, `generate:types`, redeploy; no import map, schema or migration. Every slug in `access.staffCollections` must be an auth collection (the start stops otherwise). Set `serverURL` (a proxy that rewrites `Host` otherwise blocks the 2FA code; the log names the origin). Read the start log (`N account(s) … cannot open the admin panel`) and give panel users `editor`. Own code that read the two secrets over the API → Local API on the server. `TURNSTILE_SECRET_KEY` is deprecated: with the owner move the key into the panel. Own staff collection without rules: an admin (update: or the account itself; roles only by an admin; read by staff only) where the roles are the plugin's, accounts of that collection where they are the project's own — write that collection's own rules. Existing short passwords keep working. Switches: `accounts`, `secrets`, `forms.turnstileOnConfigError`, `twoFactor.sameOrigin`, `dashboardAlerts`. `pnpm ipal:skills` | CHANGELOG "Unreleased — hardening", access.md "Account rules", security.md "Stored secrets", turnstile.md | After updating the package: `pnpm ipal:skills` (new skill versions), `pnpm payload generate:importmap`, `rm -rf .next`, restart dev, grep for the new symbol in `node_modules/@intecion/ipal-kit/dist`. diff --git a/docs/doctor.md b/docs/doctor.md index 87a99cb..f4eeb49 100644 --- a/docs/doctor.md +++ b/docs/doctor.md @@ -66,7 +66,7 @@ Added by `ipalKit` and **off until the site has `IPAL_DOCTOR_TOKEN`** (at least returns counts only — never names, e-mails or values: ```json -{ "node": "v22.20.0", "openSignUp": [], "pendingCookies": 0, "plugin": "1.15.0", "staffOpenToOthers": [], "turnstile": null, "turnstileSecretFromEnv": false, "usersSetupClosed": 0, "usersWithout2fa": 0 } +{ "node": "v22.20.0", "openSignUp": [], "pendingCookies": 0, "plugin": "1.15.0", "staffOnOwnRoles": [], "staffOpenToOthers": [], "turnstile": null, "turnstileSecretFromEnv": false, "usersSetupClosed": 0, "usersWithout2fa": 0 } ``` Turn off: `ipalKit({ doctor: false })`. Adapt: `ipalKit({ doctor: { tokenVar: 'MY_TOKEN', access: ({ req }) => isAdmin(req.user, req.payload) } })` (a logged-in staff admin may read it too; the second factor is checked for you — never test `req.user.roles` by hand, an account of another collection can carry the same value) @@ -102,7 +102,8 @@ Turn off: `ipalKit({ doctor: false })`. Adapt: `ipalKit({ doctor: { tokenVar: 'M | | `access-missing` | warning | `ipalKit` has an `access` option — without it there are no roles and every panel account is an admin | | | `csrf-empty` | warning | the config sets `serverURL` or `csrf` — otherwise Payload accepts the login cookie from any origin | | | `open-signup` | info | (deep) auth collections whose `create` rule lets an anonymous request through: sign-up is open there (intended for a customer zone — silence with a reason) | -| | `staff-accounts-open` | error | (deep) a staff collection that an account of another, non-staff auth collection may create in, update or delete from — it can make itself staff or change a staff password. The account rules are off (`accounts: false`, `adminOnlyCreate` / `adminOnlyWrite: false`) or the project's own rule is wider. Asked with a made-up outside account; a rule that throws counts as closed | +| | `staff-own-roles` | warning | (deep) a staff collection with role values of its own (not `user` / `editor` / `admin`) that runs on the plugin's default account rules: the plugin cannot rank those roles, so inside the collection every account may create an account with any role and change or delete another. Write the collection's own rules | +| | `staff-accounts-open` | error (warning for `read`) | (deep) a staff collection that an account of another, non-staff auth collection may create in, read, update, delete from or unlock — it can make itself staff, change a staff password, list the accounts or lift a login lock. The account rules are off (`accounts: false`, `adminOnlyCreate` / `adminOnlyWrite` / `staffOnlyRead: false`) or the project's own rule is wider. Asked with a made-up outside account; a rule that throws counts as closed | | | `turnstile-degraded` | warning / error | (deep) Turnstile is checking forms; while it is not (wrong or missing secret, Cloudflare down) a warning, an error once it has lasted 24 hours (counted from the recorded start to now) | | | `turnstile-env-key` | warning | (deep) the Turnstile secret key is in the panel, not in the deprecated `TURNSTILE_SECRET_KEY` environment variable | | | `cookie-scanner` | error / warning / info | `cookieScanner` on (with `crawl`, else info); deep: nothing waits for approval (warning) | diff --git a/docs/email.md b/docs/email.md index 60d97d9..9f09259 100644 --- a/docs/email.md +++ b/docs/email.md @@ -22,16 +22,12 @@ install it (nodemailer 10 ships its own types, so `@types/nodemailer` is not nee ## Config -No plugin options — SMTP (`smtpHost`, `smtpPort` (default 587), `smtpRequireTls`, `smtpUser`, +No plugin options — SMTP (`smtpHost`, `smtpPort` (default 587), `smtpUser`, `smtpPassword`, `smtpFromAddress`, `smtpFromName`) and `emailTransport` live in SiteIntegrations (E-mail sending tab). The editor configures them in the panel. -- **Require encryption** (`smtpRequireTls`, off by default): the password is sent only over an encrypted - connection — TLS on port 465, STARTTLS elsewhere. Without it, a server that offers no STARTTLS gets the - password in clear text; with it, such a server gets nothing and the send fails ("Error upgrading connection - with STARTTLS"). Tick it wherever the server supports it. A new field: Postgres / SQLite need a migration. - **The password is write-only and stays with its server**: the panel shows "A value is set"; changing the - server, port, user name or "Require encryption" asks for the password again + server, port or user name asks for the password again ([security.md](./security.md) "Stored secrets"). The plugin does **not** set `config.email` — you wire the adapter yourself (below). diff --git a/docs/security.md b/docs/security.md index 3d996ac..16c08a6 100644 --- a/docs/security.md +++ b/docs/security.md @@ -943,7 +943,7 @@ size while reading, content signature, container and macro checks, an optional ` | nothing for the field, an empty value, `null`, or `'********'` back | the stored value is kept | | a new value | replaces it (the answer shows `'********'`) | | `'[[clear]]'` (`SECRET_CLEAR`) | removes it | -| the server, the port, the user name, "Require encryption" **changed**, or the transport switched to SMTP, and **no** new password | **refused** (`400`, on the password field): "Enter the password again…" | +| the server, the port or the user name **changed** (whatever the transport), and **no** new password | **refused** (`400`, on the password field): "Enter the password again…" | In the panel the field says "A value is set. It is not shown; type a new one to replace it." and offers "Remove the stored value". @@ -951,25 +951,22 @@ the stored value". **The SMTP password stays with the server it was saved for** (`secrets.reenterOnChange`). Hiding the value is not enough on its own: an admin session could point `smtpHost` / `smtpPort` at a machine of its own, press "Send test e-mail", and read the password off the connection. So a save **through access control** (the panel, -REST, GraphQL) that changes `smtpHost`, `smtpPort`, `smtpUser`, `smtpRequireTls`, or `emailTransport` to SMTP, -while a password is stored, must send the password again — or remove it (`'[[clear]]'`, "Remove the stored -value") for a server without one. Values are compared as trimmed, lower-case text, and a value never saved -counts as the field's default, so saving the form unchanged asks for nothing. Switching to Microsoft Graph asks -for nothing either (the password is not used there). Server code — a seed, a script with the Local API and -access control off — is not asked. `ipalKit({ secrets: { reenterOnChange: false } })` = the stored password -follows the new server, as before. - -**"Require encryption"** (`smtpRequireTls`, Site integrations → E-mail sending, off by default). On port 465 the -connection is TLS from the start. On any other port the mail library upgrades with STARTTLS **when the server -offers it** — a server (or someone in between) that does not offer it gets the user name and password in clear -text. With the box ticked nothing is sent without encryption: no login, no e-mail, and the test e-mail says -"Error upgrading connection with STARTTLS". Tick it on every site whose server supports it (all the usual -providers on 587 do). It is a new field: **Postgres / SQLite need a migration** ([deployment.md](./deployment.md)). +REST, GraphQL) that changes `smtpHost`, `smtpPort` or `smtpUser` while a password is stored must send the +password again — or remove it (`'[[clear]]'`, "Remove the stored value") for a server without one. **Whatever +the transport says:** "Microsoft Graph" in the panel does not mean Graph sends — the mail adapter falls back to +SMTP when Graph is not configured, and for attachments Graph cannot take. A change of `emailTransport` alone +asks for nothing. Values are compared exactly (`587` and `'587'` are the same; another letter case or a space +is a change), and a value never saved — or a `NULL` in a SQL row — counts as the field's default, so saving +the form unchanged asks for nothing. Server code — a seed, a script with the Local API and access control off +— is not asked. `ipalKit({ secrets: { reenterOnChange: false } })` = the stored password follows the new +server, as before. A stolen admin session, or any way past the global's read rule, no longer yields a working mailbox password. What it does **not** protect: the database and its backups hold the value in plain text (encryption at rest is a separate, open question); whoever can change the config or run server code can read it; and a session that -knows nothing but may send e-mail can still **use** the mailbox through the site (send, not read). +knows nothing but may send e-mail can still **use** the mailbox through the site (send, not read). On a port +other than 465 the connection is encrypted only when the server offers STARTTLS; requiring it is a possible +later option, not part of this release. **Versions.** The global has no versions by default. A project that turns them on (`globalOverrides: { 'site-integrations': { versions: … } }`) stores the secret in every version — as in the diff --git a/reference/.agents/skills/ipal-debug/SKILL.md b/reference/.agents/skills/ipal-debug/SKILL.md index 823af16..686ccc1 100644 --- a/reference/.agents/skills/ipal-debug/SKILL.md +++ b/reference/.agents/skills/ipal-debug/SKILL.md @@ -104,10 +104,11 @@ through this procedure. Ask only when you are missing something you cannot get y | `POST /api//first-register` answers `403` on an empty collection | `accounts.firstUserRoute`: only the panel's login collection may register its first account that way (the plugin's own endpoint sits in front of Payload's) | an admin creates the account; or the collection's own `create: () => true` (sign-up); or `accounts: { firstUserRoute: [''] }` | | an editor (or a script with its token) gets `403` creating an account in the project's own `users` | `accounts.adminOnlyCreate`: only admins create staff accounts where the roles are the plugin's | create as an admin; or write the collection's `create` rule; or `adminOnlyCreate: false` | | an account gets `403` changing or deleting ANOTHER account of a staff collection (it worked before) | `accounts.adminOnlyWrite`: an admin, or the account itself (update only); on a collection with roles of its own: accounts of that collection | do it as an admin; or write the collection's `update` / `delete` rule; or `adminOnlyWrite: false` | +| an account saves its own profile and its `roles` do not change (no error) | `accounts.adminOnlyWrite`: nobody changes its own roles; with the plugin's roles only an admin changes roles | an admin changes the role; or give the `roles` field its own `access.update` | +| a logged-in visitor (customer) gets `403` reading a staff collection — an author box went empty | `accounts.staffOnlyRead`: only staff accounts read a staff collection without a `read` rule | write that collection's `read` rule; or `staffOnlyRead: false` | +| the site does not start: `[ipal] access names "…" as a staff collection, but this config has no auth collection with that slug` | a slug in `access.staffCollections` / `access.authCollection` is not an auth collection (a typo, a removed collection) | fix the slug or add the collection | | a fresh site with `access.firstUserAdmin: false`: the first account sees "Unauthorized", or the start fails with `leaves a fresh site with nobody who can open the panel` | the first account gets the default role, below the panel role | `access.defaultRole: 'editor'`, or `accounts: { panelRole: false }`, or drop `firstUserAdmin: false` | -| saving Site integrations fails on the password field: "Enter the password again…" | the server, port, user name or "Require encryption" changed (or the transport switched to SMTP) and the stored SMTP password is kept only for the settings it was saved with | type the password again; or "Remove the stored value" for a server without one; a seed with the Local API is not asked; `secrets: { reenterOnChange: false }` | -| e-mail fails with `Error upgrading connection with STARTTLS` | "Require encryption" is ticked and the server offers no STARTTLS on that port | the right port (587, or 465); or untick it (the password then travels unencrypted) | -| SQL site after the upgrade: Site integrations cannot be read, `column "smtp_require_tls" does not exist` | the new checkbox needs a migration | `pnpm payload migrate:create`, commit, deploy (deployment.md §4.3) | +| saving Site integrations fails on the password field: "Enter the password again…" | the server, port or user name changed and the stored SMTP password is kept only for the settings it was saved with — also when the transport says Microsoft Graph | type the password again; or "Remove the stored value" for a server without one; a seed with the Local API is not asked; `secrets: { reenterOnChange: false }` | | creating an account / changing a password fails with "The password must have at least 12 characters." | `accounts.password` (applies to new passwords of staff accounts, in scripts too) | a longer password; `accounts: { password: { minLength } }` or `false` | | the API returns `"smtpPassword":"********"` / own code "lost" the SMTP password or Turnstile secret | write-only secrets: reads through access control never get the value | read on the server: `payload.findGlobal({ slug: 'site-integrations' })` (access control off); `secrets: { writeOnly: false }` restores the old behaviour | | the SMTP password "disappears" after saving Site integrations | it does not: the field shows "A value is set"; an empty save keeps it | to change it type a new one; to remove it press "Remove the stored value" (API: `'[[clear]]'`) | diff --git a/reference/.agents/skills/ipal-reference/SKILL.md b/reference/.agents/skills/ipal-reference/SKILL.md index ff3531e..7b03bab 100644 --- a/reference/.agents/skills/ipal-reference/SKILL.md +++ b/reference/.agents/skills/ipal-reference/SKILL.md @@ -34,11 +34,12 @@ description: Complete map of everything @intecion/ipal-kit provides — every ip | `accounts` | on (all rules) | rules for the accounts of the staff collection; each key below | `false` = none of them | | `accounts.panelRole` | `'editor'` | the lowest role that may open the admin panel (Payload's `access.admin` on the collection with the roles): an account with only `user` sees "Unauthorized"; the API is not touched; the role decides, not the second factor. First start logs `N account(s) … cannot open the admin panel` (an error when it is everyone). Needs `access` | `'user'` / `false` = everyone, as before; `'admin'`; your own `access.admin` / `access.authAccess.admin` wins | | `accounts.adminOnlyCreate` | on | a staff collection (panel login collection, `access.authCollection`, `access.staffCollections`) without a `create` rule gets one instead of Payload's "any logged-in user" — also the project's own collection. With the plugin's roles (`access.authCollection`, or a `roles` select with only `user` / `editor` / `admin`): an admin, fully signed in. With roles of its own, or none: an account of that same collection, or a plugin admin of another staff collection | `false` = Payload's default; a `create` rule you wrote always wins | -| `accounts.adminOnlyWrite` | on | the same for `update` and `delete`: with the plugin's roles — update: an admin or the account itself, delete: an admin; otherwise an account of that same collection, or a plugin admin. Closes Payload's default, under which a visitor account could change a staff account's password. `read` is not touched | `false` = Payload's default; rules you wrote always win | +| `accounts.adminOnlyWrite` | on | the same for `update`, `delete` and `unlock`: with the plugin's roles — update: an admin or the account itself; delete, unlock: an admin; otherwise an account of that same collection, or a plugin admin. With it the collection's `roles` field (when it has no `access.update`) is closed for self-promotion: with the plugin's roles only an admin changes roles; with role values of the project's own an account never changes its own (the plugin cannot rank them — write that collection's rules). Closes Payload's default, under which a visitor account could change a staff account's password | `false` = Payload's default, the `roles` field left alone; rules you wrote always win | +| `accounts.staffOnlyRead` | on | `read` on a staff collection without a `read` rule: a fully signed-in account of a staff collection (Payload's default let a visitor account list the staff accounts) | `false` = Payload's default; a `read` rule you wrote wins | | `accounts.firstUserRoute` | `'panel'` | which auth collections `POST /api//first-register` answers for while they are empty: only the one the panel logs in with (the first account of a site → admin). Others get `403`, a second staff collection included, in any spelling of the URL (the plugin's own endpoint sits in front of Payload's); a collection whose own `create` allows an anonymous request keeps its route. With `access.firstUserAdmin: false` and a default role below the panel role, the default `panelRole` is not applied (logged) and an explicit one is refused at start | a list of slugs; `'all'` = Payload's behaviour | | `accounts.password` | `{ minLength: 12 }` | when a password is SET on a staff collection (create, first-user screen, change, reset by e-mail; panel, API and Local API): at least `minLength` characters, not the account's e-mail address. Existing passwords are never checked — a shorter one keeps logging in | `{ minLength }`; `false` = Payload's rule (3 characters) | | `secrets.writeOnly` | on | `smtpPassword` and `turnstileSecretKey` (Site integrations) are never returned: REST, GraphQL and the panel get `'********'` when a value is stored; a save with nothing / empty / the mask keeps it, a new value replaces it, `'[[clear]]'` removes it; the Local API with access control off reads the real value. The panel is the source of these secrets — no env variable. A restore of a version is masked too | `false` = returned to whoever may read the global, as before | -| `secrets.reenterOnChange` | on | a save through access control that changes `smtpHost`, `smtpPort`, `smtpUser`, `smtpRequireTls`, or switches `emailTransport` to SMTP, while a password is stored, must send the password again or remove it (`400` on the field otherwise) — so an admin session cannot send the stored password to a server of its own. The Local API with access control off is not asked | `false` = the stored password follows the new server | +| `secrets.reenterOnChange` | on | a save through access control that changes `smtpHost`, `smtpPort` or `smtpUser` while a password is stored must send the password again or remove it (`400` on the field otherwise), whatever `emailTransport` says — so an admin session cannot send the stored password to a server of its own. A change of the transport alone, and the Local API with access control off, are not asked | `false` = the stored password follows the new server | | `dashboardAlerts` | `{ integrations: 'admin', cookies: 'editor' }` | who sees the plugin's dashboard alerts: integration details (error text, link) for `integrations` and above, a neutral "ask an administrator" for editors below it, nothing for others; the cookie crawl / approval alert for `cookies` and above. With a role, a session that owes its second factor sees none | `integrations: 'editor' | 'all'`, `cookies: 'all'` (`'all'` = as before: no role and no second factor is checked) | | `adminRoute` | `'/admin'` | `config.routes.admin`; stats link and views, `IntegrationAlerts` | the project moves `app/(payload)//` itself and adds the route to the proxy matcher (security.md) | | `twoFactor` | **none = error** | `@clocklimited/payload-2fa` with `forceSetup: true` (TOTP enforced, also checked in the API) | `twoFactor: false` (discouraged); omitting the option throws `[ipal] twoFactor.issuer is required` | diff --git a/reference/.agents/skills/ipal-reference/resources/api.md b/reference/.agents/skills/ipal-reference/resources/api.md index 33cc866..cd34c13 100644 --- a/reference/.agents/skills/ipal-reference/resources/api.md +++ b/reference/.agents/skills/ipal-reference/resources/api.md @@ -67,10 +67,10 @@ Admin panel components from `@intecion/ipal-kit/admin` — the project does NOT | `isAdmin(user, source?)` | `@intecion/ipal-kit`; in client components `@intecion/ipal-kit/client` | Predicate → `boolean`: staff account with the `admin` role (see `hasMinimumRole`). In hooks and endpoints: `isAdmin(req.user, req.payload)`; in a client component: `isAdmin(user, config)` from `/client` — the main entry does not build there with webpack (`'server-only' cannot be imported…`). | | `isEditor(user, source?)` | `@intecion/ipal-kit`; in client components `@intecion/ipal-kit/client` | Predicate → `boolean`: staff account with `editor` or higher. | | `panelAccess(minimum?)`, `applyPanelRole(config, slug, role)`, `resolvePanelRole(option)`, `countBelowPanelRole(payload, slug, role)`, `DEFAULT_PANEL_ROLE` | `@intecion/ipal-kit` | `accounts.panelRole`: an `access.admin` function ("holds at least `minimum`", default `'editor'`; role only, not the second factor); the applier (skips a collection that has its own `access.admin`); the option → role or `null` when off; `{ all, below }` counts for the start-up line; `'editor'`. | -| `staffCreateAccess`, `staffUpdateAccess(slug)`, `sameStaffCollectionAccess(slug)`, `hasPluginRoles(collection)`, `applyStaffAccountAccess(config, staffSlugs, { create?, write?, pluginRoles? })` | `@intecion/ipal-kit` | `accounts.adminOnlyCreate` / `adminOnlyWrite`: the access functions — "an admin, fully signed in" (create, delete); "an admin, or the account itself" (update; self = an account of THAT collection); "an account of this staff collection, or a plugin admin of another" (a collection whose roles are not the plugin's); whether a collection carries the plugin's roles (a top-level `roles` select with only `user` / `editor` / `admin`); the applier — puts the rules on the named staff collections for the operations that have none, `pluginRoles` = slugs whose roles field is injected later. Run it before any plugin that wraps access (the 2FA package). | -| `buildFirstUserEndpoint(option?)`, `applyFirstUserRoute(config, option?)`, `openSignUpCollections(payload)`, `staffCollectionsOpenToOthers(payload)` | `@intecion/ipal-kit` | `accounts.firstUserRoute`: the plugin's own `POST /first-register` collection endpoint, matched before Payload's — `403` unless the collection is the panel's login collection (`'panel'`), is in the list, or its own `create` lets an anonymous request through; otherwise it calls Payload's handler (and sets `req.context.ipalFirstRegister`); the applier (every auth collection; `'all'` adds nothing; `endpoints: false` is left alone). For the doctor: slugs of auth collections with open sign-up; `':'` for every staff collection an account of a non-staff collection may create in, update or delete from. | +| `staffCreateAccess`, `staffUpdateAccess(slug)`, `staffReadAccess`, `sameStaffCollectionAccess(slug)`, `rolesByAdminOnly`, `rolesNotOwn(slug)`, `hasPluginRoles(collection)`, `applyStaffAccountAccess(config, staffSlugs, { create?, write?, read?, pluginRoles? })` | `@intecion/ipal-kit` | `accounts.adminOnlyCreate` / `adminOnlyWrite` / `staffOnlyRead`: the access functions — "an admin, fully signed in" (create, delete, unlock); "an admin, or the account itself" (update; self = an account of THAT collection); "a fully signed-in account of a staff collection" (read); "an account of this staff collection, or a plugin admin of another" (a collection whose roles are not the plugin's); the two field-access functions for a `roles` field (`update`: only an admin / never the account itself); whether a collection carries the plugin's roles (a `roles` select at the top level of the data with only `user` / `editor` / `admin`); the applier — puts the rules on the named staff collections for the operations that have none and closes the `roles` field where the plugin's `update` rule is in force, `pluginRoles` = slugs whose roles field is injected later. Run it before any plugin that wraps access (the 2FA package). | +| `buildFirstUserEndpoint(option?)`, `applyFirstUserRoute(config, option?)`, `adoptLateAuthCollections(payload, staffSlugs, { access?, beforeOperation?, firstUserRoute? })`, `unknownStaffCollections(payload, staffSlugs)`, `openSignUpCollections(payload)`, `staffCollectionsOpenToOthers(payload)`, `staffCollectionsOnOwnRoles(payload)` | `@intecion/ipal-kit` | `accounts.firstUserRoute`: the plugin's own `POST /first-register` collection endpoint, matched before Payload's — `403` unless the collection is the panel's login collection (`'panel'`), is in the list, or its own `create` lets an anonymous request through; otherwise it calls Payload's handler (and sets `req.context.ipalFirstRegister`); the applier (every auth collection; `'all'` adds nothing; `endpoints: false` is left alone). For the doctor: slugs of auth collections with open sign-up; `':'` for every staff collection an account of a non-staff collection may create in, read, update, delete from or unlock; slugs of staff collections with role values of their own on the default rules. `adoptLateAuthCollections` gives auth collections that a plugin listed after ipalKit added the same rules on the live config (called by the plugin at start and on a dev reload; returns the slugs); `unknownStaffCollections` lists staff slugs that are not auth collections (the plugin stops the start on any). | | `checkPassword(password, { email?, minLength? })`, `buildPasswordRuleHook({ minLength? })`, `applyPasswordRule(config, slugs, rule)`, `resolvePasswordRule(option)`, `DEFAULT_PASSWORD_MIN_LENGTH` | `@intecion/ipal-kit` | `accounts.password`: `'short' \| 'email' \| null` for a new password (length in characters); the `beforeOperation` hook for `create` / `update` / `resetPassword` (throws Payload's `ValidationError` on `password`, text in the panel's language; the account's address is looked up by id, reset token or bulk query when the request carries none; a password that is not text is refused; login is never checked); the applier; the option → `{ minLength }` or `null`; `12`. | -| `writeOnlySecret(field, options?)`, `writeOnlySecrets(fields, names, optionsByName?)`, `maskSecretAfterRead`, `keepSecretBeforeValidate`, `buildKeepSecret(options?)`, `SECRET_MASK`, `SECRET_CLEAR`, `isSecretMask(value)`, `INTEGRATION_SECRET_FIELDS`, `SMTP_PASSWORD_BOUND_TO` | `@intecion/ipal-kit` | Write-only secret fields (`secrets.writeOnly`): the wrapper for one field and for named fields anywhere in a tree (tabs, rows, groups); the two field hooks (reads through access control get `'********'`, the Local API with access control off gets the value; a save with nothing / empty / the mask keeps the stored value, `'[[clear]]'` removes it); the hook builder with options — `{ boundTo: ['siblingField'], appliesWhen?: (siblingData) => boolean }`: a save through access control that changes a bound sibling field without sending the secret throws a `ValidationError` on the secret (`secrets.reenterOnChange`); the two constants; the plugin's own secret field names (`smtpPassword`, `turnstileSecretKey`); the fields the SMTP password is bound to (`emailTransport`, `smtpHost`, `smtpPort`, `smtpUser`, `smtpRequireTls`). | +| `writeOnlySecret(field, options?)`, `writeOnlySecrets(fields, names, optionsByName?)`, `maskSecretAfterRead`, `keepSecretBeforeValidate`, `buildKeepSecret(options?)`, `SECRET_MASK`, `SECRET_CLEAR`, `isSecretMask(value)`, `INTEGRATION_SECRET_FIELDS`, `SMTP_PASSWORD_BOUND_TO` | `@intecion/ipal-kit` | Write-only secret fields (`secrets.writeOnly`): the wrapper for one field and for named fields anywhere in a tree (tabs, rows, groups); the two field hooks (reads through access control get `'********'`, the Local API with access control off gets the value; a save with nothing / empty / the mask keeps the stored value, `'[[clear]]'` removes it); the hook builder with options — `{ boundTo: ['siblingField'], appliesWhen?: (siblingData) => boolean }`: a save through access control that changes a bound sibling field without sending the secret throws a `ValidationError` on the secret (`secrets.reenterOnChange`); the two constants; the plugin's own secret field names (`smtpPassword`, `turnstileSecretKey`); the fields the SMTP password is bound to (`smtpHost`, `smtpPort`, `smtpUser` — not the transport: the mail adapter may fall back to SMTP). | | `maskSecretsOnRestore`, `maskWriteOnlySecrets(data, fields)` | `@intecion/ipal-kit` | Versions and write-only secrets: the `afterRead` hook for a global or a collection (a restore answers with the version document, fields under `version`, where field hooks do not run — it masks them there for reads through access control); the walker it uses (masks every write-only field in `data`, following tabs, rows, groups, arrays and blocks). On Site integrations by default; add the hook to your own entity that has both. | | `requestFromOwnOrigin(req, extraOrigins?)`, `ownOrigins(req, extraOrigins?)`, `reportRefusedOrigin(req, extraOrigins?)` | `@intecion/ipal-kit` | `twoFactor.sameOrigin`: `false` when a browser marks the request as coming from another origin (`Origin` not among the request's host, `serverURL`, `csrf`, `cors`, the extras; a default port written out on the host is ignored; else `Sec-Fetch-Site` not `same-origin` / `none`); `true` without those headers. `ownOrigins` → `{ hosts, origins }`. `reportRefusedOrigin` writes one log line per refused origin and process (at most 50) with the ways to allow it, and returns whether it wrote. For your own state-changing endpoint. | | `buildVerifyLimit(collection, { max?, windowMinutes?, store? })`, `verifyLimitKey(collection, id)`, `clearVerifyLimits()` | `@intecion/ipal-kit` | `twoFactor.verifyLimit`: `async (req) => Response \| null` — counts an attempt of `req.user` in memory and, unless `store: 'memory'`, in `payload.kv`; a `429` with `Retry-After` past `max`. The kv key of an account's count; emptying the in-memory counts (tests). | @@ -81,7 +81,7 @@ Admin panel components from `@intecion/ipal-kit/admin` — the project does NOT | `buildRolesField(defaultRole?, { firstUserAdmin? })` | `@intecion/ipal-kit` | The `roles` select field the plugin injects (only admins set roles; `firstUserAdmin` default `true` = the account made on "Create first user" gets `admin`). The plugin wires it itself — use it only for an auth collection the plugin does not manage. | | `injectRoles(config, accessOption)` | `@intecion/ipal-kit` | Adds `roles` to `accessOption.authCollection` in a config. The plugin calls it itself with `access` — do not call. | -**Types:** `AccountsOptions` (`accounts`: `panelRole`, `adminOnlyCreate`, `adminOnlyWrite`, `firstUserRoute`, `password`), `WriteOnlySecretOptions` (`{ boundTo?, appliesWhen? }`), `PasswordRuleOptions` (`{ minLength? }`), `FirstUserRouteOption` (`'panel' \| 'all' \| string[]`), `TurnstileOnConfigError` / `TurnstileOnConfigErrorOption` / `TurnstileFormKind` (`@intecion/ipal-kit/server`), `VerifyLimitOptions` (`twoFactor.verifyLimit`: `{ max?, windowMinutes?, store? }`), `RequireSetupOptions` (`twoFactor.requireSetup`), `TwoFactorResetOptions`, `TwoFactorSetupState`, `SafeBackRule` / `SafeBackContext` (`twoFactor.safeBack` as a function: `(back, { adminRoute, origin? }) => string`), `TotpViewComponent` (a view component as registered: a path or `{ path, exportName?, clientProps?, serverProps? }`), `SafeTotpViewProps` (`@intecion/ipal-kit/admin`), `Role` (`'user' \| 'editor' \| 'admin'`), `AccessOption` (the plugin's `access` option: `authCollection`, `defaultRole`, `authAccess`, `firstUserAdmin`, `staffCollections`). +**Types:** `AccountsOptions` (`accounts`: `panelRole`, `adminOnlyCreate`, `adminOnlyWrite`, `staffOnlyRead`, `firstUserRoute`, `password`), `StaffAccountAccessOptions` (`{ create?, write?, read?, pluginRoles? }`), `StaffAccountRules` (what the plugin put on a staff collection, in `custom.ipalAccountRules`: `{ applied, ownRoles }`), `WriteOnlySecretOptions` (`{ boundTo?, appliesWhen? }`), `PasswordRuleOptions` (`{ minLength? }`), `FirstUserRouteOption` (`'panel' \| 'all' \| string[]`), `TurnstileOnConfigError` / `TurnstileOnConfigErrorOption` / `TurnstileFormKind` (`@intecion/ipal-kit/server`), `VerifyLimitOptions` (`twoFactor.verifyLimit`: `{ max?, windowMinutes?, store? }`), `RequireSetupOptions` (`twoFactor.requireSetup`), `TwoFactorResetOptions`, `TwoFactorSetupState`, `SafeBackRule` / `SafeBackContext` (`twoFactor.safeBack` as a function: `(back, { adminRoute, origin? }) => string`), `TotpViewComponent` (a view component as registered: a path or `{ path, exportName?, clientProps?, serverProps? }`), `SafeTotpViewProps` (`@intecion/ipal-kit/admin`), `Role` (`'user' \| 'editor' \| 'admin'`), `AccessOption` (the plugin's `access` option: `authCollection`, `defaultRole`, `authAccess`, `firstUserAdmin`, `staffCollections`). ## Accessibility — widget (`accessibility`) — details: `node_modules/@intecion/ipal-kit/docs/accessibility.md` diff --git a/reference/.agents/skills/ipal-setup/SKILL.md b/reference/.agents/skills/ipal-setup/SKILL.md index 8006ad5..3cf63a9 100644 --- a/reference/.agents/skills/ipal-setup/SKILL.md +++ b/reference/.agents/skills/ipal-setup/SKILL.md @@ -250,9 +250,14 @@ the panel shows Site settings, Site integrations, Cookies, Form messages, the Fo - **Account rules** (`accounts`, on by default; `false` or key by key to change): the panel opens for `editor` and above (`panelRole`; an account with only `user` sees "Unauthorized", the API is not touched — give panel users at least `editor`); only an admin creates staff accounts, and an account is changed by an admin or by - itself — also in the project's own staff collection (`adminOnlyCreate`, `adminOnlyWrite`; a staff collection - with role values of its own gets "an account of that collection, or a plugin admin" instead, so write its - `create` / `update` / `delete` / `read` rules yourself); Payload's first-user route answers only for the + itself, nobody changes its own roles, and only staff accounts read staff accounts — also in the project's own + staff collection and in one a later plugin adds (`adminOnlyCreate`, `adminOnlyWrite`, `staffOnlyRead`). **A + staff collection with role values of its own** (not `user` / `editor` / `admin`) gets only "an account of that + collection, or a plugin admin": the plugin cannot rank your roles, so inside it every account may create an + account with any role — **write its `create` / `update` / `delete` rules and the field access of its `roles` + field yourself** (`ipal-doctor --url` → `staff-own-roles`). Give every staff collection a `roles` field: without + one each of its accounts is an admin to the plugin. Every slug in `access.staffCollections` must be an auth + collection of the config, or the site does not start; Payload's first-user route answers only for the panel's login collection (`firstUserRoute`) — so **create the first account right after the first deploy**, it becomes the admin; a new password has at least 12 characters (`password`). A customer collection with sign-up: write its own `create: () => true`; the rules do not touch it. Do not combine @@ -266,8 +271,7 @@ the panel shows Site settings, Site integrations, Cookies, Form messages, the Fo them; `TURNSTILE_SECRET_KEY` is deprecated (local test keys in `.env` still work). Read them only on the server with the Local API. `secrets: { writeOnly: false }` turns it off. Changing the SMTP server, port or user name in the panel asks for the password again (`secrets.reenterOnChange`); a seed with the Local API is - not asked. Tick **Require encryption** in Site integrations → E-mail sending where the mail server supports - STARTTLS (off by default; the field `smtpRequireTls` needs a migration on Postgres / SQLite). + not asked. - **Forms with files** are refused while Turnstile cannot check (wrong keys, Cloudflare down); text forms are still accepted. `forms: { turnstileOnConfigError: … }` changes either. - A second auth collection (`customers`, a client zone): set `admin: { user: 'users' }` in `buildConfig`; its diff --git a/reference/.agents/skills/ipal-upgrade/SKILL.md b/reference/.agents/skills/ipal-upgrade/SKILL.md index fc9572d..90092a6 100644 --- a/reference/.agents/skills/ipal-upgrade/SKILL.md +++ b/reference/.agents/skills/ipal-upgrade/SKILL.md @@ -424,11 +424,10 @@ setup screen with "Set up two-step verification by …"; after the code it is in account → "Two-step verification: Set up." and the reset button; delete the account. **→ the release with `accounts` / `secrets` (CHANGELOG "Unreleased — hardening"; PROGRAMISTA §6, item 69) — read every point, most sites change nothing:** -1. Update the package, `pnpm install`, `pnpm ipal:skills`, `pnpm payload generate:types`. No import-map change. - **One new field**: `smtpRequireTls` (a checkbox) in Site integrations — MongoDB needs nothing; **Postgres / - SQLite: `pnpm payload migrate:create`, commit, deploy the migration with the code** (deployment.md §4.3), or - Site integrations cannot be read (no e-mail, no Turnstile). The verify count uses Payload's own `payload-kv` - collection. +1. Update the package, `pnpm install`, `pnpm ipal:skills`, `pnpm payload generate:types`. No import-map change, **no + schema change and no migration** on any database (the verify count uses Payload's own `payload-kv` + collection). `grep -n "staffCollections\|authCollection" src/payload.config.ts`: every slug there must be an + auth collection of the config — a wrong one now stops the start with the slug in the message. 2. **Panel access by role.** After the first start read the log: `[ipal] N account(s) of "users" are below the role "editor" and cannot open the admin panel`. Those accounts (role `user`, or no role) now see "Unauthorized" in the panel. Give the people who work in the panel `editor`, or set @@ -440,11 +439,9 @@ account → "Two-step verification: Set up." and the reset button; delete the ac them over REST / GraphQL as an admin, or with `overrideAccess: false`, now gets `'********'`: read them on the server with `payload.findGlobal({ slug: 'site-integrations' })`. A script that saves the whole global back keeps the secrets (the mask means "keep"). **New:** a save in the panel or over the API that changes the SMTP - server, port, user name or "Require encryption" must send the password again ("Enter the password again…"); - a script that does that over REST / GraphQL sends the password with it, a seed with the Local API is not - asked. `secrets: { reenterOnChange: false }` turns it off. With the owner, consider ticking **Require - encryption** (Site integrations → E-mail sending) where the server supports STARTTLS, then send a test - e-mail. During a rolling update a page opened under the new version and saved against the OLD one stores + server, port or user name must send the password again ("Enter the password again…"), also when the transport + is set to Microsoft Graph; a script that does that over REST / GraphQL sends the password with it, a seed + with the Local API is not asked. `secrets: { reenterOnChange: false }` turns it off. During a rolling update a page opened under the new version and saved against the OLD one stores `********` as the password: after the deploy, check that a test e-mail goes out. 4. **`TURNSTILE_SECRET_KEY` is deprecated** (it still works). If the log says `[ipal] Deprecated: the Turnstile secret key comes from the TURNSTILE_SECRET_KEY environment variable` or `ipal-doctor --url` reports @@ -455,18 +452,26 @@ account → "Two-step verification: Set up." and the reset button; delete the ac File field is now refused (text forms are accepted as before). Check `ipal-doctor --url` → no `turnstile-degraded`; to keep the old behaviour: `forms: { turnstileOnConfigError: { files: 'allow' } }`. 6. **Account creation and changes.** A project whose **own** staff collection has no `create` / `update` / - `delete` rule gets one (before: any signed-in account of any auth collection — a customer could change a - staff password): + `delete` / `unlock` / `read` rule gets one (before: any signed-in account of any auth collection — a customer + could change a staff password, list the staff accounts, lift a login lock): - the collection carries the plugin's roles (`access.authCollection`, or a `roles` select with only `user` / - `editor` / `admin`): create and delete — an admin; update — an admin or the account itself. **Check:** does - a non-admin create or edit other accounts there today? Then write the rule you want; + `editor` / `admin`): create, delete, unlock — an admin; update — an admin or the account itself; its + `roles` field — only an admin (when the field has no `access.update` of its own). **Check:** does a + non-admin create or edit other accounts, or change roles, there today? Then write the rule you want; - the collection has **role values of its own** (`superadmin`, …) or no roles: accounts of that collection - keep working as before; accounts of other collections are refused. Nothing to do, but write your own rules - — the plugin does not know your roles. + keep working as before, except that an account no longer changes its **own** roles; accounts of other + collections are refused. **Write your own rules** — the plugin does not know your roles, and inside the + collection every account can still create an account with any role (`ipal-doctor --url` → + `staff-own-roles`); + - `read`: only staff accounts read a staff collection. **Check:** does the front end show staff accounts + (an author box) to logged-in visitors with the visitor's session? Then write that collection's `read` rule, + or `accounts: { staffOnlyRead: false }`. Anonymous visitors never could. + A staff collection added by a plugin listed after ipalKit gets the same rules at start. `first-register` on any auth collection other than the panel's login collection answers `403` unless that collection allows sign-up. `access.firstUserAdmin: false` with a default role below `editor`: the panel role is not applied (a warning at start), or — with `accounts.panelRole` set — the start fails with the fix in the - message. Wanted otherwise: `accounts: { adminOnlyCreate: false, adminOnlyWrite: false, firstUserRoute: 'all' }`. + message. Wanted otherwise: `accounts: { adminOnlyCreate: false, adminOnlyWrite: false, staffOnlyRead: false, + firstUserRoute: 'all' }`. 7. **Passwords.** New passwords of staff accounts need 12 characters; **existing shorter passwords keep working** — nobody is logged out or asked to change. A script that creates staff accounts with a short password fails with a validation error: lengthen it, or `accounts: { password: { minLength: 8 } }`. @@ -482,7 +487,7 @@ account → "Two-step verification: Set up." and the reset button; delete the ac error text; accounts with only `user` see no alerts. `dashboardAlerts: { integrations: 'all' }` restores it (`'all'` checks no role and no second factor). **Check:** `pnpm exec ipal-doctor --url ` (new rules: `access-missing`, `csrf-empty`, `open-signup`, -`staff-accounts-open`, `turnstile-degraded`, `turnstile-env-key`); as an admin `GET /api/globals/site-integrations` shows +`staff-accounts-open`, `staff-own-roles`, `turnstile-degraded`, `turnstile-env-key`); as an admin `GET /api/globals/site-integrations` shows `"smtpPassword":"********"`; a test e-mail and a test form still work; an editor and an admin still log in. ## 2. Inventory (no code changes)