Skip to content

Commit ea6dbff

Browse files
committed
wip(plugin-auth): a platform administrator's revoke of someone else's API key holds against its owner
Claude-Session: https://claude.ai/code/session_01QUs3BuLtRmSkjNPDYrwA9T Co-authored-by: Claude <noreply@anthropic.com>
1 parent 6846513 commit ea6dbff

17 files changed

Lines changed: 378 additions & 73 deletions

‎packages/core/src/security/api-key-lifecycle.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,4 +368,22 @@ describe('[#23944] the revoked refusal agrees with the declared restore action',
368368
expect(endedMessage).not.toMatch(/can restore it/);
369369
expect(endedMessage).toContain('POST /api/v1/keys');
370370
});
371+
372+
it('a key a platform administrator suspended names a platform administrator as its only restorer', async () => {
373+
// `revoked_reason: administrator_suspended` is stamped by plugin-auth's
374+
// restore guard when a platform administrator revokes a key they do not
375+
// own, or written by a host that stops a key itself, and the restore door
376+
// refuses the owner on that reason. The text follows the door. Code,
377+
// status and every carried field stay those of any revoked key.
378+
const suspended = await resolveApiKeyAdmission(
379+
makeQl({ revoked: true, revoked_reason: 'administrator_suspended' }), headers(), NOW, undefined, undefined, policy(),
380+
);
381+
382+
expect(suspended.outcome === 'lifecycle' && suspended.refusal).toMatchObject({ code: 'API_KEY_REVOKED', keyId: KEY_ID, userId: OWNER });
383+
const suspendedMessage = suspended.outcome === 'lifecycle' ? suspended.refusal.message : '';
384+
expect(suspendedMessage).toMatch(/was suspended by a platform administrator\. Only a platform administrator can restore it/);
385+
expect(suspendedMessage).not.toMatch(/owner/i);
386+
expect(suspendedMessage).toContain('Restore API Key');
387+
expect(suspendedMessage).toContain('POST /api/v1/keys');
388+
});
371389
});

