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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .changeset/32115-scim-deactivation-revokes-api-keys.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
'@objectstack/plugin-auth': patch
'@objectstack/core': patch
'@objectstack/platform-objects': patch
---

fix(plugin-auth): a directory deactivation revokes the user's API keys, and no one restores them

Clause-②: yes (widening)
Metadata-protocol: none

**The rule.** Deactivating a user through SCIM (`active: false`), or deleting one (`DELETE /Users/{id}`), revokes every API key the user owns. Each key row stays, with `revoked: true` and `revoked_reason: scim_deactivated`. A later re-activation lifts the directory's ban and re-arms none of those keys: the person creates a new key (`POST /api/v1/keys`, or the API Keys page) and replaces the old one wherever it is configured. An administrator's own ban and unban are unchanged and leave keys alone. The user's local password is not changed by this release.

**Who can restore such a key.** No one, from a user context. The owner's Restore is refused `403 PERMISSION_DENIED`, and so is a platform administrator's, naming the reason and the new-key road. The AI service account door (`POST /api/v1/auth/service-account/restore-key`) refuses it the same way. The key door's `403 API_KEY_REVOKED` says the key cannot be restored and names no restorer. A key the user had already revoked, or that carried `admin_password_reset` or `administrator_suspended`, is restamped with `scim_deactivated` by the deactivation; a key that carried `organization_membership_ended` keeps it, since no one restores either.

**`@objectstack/platform-objects`: `sys_api_key.revoked_reason` gains the option `scim_deactivated`** ("Deactivated by the directory"), beside `admin_password_reset`, `organization_membership_ended` and `administrator_suspended`. The column stays readonly and off the ADR-0092 D2 whitelist, so no data-API write sets or clears it. The field's help text names the new reason and that no one restores it; every shipped locale carries the new option and help.

**If the revocation does not finish.** The deactivation still lands: the account is disabled and the SCIM request succeeds. The server logs one `error` line naming the user, how many keys were and were not revoked, and the remedy (revoke the remaining `sys_api_key` rows with that reason). The next SCIM write that leaves the user inactive runs the revocation again.
6 changes: 6 additions & 0 deletions content/docs/permissions/authentication.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,12 @@ like any banned account's, with one field added:
sends `active: true` again. An administrator's ban that a deactivation
arrived on top of keeps the administrator's reason, and answers as an
administrator's ban.
- A deactivation, or a `DELETE /Users/{id}`, also revokes every API key the
user owns (`revoked_reason: scim_deactivated`). A re-activation re-arms none
of them, and no one can restore them: the owner's Restore and a platform
administrator's are both refused `403 PERMISSION_DENIED`. The person creates
a new key under **Account → Developer → API Keys** and replaces the old one
wherever it is configured.
- The cause is told only after the password verified: a wrong password is the
ordinary `401 INVALID_EMAIL_OR_PASSWORD`, whatever the account's state. It
names no connection, provider or other account.
Expand Down
30 changes: 15 additions & 15 deletions content/docs/permissions/tenant-audit-census.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ are reported as `undecidable` rather than assumed either way.

The same holds twice over for the context. An options argument spelled as a
literal can be read; one spelled `options`, `{ ...opts }`, or handed through a
forwarding shim cannot, and **59 of the 310 sites are spelled that way**. A
forwarding shim cannot, and **59 of the 311 sites are spelled that way**. A
context resolved from an inline literal or a local `const` can be tested for
`isSystem`; one arriving from a helper call cannot.

Expand Down Expand Up @@ -197,10 +197,10 @@ reproduce them. Where it disagrees, it disagrees on the page:

| carried figure | where it survives | this census |
| :--- | :--- | ---: |
| 175 write call sites | quoted in the merged changeset | **310** |
| 175 write call sites | quoted in the merged changeset | **311** |
| 24 carrying no tenant context | quoted in the merged changeset | **3** provable and tenancy-enabled; **32** more whose options argument is unreadable |
| 127 of 175 statically decidable, 48 runtime-parameter-name sites | restated on the `isSystem`-scoping card | **216 of 310** decidable, **94** undecidable |
| 135 (77%) silenced by the `isSystem` guard before the posture gate | the lost issue body — **no surviving corroboration** | **not reproduced**: 174 decidably elevated, 0 decidably not, 124 undecidable |
| 127 of 175 statically decidable, 48 runtime-parameter-name sites | restated on the `isSystem`-scoping card | **216 of 311** decidable, **95** undecidable |
| 135 (77%) silenced by the `isSystem` guard before the posture gate | the lost issue body — **no surviving corroboration** | **not reproduced**: 174 decidably elevated, 0 decidably not, 125 undecidable |
| 141 and 132, two independent re-derivations | the card that filed this work | — |

**The differences are not reconciled, and deliberately so.** The old census's
Expand All @@ -217,11 +217,11 @@ would report a smaller number and would not say so.

