@jini-ai/user-management 0.7.3-next.2 → 0.7.3-next.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -2
- package/dist/admin/adapters/memory.js +4 -4
- package/dist/admin-http/auth/auth-request.d.ts +112 -0
- package/dist/admin-http/auth/auth-request.js +32 -0
- package/dist/admin-http/auth/boot-redemption.d.ts +9 -0
- package/dist/admin-http/auth/boot-redemption.js +17 -0
- package/dist/admin-http/auth/boot-session.d.ts +30 -0
- package/dist/admin-http/auth/boot-session.js +40 -0
- package/dist/admin-http/auth/current-user.d.ts +28 -0
- package/dist/admin-http/auth/current-user.js +34 -0
- package/dist/admin-http/auth/index.d.ts +17 -0
- package/dist/admin-http/auth/index.js +9 -0
- package/dist/admin-http/auth/local-boot-session.d.ts +9 -0
- package/dist/admin-http/auth/local-boot-session.js +30 -0
- package/dist/admin-http/auth/logout.d.ts +10 -0
- package/dist/admin-http/auth/logout.js +17 -0
- package/dist/admin-http/auth/mfa-login.d.ts +30 -0
- package/dist/admin-http/auth/mfa-login.js +43 -0
- package/dist/admin-http/auth/password-login.d.ts +35 -0
- package/dist/admin-http/auth/password-login.js +52 -0
- package/dist/admin-http/auth/password-status.d.ts +34 -0
- package/dist/admin-http/auth/password-status.js +42 -0
- package/dist/admin-http/http/api-keys.d.ts +45 -0
- package/dist/admin-http/http/api-keys.js +28 -0
- package/dist/admin-http/http/users.d.ts +71 -0
- package/dist/admin-http/http/users.js +42 -0
- package/dist/admin-http/owner/mfa-deps.d.ts +41 -0
- package/dist/admin-http/owner/mfa-deps.js +26 -0
- package/dist/admin-http/owner/mfa-routes.d.ts +72 -0
- package/dist/admin-http/owner/mfa-routes.js +105 -0
- package/dist/admin-http/owner/passkey-admission.d.ts +46 -0
- package/dist/admin-http/owner/passkey-admission.js +23 -0
- package/dist/admin-http/owner/passkey-route-deps.d.ts +53 -0
- package/dist/admin-http/owner/passkey-route-deps.js +33 -0
- package/dist/admin-http/owner/passkey-routes.d.ts +146 -0
- package/dist/admin-http/owner/passkey-routes.js +98 -0
- package/dist/admin-http/owner/recovery-routes.d.ts +71 -0
- package/dist/admin-http/owner/recovery-routes.js +112 -0
- package/dist/admin-http/routes/api-keys/create-principal.d.ts +26 -0
- package/dist/admin-http/routes/api-keys/create-principal.js +37 -0
- package/dist/admin-http/routes/api-keys/issue.d.ts +32 -0
- package/dist/admin-http/routes/api-keys/issue.js +38 -0
- package/dist/admin-http/routes/api-keys/revoke.d.ts +26 -0
- package/dist/admin-http/routes/api-keys/revoke.js +31 -0
- package/dist/admin-http/routes/api-keys/shared.d.ts +46 -0
- package/dist/admin-http/routes/api-keys/shared.js +38 -0
- package/dist/admin-http/routes/users/access-shared.d.ts +103 -0
- package/dist/admin-http/routes/users/access-shared.js +85 -0
- package/dist/admin-http/routes/users/assign-role.d.ts +24 -0
- package/dist/admin-http/routes/users/assign-role.js +30 -0
- package/dist/admin-http/routes/users/attach-policy.d.ts +25 -0
- package/dist/admin-http/routes/users/attach-policy.js +31 -0
- package/dist/admin-http/routes/users/create-policy.d.ts +19 -0
- package/dist/admin-http/routes/users/create-policy.js +28 -0
- package/dist/admin-http/routes/users/create-role.d.ts +15 -0
- package/dist/admin-http/routes/users/create-role.js +21 -0
- package/dist/admin-http/routes/users/create.d.ts +32 -0
- package/dist/admin-http/routes/users/create.js +67 -0
- package/dist/admin-http/routes/users/delete-policy.d.ts +16 -0
- package/dist/admin-http/routes/users/delete-policy.js +24 -0
- package/dist/admin-http/routes/users/delete-role.d.ts +16 -0
- package/dist/admin-http/routes/users/delete-role.js +24 -0
- package/dist/admin-http/routes/users/delete.d.ts +35 -0
- package/dist/admin-http/routes/users/delete.js +35 -0
- package/dist/admin-http/routes/users/disable.d.ts +31 -0
- package/dist/admin-http/routes/users/disable.js +38 -0
- package/dist/admin-http/routes/users/enable.d.ts +32 -0
- package/dist/admin-http/routes/users/enable.js +45 -0
- package/dist/admin-http/routes/users/list-policies.d.ts +18 -0
- package/dist/admin-http/routes/users/list-policies.js +20 -0
- package/dist/admin-http/routes/users/list-policy-permissions.d.ts +28 -0
- package/dist/admin-http/routes/users/list-policy-permissions.js +30 -0
- package/dist/admin-http/routes/users/list-roles.d.ts +18 -0
- package/dist/admin-http/routes/users/list-roles.js +20 -0
- package/dist/admin-http/routes/users/list.d.ts +40 -0
- package/dist/admin-http/routes/users/list.js +82 -0
- package/dist/admin-http/routes/users/remove-policy-permission.d.ts +48 -0
- package/dist/admin-http/routes/users/remove-policy-permission.js +62 -0
- package/dist/admin-http/routes/users/reset-password.d.ts +33 -0
- package/dist/admin-http/routes/users/reset-password.js +52 -0
- package/dist/admin-http/routes/users/shared.d.ts +124 -0
- package/dist/admin-http/routes/users/shared.js +93 -0
- package/dist/admin-http/routes/users/update-policy.d.ts +25 -0
- package/dist/admin-http/routes/users/update-policy.js +30 -0
- package/dist/admin-http/routes/users/update-role.d.ts +23 -0
- package/dist/admin-http/routes/users/update-role.js +29 -0
- package/dist/admin-http/routes/users/update.d.ts +35 -0
- package/dist/admin-http/routes/users/update.js +78 -0
- package/dist/admin-http/routes/users/write-policy-permission.d.ts +31 -0
- package/dist/admin-http/routes/users/write-policy-permission.js +45 -0
- package/dist/core/ports.d.ts +22 -3
- package/dist/core/types.d.ts +17 -5
- package/dist/core/types.js +12 -0
- package/dist/identity/api-key-secret.d.ts +68 -0
- package/dist/identity/api-key-secret.js +229 -0
- package/dist/identity/api-key-service.d.ts +144 -0
- package/dist/identity/api-key-service.js +389 -0
- package/dist/identity/api-key-types.d.ts +79 -0
- package/dist/identity/api-key-types.js +2 -0
- package/dist/identity/boot-session-token.d.ts +18 -0
- package/dist/identity/boot-session-token.js +92 -0
- package/dist/identity/builtin-role-grants.d.ts +120 -0
- package/dist/identity/builtin-role-grants.js +88 -0
- package/dist/identity/delete-user-service.d.ts +195 -0
- package/dist/identity/delete-user-service.js +275 -0
- package/dist/identity/owner-reset-env.d.ts +37 -0
- package/dist/identity/owner-reset-env.js +38 -0
- package/dist/identity/permission-grants.d.ts +31 -0
- package/dist/identity/permission-grants.js +12 -0
- package/dist/identity/permission-list-tool.d.ts +35 -0
- package/dist/identity/permission-list-tool.js +47 -0
- package/dist/identity/repo.authentication.d.ts +57 -0
- package/dist/identity/repo.authentication.js +153 -0
- package/dist/identity/repo.authorization.d.ts +82 -0
- package/dist/identity/repo.authorization.js +203 -0
- package/dist/identity/repo.d.ts +87 -0
- package/dist/identity/repo.js +167 -0
- package/dist/identity/repo.memory.d.ts +31 -0
- package/dist/identity/repo.memory.js +37 -0
- package/dist/identity/role-manage-permission.d.ts +34 -0
- package/dist/identity/role-manage-permission.js +39 -0
- package/dist/identity/site-key-permission.d.ts +66 -0
- package/dist/identity/site-key-permission.js +92 -0
- package/dist/identity/sql/kernel-user-purge.d.ts +19 -0
- package/dist/identity/sql/kernel-user-purge.js +34 -0
- package/dist/identity/sql/kernel-user-trash-store.d.ts +15 -0
- package/dist/identity/sql/kernel-user-trash-store.js +41 -0
- package/dist/identity/sql/user-trash-adapter.d.ts +87 -0
- package/dist/identity/sql/user-trash-adapter.js +124 -0
- package/dist/identity/tool-registrations.d.ts +100 -0
- package/dist/identity/tool-registrations.js +257 -0
- package/dist/identity/user-manage-permission.d.ts +8 -0
- package/dist/identity/user-manage-permission.js +8 -0
- package/dist/identity/user-purge-types.d.ts +85 -0
- package/dist/identity/user-purge-types.js +17 -0
- package/dist/identity/user-purge.d.ts +69 -0
- package/dist/identity/user-purge.js +46 -0
- package/dist/identity/username-change-ports.d.ts +15 -0
- package/dist/identity/username-change-ports.js +22 -0
- package/dist/mail/site/capture-clear.d.ts +58 -0
- package/dist/mail/site/capture-clear.js +21 -0
- package/dist/mail/status/agent-tools.d.ts +65 -0
- package/dist/mail/status/agent-tools.js +22 -0
- package/dist/mail/status/delivery-agent-tools.d.ts +206 -0
- package/dist/mail/status/delivery-agent-tools.js +63 -0
- package/dist/mail/status/delivery-tool-registrations.d.ts +216 -0
- package/dist/mail/status/delivery-tool-registrations.js +110 -0
- package/dist/mail/status/domain-deps.d.ts +25 -0
- package/dist/mail/status/domain-deps.js +23 -0
- package/dist/mail/status/permissions.d.ts +43 -0
- package/dist/mail/status/permissions.js +45 -0
- package/dist/mail/status/provider-agent-tools.d.ts +38 -0
- package/dist/mail/status/provider-agent-tools.js +17 -0
- package/dist/mail/status/provider-operations.d.ts +166 -0
- package/dist/mail/status/provider-operations.js +121 -0
- package/dist/mail/status/provider-tool-registrations.d.ts +65 -0
- package/dist/mail/status/provider-tool-registrations.js +106 -0
- package/dist/mail/status/tool-registrations.d.ts +152 -0
- package/dist/mail/status/tool-registrations.js +112 -0
- package/dist/member-login/credentials.d.ts +40 -0
- package/dist/member-login/credentials.js +26 -0
- package/dist/member-login/link-service.d.ts +66 -0
- package/dist/member-login/link-service.js +141 -0
- package/dist/member-login/oidc-login.d.ts +132 -0
- package/dist/member-login/oidc-login.js +206 -0
- package/dist/member-login/oidc-request.d.ts +80 -0
- package/dist/member-login/oidc-request.js +86 -0
- package/dist/member-login/providers.d.ts +79 -0
- package/dist/member-login/providers.js +41 -0
- package/dist/member-login/ready-providers.d.ts +17 -0
- package/dist/member-login/ready-providers.js +11 -0
- package/dist/member-login/unlink-identity.d.ts +26 -0
- package/dist/member-login/unlink-identity.js +59 -0
- package/dist/members/access-resolver.d.ts +107 -0
- package/dist/members/access-resolver.js +231 -0
- package/dist/members/agent-tools.d.ts +14 -0
- package/dist/members/agent-tools.js +139 -0
- package/dist/members/auth-mail.d.ts +27 -0
- package/dist/members/auth-mail.js +21 -0
- package/dist/members/capability-card.d.ts +18 -0
- package/dist/members/capability-card.js +27 -0
- package/dist/members/consent-service.d.ts +115 -0
- package/dist/members/consent-service.js +179 -0
- package/dist/members/member-admin-writes.d.ts +73 -0
- package/dist/members/member-admin-writes.js +149 -0
- package/dist/members/member-challenge-request.d.ts +59 -0
- package/dist/members/member-challenge-request.js +145 -0
- package/dist/members/member-challenge.d.ts +37 -0
- package/dist/members/member-challenge.js +84 -0
- package/dist/members/member-credentials.d.ts +35 -0
- package/dist/members/member-credentials.js +57 -0
- package/dist/members/member-sign-in.d.ts +44 -0
- package/dist/members/member-sign-in.js +130 -0
- package/dist/members/member-validation.d.ts +5 -0
- package/dist/members/member-validation.js +13 -0
- package/dist/members/password-auth.d.ts +55 -0
- package/dist/members/password-auth.js +177 -0
- package/dist/members/ports.d.ts +455 -0
- package/dist/members/ports.js +21 -0
- package/dist/members/public-member-auth-response.d.ts +68 -0
- package/dist/members/public-member-auth-response.js +45 -0
- package/dist/members/public-member-response.d.ts +25 -0
- package/dist/members/public-member-response.js +15 -0
- package/dist/members/repo.d.ts +199 -0
- package/dist/members/repo.js +324 -0
- package/dist/members/repo.memory.d.ts +276 -0
- package/dist/members/repo.memory.js +395 -0
- package/dist/members/repo.rows.d.ts +153 -0
- package/dist/members/repo.rows.js +250 -0
- package/dist/members/repo.sessions.d.ts +80 -0
- package/dist/members/repo.sessions.js +166 -0
- package/dist/members/repo.sql.d.ts +9 -0
- package/dist/members/repo.sql.js +11 -0
- package/dist/members/subscriber-directory.d.ts +85 -0
- package/dist/members/subscriber-directory.js +70 -0
- package/dist/members/tool-registrations.d.ts +143 -0
- package/dist/members/tool-registrations.js +247 -0
- package/dist/members/trash-member.d.ts +24 -0
- package/dist/members/trash-member.js +24 -0
- package/dist/members/types.d.ts +321 -0
- package/dist/members/types.js +34 -0
- package/dist/members/write-service.d.ts +17 -0
- package/dist/members/write-service.js +15 -0
- package/dist/newsletter/agent-tools.d.ts +20 -0
- package/dist/newsletter/agent-tools.js +236 -0
- package/dist/newsletter/campaign-write-service.d.ts +92 -0
- package/dist/newsletter/campaign-write-service.js +190 -0
- package/dist/newsletter/campaign.d.ts +53 -0
- package/dist/newsletter/campaign.js +95 -0
- package/dist/newsletter/confirmation.d.ts +75 -0
- package/dist/newsletter/confirmation.js +142 -0
- package/dist/newsletter/data-module-manifest.d.ts +68 -0
- package/dist/newsletter/data-module-manifest.js +126 -0
- package/dist/newsletter/delivery/tool-registrations.d.ts +67 -0
- package/dist/newsletter/delivery/tool-registrations.js +229 -0
- package/dist/newsletter/errors.d.ts +93 -0
- package/dist/newsletter/errors.js +93 -0
- package/dist/newsletter/hooks.d.ts +59 -0
- package/dist/newsletter/hooks.js +49 -0
- package/dist/newsletter/http-error-responses.d.ts +17 -0
- package/dist/newsletter/http-error-responses.js +96 -0
- package/dist/newsletter/launch-gate.d.ts +62 -0
- package/dist/newsletter/launch-gate.js +29 -0
- package/dist/newsletter/lists.d.ts +60 -0
- package/dist/newsletter/lists.js +83 -0
- package/dist/newsletter/ports.d.ts +278 -0
- package/dist/newsletter/ports.js +2 -0
- package/dist/newsletter/repo-sends.d.ts +82 -0
- package/dist/newsletter/repo-sends.js +178 -0
- package/dist/newsletter/repo-subscribers.d.ts +82 -0
- package/dist/newsletter/repo-subscribers.js +193 -0
- package/dist/newsletter/repo.d.ts +61 -0
- package/dist/newsletter/repo.js +147 -0
- package/dist/newsletter/repo.memory.d.ts +201 -0
- package/dist/newsletter/repo.memory.js +250 -0
- package/dist/newsletter/repo.rows.d.ts +221 -0
- package/dist/newsletter/repo.rows.js +260 -0
- package/dist/newsletter/send-pipeline.d.ts +236 -0
- package/dist/newsletter/send-pipeline.js +514 -0
- package/dist/newsletter/subscriptions.d.ts +87 -0
- package/dist/newsletter/subscriptions.js +119 -0
- package/dist/newsletter/tool-registrations.d.ts +89 -0
- package/dist/newsletter/tool-registrations.deps.d.ts +9 -0
- package/dist/newsletter/tool-registrations.deps.js +9 -0
- package/dist/newsletter/tool-registrations.js +133 -0
- package/dist/newsletter/tool-registrations.read.d.ts +76 -0
- package/dist/newsletter/tool-registrations.read.js +140 -0
- package/dist/newsletter/tool-registrations.write.d.ts +54 -0
- package/dist/newsletter/tool-registrations.write.js +229 -0
- package/dist/newsletter/types.d.ts +279 -0
- package/dist/newsletter/types.js +23 -0
- package/dist/newsletter/unsubscribe.d.ts +41 -0
- package/dist/newsletter/unsubscribe.js +100 -0
- package/dist/project-keys/attached-vault.d.ts +23 -0
- package/dist/project-keys/attached-vault.js +65 -0
- package/dist/project-keys/create-vault.d.ts +17 -0
- package/dist/project-keys/create-vault.js +29 -0
- package/dist/project-keys/service.d.ts +133 -0
- package/dist/project-keys/service.js +128 -0
- package/dist/project-keys/site-references.d.ts +30 -0
- package/dist/project-keys/site-references.js +63 -0
- package/dist/project-keys/site-sealer.d.ts +28 -0
- package/dist/project-keys/site-sealer.js +64 -0
- package/dist/project-keys/sql/attachments.d.ts +33 -0
- package/dist/project-keys/sql/attachments.js +55 -0
- package/dist/project-keys/tools.d.ts +86 -0
- package/dist/project-keys/tools.js +66 -0
- package/dist/public-http/routes/mail/feedback.d.ts +44 -0
- package/dist/public-http/routes/mail/feedback.js +17 -0
- package/dist/public-http/routes/newsletter/confirm.d.ts +38 -0
- package/dist/public-http/routes/newsletter/confirm.js +33 -0
- package/dist/public-http/routes/newsletter/page.d.ts +29 -0
- package/dist/public-http/routes/newsletter/page.js +34 -0
- package/dist/public-http/routes/newsletter/unsubscribe.d.ts +33 -0
- package/dist/public-http/routes/newsletter/unsubscribe.js +35 -0
- package/dist/react/auth/Passkeys.d.ts +2 -34
- package/dist/react/auth/RecoveryCodesCard.d.ts +27 -0
- package/dist/react/auth/RecoveryCodesCard.hooks.d.ts +67 -0
- package/dist/react/auth/RecoveryCodesCard.hooks.js +38 -0
- package/dist/react/auth/RecoveryCodesCard.js +56 -0
- package/dist/react/auth/TotpSettings.d.ts +2 -23
- package/dist/react/auth/local-owner-signin.d.ts +40 -0
- package/dist/react/auth/local-owner-signin.js +25 -0
- package/dist/react/auth/owner-mfa-api.d.ts +10 -0
- package/dist/react/auth/owner-mfa-api.js +17 -0
- package/dist/react/auth/owner-passkey-api.d.ts +11 -0
- package/dist/react/auth/owner-passkey-api.js +17 -0
- package/dist/react/auth/owner-recovery-api.d.ts +51 -0
- package/dist/react/auth/owner-recovery-api.js +29 -0
- package/dist/react/auth/owner-request.d.ts +7 -0
- package/dist/react/auth/owner-request.js +2 -0
- package/dist/react/index.d.ts +10 -0
- package/dist/react/index.js +6 -0
- package/dist/react/mail/Email.d.ts +20 -0
- package/dist/react/mail/Email.js +143 -0
- package/dist/react/mail/EmailProviderTab.d.ts +34 -0
- package/dist/react/mail/EmailProviderTab.js +132 -0
- package/dist/react/mail/EmailSegments.d.ts +24 -0
- package/dist/react/mail/EmailSegments.js +15 -0
- package/dist/react/mail/EmailTemplateEditor.d.ts +146 -0
- package/dist/react/mail/EmailTemplateEditor.js +116 -0
- package/dist/react/mail/email-view.types.d.ts +236 -0
- package/dist/react/mail/email-view.types.js +2 -0
- package/dist/react/members/Members.d.ts +5 -3
- package/dist/react/members/Members.js +3 -3
- package/dist/react/members/api/members-api.d.ts +37 -0
- package/dist/react/members/api/members-api.js +16 -0
- package/dist/react/members/hooks/use-members.hooks.js +2 -1
- package/dist/react/members/members-i18n.d.ts +23 -0
- package/dist/react/members/members-i18n.js +25 -0
- package/dist/react/members/members-i18n.locales-a.d.ts +4 -0
- package/dist/react/members/members-i18n.locales-a.js +294 -0
- package/dist/react/members/members-i18n.locales-b.d.ts +4 -0
- package/dist/react/members/members-i18n.locales-b.js +265 -0
- package/dist/react/models.d.ts +1 -49
- package/dist/react/ports.d.ts +3 -143
- package/dist/react/roles/api/roles-api.d.ts +74 -0
- package/dist/react/roles/api/roles-api.js +22 -0
- package/dist/react/testing.js +18 -9
- package/dist/react/users/UsersPanel.d.ts +30 -0
- package/dist/react/users/UsersPanel.hooks.d.ts +8 -0
- package/dist/react/users/UsersPanel.hooks.js +9 -0
- package/dist/react/users/UsersPanel.js +9 -0
- package/dist/react/users/api/users-api.d.ts +65 -0
- package/dist/react/users/api/users-api.js +46 -0
- package/dist/react/users/hooks/use-localized-users.hooks.d.ts +43 -0
- package/dist/react/users/hooks/use-localized-users.hooks.js +15 -0
- package/dist/react/users/hooks/use-users-state.hooks.d.ts +18 -18
- package/dist/react/users/password-reset-notice.d.ts +8 -0
- package/dist/react/users/password-reset-notice.js +36 -0
- package/dist/server/admin-crud-service.d.ts +4 -10
- package/dist/server/admin-crud-service.js +20 -6
- package/dist/server/agent-tool-registrations.js +20 -5
- package/dist/server/agent-tools.js +16 -3
- package/dist/server/auth-challenge.d.ts +1 -1
- package/dist/server/auth-service.js +2 -1
- package/dist/server/grant-service.d.ts +1 -0
- package/dist/server/grant-service.js +7 -4
- package/dist/server/mfa/passkey-service.d.ts +2 -2
- package/dist/server/mfa/passkey-service.js +1 -1
- package/dist/server/mfa/service.js +6 -4
- package/dist/server/repo.memory.d.ts +30 -2
- package/dist/server/repo.memory.js +58 -4
- package/dist/server/seed.js +3 -3
- package/dist/server/sql/assignments.d.ts +90 -0
- package/dist/server/sql/assignments.js +128 -0
- package/dist/server/sql/index.d.ts +6 -0
- package/dist/server/sql/index.js +5 -0
- package/dist/server/sql/kernel.d.ts +9 -0
- package/dist/server/sql/kernel.js +2 -0
- package/dist/server/sql/mfa.d.ts +36 -0
- package/dist/server/sql/mfa.js +51 -0
- package/dist/server/sql/passkeys.d.ts +25 -0
- package/dist/server/sql/passkeys.js +33 -0
- package/dist/server/sql/recovery-codes.d.ts +22 -0
- package/dist/server/sql/recovery-codes.js +32 -0
- package/package.json +909 -11
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { defineJsonRoute, ok } from "@jini-ai/core/contracts/server";
|
|
2
|
+
import { rejectRoute } from "@jini-ai/core/errors/route-refusal";
|
|
3
|
+
import { ACCESS_FORBIDDEN, ACCESS_GRANT_EXCEEDS_ISSUER, ACCESS_NOT_FOUND, ACCESS_VALIDATION, accessActorId, accessBody, accessPathParam, accessPermissionUnknown, optionalString, rejectAccessError, } from "./access-shared.js";
|
|
4
|
+
/**
|
|
5
|
+
* POST policies/:policyId/permissions — `WRITE_POLICY_PERMISSION` (SPEC-006 0.6.0, INV-07 — first
|
|
6
|
+
* HTTP route for a transition specified since v0.5.3, AC-32). Gated by `role.manage`; refuses an
|
|
7
|
+
* unregistered permission (`PERMISSION_UNKNOWN`), a built-in or frozen parent policy
|
|
8
|
+
* (`VALIDATION_ERROR`, INV-06/AC-26), or a permission the caller does not hold unconstrained
|
|
9
|
+
* (`GRANT_EXCEEDS_ISSUER`, INV-07/AC-24).
|
|
10
|
+
*/
|
|
11
|
+
export const policyPermissionWriteRoute = defineJsonRoute({
|
|
12
|
+
method: "post",
|
|
13
|
+
path: "/api/admin/v1/workspaces/:workspaceId/policies/:policyId/permissions",
|
|
14
|
+
// Coerce the HTTP payload while leaving grant validation to the identity service.
|
|
15
|
+
parse: (raw) => {
|
|
16
|
+
const body = accessBody({ body: raw.body });
|
|
17
|
+
return ok({ value: {
|
|
18
|
+
policyId: accessPathParam({ params: raw.params, name: "policyId" }), permission: String(body.permission ?? ""), requestedPermission: body.permission,
|
|
19
|
+
resourceType: optionalString({ value: body.resourceType }), constraintJson: optionalString({ value: body.constraintJson }),
|
|
20
|
+
} });
|
|
21
|
+
},
|
|
22
|
+
handle: async ({ input, deps, context }) => {
|
|
23
|
+
const callerPrincipalId = accessActorId({ context });
|
|
24
|
+
// A host-reserved permission is refused before any grant work, by the raw value the client sent
|
|
25
|
+
// (strict equality, as before): no role, however privileged its granter, may carry it.
|
|
26
|
+
if (deps.ungrantablePermissions.includes(input.requestedPermission)) {
|
|
27
|
+
rejectRoute({ status: 403, error: deps.ungrantablePermissionRefusal, code: "FORBIDDEN" });
|
|
28
|
+
}
|
|
29
|
+
// `PermissionUnknownError` echoes the request's own permission, so this ladder is per request.
|
|
30
|
+
const mappings = [ACCESS_FORBIDDEN, ACCESS_GRANT_EXCEEDS_ISSUER, accessPermissionUnknown({ requested: input.requestedPermission }), ACCESS_VALIDATION, ACCESS_NOT_FOUND];
|
|
31
|
+
try {
|
|
32
|
+
const { policyPermission } = await deps.writePolicyPermission({ deps: deps.identityServiceDeps(), input: { workspaceId: deps.workspaceId, callerPrincipalId, policyId: input.policyId, permission: input.permission } },
|
|
33
|
+
// An absent scope field is omitted (exact optional types); the service reads it as unscoped either way.
|
|
34
|
+
{
|
|
35
|
+
...(input.resourceType === undefined ? {} : { resourceType: input.resourceType }),
|
|
36
|
+
...(input.constraintJson === undefined ? {} : { constraintJson: input.constraintJson }),
|
|
37
|
+
});
|
|
38
|
+
return ok({ value: { policyPermission } });
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
return rejectAccessError({ err, mappings });
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
}, { successStatus: 201 });
|
|
45
|
+
//# sourceMappingURL=write-policy-permission.js.map
|
package/dist/core/ports.d.ts
CHANGED
|
@@ -48,7 +48,20 @@ export interface UserRepoPort {
|
|
|
48
48
|
list(required: {
|
|
49
49
|
workspaceId: UUID;
|
|
50
50
|
}): Promise<UserRecord[]>;
|
|
51
|
-
save(
|
|
51
|
+
/** Whole-row save. With `expectedVersion`, refuses (RecordVersionConflictError) unless the stored user is still at that version — the editor's basis. Create/seed passes none. */
|
|
52
|
+
save(record: UserRecord, optional?: {
|
|
53
|
+
expectedVersion?: number;
|
|
54
|
+
}): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Set only `lastLoginAt` on an existing row (no-op when it is gone). Login paths use this instead
|
|
57
|
+
* of a whole-row `save`, so a password reset, rename or email change that commits between login's
|
|
58
|
+
* read and its timestamp write is never reverted by a stale snapshot.
|
|
59
|
+
*/
|
|
60
|
+
recordLogin(required: {
|
|
61
|
+
workspaceId: UUID;
|
|
62
|
+
principalId: UUID;
|
|
63
|
+
lastLoginAt: ISODateTime;
|
|
64
|
+
}): Promise<void>;
|
|
52
65
|
}
|
|
53
66
|
export interface SessionRepoPort {
|
|
54
67
|
findById(required: {
|
|
@@ -88,7 +101,10 @@ export interface RoleRepoPort {
|
|
|
88
101
|
list(required: {
|
|
89
102
|
workspaceId: UUID;
|
|
90
103
|
}): Promise<RoleRecord[]>;
|
|
91
|
-
save(
|
|
104
|
+
/** Whole-row save. With `expectedVersion`, refuses (RecordVersionConflictError) unless the stored role is still at that version — the editor's basis. Create/seed passes none. */
|
|
105
|
+
save(record: RoleRecord, optional?: {
|
|
106
|
+
expectedVersion?: number;
|
|
107
|
+
}): Promise<void>;
|
|
92
108
|
/**. Callers must apply the is_builtin + zero-reference guards
|
|
93
109
|
* themselves (see `admin-crud-service.ts`'s `deleteRole`) — this method performs the row deletion
|
|
94
110
|
* only, no business rule (mirrors `WorkspaceRepoPort.delete`'s convention).
|
|
@@ -111,7 +127,10 @@ export interface PolicyRepoPort {
|
|
|
111
127
|
list(required: {
|
|
112
128
|
workspaceId: UUID;
|
|
113
129
|
}): Promise<PolicyRecord[]>;
|
|
114
|
-
save(
|
|
130
|
+
/** Whole-row save. With `expectedVersion`, refuses (RecordVersionConflictError) unless the stored policy is still at that version — the editor's basis. Create/seed passes none. */
|
|
131
|
+
save(record: PolicyRecord, optional?: {
|
|
132
|
+
expectedVersion?: number;
|
|
133
|
+
}): Promise<void>;
|
|
115
134
|
/**. See `RoleRepoPort.delete`'s doc — same "no business rule here"
|
|
116
135
|
* contract.
|
|
117
136
|
* See docs/decisions/DR-002-grant-authority-and-admin-safety.md.
|
package/dist/core/types.d.ts
CHANGED
|
@@ -27,11 +27,7 @@ import type { ISODateTime, UUID } from "@jini-ai/core/primitives";
|
|
|
27
27
|
export type PrincipalKind = "user" | "agent" | "api_key" | "system" | "member";
|
|
28
28
|
/** Disable-only lifecycle — there is no hard-delete state. See docs/decisions/DR-001-identity-and-session-boundary.md. */
|
|
29
29
|
export type PrincipalStatus = "active" | "disabled";
|
|
30
|
-
|
|
31
|
-
export type PasskeyOptions = {
|
|
32
|
-
challenge: string;
|
|
33
|
-
[key: string]: unknown;
|
|
34
|
-
};
|
|
30
|
+
export type { PasskeyOptions } from "@jini-ai/core/contracts/site/user-management-react";
|
|
35
31
|
/**
|
|
36
32
|
* Root identity row for every actor. `change_set.actorId` references
|
|
37
33
|
* a principal by composite `(workspaceId, id)`.
|
|
@@ -62,6 +58,8 @@ export interface UserRecord {
|
|
|
62
58
|
/** argon2id hash; the raw password is never stored. See docs/decisions/DR-001-identity-and-session-boundary.md. */
|
|
63
59
|
passwordHash: string;
|
|
64
60
|
lastLoginAt?: ISODateTime | undefined;
|
|
61
|
+
/** Edit basis for optimistic concurrency: 1 on create, +1 on each versioned save. Never a credential. */
|
|
62
|
+
version: number;
|
|
65
63
|
}
|
|
66
64
|
/**
|
|
67
65
|
* Revocable server-side session. `tokenHash` is a hash of the opaque
|
|
@@ -87,6 +85,8 @@ export interface RoleRecord {
|
|
|
87
85
|
workspaceId: UUID;
|
|
88
86
|
name: string;
|
|
89
87
|
isBuiltin: boolean;
|
|
88
|
+
/** Edit basis for optimistic concurrency: 1 on create, +1 on each versioned save. Never a credential. */
|
|
89
|
+
version: number;
|
|
90
90
|
}
|
|
91
91
|
/**
|
|
92
92
|
* A permission bundle. `isFrozen` is reserved for the API-key
|
|
@@ -102,6 +102,8 @@ export interface PolicyRecord {
|
|
|
102
102
|
description?: string | undefined;
|
|
103
103
|
isBuiltin: boolean;
|
|
104
104
|
isFrozen: boolean;
|
|
105
|
+
/** Edit basis for optimistic concurrency: 1 on create, +1 on each versioned save. Never a credential. */
|
|
106
|
+
version: number;
|
|
105
107
|
}
|
|
106
108
|
/**
|
|
107
109
|
* A single permission carried by a policy. `resourceType`
|
|
@@ -147,6 +149,16 @@ export declare class IdentityValidationError extends Error {
|
|
|
147
149
|
message: string;
|
|
148
150
|
}, optional?: ErrorOptions);
|
|
149
151
|
}
|
|
152
|
+
/** The fixed public text of a refused MFA login proof (wrong, replayed or expired code). */
|
|
153
|
+
export declare const MFA_PROOF_REFUSED_MESSAGE = "The authenticator code was not accepted or has expired. Enter a fresh code, or sign in again to start a new attempt.";
|
|
154
|
+
/**
|
|
155
|
+
* A refused MFA proof: the one MFA failure whose text a login route may put in a response body.
|
|
156
|
+
* Its message is always {@link MFA_PROOF_REFUSED_MESSAGE}, so no proof, token or collaborator text can
|
|
157
|
+
* reach the caller through it. Extends {@link IdentityValidationError} so existing 400 mappings hold.
|
|
158
|
+
*/
|
|
159
|
+
export declare class MfaProofRefusedError extends IdentityValidationError {
|
|
160
|
+
constructor(_required?: Record<string, never>, optional?: ErrorOptions);
|
|
161
|
+
}
|
|
150
162
|
/** Raised when a referenced principal/user/role/policy is not found. */
|
|
151
163
|
export declare class IdentityNotFoundError extends Error {
|
|
152
164
|
constructor({ message }: {
|
package/dist/core/types.js
CHANGED
|
@@ -4,6 +4,18 @@ export class IdentityValidationError extends Error {
|
|
|
4
4
|
super(message, optional);
|
|
5
5
|
}
|
|
6
6
|
}
|
|
7
|
+
/** The fixed public text of a refused MFA login proof (wrong, replayed or expired code). */
|
|
8
|
+
export const MFA_PROOF_REFUSED_MESSAGE = 'The authenticator code was not accepted or has expired. Enter a fresh code, or sign in again to start a new attempt.';
|
|
9
|
+
/**
|
|
10
|
+
* A refused MFA proof: the one MFA failure whose text a login route may put in a response body.
|
|
11
|
+
* Its message is always {@link MFA_PROOF_REFUSED_MESSAGE}, so no proof, token or collaborator text can
|
|
12
|
+
* reach the caller through it. Extends {@link IdentityValidationError} so existing 400 mappings hold.
|
|
13
|
+
*/
|
|
14
|
+
export class MfaProofRefusedError extends IdentityValidationError {
|
|
15
|
+
constructor(_required = {}, optional = {}) {
|
|
16
|
+
super({ message: MFA_PROOF_REFUSED_MESSAGE }, optional);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
7
19
|
/** Raised when a referenced principal/user/role/policy is not found. */
|
|
8
20
|
export class IdentityNotFoundError extends Error {
|
|
9
21
|
constructor({ message }, optional = {}) {
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { ApiKeySecretHasherPort } from "./api-key-types.js";
|
|
2
|
+
/** A freshly minted key: the raw string is returned to the issuer ONCE and never persisted. */
|
|
3
|
+
export interface MintedApiKey {
|
|
4
|
+
/** The full `<scheme prefix><handle>.<secret>` string. Never store, log, or re-derive this. */
|
|
5
|
+
rawKey: string;
|
|
6
|
+
/** The non-secret half, persisted as `api_keys.prefix`. */
|
|
7
|
+
prefix: string;
|
|
8
|
+
/** The secret half, to be handed to `ApiKeySecretHasherPort.hash` and then dropped. */
|
|
9
|
+
secret: string;
|
|
10
|
+
}
|
|
11
|
+
/** Key minting and parsing bound to one host scheme prefix (see the file header). */
|
|
12
|
+
export interface ApiKeySecret {
|
|
13
|
+
/** Mint a new key under the bound prefix; see `MintedApiKey`. */
|
|
14
|
+
mintApiKey(): MintedApiKey;
|
|
15
|
+
/** Split a presented raw key; `null` unless it carries exactly the bound prefix. */
|
|
16
|
+
parseApiKey(required: {
|
|
17
|
+
rawKey: string;
|
|
18
|
+
}, _options?: Record<string, never>): {
|
|
19
|
+
prefix: string;
|
|
20
|
+
secret: string;
|
|
21
|
+
} | null;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Bind minting and parsing to the host's non-secret scheme marker (e.g. `acme_ak_`).
|
|
25
|
+
*
|
|
26
|
+
* @param required.prefix - lowercase letters, digits and `_`, starting with a letter. Every key the
|
|
27
|
+
* host has issued carries it, so the host binds one value for its lifetime.
|
|
28
|
+
* @throws {TypeError} for a prefix outside that alphabet, before any key is minted under it.
|
|
29
|
+
* @complexity O(1) — compiles one anchored pattern.
|
|
30
|
+
*/
|
|
31
|
+
export declare function createApiKeySecret({ prefix }: {
|
|
32
|
+
prefix: string;
|
|
33
|
+
}, _optional?: Record<string, never>): ApiKeySecret;
|
|
34
|
+
/**
|
|
35
|
+
* The reference `ApiKeySecretHasherPort` — scrypt with per-key salts and a constant-time compare.
|
|
36
|
+
*
|
|
37
|
+
* `verify` never throws: a malformed, foreign, or truncated `key_hash` resolves `false`, so a
|
|
38
|
+
* corrupted row degrades to "credential rejected" rather than to a 500 or an auth bypass (the same
|
|
39
|
+
* fail-closed contract `Argon2PasswordHasher.verify` already holds for passwords).
|
|
40
|
+
*
|
|
41
|
+
* @complexity O(1) calls into `node:crypto`; cost is set by `SCRYPT_PARAMS`, not by input size.
|
|
42
|
+
* @overallScore 100
|
|
43
|
+
*/
|
|
44
|
+
export declare class ScryptApiKeySecretHasher implements ApiKeySecretHasherPort {
|
|
45
|
+
hash({ secret }: {
|
|
46
|
+
secret: string;
|
|
47
|
+
}, _options?: Record<string, never>): Promise<string>;
|
|
48
|
+
verify({ storedHash, secret }: {
|
|
49
|
+
storedHash: string;
|
|
50
|
+
secret: string;
|
|
51
|
+
}, _options?: Record<string, never>): Promise<boolean>;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* A stored-hash string over a value no caller can ever present, so a lookup that found no row can
|
|
55
|
+
* still spend one real derivation instead of returning immediately (see `authenticateApiKey`).
|
|
56
|
+
* Without it, "no key carries this prefix" and "this prefix exists but the secret is wrong" are
|
|
57
|
+
* distinguishable by response time.
|
|
58
|
+
*
|
|
59
|
+
* Drawn from the CSPRNG rather than hardcoded, so it is not a recognizable constant in a heap dump
|
|
60
|
+
* or a leaked build, and memoized per hasher so the cost is paid once per process.
|
|
61
|
+
*
|
|
62
|
+
* @complexity O(1) after the first call for a given hasher.
|
|
63
|
+
* @overallScore 100
|
|
64
|
+
*/
|
|
65
|
+
export declare function decoyKeyHash({ hasher }: {
|
|
66
|
+
hasher: ApiKeySecretHasherPort;
|
|
67
|
+
}, _optional?: Record<string, never>): Promise<string>;
|
|
68
|
+
//# sourceMappingURL=api-key-secret.d.ts.map
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { randomBytes, scrypt, timingSafeEqual } from "node:crypto";
|
|
2
|
+
/**
|
|
3
|
+
* @file Minting, parsing, and hashing of raw API-key strings (SPEC-006 REQ-08, INV-05).
|
|
4
|
+
*
|
|
5
|
+
* Purpose:
|
|
6
|
+
* One place owns the entire secret lifecycle for `api_keys`, so no route or repo file ever has to
|
|
7
|
+
* touch a raw key beyond handing it straight to the caller once. Everything here is pure — no
|
|
8
|
+
* repo, no clock, no db handle — which is why it is unit-testable without an HTTP harness.
|
|
9
|
+
*
|
|
10
|
+
* ## Key shape
|
|
11
|
+
* `<scheme prefix><12 hex>.<43 base64url chars>` splits into two halves with different jobs:
|
|
12
|
+
* - `<scheme prefix><12 hex>` — the NON-secret prefix, persisted in the clear as `api_keys.prefix`
|
|
13
|
+
* and unique per workspace. It exists to make verification a single indexed row read. The scheme
|
|
14
|
+
* prefix (e.g. `acme_ak_`) is a recognizable marker so a leaked key is greppable by secret scanners.
|
|
15
|
+
* It is product identity, so the host supplies it through `createApiKeySecret({ prefix })`; every
|
|
16
|
+
* issued key carries it, so a host must never change the value it binds.
|
|
17
|
+
* - `<43 base64url chars>` — `randomBytes(32)`, i.e. **256 bits** of CSPRNG entropy. This is the
|
|
18
|
+
* only part that is secret and the only part that is hashed.
|
|
19
|
+
*
|
|
20
|
+
* ## Why scrypt, and why at THIS cost
|
|
21
|
+
* A password hash defends a low-entropy human-chosen input against offline dictionary search, so
|
|
22
|
+
* it is tuned as slowly as the login path can bear (`Argon2PasswordHasher`: 19 MiB, t=2). An API
|
|
23
|
+
* key's input is 256 CSPRNG bits, where offline search is already infeasible at any work factor,
|
|
24
|
+
* but the credential is presented on EVERY request rather than once per login. So this is a
|
|
25
|
+
* separate port from `PasswordHasherPort` with a separate tuning, not a reuse of it:
|
|
26
|
+
* - **Salted and slow, not a bare digest.** A per-key 16-byte salt plus a memory-hard KDF means a
|
|
27
|
+
* stolen `api_keys` table yields no precomputation, no cross-row amortization, and no rainbow
|
|
28
|
+
* table — the properties an unsalted SHA of a secret gives away for free.
|
|
29
|
+
* - **`N=2^14, r=8, p=1`** (~16 MiB, tens of milliseconds on commodity hardware) rather than a
|
|
30
|
+
* password-grade cost, because the entropy above already carries the offline-attack argument and
|
|
31
|
+
* the per-request budget is real. Raising it is safe and is a one-line change; the stored digest
|
|
32
|
+
* records its own parameters (below) so already-issued keys keep verifying across a re-tune.
|
|
33
|
+
* - **`node:crypto` only.** No new dependency, and no native binding on the request hot path.
|
|
34
|
+
*
|
|
35
|
+
* Stored format: `scrypt$<N>$<r>$<p>$<salt base64url>$<digest base64url>`. Parameters travel with
|
|
36
|
+
* the digest so verification never has to assume the constants a row was written under.
|
|
37
|
+
*
|
|
38
|
+
* Comparison is `timingSafeEqual` over the raw digest bytes. Nothing in this file branches on the
|
|
39
|
+
* CONTENT of a secret or a digest; the only early returns are on structural facts (a malformed
|
|
40
|
+
* stored hash, a wrong-length digest), never on how far a comparison got.
|
|
41
|
+
*/
|
|
42
|
+
/** Bytes of the non-secret lookup handle (48 bits, hex-encoded to 12 chars). */
|
|
43
|
+
const HANDLE_BYTES = 6;
|
|
44
|
+
/** Bytes of the secret half. 32 = 256 bits, the entropy the file header's argument rests on. */
|
|
45
|
+
const SECRET_BYTES = 32;
|
|
46
|
+
/** Separates prefix from secret. `.` can never appear in base64url, so the split is unambiguous. */
|
|
47
|
+
const KEY_SEPARATOR = ".";
|
|
48
|
+
/** The alphabet a host scheme prefix may use. It holds no regex metacharacter, so the anchored
|
|
49
|
+
* pattern built from it needs no escaping, and it can never contain `KEY_SEPARATOR`. */
|
|
50
|
+
const SCHEME_PREFIX_SHAPE = /^[a-z][a-z0-9_]*$/;
|
|
51
|
+
/** scrypt cost parameters for NEWLY written digests. See the file header for the tuning argument. */
|
|
52
|
+
const SCRYPT_PARAMS = { N: 16384, r: 8, p: 1 };
|
|
53
|
+
/** Derived-key length in bytes. */
|
|
54
|
+
const SCRYPT_KEYLEN = 32;
|
|
55
|
+
/** `128 * N * r` is scrypt's own requirement (16 MiB here); the headroom covers `p` and overhead. */
|
|
56
|
+
const SCRYPT_MAXMEM = 64 * 1024 * 1024;
|
|
57
|
+
/** Salt length in bytes. */
|
|
58
|
+
const SALT_BYTES = 16;
|
|
59
|
+
/**
|
|
60
|
+
* Mint a new API key from the CSPRNG.
|
|
61
|
+
*
|
|
62
|
+
* @returns the raw key plus its two halves, already split so the caller never re-parses its own
|
|
63
|
+
* output.
|
|
64
|
+
* @complexity O(1) — two `randomBytes` draws of fixed size.
|
|
65
|
+
* @overallScore 100
|
|
66
|
+
*/
|
|
67
|
+
function mintApiKey({ keySchemePrefix }, _options = {}) {
|
|
68
|
+
const prefix = `${keySchemePrefix}${randomBytes(HANDLE_BYTES).toString("hex")}`;
|
|
69
|
+
const secret = randomBytes(SECRET_BYTES).toString("base64url");
|
|
70
|
+
return { rawKey: `${prefix}${KEY_SEPARATOR}${secret}`, prefix, secret };
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Split a presented raw key back into its two halves.
|
|
74
|
+
*
|
|
75
|
+
* @param required.rawKey - the untrusted credential exactly as presented by a caller.
|
|
76
|
+
* @param required.prefixPattern - `<scheme prefix>` + exactly 12 lowercase hex characters, anchored.
|
|
77
|
+
* @returns `{ prefix, secret }`, or `null` when `rawKey` is not shaped like a key this runtime
|
|
78
|
+
* mints — which the caller must treat as "no such credential", never as an error worth reporting
|
|
79
|
+
* in detail (a parse-failure message that distinguishes shapes is an oracle).
|
|
80
|
+
* @complexity O(1) — one `indexOf` and one anchored regex over a bounded prefix.
|
|
81
|
+
* @overallScore 100
|
|
82
|
+
*/
|
|
83
|
+
function parseApiKey({ rawKey, prefixPattern }, _options = {}) {
|
|
84
|
+
const separatorAt = rawKey.indexOf(KEY_SEPARATOR);
|
|
85
|
+
if (separatorAt <= 0)
|
|
86
|
+
return null;
|
|
87
|
+
const prefix = rawKey.slice(0, separatorAt);
|
|
88
|
+
const secret = rawKey.slice(separatorAt + 1);
|
|
89
|
+
if (secret.length === 0 || !prefixPattern.test(prefix))
|
|
90
|
+
return null;
|
|
91
|
+
return { prefix, secret };
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Bind minting and parsing to the host's non-secret scheme marker (e.g. `acme_ak_`).
|
|
95
|
+
*
|
|
96
|
+
* @param required.prefix - lowercase letters, digits and `_`, starting with a letter. Every key the
|
|
97
|
+
* host has issued carries it, so the host binds one value for its lifetime.
|
|
98
|
+
* @throws {TypeError} for a prefix outside that alphabet, before any key is minted under it.
|
|
99
|
+
* @complexity O(1) — compiles one anchored pattern.
|
|
100
|
+
*/
|
|
101
|
+
export function createApiKeySecret({ prefix }, _optional = {}) {
|
|
102
|
+
if (!SCHEME_PREFIX_SHAPE.test(prefix))
|
|
103
|
+
throw new TypeError("api-key scheme prefix must be lowercase letters, digits or '_', starting with a letter");
|
|
104
|
+
const prefixPattern = new RegExp(`^${prefix}[0-9a-f]{12}$`);
|
|
105
|
+
return {
|
|
106
|
+
mintApiKey: () => mintApiKey({ keySchemePrefix: prefix }),
|
|
107
|
+
parseApiKey: ({ rawKey }, _options = {}) => parseApiKey({ rawKey, prefixPattern }),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function deriveKey({ secret, salt, params }, _options = {}) {
|
|
111
|
+
return new Promise((resolve, reject) => {
|
|
112
|
+
scrypt(secret, salt, SCRYPT_KEYLEN, { ...params, maxmem: SCRYPT_MAXMEM }, (err, derived) => {
|
|
113
|
+
if (err)
|
|
114
|
+
reject(err);
|
|
115
|
+
else
|
|
116
|
+
resolve(derived);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
/** True iff `N`/`r`/`p` are all integers — the shape scrypt's own parameters must have before
|
|
121
|
+
* they are safe to bounds-check at all. */
|
|
122
|
+
function isIntegerTriple({ N, r, p }, _options = {}) {
|
|
123
|
+
return Number.isInteger(N) && Number.isInteger(r) && Number.isInteger(p);
|
|
124
|
+
}
|
|
125
|
+
/** True iff `N`/`r`/`p` are within the bounds a legitimately-written digest can have: strictly
|
|
126
|
+
* positive (`N` additionally > 1, scrypt's own requirement), and under the memory ceiling. Refuses
|
|
127
|
+
* to spend unbounded memory on parameters read out of a row (a hand-edited or hostile `key_hash`
|
|
128
|
+
* must not become a denial-of-service knob) — `128 * N * r` is scrypt's own footprint. Its CPU work
|
|
129
|
+
* grows linearly with `p` (`128 * N * r * p` bytes mixed), so the same ceiling bounds `p` too. This
|
|
130
|
+
* file writes `p=1`, so no digest it wrote is refused. */
|
|
131
|
+
function isWithinScryptBounds({ N, r, p }, _options = {}) {
|
|
132
|
+
if (N <= 1 || r <= 0 || p <= 0)
|
|
133
|
+
return false;
|
|
134
|
+
return 128 * N * r * p <= SCRYPT_MAXMEM;
|
|
135
|
+
}
|
|
136
|
+
/** Parses and validates the three numeric scrypt cost parameters embedded in a stored hash.
|
|
137
|
+
* Returns `null` for anything non-integer, non-positive, or exceeding the memory ceiling. */
|
|
138
|
+
function parseStoredHashParams({ rawN, rawR, rawP }, _options = {}) {
|
|
139
|
+
const N = Number(rawN);
|
|
140
|
+
const r = Number(rawR);
|
|
141
|
+
const p = Number(rawP);
|
|
142
|
+
if (!isIntegerTriple({ N, r, p }))
|
|
143
|
+
return null;
|
|
144
|
+
if (!isWithinScryptBounds({ N, r, p }))
|
|
145
|
+
return null;
|
|
146
|
+
return { N, r, p };
|
|
147
|
+
}
|
|
148
|
+
/** Split a stored `scrypt$...` string. Returns `null` for anything this file did not write. */
|
|
149
|
+
function parseStoredHash({ storedHash }, _options = {}) {
|
|
150
|
+
const [scheme, rawN, rawR, rawP, rawSalt, rawDigest, ...extra] = storedHash.split("$");
|
|
151
|
+
if (scheme !== "scrypt" || rawN === undefined || rawR === undefined || rawP === undefined)
|
|
152
|
+
return null;
|
|
153
|
+
if (rawSalt === undefined || rawDigest === undefined || extra.length > 0)
|
|
154
|
+
return null;
|
|
155
|
+
return parseStoredHashBody({ rawN, rawR, rawP, rawSalt, rawDigest });
|
|
156
|
+
}
|
|
157
|
+
function parseStoredHashBody({ rawN, rawR, rawP, rawSalt, rawDigest }) {
|
|
158
|
+
const params = parseStoredHashParams({ rawN, rawR, rawP });
|
|
159
|
+
if (!params)
|
|
160
|
+
return null;
|
|
161
|
+
const bytes = decodeStoredHashBytes({ rawSalt, rawDigest });
|
|
162
|
+
return bytes ? { params, ...bytes } : null;
|
|
163
|
+
}
|
|
164
|
+
function decodeStoredHashBytes({ rawSalt, rawDigest }, _options = {}) {
|
|
165
|
+
const salt = Buffer.from(rawSalt, "base64url");
|
|
166
|
+
const digest = Buffer.from(rawDigest, "base64url");
|
|
167
|
+
if (salt.length === 0 || digest.length === 0)
|
|
168
|
+
return null;
|
|
169
|
+
return { salt, digest };
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* The reference `ApiKeySecretHasherPort` — scrypt with per-key salts and a constant-time compare.
|
|
173
|
+
*
|
|
174
|
+
* `verify` never throws: a malformed, foreign, or truncated `key_hash` resolves `false`, so a
|
|
175
|
+
* corrupted row degrades to "credential rejected" rather than to a 500 or an auth bypass (the same
|
|
176
|
+
* fail-closed contract `Argon2PasswordHasher.verify` already holds for passwords).
|
|
177
|
+
*
|
|
178
|
+
* @complexity O(1) calls into `node:crypto`; cost is set by `SCRYPT_PARAMS`, not by input size.
|
|
179
|
+
* @overallScore 100
|
|
180
|
+
*/
|
|
181
|
+
export class ScryptApiKeySecretHasher {
|
|
182
|
+
async hash({ secret }, _options = {}) {
|
|
183
|
+
const salt = randomBytes(SALT_BYTES);
|
|
184
|
+
const derived = await deriveKey({ secret, salt, params: SCRYPT_PARAMS });
|
|
185
|
+
const { N, r, p } = SCRYPT_PARAMS;
|
|
186
|
+
return `scrypt$${N}$${r}$${p}$${salt.toString("base64url")}$${derived.toString("base64url")}`;
|
|
187
|
+
}
|
|
188
|
+
async verify({ storedHash, secret }, _options = {}) {
|
|
189
|
+
const parsed = parseStoredHash({ storedHash });
|
|
190
|
+
if (!parsed)
|
|
191
|
+
return false;
|
|
192
|
+
try {
|
|
193
|
+
const derived = await deriveKey({ secret, salt: parsed.salt, params: parsed.params });
|
|
194
|
+
// Length mismatch is a property of the STORED row, not of the presented secret, so this
|
|
195
|
+
// early return leaks nothing about the credential — and `timingSafeEqual` throws on
|
|
196
|
+
// unequal lengths, so the guard is required, not merely defensive.
|
|
197
|
+
if (derived.length !== parsed.digest.length)
|
|
198
|
+
return false;
|
|
199
|
+
return timingSafeEqual(derived, parsed.digest);
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
/** One decoy per hasher instance, built on first use — never at import time (this module must be
|
|
207
|
+
* free of import-time side effects, and the derivation below is deliberately expensive). */
|
|
208
|
+
const decoyByHasher = new WeakMap();
|
|
209
|
+
/**
|
|
210
|
+
* A stored-hash string over a value no caller can ever present, so a lookup that found no row can
|
|
211
|
+
* still spend one real derivation instead of returning immediately (see `authenticateApiKey`).
|
|
212
|
+
* Without it, "no key carries this prefix" and "this prefix exists but the secret is wrong" are
|
|
213
|
+
* distinguishable by response time.
|
|
214
|
+
*
|
|
215
|
+
* Drawn from the CSPRNG rather than hardcoded, so it is not a recognizable constant in a heap dump
|
|
216
|
+
* or a leaked build, and memoized per hasher so the cost is paid once per process.
|
|
217
|
+
*
|
|
218
|
+
* @complexity O(1) after the first call for a given hasher.
|
|
219
|
+
* @overallScore 100
|
|
220
|
+
*/
|
|
221
|
+
export function decoyKeyHash({ hasher }, _optional = {}) {
|
|
222
|
+
const existing = decoyByHasher.get(hasher);
|
|
223
|
+
if (existing)
|
|
224
|
+
return existing;
|
|
225
|
+
const created = hasher.hash({ secret: randomBytes(SECRET_BYTES).toString("base64url") });
|
|
226
|
+
decoyByHasher.set(hasher, created);
|
|
227
|
+
return created;
|
|
228
|
+
}
|
|
229
|
+
//# sourceMappingURL=api-key-secret.js.map
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import type { UUID } from "@jini-ai/core/primitives";
|
|
2
|
+
import { type PrincipalRecord } from "../core/index.js";
|
|
3
|
+
import type { AuthServiceDeps } from "../server/auth-service.js";
|
|
4
|
+
import { type ApiKeySecret } from "./api-key-secret.js";
|
|
5
|
+
import type { ApiKeyRecord, ApiKeyRepoPort, ApiKeySecretHasherPort } from "./api-key-types.js";
|
|
6
|
+
/** Deps the transitions below need: the nine identity repos plus the two api-key-specific seams. */
|
|
7
|
+
export interface ApiKeyServiceDeps extends AuthServiceDeps {
|
|
8
|
+
apiKeys: ApiKeyRepoPort;
|
|
9
|
+
secretHasher: ApiKeySecretHasherPort;
|
|
10
|
+
}
|
|
11
|
+
export interface CreateApiKeyPrincipalInput {
|
|
12
|
+
workspaceId: UUID;
|
|
13
|
+
callerPrincipalId: UUID;
|
|
14
|
+
displayName: unknown;
|
|
15
|
+
/** Optional; only `"api_key"` (or absent) is accepted — see the refusal below. */
|
|
16
|
+
kind?: unknown;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* `CREATE_PRINCIPAL` for machine identities (api.spec §1 `APIKEY_PRINCIPAL_CREATE`, 0.7.0). Mints
|
|
20
|
+
* an ACTIVE, GRANTLESS `kind='api_key'` principal — no `principal_roles`, no `principal_policies`
|
|
21
|
+
* — which is exactly the precondition `issueApiKey` re-verifies.
|
|
22
|
+
*
|
|
23
|
+
* `kind` is accepted but constrained to `"api_key"`: humans are minted only by `CREATE_USER` and
|
|
24
|
+
* `system`/`user-local` only by first-boot seeding, so this endpoint can never become a second
|
|
25
|
+
* creation path for a privileged kind. `workspaceId` comes from the caller's own credential; there
|
|
26
|
+
* is no caller-supplied workspace field and therefore no cross-workspace mint.
|
|
27
|
+
*
|
|
28
|
+
* @throws {IdentityForbiddenError} caller lacks `apikey.manage` (403).
|
|
29
|
+
* @throws {IdentityValidationError} blank/oversize `displayName`, or `kind` other than `api_key` (400).
|
|
30
|
+
* @complexity O(1) — one permission check, one save.
|
|
31
|
+
* @overallScore 100
|
|
32
|
+
*/
|
|
33
|
+
export declare function createApiKeyPrincipal(required: {
|
|
34
|
+
deps: ApiKeyServiceDeps;
|
|
35
|
+
input: CreateApiKeyPrincipalInput;
|
|
36
|
+
}): Promise<{
|
|
37
|
+
principal: PrincipalRecord;
|
|
38
|
+
}>;
|
|
39
|
+
export interface IssueApiKeyInput {
|
|
40
|
+
workspaceId: UUID;
|
|
41
|
+
callerPrincipalId: UUID;
|
|
42
|
+
principalId: unknown;
|
|
43
|
+
label: unknown;
|
|
44
|
+
policyIds: unknown;
|
|
45
|
+
expiresAt?: unknown;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* `ISSUE_API_KEY` (state.spec §3). Snapshots the requested policies into a fresh `isFrozen` policy,
|
|
49
|
+
* attaches it to the bound `kind='api_key'` principal, and returns the raw key ONCE.
|
|
50
|
+
*
|
|
51
|
+
* The raw key is the only value in this codebase that is returned and never stored: `api_keys`
|
|
52
|
+
* holds a digest of its secret half plus its non-secret prefix, so no later read of any table can
|
|
53
|
+
* reconstruct it (INV-05).
|
|
54
|
+
*
|
|
55
|
+
* Writes happen only after every check passes, in this order: validate body (400) → resolve target
|
|
56
|
+
* (404/400) → resolve sources (404/400) → INV-07 clamp (403) → write. A refused issuance therefore
|
|
57
|
+
* leaves no partial rows, including no orphan frozen policy.
|
|
58
|
+
*
|
|
59
|
+
* @throws {IdentityForbiddenError} caller lacks `apikey.manage` (403).
|
|
60
|
+
* @throws {IdentityValidationError} bad body, non-`api_key` target, non-grantless target, or a
|
|
61
|
+
* `*`-bearing source policy (400).
|
|
62
|
+
* @throws {IdentityNotFoundError} unknown principal or policy (404).
|
|
63
|
+
* @throws {GrantExceedsIssuerError} the snapshot would exceed the issuer's own authority (403).
|
|
64
|
+
* @complexity O(p) repo reads for p source policies, plus one `resolveEffectivePermissions`, plus
|
|
65
|
+
* O(k) writes for the k permission rows copied.
|
|
66
|
+
* @overallScore 100
|
|
67
|
+
*/
|
|
68
|
+
export declare function issueApiKey(required: {
|
|
69
|
+
deps: ApiKeyServiceDeps;
|
|
70
|
+
input: IssueApiKeyInput;
|
|
71
|
+
keySecret: ApiKeySecret;
|
|
72
|
+
}, _optional?: Record<string, never>): Promise<{
|
|
73
|
+
apiKey: ApiKeyRecord;
|
|
74
|
+
rawKey: string;
|
|
75
|
+
}>;
|
|
76
|
+
/**
|
|
77
|
+
* `REVOKE_API_KEY` (state.spec §3). Sets `revokedAt` and empties the key's issuance snapshot, so
|
|
78
|
+
* the next request presenting the key is rejected AND the bound principal is left holding nothing.
|
|
79
|
+
* Idempotent: revoking an already-revoked key succeeds without moving the original timestamp.
|
|
80
|
+
*
|
|
81
|
+
* **Disclosed deviation from state.spec §3.** That row calls for retiring the snapshot policy
|
|
82
|
+
* outright — "its `principal_policies` row + the frozen `policies` row + its `policy_permissions`".
|
|
83
|
+
* `PrincipalPolicyRepoPort` (`@jini-ai/user-management`) exposes only `listByPrincipalId`/
|
|
84
|
+
* `listByPolicyId`/`save`, with no delete, and the port is not this repo's to change. Deleting the
|
|
85
|
+
* `policies` row while its join row survives would leave exactly the dangling reference INV-09
|
|
86
|
+
* exists to prevent, so this instead empties the snapshot via `deleteByPolicyId` and leaves the
|
|
87
|
+
* (now permission-less, still `isFrozen`) policy and its join row in place. The security outcome is
|
|
88
|
+
* identical — the principal's effective permission set is empty — and no invariant is broken.
|
|
89
|
+
*
|
|
90
|
+
* @throws {IdentityForbiddenError} caller lacks `apikey.manage` (403).
|
|
91
|
+
* @throws {IdentityNotFoundError} no such key in the caller's workspace (404).
|
|
92
|
+
* @complexity O(1) repo operations.
|
|
93
|
+
* @overallScore 100
|
|
94
|
+
*/
|
|
95
|
+
export declare function revokeApiKey(required: {
|
|
96
|
+
deps: ApiKeyServiceDeps;
|
|
97
|
+
input: {
|
|
98
|
+
workspaceId: UUID;
|
|
99
|
+
callerPrincipalId: UUID;
|
|
100
|
+
keyId: string;
|
|
101
|
+
};
|
|
102
|
+
}): Promise<{
|
|
103
|
+
apiKey: ApiKeyRecord;
|
|
104
|
+
}>;
|
|
105
|
+
/**
|
|
106
|
+
* Resolve a presented raw key to its principal, applying every fail-closed check. The Bearer-auth
|
|
107
|
+
* counterpart of `@jini-ai/user-management`'s `validateSession`, and deliberately the same shape: it
|
|
108
|
+
* returns `null` for EVERY rejection reason rather than throwing a distinguishable error, so a
|
|
109
|
+
* caller cannot tell "unknown key" from "revoked key" from "expired key" from "disabled principal".
|
|
110
|
+
*
|
|
111
|
+
* Timing is handled the same way. A prefix that matches no row still spends one real key
|
|
112
|
+
* derivation against `decoyKeyHash`, so an attacker cannot enumerate valid prefixes by clocking
|
|
113
|
+
* the response; and the revoked/expired/status checks run AFTER verification, so they never
|
|
114
|
+
* short-circuit ahead of the constant-time comparison.
|
|
115
|
+
*
|
|
116
|
+
* @returns the bound principal and its key row, or `null` — never a reason.
|
|
117
|
+
* @complexity O(1) — one indexed row read, one key derivation, one principal read, one save.
|
|
118
|
+
* @overallScore 100
|
|
119
|
+
*/
|
|
120
|
+
export declare function authenticateApiKey(required: {
|
|
121
|
+
deps: ApiKeyServiceDeps;
|
|
122
|
+
input: {
|
|
123
|
+
workspaceId: UUID;
|
|
124
|
+
rawKey: string;
|
|
125
|
+
};
|
|
126
|
+
keySecret: ApiKeySecret;
|
|
127
|
+
}): Promise<{
|
|
128
|
+
principal: PrincipalRecord;
|
|
129
|
+
apiKey: ApiKeyRecord;
|
|
130
|
+
} | null>;
|
|
131
|
+
/** Bind the host's key format (`createApiKeySecret`) once at composition; call sites keep `{ deps, input }`. */
|
|
132
|
+
export declare function createApiKeyService({ keySecret }: {
|
|
133
|
+
keySecret: ApiKeySecret;
|
|
134
|
+
}, _optional?: Record<string, never>): {
|
|
135
|
+
issueApiKey: (required: Omit<Parameters<typeof issueApiKey>[0], "keySecret">) => Promise<{
|
|
136
|
+
apiKey: ApiKeyRecord;
|
|
137
|
+
rawKey: string;
|
|
138
|
+
}>;
|
|
139
|
+
authenticateApiKey: (required: Omit<Parameters<typeof authenticateApiKey>[0], "keySecret">) => Promise<{
|
|
140
|
+
principal: PrincipalRecord;
|
|
141
|
+
apiKey: ApiKeyRecord;
|
|
142
|
+
} | null>;
|
|
143
|
+
};
|
|
144
|
+
//# sourceMappingURL=api-key-service.d.ts.map
|