‎packages/core/src/security/api-key.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,11 @@ function lifecycleRefusalOf(
313313
// (`sys_api_key`'s own row action): the key works at once, no re-issue.
314314
// Who may clear it depends on why it was set, read off the row's
315315
// `revoked_reason`: a key an administrator's forced password reset
316-
// revoked (`admin_password_reset`) is restored by a platform
317-
// administrator only (plugin-auth `api-key-restore-guard.ts` refuses its
318-
// owner); a key revoked because its owner's membership in the
316+
// revoked (`admin_password_reset`), and a key a platform administrator
317+
// revoked although it is not theirs (`administrator_suspended`), is
318+
// restored by a platform administrator only (plugin-auth
319+
// `api-key-restore-guard.ts` refuses its owner); a key revoked because
320+
// its owner's membership in the
319321
// organization ended (`organization_membership_ended`, written by the
320322
// host that removed them) by no one, the same guard refusing every
321323
// user-context restore of it; any other revoked key by its owner or a
@@ -326,6 +328,10 @@ function lifecycleRefusalOf(
326328
? `${label} was revoked by an administrator's forced password reset. Only a platform administrator can `
327329
+ 'restore it (the Restore API Key action on the API Keys list); otherwise create a new key '
328330
+ '(POST /api/v1/keys, or the API Keys page) and replace this one wherever it is configured.'
331+
: row.revoked_reason === 'administrator_suspended'
332+
? `${label} was suspended by a platform administrator. Only a platform administrator can restore it `
333+
+ '(the Restore API Key action on the API Keys list); otherwise create a new key (POST /api/v1/keys, or '
334+
+ 'the API Keys page) and replace this one wherever it is configured.'
329335
: row.revoked_reason === 'organization_membership_ended'
330336
? `${label} was revoked because its owner's membership in the organization ended, and it cannot be `
331337
+ 'restored. A member of the organization creates a new key (POST /api/v1/keys, or the API Keys page) '

‎packages/platform-objects/src/apps/translations/ar.objects.generated.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,10 +1160,11 @@ export const arObjects: NonNullable<TranslationData['objects']> = {
11601160
},
11611161
revoked_reason: {
11621162
label: "سبب الإلغاء",
1163-
help: "سبب إبطال المفتاح، حين يحدد من يستطيع استعادته. إعادة تعيين كلمة المرور من قِبل المسؤول: لا يستطيع استعادة المفتاح إلا مسؤول المنصة. انتهاء العضوية في المؤسسة: غادر المالك المؤسسة، ولا يستطيع أحد استعادة المفتاح؛ وينشئ عضوٌ مفتاحًا جديدًا. يُمسح عند استعادة المفتاح. فارغ للمفتاح المُبطَل من قائمة مفاتيح API.",
1163+
help: "سبب إبطال المفتاح، حين يحدد من يستطيع استعادته. إعادة تعيين كلمة المرور من قِبل المسؤول: لا يستطيع استعادة المفتاح إلا مسؤول المنصة. انتهاء العضوية في المؤسسة: غادر المالك المؤسسة، ولا يستطيع أحد استعادة المفتاح؛ وينشئ عضوٌ مفتاحًا جديدًا. معلّق من قِبل مسؤول: أبطل مسؤول المنصة مفتاحًا لا يملكه، ولا يستطيع استعادته إلا مسؤول المنصة. يُمسح عند استعادة المفتاح. فارغ للمفتاح الذي أبطله مالكه من قائمة مفاتيح API.",
11641164
options: {
11651165
admin_password_reset: "إعادة تعيين كلمة المرور من قِبل المسؤول",
1166-
organization_membership_ended: "انتهاء العضوية في المؤسسة"
1166+
organization_membership_ended: "انتهاء العضوية في المؤسسة",
1167+
administrator_suspended: "معلّق من قِبل مسؤول"
11671168
}
11681169
},
11691170
key: {

‎packages/platform-objects/src/apps/translations/de.objects.generated.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,10 +1160,11 @@ export const deObjects: NonNullable<TranslationData['objects']> = {
11601160
},
11611161
revoked_reason: {
11621162
label: "Widerrufsgrund",
1163-
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. Wird beim Wiederherstellen des Schlüssels gelöscht. Leer bei einem Schlüssel, der in der Liste der API-Schlüssel widerrufen wurde.",
1163+
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.",
11641164
options: {
11651165
admin_password_reset: "Passwortzurücksetzung durch Administrator",
1166-
organization_membership_ended: "Mitgliedschaft in der Organisation beendet"
1166+
organization_membership_ended: "Mitgliedschaft in der Organisation beendet",
1167+
administrator_suspended: "Von einem Administrator gesperrt"
11671168
}
11681169
},
11691170
key: {

‎packages/platform-objects/src/apps/translations/en.objects.generated.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,10 +1160,11 @@ export const enObjects: NonNullable<TranslationData['objects']> = {
11601160
},
11611161
revoked_reason: {
11621162
label: "Revoke Reason",
1163-
help: "Why the key was revoked, where that decides who can restore it. Administrator password reset: only a platform administrator can restore the key. Organization membership ended: the owner left the organization, and no one can restore the key; a member creates a new one. Cleared when the key is restored. Empty for a key revoked from the API Keys list.",
1163+
help: "Why the key was revoked, where that decides who can restore it. Administrator password reset: only a platform administrator can restore the key. Organization membership ended: the owner left the organization, and no one can restore the key; a member creates a new one. Suspended by an administrator: a platform administrator revoked a key that is not theirs, and only a platform administrator can restore it. Cleared when the key is restored. Empty for a key its owner revoked from the API Keys list.",
11641164
options: {
11651165
admin_password_reset: "Administrator password reset",
1166-
organization_membership_ended: "Organization membership ended"
1166+
organization_membership_ended: "Organization membership ended",
1167+
administrator_suspended: "Suspended by an administrator"
11671168
}
11681169
},
11691170
key: {

‎packages/platform-objects/src/apps/translations/es-ES.objects.generated.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,10 +1160,11 @@ export const esESObjects: NonNullable<TranslationData['objects']> = {
11601160
},
11611161
revoked_reason: {
11621162
label: "Motivo de la revocación",
1163-
help: "Por qué se revocó la clave, cuando eso decide quién puede restaurarla. Restablecimiento forzado de la contraseña por un administrador: solo un administrador de la plataforma puede restaurar la clave. Fin de la pertenencia a la organización: el propietario dejó la organización y nadie puede restaurar la clave; un miembro crea una nueva. Se borra cuando la clave se restaura. Vacío para una clave revocada desde la lista de claves de API.",
1163+
help: "Por qué se revocó la clave, cuando eso decide quién puede restaurarla. Restablecimiento forzado de la contraseña por un administrador: solo un administrador de la plataforma puede restaurar la clave. Fin de la pertenencia a la organización: el propietario dejó la organización y nadie puede restaurar la clave; un miembro crea una nueva. Suspendida por un administrador: un administrador de la plataforma revocó una clave que no es suya, y solo un administrador de la plataforma puede restaurarla. Se borra cuando la clave se restaura. Vacío para una clave que su propietario revocó desde la lista de claves de API.",
11641164
options: {
11651165
admin_password_reset: "Restablecimiento forzado de la contraseña por un administrador",
1166-
organization_membership_ended: "Fin de la pertenencia a la organización"
1166+
organization_membership_ended: "Fin de la pertenencia a la organización",
1167+
administrator_suspended: "Suspendida por un administrador"
11671168
}
11681169
},
11691170
key: {

‎packages/platform-objects/src/apps/translations/fr.objects.generated.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,10 +1160,11 @@ export const frObjects: NonNullable<TranslationData['objects']> = {
11601160
},
11611161
revoked_reason: {
11621162
label: "Motif de la révocation",
1163-
help: "Motif de la révocation de la clé, lorsqu'il détermine qui peut la restaurer. Réinitialisation du mot de passe par un administrateur : seul un administrateur de la plateforme peut restaurer la clé. Fin de l'appartenance à l'organisation : le propriétaire a quitté l'organisation et personne ne peut restaurer la clé ; un membre en crée une nouvelle. Effacé lorsque la clé est restaurée. Vide pour une clé révoquée depuis la liste Clés API.",
1163+
help: "Motif de la révocation de la clé, lorsqu'il détermine qui peut la restaurer. Réinitialisation du mot de passe par un administrateur : seul un administrateur de la plateforme peut restaurer la clé. Fin de l'appartenance à l'organisation : le propriétaire a quitté l'organisation et personne ne peut restaurer la clé ; un membre en crée une nouvelle. Suspendue par un administrateur : un administrateur de la plateforme a révoqué une clé qui ne lui appartient pas, et seul un administrateur de la plateforme peut la restaurer. Effacé lorsque la clé est restaurée. Vide pour une clé que son propriétaire a révoquée depuis la liste Clés API.",
11641164
options: {
11651165
admin_password_reset: "Réinitialisation du mot de passe par un administrateur",
1166-
organization_membership_ended: "Fin de l'appartenance à l'organisation"
1166+
organization_membership_ended: "Fin de l'appartenance à l'organisation",
1167+
administrator_suspended: "Suspendue par un administrateur"
11671168
}
11681169
},
11691170
key: {

‎packages/platform-objects/src/apps/translations/ja-JP.objects.generated.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,10 +1160,11 @@ export const jaJPObjects: NonNullable<TranslationData['objects']> = {
11601160
},
11611161
revoked_reason: {
11621162
label: "失効理由",
1163-
help: "キーが失効した理由で、誰が復元できるかを左右する場合に記録されます。管理者によるパスワードの強制リセット:キーを復元できるのはプラットフォーム管理者のみです。組織メンバーシップの終了:所有者が組織を離れたため、誰もキーを復元できません。組織のメンバーが新しいキーを作成します。キーを復元するとクリアされます。API キー一覧から失効させたキーでは空です。",
1163+
help: "キーが失効した理由で、誰が復元できるかを左右する場合に記録されます。管理者によるパスワードの強制リセット:キーを復元できるのはプラットフォーム管理者のみです。組織メンバーシップの終了:所有者が組織を離れたため、誰もキーを復元できません。組織のメンバーが新しいキーを作成します。管理者による一時停止:プラットフォーム管理者が自分のものではないキーを失効させたため、キーを復元できるのはプラットフォーム管理者のみです。キーを復元するとクリアされます。所有者が API キー一覧から失効させたキーでは空です。",
11641164
options: {
11651165
admin_password_reset: "管理者によるパスワードの強制リセット",
1166-
organization_membership_ended: "組織メンバーシップの終了"
1166+
organization_membership_ended: "組織メンバーシップの終了",
1167+
administrator_suspended: "管理者による一時停止"
11671168
}
11681169
},
11691170
key: {

‎packages/platform-objects/src/apps/translations/pt-BR.objects.generated.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,10 +1160,11 @@ export const ptBRObjects: NonNullable<TranslationData['objects']> = {
11601160
},
11611161
revoked_reason: {
11621162
label: "Motivo da revogação",
1163-
help: "Por que a chave foi revogada, quando isso decide quem pode restaurá-la. Redefinição de senha pelo administrador: somente um administrador da plataforma pode restaurar a chave. Fim da associação à organização: o proprietário saiu da organização e ninguém pode restaurar a chave; um membro cria uma nova. Limpo quando a chave é restaurada. Vazio para uma chave revogada na lista de Chaves de API.",
1163+
help: "Por que a chave foi revogada, quando isso decide quem pode restaurá-la. Redefinição de senha pelo administrador: somente um administrador da plataforma pode restaurar a chave. Fim da associação à organização: o proprietário saiu da organização e ninguém pode restaurar a chave; um membro cria uma nova. Suspensa por um administrador: um administrador da plataforma revogou uma chave que não é dele, e somente um administrador da plataforma pode restaurá-la. Limpo quando a chave é restaurada. Vazio para uma chave que o proprietário revogou na lista de Chaves de API.",
11641164
options: {
11651165
admin_password_reset: "Redefinição de senha pelo administrador",
1166-
organization_membership_ended: "Fim da associação à organização"
1166+
organization_membership_ended: "Fim da associação à organização",
1167+
administrator_suspended: "Suspensa por um administrador"
11671168
}
11681169
},
11691170
key: {

‎packages/platform-objects/src/apps/translations/ru.objects.generated.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,10 +1160,11 @@ export const ruObjects: NonNullable<TranslationData['objects']> = {
11601160
},
11611161
revoked_reason: {
11621162
label: "Причина отзыва",
1163-
help: "Почему ключ был отозван, если от этого зависит, кто может его восстановить. Сброс пароля администратором: восстановить ключ может только администратор платформы. Прекращено членство в организации: владелец покинул организацию, и восстановить ключ не может никто; участник создаёт новый. Очищается при восстановлении ключа. Пусто для ключа, отозванного из списка API-ключей.",
1163+
help: "Почему ключ был отозван, если от этого зависит, кто может его восстановить. Сброс пароля администратором: восстановить ключ может только администратор платформы. Прекращено членство в организации: владелец покинул организацию, и восстановить ключ не может никто; участник создаёт новый. Приостановлен администратором: администратор платформы отозвал ключ, который ему не принадлежит, и восстановить его может только администратор платформы. Очищается при восстановлении ключа. Пусто для ключа, который владелец отозвал из списка API-ключей.",
11641164
options: {
11651165
admin_password_reset: "Сброс пароля администратором",
1166-
organization_membership_ended: "Прекращено членство в организации"
1166+
organization_membership_ended: "Прекращено членство в организации",
1167+
administrator_suspended: "Приостановлен администратором"
11671168
}
11681169
},
11691170
key: {

0 commit comments

Comments
 (0)