The fourth row is the one worth flagging to anyone citing it. **The 135 / 77%
figure has no surviving corroboration anywhere in the tree.** This census reads
174 of 310 (56%) as decidably elevated, with 124 more whose elevation is a
174 of 311 (56%) as decidably elevated, with 125 more whose elevation is a
run-time fact — so the claim is neither confirmed nor refuted, and the honest
answer is that a static reading cannot settle it.

⇒ **Cite `3 / 310`, and say what it is**: the sites whose options argument was
⇒ **Cite `3 / 311`, and say what it is**: the sites whose options argument was
READ and holds no tenant context, against a decidably tenancy-enabled object.
That is the control's provable yield surface. ⛔ Do not cite it as "the sites
without tenant context" — **32 further sites** have an options argument this
Expand All @@ -233,31 +233,31 @@ cannot read, and they are neither in nor out.

| what | count |
| :--- | ---: |
| write call sites on the application surface | **310** |
| write call sites on the application surface | **311** |
| …whose object name is statically decidable | 216 |
| …whose object name is chosen at run time | 94 |
| …whose object name is chosen at run time | 95 |
| …against an object with tenancy ENABLED | 209 |
| …against an object that declares tenancy off | 7 |
| threading a tenant context | 239 |
| threading a tenant context | 240 |
| PROVABLY carrying none (options read, no context key) | **12** |
| …of those, against a decidably tenancy-enabled object | **3** |
| options argument UNREADABLE — may or may not carry one | 59 |
| …of those, against a decidably tenancy-enabled object | 32 |
| threading a decidably ELEVATED (`isSystem`) context | 174 |
| threading a context that is decidably NOT elevated | 0 |
| threading a context whose elevation is a run-time fact | 124 |
| threading a context whose elevation is a run-time fact | 125 |

| how the instrument reached the site | count |
| :--- | ---: |
| receiver carried a readable engine type | 248 |
| receiver carried a readable engine type | 249 |
| receiver erased, placed by the object NAME | 52 |
| receiver erased, placed by an `object: string` PARAMETER | 5 |
| receiver erased, placed by an `UNTYPED_RECEIVERS` row | 5 |

| object name spelled inline | 131 |
| object name spelled through a `const` | 85 |
| object name is an `object: string` parameter | 10 |
| object name is some other run-time expression | 84 |
| object name is some other run-time expression | 85 |

### Subtractions the census could NOT defend — enforced

Expand Down Expand Up @@ -307,12 +307,12 @@ holds still. They are required to be HERE and to say WHEN they were true;
their values are not compared. The reasoning, and the measurement behind it,
are in `scripts/check-tenant-audit-census.mjs`.

Measured on 2026-11-13 at `cc6cce96c`.
Measured on 2026-11-13 at `fc310c98b`.

| corpus scale (not enforced) | count |
| :--- | ---: |
| tracked non-test sources scanned | 1149 |
| engine-shaped types recognised | 135 |
| tracked non-test sources scanned | 1150 |
| engine-shaped types recognised | 136 |
| declared objects in the registry | 137 |
| same-named calls subtracted as non-engine | 293 |

Expand Down
15 changes: 8 additions & 7 deletions docs/audits/2026-08-tenant-audit-write-call-sites.counts.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ silent, and `node scripts/tenant-audit-census.mjs --write` is the resolution.

| Measure | Value |
|---|---:|
| Write call sites | 310 |
| Write call sites | 311 |
| Object name statically decidable | 216 |
| Object name chosen at run time | 94 |
| Object name chosen at run time | 95 |
| Against a tenancy-enabled object | 209 |
| Against an object declaring tenancy off | 7 |
| Threading a tenant context | 239 |
| Threading a tenant context | 240 |
| Provably carrying none | 12 |
| …and decidably tenancy-enabled | 3 |
| Options argument unreadable | 59 |
| …and decidably tenancy-enabled | 32 |
| Threading a decidably elevated context | 174 |
| Threading a decidably non-elevated context | 0 |
| Threading a context of undecidable elevation | 124 |
| Threading a context of undecidable elevation | 125 |

## Subtractions the census could NOT defend — enforced

Expand Down Expand Up @@ -90,12 +90,12 @@ holds still. They are required to be HERE and to say WHEN they were true;
their values are not compared. The reasoning, and the measurement behind it,
are in `scripts/check-tenant-audit-census.mjs`.

Measured on 2026-11-13 at `cc6cce96c`.
Measured on 2026-11-13 at `fc310c98b`.

| corpus scale (not enforced) | count |
| :--- | ---: |
| tracked non-test sources scanned | 1149 |
| engine-shaped types recognised | 135 |
| tracked non-test sources scanned | 1150 |
| engine-shaped types recognised | 136 |
| declared objects in the registry | 137 |
| same-named calls subtracted as non-engine | 293 |

Expand Down Expand Up @@ -187,6 +187,7 @@ Measured on 2026-11-13 at `cc6cce96c`.
| `packages/plugins/plugin-auth/src/scim-connection-admin.ts` | `insert` | `sys_audit_log` | enabled | elevated | 1 |
| `packages/plugins/plugin-auth/src/scim-connection-service.ts` | `insert` | `sys_scim_connection_credential` | enabled | PROVABLY NONE | 1 |
| `packages/plugins/plugin-auth/src/scim-connection-service.ts` | `update` | `sys_scim_connection_credential` | enabled | elevated | 2 |
| `packages/plugins/plugin-auth/src/scim-deactivation-key-revocation.ts` | `update` | `SystemObjectName.API_KEY` | undecidable | context, elevation undecidable | 1 |
| `packages/plugins/plugin-auth/src/scim-group-projection.ts` | `delete` | `sys_user_permission_set` | enabled | PROVABLY NONE | 1 |
| `packages/plugins/plugin-auth/src/scim-group-projection.ts` | `insert` | `sys_user_permission_set` | enabled | elevated | 1 |
| `packages/plugins/plugin-auth/src/scim-identity-source.ts` | `update` | `sys_user` | enabled | context, elevation undecidable | 1 |
Expand Down
19 changes: 19 additions & 0 deletions packages/core/src/security/api-key-lifecycle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,4 +386,23 @@ describe('[#23944] the revoked refusal agrees with the declared restore action',
expect(suspendedMessage).toContain('Restore API Key');
expect(suspendedMessage).toContain('POST /api/v1/keys');
});

it('a key the directory deactivation revoked names no restorer, only the new-key road', async () => {
// `revoked_reason: scim_deactivated` is stamped by plugin-auth when the
// organization's directory deactivates or deletes the owner through SCIM,
// and its restore door refuses every user-context restore on that reason,
// a platform administrator's included, after a re-activation too. The text
// follows the door: it offers no restore anyone could make. Code, status
// and every carried field stay those of any revoked key.
const deactivated = await resolveApiKeyAdmission(
makeQl({ revoked: true, revoked_reason: 'scim_deactivated' }), headers(), NOW, undefined, undefined, policy(),
);

expect(deactivated.outcome === 'lifecycle' && deactivated.refusal).toMatchObject({ code: 'API_KEY_REVOKED', keyId: KEY_ID, userId: OWNER });
const deactivatedMessage = deactivated.outcome === 'lifecycle' ? deactivated.refusal.message : '';
expect(deactivatedMessage).toMatch(/directory deactivated its owner, and it cannot be restored/);
expect(deactivatedMessage).not.toMatch(/can restore it/);
expect(deactivatedMessage).not.toContain('Restore API Key');
expect(deactivatedMessage).toContain('POST /api/v1/keys');
});
});
16 changes: 12 additions & 4 deletions packages/core/src/security/api-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,10 +424,14 @@ function lifecycleRefusalOf(
// its owner's membership in the
// organization ended (`organization_membership_ended`, written by the
// host that removed them) by no one, the same guard refusing every
// user-context restore of it; any other revoked key by its owner or a
// platform administrator. The text names exactly those restorers, and
// says the key cannot come back only where no restorer exists. Rotation
// stays the other road, for a key that should not come back.
// user-context restore of it; a key revoked because the organization's
// directory deactivated or deleted its owner through SCIM
// (`scim_deactivated`, written by plugin-auth's directory deactivation)
// by no one either, a re-activation included; any other revoked key by
// its owner or a platform administrator. The text names exactly those
// restorers, and says the key cannot come back only where no restorer
// exists. Rotation stays the other road, for a key that should not come
// back.
message: row.revoked_reason === 'admin_password_reset'
? `${label} was revoked by an administrator's forced password reset. Only a platform administrator can `
+ 'restore it (the Restore API Key action on the API Keys list); otherwise create a new key '
Expand All @@ -440,6 +444,10 @@ function lifecycleRefusalOf(
? `${label} was revoked because its owner's membership in the organization ended, and it cannot be `
+ 'restored. A member of the organization creates a new key (POST /api/v1/keys, or the API Keys page) '
+ 'and replaces this one wherever it is configured.'
: row.revoked_reason === 'scim_deactivated'
? `${label} was revoked because the organization's directory deactivated its owner, and it cannot be `
+ 'restored, even after the owner is re-activated. Its owner creates a new key (POST /api/v1/keys, or the '
+ 'API Keys page) and replaces this one wherever it is configured.'
: `${label} was revoked. Its owner or a platform administrator can restore it (the Restore API Key action `
+ 'on the API Keys list); otherwise create a new key (POST /api/v1/keys, or the API Keys page) and replace '
+ 'this one wherever it is configured.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1209,11 +1209,12 @@ export const arObjects: NonNullable<TranslationData['objects']> = {
},
revoked_reason: {
label: "سبب الإلغاء",
help: "سبب إبطال المفتاح، حين يحدد من يستطيع استعادته. إعادة تعيين كلمة المرور من قِبل المسؤول: لا يستطيع استعادة المفتاح إلا مسؤول المنصة. انتهاء العضوية في المؤسسة: غادر المالك المؤسسة، ولا يستطيع أحد استعادة المفتاح؛ وينشئ عضوٌ مفتاحًا جديدًا. معلّق من قِبل مسؤول: أبطل مسؤول المنصة مفتاحًا لا يملكه، ولا يستطيع استعادته إلا مسؤول المنصة. يُمسح عند استعادة المفتاح. فارغ للمفتاح الذي أبطله مالكه من قائمة مفاتيح API.",
help: "سبب إبطال المفتاح، حين يحدد من يستطيع استعادته. إعادة تعيين كلمة المرور من قِبل المسؤول: لا يستطيع استعادة المفتاح إلا مسؤول المنصة. انتهاء العضوية في المؤسسة: غادر المالك المؤسسة، ولا يستطيع أحد استعادة المفتاح؛ وينشئ عضوٌ مفتاحًا جديدًا. معلّق من قِبل مسؤول: أبطل مسؤول المنصة مفتاحًا لا يملكه، ولا يستطيع استعادته إلا مسؤول المنصة. أُلغي تفعيله من قِبل الدليل: ألغى دليل المؤسسة (SCIM) تفعيل المالك أو حذفه، ولا يستطيع أحد استعادة المفتاح، حتى بعد إعادة تفعيل المالك؛ وينشئ المالك مفتاحًا جديدًا. يُمسح عند استعادة المفتاح. فارغ للمفتاح الذي أبطله مالكه من قائمة مفاتيح API.",
options: {
admin_password_reset: "إعادة تعيين كلمة المرور من قِبل المسؤول",
organization_membership_ended: "انتهاء العضوية في المؤسسة",
administrator_suspended: "معلّق من قِبل مسؤول"
administrator_suspended: "معلّق من قِبل مسؤول",
scim_deactivated: "أُلغي تفعيله من قِبل الدليل"
}
},
key: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1209,11 +1209,12 @@ export const deObjects: NonNullable<TranslationData['objects']> = {
},
revoked_reason: {
label: "Widerrufsgrund",
help: "Warum der Schlüssel widerrufen wurde, sofern das entscheidet, wer ihn wiederherstellen kann. Passwortzurücksetzung durch Administrator: Nur ein Plattformadministrator kann den Schlüssel wiederherstellen. Mitgliedschaft in der Organisation beendet: Der Eigentümer hat die Organisation verlassen, und niemand kann den Schlüssel wiederherstellen; ein Mitglied legt einen neuen an. Von einem Administrator gesperrt: Ein Plattformadministrator hat einen Schlüssel widerrufen, der ihm nicht gehört, und nur ein Plattformadministrator kann ihn wiederherstellen. Wird beim Wiederherstellen des Schlüssels gelöscht. Leer bei einem Schlüssel, den sein Eigentümer in der Liste der API-Schlüssel widerrufen hat.",
help: "Warum der Schlüssel widerrufen wurde, sofern das entscheidet, wer ihn wiederherstellen kann. Passwortzurücksetzung durch Administrator: Nur ein Plattformadministrator kann den Schlüssel wiederherstellen. Mitgliedschaft in der Organisation beendet: Der Eigentümer hat die Organisation verlassen, und niemand kann den Schlüssel wiederherstellen; ein Mitglied legt einen neuen an. Von einem Administrator gesperrt: Ein Plattformadministrator hat einen Schlüssel widerrufen, der ihm nicht gehört, und nur ein Plattformadministrator kann ihn wiederherstellen. Durch das Verzeichnis deaktiviert: Das Verzeichnis der Organisation (SCIM) hat den Eigentümer deaktiviert oder gelöscht, und niemand kann den Schlüssel wiederherstellen, auch nicht nach der Reaktivierung des Eigentümers; der Eigentümer legt einen neuen an. Wird beim Wiederherstellen des Schlüssels gelöscht. Leer bei einem Schlüssel, den sein Eigentümer in der Liste der API-Schlüssel widerrufen hat.",
options: {
admin_password_reset: "Passwortzurücksetzung durch Administrator",
organization_membership_ended: "Mitgliedschaft in der Organisation beendet",
administrator_suspended: "Von einem Administrator gesperrt"
administrator_suspended: "Von einem Administrator gesperrt",
scim_deactivated: "Durch das Verzeichnis deaktiviert"
}
},
key: {
Expand Down
Loading
Loading