@fabrika/iam 0.0.1 → 0.9.0-dev.26
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/fabrika.config.ts +267 -0
- package/migrations/0001_init.sql +316 -0
- package/migrations/0002_oauth.sql +38 -0
- package/migrations/0003_contract_apps.sql +11 -0
- package/migrations/0004_membership.sql +93 -0
- package/migrations/0005_workloads.sql +23 -0
- package/migrations/0006_membership_transport_keys.sql +16 -0
- package/migrations/0007_member_directory.sql +7 -0
- package/migrations/0008_durable_audit.sql +28 -0
- package/migrations/0009_member_lookups.sql +7 -0
- package/migrations/0010_workload_issues.sql +6 -0
- package/migrations/0011_app_presentation.sql +15 -0
- package/migrations/0012_external_principals.sql +10 -0
- package/migrations/0013_app_mail_templates.sql +14 -0
- package/migrations/0014_invitation_wording.sql +8 -0
- package/migrations/0015_app_schema_revisions.sql +15 -0
- package/migrations/0016_principal_grant_revision.sql +9 -0
- package/migrations/0017_app_sign_ins.sql +12 -0
- package/migrations/0018_app_members.sql +13 -0
- package/migrations/0019_app_mail_html.sql +7 -0
- package/migrations/0020_public_workloads.sql +34 -0
- package/migrations/0021_installation_brand.sql +19 -0
- package/migrations/0022_password_policy.sql +12 -0
- package/migrations/0023_terminals.sql +155 -0
- package/migrations/0024_app_terminals.sql +10 -0
- package/migrations/0025_terminal_completion.sql +10 -0
- package/migrations/0026_terminal_generation.sql +12 -0
- package/migrations/0027_application_exact_actions.sql +28 -0
- package/migrations/0028_oauth_client_assertions.sql +10 -0
- package/migrations/0029_role_via.sql +6 -0
- package/migrations/0030_membership_role_via.sql +12 -0
- package/migrations/0031_person_locale.sql +11 -0
- package/migrations-postgres/0001_init.sql +331 -0
- package/migrations-postgres/0002_oauth.sql +36 -0
- package/migrations-postgres/0003_contract_apps.sql +8 -0
- package/migrations-postgres/0004_membership.sql +92 -0
- package/migrations-postgres/0005_workloads.sql +18 -0
- package/migrations-postgres/0006_membership_transport_keys.sql +12 -0
- package/migrations-postgres/0007_member_directory.sql +7 -0
- package/migrations-postgres/0008_durable_audit.sql +8 -0
- package/migrations-postgres/0009_member_lookups.sql +7 -0
- package/migrations-postgres/0010_workload_issues.sql +6 -0
- package/migrations-postgres/0011_app_presentation.sql +15 -0
- package/migrations-postgres/0012_external_principals.sql +10 -0
- package/migrations-postgres/0013_app_mail_templates.sql +14 -0
- package/migrations-postgres/0014_invitation_wording.sql +8 -0
- package/migrations-postgres/0015_app_schema_revisions.sql +15 -0
- package/migrations-postgres/0016_principal_grant_revision.sql +9 -0
- package/migrations-postgres/0017_app_sign_ins.sql +12 -0
- package/migrations-postgres/0018_app_members.sql +13 -0
- package/migrations-postgres/0019_app_mail_html.sql +7 -0
- package/migrations-postgres/0020_public_workloads.sql +9 -0
- package/migrations-postgres/0021_installation_brand.sql +19 -0
- package/migrations-postgres/0022_password_policy.sql +12 -0
- package/migrations-postgres/0023_terminals.sql +70 -0
- package/migrations-postgres/0024_app_terminals.sql +10 -0
- package/migrations-postgres/0025_terminal_completion.sql +10 -0
- package/migrations-postgres/0026_terminal_generation.sql +12 -0
- package/migrations-postgres/0027_application_exact_actions.sql +28 -0
- package/migrations-postgres/0028_oauth_client_assertions.sql +9 -0
- package/migrations-postgres/0029_role_via.sql +4 -0
- package/migrations-postgres/0030_membership_role_via.sql +7 -0
- package/migrations-postgres/0031_person_locale.sql +11 -0
- package/package.json +69 -8
- package/src/admin/access.ts +47 -0
- package/src/admin/api-keys.ts +280 -0
- package/src/admin/app-people.ts +209 -0
- package/src/admin/app-schema.ts +308 -0
- package/src/admin/audit.ts +81 -0
- package/src/admin/brand.ts +54 -0
- package/src/admin/connections.ts +48 -0
- package/src/admin/context.ts +70 -0
- package/src/admin/grant-support.ts +192 -0
- package/src/admin/grants.ts +189 -0
- package/src/admin/handlers.ts +102 -0
- package/src/admin/http.ts +24 -0
- package/src/admin/membership-keys.ts +38 -0
- package/src/admin/pagination.ts +28 -0
- package/src/admin/password-policy.ts +48 -0
- package/src/admin/passwords.ts +78 -0
- package/src/admin/policies.ts +136 -0
- package/src/admin/principals.ts +226 -0
- package/src/admin/router.ts +291 -0
- package/src/admin/rpc.ts +387 -0
- package/src/admin/sessions.ts +115 -0
- package/src/admin/share-links.ts +127 -0
- package/src/admin/terminals.ts +115 -0
- package/src/admin/user-admin.ts +76 -0
- package/src/admin/workloads.ts +85 -0
- package/src/app-presentation.ts +178 -0
- package/src/app.ts +158 -0
- package/src/auth/cookies.ts +64 -0
- package/src/auth/failure.ts +25 -0
- package/src/auth/handoff.ts +136 -0
- package/src/auth/http.ts +88 -0
- package/src/auth/invitations.ts +220 -0
- package/src/auth/known-device.ts +44 -0
- package/src/auth/login.ts +162 -0
- package/src/auth/oidc-flight.ts +91 -0
- package/src/auth/oidc.ts +148 -0
- package/src/auth/password.ts +416 -0
- package/src/auth/routes.ts +108 -0
- package/src/auth/sessions.ts +249 -0
- package/src/auth/terminals.ts +284 -0
- package/src/auth.ts +193 -0
- package/src/binding-identity.ts +25 -0
- package/src/bounded-body.ts +35 -0
- package/src/catalog/cs.ts +147 -0
- package/src/catalog/en.ts +148 -0
- package/src/catalog/index.ts +122 -0
- package/src/catalog/uk.ts +164 -0
- package/src/client-address.ts +39 -0
- package/src/common-passwords.ts +37 -0
- package/src/contract-rules.ts +80 -0
- package/src/cron.ts +54 -0
- package/src/db.ts +128 -0
- package/src/delegation.ts +100 -0
- package/src/device-http.ts +39 -0
- package/src/device.ts +269 -0
- package/src/email-identity.ts +2 -0
- package/src/env.ts +132 -0
- package/src/handoff.ts +175 -0
- package/src/html.ts +4 -0
- package/src/human-admission.ts +40 -0
- package/src/identification.ts +185 -0
- package/src/index.ts +292 -0
- package/src/installation-brand.ts +82 -0
- package/src/issue.ts +265 -0
- package/src/json.ts +30 -0
- package/src/log.ts +26 -0
- package/src/membership-http.ts +135 -0
- package/src/membership.ts +1210 -0
- package/src/messages.ts +44 -0
- package/src/narrow-permissions.ts +26 -0
- package/src/node/browser-identity.ts +69 -0
- package/src/node/migrate.ts +52 -0
- package/src/node/prune.ts +34 -0
- package/src/node/runtime.ts +221 -0
- package/src/node/server.ts +104 -0
- package/src/oauth-client-auth.ts +93 -0
- package/src/oauth-client.ts +145 -0
- package/src/oauth-config.ts +72 -0
- package/src/oauth-http.ts +262 -0
- package/src/oauth.ts +272 -0
- package/src/oidc.ts +260 -0
- package/src/origin.ts +29 -0
- package/src/password-crypto.ts +148 -0
- package/src/password-db.ts +419 -0
- package/src/password-minimum.ts +44 -0
- package/src/password-pages.ts +397 -0
- package/src/password-policy.ts +79 -0
- package/src/password-service.ts +67 -0
- package/src/person-locale.ts +103 -0
- package/src/proxy-proof.ts +36 -0
- package/src/relay-mail.ts +64 -0
- package/src/repositories/app-schema.ts +550 -0
- package/src/repositories/audit.ts +405 -0
- package/src/repositories/brand.ts +66 -0
- package/src/repositories/credentials.ts +331 -0
- package/src/repositories/device.ts +137 -0
- package/src/repositories/grants.ts +404 -0
- package/src/repositories/handoff.ts +103 -0
- package/src/repositories/membership-transport.ts +49 -0
- package/src/repositories/membership.ts +875 -0
- package/src/repositories/oauth.ts +122 -0
- package/src/repositories/password-policy.ts +44 -0
- package/src/repositories/principals.ts +358 -0
- package/src/repositories/sessions.ts +339 -0
- package/src/repositories/sql.ts +23 -0
- package/src/repositories/terminals.ts +346 -0
- package/src/repositories/workloads.ts +134 -0
- package/src/request-id.ts +46 -0
- package/src/resolve.ts +396 -0
- package/src/retention.ts +34 -0
- package/src/roles.ts +54 -0
- package/src/rpc-http.ts +333 -0
- package/src/rpc-inputs.ts +110 -0
- package/src/rpc.ts +440 -0
- package/src/secret.ts +45 -0
- package/src/service.ts +59 -0
- package/src/services.ts +199 -0
- package/src/signing.ts +260 -0
- package/src/stored-chain.ts +23 -0
- package/src/stored-permissions.ts +34 -0
- package/src/terminals.ts +15 -0
- package/src/tokens.ts +506 -0
- package/src/workload-token.ts +130 -0
- package/types/fabrika.config.d.ts +11 -0
- package/types/src/admin/access.d.ts +19 -0
- package/types/src/admin/api-keys.d.ts +26 -0
- package/types/src/admin/app-people.d.ts +8 -0
- package/types/src/admin/app-schema.d.ts +32 -0
- package/types/src/admin/audit.d.ts +10 -0
- package/types/src/admin/brand.d.ts +10 -0
- package/types/src/admin/connections.d.ts +5 -0
- package/types/src/admin/context.d.ts +46 -0
- package/types/src/admin/grant-support.d.ts +59 -0
- package/types/src/admin/grants.d.ts +8 -0
- package/types/src/admin/handlers.d.ts +82 -0
- package/types/src/admin/http.d.ts +9 -0
- package/types/src/admin/membership-keys.d.ts +8 -0
- package/types/src/admin/pagination.d.ts +5 -0
- package/types/src/admin/password-policy.d.ts +9 -0
- package/types/src/admin/passwords.d.ts +5 -0
- package/types/src/admin/policies.d.ts +15 -0
- package/types/src/admin/principals.d.ts +15 -0
- package/types/src/admin/router.d.ts +75 -0
- package/types/src/admin/rpc.d.ts +6 -0
- package/types/src/admin/sessions.d.ts +14 -0
- package/types/src/admin/share-links.d.ts +21 -0
- package/types/src/admin/terminals.d.ts +13 -0
- package/types/src/admin/user-admin.d.ts +30 -0
- package/types/src/admin/workloads.d.ts +5 -0
- package/types/src/app-presentation.d.ts +86 -0
- package/types/src/app.d.ts +62 -0
- package/types/src/auth/cookies.d.ts +29 -0
- package/types/src/auth/failure.d.ts +47 -0
- package/types/src/auth/handoff.d.ts +66 -0
- package/types/src/auth/http.d.ts +29 -0
- package/types/src/auth/invitations.d.ts +18 -0
- package/types/src/auth/known-device.d.ts +12 -0
- package/types/src/auth/login.d.ts +10 -0
- package/types/src/auth/oidc-flight.d.ts +39 -0
- package/types/src/auth/oidc.d.ts +7 -0
- package/types/src/auth/password.d.ts +7 -0
- package/types/src/auth/routes.d.ts +15 -0
- package/types/src/auth/sessions.d.ts +60 -0
- package/types/src/auth/terminals.d.ts +47 -0
- package/types/src/auth.d.ts +70 -0
- package/types/src/binding-identity.d.ts +12 -0
- package/types/src/bounded-body.d.ts +12 -0
- package/types/src/catalog/cs.d.ts +2 -0
- package/types/src/catalog/en.d.ts +2 -0
- package/types/src/catalog/index.d.ts +112 -0
- package/types/src/catalog/uk.d.ts +2 -0
- package/types/src/client-address.d.ts +31 -0
- package/types/src/common-passwords.d.ts +2 -0
- package/types/src/contract-rules.d.ts +25 -0
- package/types/src/cron.d.ts +15 -0
- package/types/src/db.d.ts +58 -0
- package/types/src/delegation.d.ts +38 -0
- package/types/src/device-http.d.ts +2 -0
- package/types/src/device.d.ts +11 -0
- package/types/src/email-identity.d.ts +1 -0
- package/types/src/env.d.ts +127 -0
- package/types/src/handoff.d.ts +57 -0
- package/types/src/html.d.ts +2 -0
- package/types/src/human-admission.d.ts +22 -0
- package/types/src/identification.d.ts +30 -0
- package/types/src/index.d.ts +62 -0
- package/types/src/installation-brand.d.ts +22 -0
- package/types/src/issue.d.ts +62 -0
- package/types/src/json.d.ts +15 -0
- package/types/src/log.d.ts +15 -0
- package/types/src/membership-http.d.ts +8 -0
- package/types/src/membership.d.ts +156 -0
- package/types/src/messages.d.ts +20 -0
- package/types/src/narrow-permissions.d.ts +7 -0
- package/types/src/node/browser-identity.d.ts +1 -0
- package/types/src/node/migrate.d.ts +4 -0
- package/types/src/node/prune.d.ts +1 -0
- package/types/src/node/runtime.d.ts +51 -0
- package/types/src/node/server.d.ts +5 -0
- package/types/src/oauth-client-auth.d.ts +26 -0
- package/types/src/oauth-client.d.ts +17 -0
- package/types/src/oauth-config.d.ts +16 -0
- package/types/src/oauth-http.d.ts +7 -0
- package/types/src/oauth.d.ts +51 -0
- package/types/src/oidc.d.ts +81 -0
- package/types/src/origin.d.ts +9 -0
- package/types/src/password-crypto.d.ts +37 -0
- package/types/src/password-db.d.ts +134 -0
- package/types/src/password-minimum.d.ts +23 -0
- package/types/src/password-pages.d.ts +143 -0
- package/types/src/password-policy.d.ts +19 -0
- package/types/src/password-service.d.ts +24 -0
- package/types/src/person-locale.d.ts +50 -0
- package/types/src/proxy-proof.d.ts +21 -0
- package/types/src/relay-mail.d.ts +25 -0
- package/types/src/repositories/app-schema.d.ts +244 -0
- package/types/src/repositories/audit.d.ts +187 -0
- package/types/src/repositories/brand.d.ts +41 -0
- package/types/src/repositories/credentials.d.ts +148 -0
- package/types/src/repositories/device.d.ts +50 -0
- package/types/src/repositories/grants.d.ts +177 -0
- package/types/src/repositories/handoff.d.ts +52 -0
- package/types/src/repositories/membership-transport.d.ts +31 -0
- package/types/src/repositories/membership.d.ts +273 -0
- package/types/src/repositories/oauth.d.ts +55 -0
- package/types/src/repositories/password-policy.d.ts +25 -0
- package/types/src/repositories/principals.d.ts +159 -0
- package/types/src/repositories/sessions.d.ts +150 -0
- package/types/src/repositories/sql.d.ts +13 -0
- package/types/src/repositories/terminals.d.ts +144 -0
- package/types/src/repositories/workloads.d.ts +61 -0
- package/types/src/request-id.d.ts +25 -0
- package/types/src/resolve.d.ts +118 -0
- package/types/src/retention.d.ts +18 -0
- package/types/src/roles.d.ts +34 -0
- package/types/src/rpc-http.d.ts +53 -0
- package/types/src/rpc-inputs.d.ts +707 -0
- package/types/src/rpc.d.ts +4 -0
- package/types/src/secret.d.ts +21 -0
- package/types/src/service.d.ts +19 -0
- package/types/src/services.d.ts +72 -0
- package/types/src/signing.d.ts +72 -0
- package/types/src/stored-chain.d.ts +6 -0
- package/types/src/stored-permissions.d.ts +12 -0
- package/types/src/terminals.d.ts +7 -0
- package/types/src/tokens.d.ts +113 -0
- package/types/src/workload-token.d.ts +7 -0
- package/README.md +0 -3
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { ApproveDeviceAuthorizationInput, ApproveDeviceAuthorizationResult, AssertIdentityInput, AssertIdentityResult, AssignMemberInput, AssignMemberResult, AuditInput, CancelIdentificationInput, CancelIdentificationResult, CreateScopeInput, CreateScopeResult, DenyDeviceAuthorizationResult, ExchangeAuthCodeInput, ExchangeAuthCodeResult, FindMemberInput, FindMemberResult, IamHandoffRpc, IamMembershipRpc, IamRpc, IamTerminalRpc, InspectDeviceAuthorizationInput, InspectDeviceAuthorizationResult, InspectIdentificationInput, InspectIdentificationResult, IssueKeyInput, IssueKeyResult, IssueLinkInput, IssueLinkResult, Jwks, ListAppMembersInput, ListAppMembersResult, ListMembersInput, ListMembersResult, ListOwnDeviceAuthorizationsInput, ListOwnDeviceAuthorizationsResult, ListPrincipalsInput, ListPrincipalsResult, MintFromKeyInput, MintFromKeyResult, MintTokenInput, MintTokenResult, RequestDelegationInput, RequestDelegationResult, RevokeKeyInput, RevokeKeyResult, RevokeLinkInput, RevokeLinkResult, RevokeMemberInput, RevokeMemberResult } from '@fabrika/auth-core';
|
|
2
|
+
import { WorkerEntrypoint } from 'cloudflare:workers';
|
|
3
|
+
import type { Env } from './env';
|
|
4
|
+
export interface WorkerBindings extends Omit<Env, 'DB' | 'REPOSITORIES' | 'FABRIKA_IAM_SIGNING_KEYS' | 'FABRIKA_IAM_PROVISIONING_KEY' | 'EMAIL_CONFIG' | 'EMAIL_PROVIDERS' | 'PASSWORD_COST'> {
|
|
5
|
+
DB: D1Database;
|
|
6
|
+
FABRIKA_IAM_SIGNING_KEYS?: string;
|
|
7
|
+
FABRIKA_IAM_PROVISIONING_KEY?: string;
|
|
8
|
+
/** Control's public origin: with a provider and the provisioning key, IAM's mail goes through Control's relay. */
|
|
9
|
+
FABRIKA_CONTROL_URL?: string;
|
|
10
|
+
/** The mail transport's vars and secrets, whichever provider they name. */
|
|
11
|
+
[emailVariable: `FABRIKA_EMAIL_${string}`]: string | undefined;
|
|
12
|
+
}
|
|
13
|
+
/** Present native Worker bindings as the runtime-neutral IAM environment. */
|
|
14
|
+
export declare function iamEnv(bindings: WorkerBindings): Env;
|
|
15
|
+
/**
|
|
16
|
+
* What an application's Workers call over `IAM`: the proxy mints and redeems, the SDK verifies, lists and
|
|
17
|
+
* audits, and the framework requests membership operations on its caller's behalf and identifies people at terminals.
|
|
18
|
+
* An identification operation is pinned to the application named by the binding's `props` (`binding-identity.ts`).
|
|
19
|
+
*/
|
|
20
|
+
export type IamApplicationRpc = Pick<IamRpc, 'getJwks' | 'mintToken' | 'mintFromKey' | 'listPrincipals' | 'audit'> & IamHandoffRpc & IamMembershipRpc & IamTerminalRpc;
|
|
21
|
+
/**
|
|
22
|
+
* The entrypoint every application Worker and its proxy bind (`@fabrika/provider-cloudflare` refuses any
|
|
23
|
+
* other). It holds no getter or field: workerd serves every prototype member over RPC, and a getter
|
|
24
|
+
* returning the env or the RPC object would hand a caller IAM's secrets and every method withheld here.
|
|
25
|
+
*/
|
|
26
|
+
export declare class PropustkaApplication extends WorkerEntrypoint<WorkerBindings> implements IamApplicationRpc {
|
|
27
|
+
mintToken(input: MintTokenInput): Promise<MintTokenResult>;
|
|
28
|
+
mintFromKey(input: MintFromKeyInput): Promise<MintFromKeyResult>;
|
|
29
|
+
/** Cross-host handoff redemption (ADR-0022), absent from `IamRpc`: the proxy Worker narrows this binding structurally. */
|
|
30
|
+
exchangeAuthCode(input: ExchangeAuthCodeInput): Promise<ExchangeAuthCodeResult>;
|
|
31
|
+
getJwks(): Promise<Jwks>;
|
|
32
|
+
audit(event: AuditInput): Promise<void>;
|
|
33
|
+
listPrincipals(input: ListPrincipalsInput): Promise<ListPrincipalsResult>;
|
|
34
|
+
requestDelegation(input: RequestDelegationInput): Promise<RequestDelegationResult>;
|
|
35
|
+
createScope(input: CreateScopeInput): Promise<CreateScopeResult>;
|
|
36
|
+
assignMember(input: AssignMemberInput): Promise<AssignMemberResult>;
|
|
37
|
+
revokeMember(input: RevokeMemberInput): Promise<RevokeMemberResult>;
|
|
38
|
+
listMembers(input: ListMembersInput): Promise<ListMembersResult>;
|
|
39
|
+
listAppMembers(input: ListAppMembersInput): Promise<ListAppMembersResult>;
|
|
40
|
+
findMember(input: FindMemberInput): Promise<FindMemberResult>;
|
|
41
|
+
issueLink(input: IssueLinkInput): Promise<IssueLinkResult>;
|
|
42
|
+
revokeLink(input: RevokeLinkInput): Promise<RevokeLinkResult>;
|
|
43
|
+
inspectIdentification(input: InspectIdentificationInput): Promise<InspectIdentificationResult>;
|
|
44
|
+
assertIdentity(input: AssertIdentityInput): Promise<AssertIdentityResult>;
|
|
45
|
+
cancelIdentification(input: CancelIdentificationInput): Promise<CancelIdentificationResult>;
|
|
46
|
+
}
|
|
47
|
+
/** The default export: the whole `IamRpc`, `/admin/*` + `/auth/*`, and the cron. Only platform components bind it. */
|
|
48
|
+
export declare class Propustka extends PropustkaApplication implements IamRpc, IamHandoffRpc {
|
|
49
|
+
inspectDeviceAuthorization(input: InspectDeviceAuthorizationInput): Promise<InspectDeviceAuthorizationResult>;
|
|
50
|
+
approveDeviceAuthorization(input: ApproveDeviceAuthorizationInput): Promise<ApproveDeviceAuthorizationResult>;
|
|
51
|
+
denyDeviceAuthorization(input: InspectDeviceAuthorizationInput): Promise<DenyDeviceAuthorizationResult>;
|
|
52
|
+
listOwnDeviceAuthorizations(input: ListOwnDeviceAuthorizationsInput): Promise<ListOwnDeviceAuthorizationsResult>;
|
|
53
|
+
revokeKey(input: RevokeKeyInput): Promise<RevokeKeyResult>;
|
|
54
|
+
issueKey(input: IssueKeyInput): Promise<IssueKeyResult>;
|
|
55
|
+
fetch(request: Request): Promise<Response>;
|
|
56
|
+
/**
|
|
57
|
+
* Daily cron (see `triggers.crons`): prune old auth-log and password-transient rows.
|
|
58
|
+
* `WorkerEntrypoint.scheduled` receives only the controller; `env`/`ctx` come from `this`.
|
|
59
|
+
*/
|
|
60
|
+
scheduled(_controller: ScheduledController): Promise<void>;
|
|
61
|
+
}
|
|
62
|
+
export default Propustka;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type InstallationBrand } from '@fabrika/proxy-core/brand';
|
|
2
|
+
import type { InstallationBrandImages, InstallationBrandRow } from './repositories/brand';
|
|
3
|
+
import type { Services } from './services';
|
|
4
|
+
/** How often a stored logo the check refuses is logged again, so the reason the pages lost it stays in the logs. */
|
|
5
|
+
export declare const REFUSED_BRAND_WARN_INTERVAL_MS: number;
|
|
6
|
+
/**
|
|
7
|
+
* The brand a stored row holds, checked again as every reader of a brand checks it (`@fabrika/proxy-core/brand`), or
|
|
8
|
+
* null: for no row, for a cleared one, and for one the check now refuses, which then draws the fabrika mark.
|
|
9
|
+
*
|
|
10
|
+
* Every page reads the row, and it changes only with `brand.set` and `brand.clear`, so the check of the images last
|
|
11
|
+
* read is kept and a row with the same images takes its answer: comparing the stored strings is far cheaper than
|
|
12
|
+
* decoding them again. The key is the images themselves, never a time, so a change is checked whichever instance made it.
|
|
13
|
+
* A refused logo is logged when it is checked and again every `REFUSED_BRAND_WARN_INTERVAL_MS` while pages read it.
|
|
14
|
+
*/
|
|
15
|
+
export declare function storedBrand(row: InstallationBrandRow | null, now?: number): InstallationBrand | null;
|
|
16
|
+
/** The images of `brand` as the repository stores them. */
|
|
17
|
+
export declare function brandImages(brand: InstallationBrand): InstallationBrandImages;
|
|
18
|
+
/**
|
|
19
|
+
* The brand every IAM page draws, read once per render. A logo is decoration: a read that fails draws the fabrika mark
|
|
20
|
+
* and logs the failure's message, never the row, so a page that would otherwise render never fails for its logo.
|
|
21
|
+
*/
|
|
22
|
+
export declare function installationBrand(services: Services): Promise<InstallationBrand | null>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Issuing credentials: `issueKey` writes an opaque, stored, revocable `px_` credential (API key /
|
|
3
|
+
* share link). The token's EFFECTIVE permissions are resolved at use time (`mintFromKey`); this just
|
|
4
|
+
* persists the row.
|
|
5
|
+
*
|
|
6
|
+
* Issuance is DELEGATED: the issuer (resolved server-side from the forwarded credentials, never
|
|
7
|
+
* self-asserted) may only grant what it itself holds — the same `permits` rule `can()` uses. The
|
|
8
|
+
* Worker entrypoint resolves the issuer and writes the audit row; this module is the pure-ish core.
|
|
9
|
+
*/
|
|
10
|
+
import { type IssueKeyInput, type IssueKeyResult, type KeyGrant, type PermissionEntry, type RevokeKeyInput, type RevokeKeyResult } from '@fabrika/auth-core';
|
|
11
|
+
import type { AuditEventInput } from './db';
|
|
12
|
+
import type { Services } from './services';
|
|
13
|
+
/** The resolved caller (issuer), as `index.ts` resolves it from the forwarded JWT. */
|
|
14
|
+
interface Issuer {
|
|
15
|
+
id: string;
|
|
16
|
+
permissions: PermissionEntry[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* What `issueKey` decided. A refusal with a `problem` was a malformed request (expiry, catalog), not a
|
|
20
|
+
* lack of authority: the admin path answers it with a 400 that names the problem, and the RPC still
|
|
21
|
+
* answers `not_allowed`, its only refusal reason.
|
|
22
|
+
*/
|
|
23
|
+
export interface IssueOutcome {
|
|
24
|
+
result: IssueKeyResult;
|
|
25
|
+
auditLabel?: string;
|
|
26
|
+
problem?: string;
|
|
27
|
+
}
|
|
28
|
+
/** The record of an issued key, given the ids the issuance generated; written in the key's own transaction. */
|
|
29
|
+
export type IssueRecord = (issued: {
|
|
30
|
+
credentialId: string;
|
|
31
|
+
principalId: string | undefined;
|
|
32
|
+
}) => AuditEventInput;
|
|
33
|
+
/**
|
|
34
|
+
* Delegation check (pure): every requested grant must be covered by the issuer's permissions on its
|
|
35
|
+
* scope, using the same `permits` matching as `can()`. Returns the first uncovered grant, or null.
|
|
36
|
+
*/
|
|
37
|
+
export declare function findUncoveredGrant(issuerPermissions: PermissionEntry[], grants: KeyGrant[]): KeyGrant | null;
|
|
38
|
+
/** Why `expiresAt` is not an acceptable key expiry at `now` (both unix seconds), or null when it is. */
|
|
39
|
+
export declare function keyExpiryProblem(expiresAt: number, now: number): string | null;
|
|
40
|
+
/**
|
|
41
|
+
* Issue an opaque `px_` credential.
|
|
42
|
+
*
|
|
43
|
+
* `app` is the issuer's VERIFIED app, and every credential this function writes is bound to it. That
|
|
44
|
+
* binding is what makes delegation mean anything: the grants below are checked against the issuer's
|
|
45
|
+
* permissions *for this app*, so a credential that could be spent at another one would convert
|
|
46
|
+
* app-scoped authority into installation-wide authority (SEC-2). For the same reason every granted
|
|
47
|
+
* action must be an exact action of that app's catalog, and every key must expire within
|
|
48
|
+
* `MAX_KEY_LIFETIME_SECONDS`.
|
|
49
|
+
*/
|
|
50
|
+
export declare function issueKey(services: Services, input: IssueKeyInput, issuer: Issuer, app: string, record?: IssueRecord): Promise<IssueOutcome>;
|
|
51
|
+
/**
|
|
52
|
+
* Revoke an opaque `px_` credential by id, for the caller's VERIFIED `app`. A credential bound to any
|
|
53
|
+
* other app — or to none, a cross-app key — is `not_found`, the same answer as an unknown id, so one
|
|
54
|
+
* app cannot probe or end another app's keys. Within the app, authorization mirrors the old capability
|
|
55
|
+
* revoke: the original issuer may always revoke; otherwise, for an ANONYMOUS credential (a share
|
|
56
|
+
* link), the caller must be able to re-issue its grants — hold every granted action, checked with the
|
|
57
|
+
* same `findUncoveredGrant` as issue. A principal-bound credential is managed through the principal
|
|
58
|
+
* path (the api-keys page), so a non-issuer caller cannot revoke it by id here. Idempotent — a second
|
|
59
|
+
* revoke returns `{ ok: true, revoked: false }`.
|
|
60
|
+
*/
|
|
61
|
+
export declare function revokeKey(services: Services, input: RevokeKeyInput, revoker: Issuer, app: string, record?: AuditEventInput): Promise<RevokeKeyResult>;
|
|
62
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** `JSON.parse` typed to return `unknown` (the built-in returns `any`). */
|
|
2
|
+
export declare function parseJson(text: string): unknown;
|
|
3
|
+
/**
|
|
4
|
+
* `parseJson` that yields `null` instead of throwing on malformed text.
|
|
5
|
+
*
|
|
6
|
+
* The JSON-bearing TEXT columns (`audit_events.diff`/`metadata`, `roles.permissions`,
|
|
7
|
+
* `grants.permissions`) used to carry a `CHECK (json_valid(...))`, which let read paths parse
|
|
8
|
+
* without a guard. That check is SQLite-only (Postgres has no equivalent inside the common
|
|
9
|
+
* subset), so it is gone from the migrations and the guarantee now lives at the two ends: the
|
|
10
|
+
* only writer JSON-encodes, and every reader goes through here. A hand-written or out-of-band
|
|
11
|
+
* row can therefore no longer 500 the admin API or break an authenticate().
|
|
12
|
+
*/
|
|
13
|
+
export declare function parseJsonOrNull(text: string): unknown;
|
|
14
|
+
/** Read a property off an unknown value (undefined when absent / not an object). */
|
|
15
|
+
export declare function prop(value: unknown, key: string): unknown;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ONE place IAM turns a caught value into a log line.
|
|
3
|
+
*
|
|
4
|
+
* The package invariant is that a secret, a key, or an error object that may quote a connection
|
|
5
|
+
* string never reaches a log. `console.error('…', err)` breaks it silently: a driver error carries
|
|
6
|
+
* the DSN it failed to connect with, and a fetch error carries the URL — which, on the mint path, is
|
|
7
|
+
* an IAM address with a shared secret in a header the runtime may attach to the message. Only the
|
|
8
|
+
* MESSAGE crosses this boundary, and only when it is a real `Error`; anything else is reported by
|
|
9
|
+
* shape alone. See SEC-8.
|
|
10
|
+
*/
|
|
11
|
+
export declare function logError(message: string, cause: unknown): void;
|
|
12
|
+
/** The same rule for a recoverable condition — a path that carried on after catching. */
|
|
13
|
+
export declare function logWarn(message: string, cause: unknown): void;
|
|
14
|
+
/** The safe half of a caught value: an `Error`'s own message, otherwise its type and nothing else. */
|
|
15
|
+
export declare function describeError(cause: unknown): string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IamMembershipRpc, IamTerminalRpc } from '@fabrika/auth-core';
|
|
2
|
+
import type { Services } from './services';
|
|
3
|
+
/** The path the surface is mounted under: `/membership/<method>`, one segment. */
|
|
4
|
+
export declare const MEMBERSHIP_TRANSPORT_PREFIX = "/membership/";
|
|
5
|
+
/** The operations an application requests on its caller's behalf, and the identifications at its terminals (ADR-0067). */
|
|
6
|
+
export type MembershipTransportRpc = Omit<IamMembershipRpc, 'requestDelegation'> & IamTerminalRpc;
|
|
7
|
+
/** Serve one membership call of an application. */
|
|
8
|
+
export declare function handleMembershipTransport(request: Request, services: Services, rpc: MembershipTransportRpc): Promise<Response>;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The membership operations of a multi-tenant application (ADR-0012 §6; ADR-0022
|
|
3
|
+
* rule 6): delegation grants, scope creation, membership, invitations and share links.
|
|
4
|
+
*
|
|
5
|
+
* Every operation resolves the caller from its own credential and evaluates it against the caller's LIVE
|
|
6
|
+
* permissions at the credential's verified app. The application names no actor and writes no grant: IAM
|
|
7
|
+
* generates every value, writes every grant and issues every key. Scopes stay flat — a value is checked as
|
|
8
|
+
* itself; only a share link names its containment chain, and the framework re-checks that chain per request.
|
|
9
|
+
*/
|
|
10
|
+
import { type AppMemberItem, type AssignMemberInput, type AssignMemberResult, type CreateScopeInput, type CreateScopeResult, type FindMemberInput, type FindMemberResult, type InvitationAcceptance, type IssueLinkInput, type IssueLinkResult, type ListAppMembersInput, type ListAppMembersResult, type ListMembersInput, type ListMembersResult, type RequestDelegationInput, type RequestDelegationResult, type RevokeLinkInput, type RevokeLinkResult, type RevokeMemberInput, type RevokeMemberResult } from '@fabrika/auth-core';
|
|
11
|
+
import { type AppMembersRow, type InvitationRow, type PrincipalRow } from './db';
|
|
12
|
+
import type { Env, RequestContext } from './env';
|
|
13
|
+
import type { StoredPasswordHash } from './password-crypto';
|
|
14
|
+
import type { Services } from './services';
|
|
15
|
+
/** How long an invitation may wait for its addressee. */
|
|
16
|
+
export declare const INVITATION_TTL_SECONDS: number;
|
|
17
|
+
/** The path of IAM's page that accepts an invitation; the one-time token rides in the fragment. */
|
|
18
|
+
export declare const INVITATION_ACCEPT_PATH = "/auth/invitations/accept";
|
|
19
|
+
type CallerEnv = Pick<Env, 'FABRIKA_IAM_SIGNING_KEYS' | 'FABRIKA_IAM_PROVISIONING_KEY' | 'ENVIRONMENT'>;
|
|
20
|
+
export declare function requestDelegation(services: Services, env: CallerEnv, ctx: RequestContext, input: RequestDelegationInput): Promise<RequestDelegationResult>;
|
|
21
|
+
/**
|
|
22
|
+
* A value of a top-level dimension. The caller holds the creating endpoint's action globally: a value it
|
|
23
|
+
* does not yet belong to cannot be the scope of its authority. A contained dimension's values are rows of
|
|
24
|
+
* the application, not values IAM creates.
|
|
25
|
+
*/
|
|
26
|
+
export declare function createScope(services: Services, env: CallerEnv, ctx: RequestContext, input: CreateScopeInput): Promise<CreateScopeResult>;
|
|
27
|
+
/**
|
|
28
|
+
* Assign a role, or invite an address to it. An address always becomes an invitation, also when a
|
|
29
|
+
* principal already holds it: only the mailbox's owner, proving it with the emailed link, may accept.
|
|
30
|
+
*/
|
|
31
|
+
export declare function assignMember(services: Services, env: CallerEnv, ctx: RequestContext, input: AssignMemberInput): Promise<AssignMemberResult>;
|
|
32
|
+
/**
|
|
33
|
+
* Remove membership roles, or cancel an invitation. Every role removed must be one the caller could
|
|
34
|
+
* assign, checked before anything is removed. The creator role goes first and only while another
|
|
35
|
+
* principal still holds it, so a value never loses its last creator.
|
|
36
|
+
*/
|
|
37
|
+
export declare function revokeMember(services: Services, env: CallerEnv, ctx: RequestContext, input: RevokeMemberInput): Promise<RevokeMemberResult>;
|
|
38
|
+
export declare function listMembers(services: Services, env: CallerEnv, ctx: RequestContext, input: ListMembersInput): Promise<ListMembersResult>;
|
|
39
|
+
/**
|
|
40
|
+
* One principal among the members of `scope`, for an endpoint on, in or below its dimension. IAM establishes the
|
|
41
|
+
* authority itself, from nothing the application asserts: `action` must be one of the dimension's `lookups` (the
|
|
42
|
+
* actions of the approved endpoints that read this directory, from the reconciled schema), and the caller must hold it
|
|
43
|
+
* on `scope` itself (global included). IAM holds no containment below a value, so a grant on a contained object does
|
|
44
|
+
* not count. The caller learns only whether the principal it named is a member, and its label where the directory
|
|
45
|
+
* shows labels; an unknown id answers the same `null` as a non-member.
|
|
46
|
+
*/
|
|
47
|
+
/**
|
|
48
|
+
* One page of the application's own people: every principal holding a role of it (`listAppMemberIds`). Needs the
|
|
49
|
+
* application's `members.list` held globally; labels where it declares `directory: 'labels'` or to its `members.manage`
|
|
50
|
+
* held globally, which alone sees addresses and last sign-ins.
|
|
51
|
+
*/
|
|
52
|
+
export declare function listAppMembers(services: Services, env: CallerEnv, _ctx: RequestContext, input: ListAppMembersInput): Promise<ListAppMembersResult>;
|
|
53
|
+
/**
|
|
54
|
+
* One page of the people of `app`, as a holder of its `members.list` sees them; `manager` adds labels, addresses and last
|
|
55
|
+
* sign-ins. `next` is the page's last id while another principal follows it, null on the last page.
|
|
56
|
+
*/
|
|
57
|
+
export declare function appMemberPage(services: Services, app: string, people: AppMembersRow, manager: boolean, after: string | null, limit: number): Promise<{
|
|
58
|
+
members: AppMemberItem[];
|
|
59
|
+
next: string | null;
|
|
60
|
+
}>;
|
|
61
|
+
export declare function findMember(services: Services, env: CallerEnv, ctx: RequestContext, input: FindMemberInput): Promise<FindMemberResult>;
|
|
62
|
+
export type AcceptInvitationOutcome = {
|
|
63
|
+
ok: true;
|
|
64
|
+
invitation: InvitationRow;
|
|
65
|
+
}
|
|
66
|
+
/** Unknown, used, cancelled or expired: one answer, so a page reveals nothing about a token. */
|
|
67
|
+
| {
|
|
68
|
+
ok: false;
|
|
69
|
+
reason: 'invalid';
|
|
70
|
+
}
|
|
71
|
+
/** The signed-in principal does not own the invited mailbox. */
|
|
72
|
+
| {
|
|
73
|
+
ok: false;
|
|
74
|
+
reason: 'wrong_principal';
|
|
75
|
+
}
|
|
76
|
+
/** The inviter could no longer give the role. */
|
|
77
|
+
| {
|
|
78
|
+
ok: false;
|
|
79
|
+
reason: 'not_allowed';
|
|
80
|
+
}
|
|
81
|
+
/** The signed-in principal is external and the role is not declared external (ADR-0051). */
|
|
82
|
+
| {
|
|
83
|
+
ok: false;
|
|
84
|
+
reason: 'not_eligible';
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Accept an invitation for a signed-in principal. The emailed one-time token proves control of the
|
|
88
|
+
* mailbox, and the principal must own that mailbox. The inviter's authority is checked again here,
|
|
89
|
+
* against its permissions now, and its assigning role once more inside the write that consumes the
|
|
90
|
+
* invitation, so an invitation outlives no revocation of the person who sent it.
|
|
91
|
+
*/
|
|
92
|
+
export declare function acceptInvitation(services: Services, principal: PrincipalRow, token: string, requestId: string): Promise<AcceptInvitationOutcome>;
|
|
93
|
+
/**
|
|
94
|
+
* What an invitation link offers the browser that submits it. `create`: the role is declared external, the
|
|
95
|
+
* installation enables password authentication and e-mail, no principal holds the invited mailbox, the organization
|
|
96
|
+
* does not name it (`organizationMailbox`), and the inviter could still give the role — so accepting creates the
|
|
97
|
+
* external principal with a password the person chooses (ADR-0020). `no_account`: no principal holds the mailbox and
|
|
98
|
+
* nothing here would create one, so its owner cannot accept until someone gives it an account. `sign_in`: every other
|
|
99
|
+
* open invitation, accepted by the mailbox's principal signed in here. Reading the offer changes nothing.
|
|
100
|
+
*/
|
|
101
|
+
export type InvitationOffer = {
|
|
102
|
+
readonly kind: 'invalid';
|
|
103
|
+
} | {
|
|
104
|
+
readonly kind: 'not_allowed';
|
|
105
|
+
} | {
|
|
106
|
+
readonly kind: 'sign_in';
|
|
107
|
+
readonly invitation: InvitationRow;
|
|
108
|
+
} | {
|
|
109
|
+
readonly kind: 'no_account';
|
|
110
|
+
readonly invitation: InvitationRow;
|
|
111
|
+
} | {
|
|
112
|
+
readonly kind: 'create';
|
|
113
|
+
readonly invitation: InvitationRow;
|
|
114
|
+
};
|
|
115
|
+
export declare function invitationOffer(services: Services, token: string): Promise<InvitationOffer>;
|
|
116
|
+
/**
|
|
117
|
+
* How the owner of an open invitation's mailbox accepts it now (`InvitationAcceptance`): the e-mail and the accept
|
|
118
|
+
* page say what this answers, and promise a password only when accepting creates the account. A mailbox no principal
|
|
119
|
+
* holds that single sign-on admits (`admitted`) may still get its principal there, so it is `sign_in`.
|
|
120
|
+
*/
|
|
121
|
+
export declare function invitationAcceptance(services: Services, invitation: InvitationRow): Promise<InvitationAcceptance>;
|
|
122
|
+
export type AcceptCreatingOutcome = {
|
|
123
|
+
ok: true;
|
|
124
|
+
invitation: InvitationRow;
|
|
125
|
+
principal: PrincipalRow;
|
|
126
|
+
} | {
|
|
127
|
+
ok: false;
|
|
128
|
+
reason: 'invalid' | 'not_allowed' | 'not_eligible';
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* The invitation creates no principal now: another acceptance or sign-in gave the mailbox one first, or the
|
|
132
|
+
* installation or the organization's addresses changed. Whoever holds the mailbox signs in and accepts.
|
|
133
|
+
*/
|
|
134
|
+
| {
|
|
135
|
+
ok: false;
|
|
136
|
+
reason: 'sign_in';
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Accept an `InvitationOffer` of kind `create` with the password the person chose (already checked by the password
|
|
140
|
+
* policy and hashed): the external principal, its password, the grant, the consumed invitation and their records in
|
|
141
|
+
* one transaction (`MembershipRepository.acceptAsNewPrincipal`). Everything the offer checked is checked again.
|
|
142
|
+
*/
|
|
143
|
+
export declare function acceptCreatingPrincipal(services: Services, invitation: InvitationRow, password: StoredPasswordHash, requestId: string): Promise<AcceptCreatingOutcome>;
|
|
144
|
+
/**
|
|
145
|
+
* Issue a share link: an anonymous `px_` key bound to the app, the mount and the whole chain, with the
|
|
146
|
+
* mount's grants frozen on the object. The caller holds the mount's `issuedBy` and every grant on some
|
|
147
|
+
* link of the chain — the delegation rule of every key IAM issues. A job issues only for the mount its
|
|
148
|
+
* declaration names, and holds those actions app-wide: it issues for any object of the mount's dimension.
|
|
149
|
+
*/
|
|
150
|
+
export declare function issueLink(services: Services, env: CallerEnv, ctx: RequestContext, input: IssueLinkInput): Promise<IssueLinkResult>;
|
|
151
|
+
/**
|
|
152
|
+
* Revoke a link: by its issuer, or by a holder of `members.manage` on a value of its chain. A job revokes only a link
|
|
153
|
+
* it issued, of the mount its declaration still names.
|
|
154
|
+
*/
|
|
155
|
+
export declare function revokeLink(services: Services, env: CallerEnv, ctx: RequestContext, input: RevokeLinkInput): Promise<RevokeLinkResult>;
|
|
156
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type MessageKind, type MessageValues, type RenderedMessage } from '@fabrika/auth-core';
|
|
2
|
+
import { type EmailMessage } from '@fabrika/email';
|
|
3
|
+
import { type AppPresentation } from './app-presentation';
|
|
4
|
+
import type { Services } from './services';
|
|
5
|
+
/** How long one send may take. IAM has no request-scoped signal that outlives `waitUntil`, so each send carries its own. */
|
|
6
|
+
export declare const EMAIL_SEND_DEADLINE_MS = 30000;
|
|
7
|
+
/**
|
|
8
|
+
* The template IAM renders a presentation's `kind` e-mail with: the application's own wording in the presentation's
|
|
9
|
+
* language when it declares one, else the catalog's (`iamMessageTemplate`, which `fabrika app dev`'s stand-in IAM
|
|
10
|
+
* renders with too).
|
|
11
|
+
*/
|
|
12
|
+
export declare function messageTemplateFor<K extends MessageKind>(services: Services, presentation: AppPresentation, kind: K): Promise<(values: MessageValues[K]) => RenderedMessage>;
|
|
13
|
+
/** One IAM e-mail: the template of its kind rendered from the closed values, to one mailbox. */
|
|
14
|
+
export declare function renderEmail<K extends MessageKind>(services: Services, input: {
|
|
15
|
+
readonly to: string;
|
|
16
|
+
readonly presentation: AppPresentation;
|
|
17
|
+
readonly kind: K;
|
|
18
|
+
readonly values: MessageValues[K];
|
|
19
|
+
readonly idempotencyKey: string;
|
|
20
|
+
}): Promise<EmailMessage>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type KeyGrant, type PermissionEntry } from '@fabrika/auth-core';
|
|
2
|
+
/**
|
|
3
|
+
* Intersect live permissions with a ceiling: an OAuth scope's grants, or a terminal's patterns for an application. The
|
|
4
|
+
* ceiling never adds anything: each result is the narrower action and the narrower scope of one held entry and one
|
|
5
|
+
* ceiling entry that overlap, so a held `*` under a ceiling `a.read` yields `a.read`.
|
|
6
|
+
*/
|
|
7
|
+
export declare function narrowPermissions(live: readonly PermissionEntry[], ceiling: readonly KeyGrant[]): PermissionEntry[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type BrowserIdentityRole = 'admin' | 'operations-notes';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { PostgresDatabase, type PostgresMigration, type PostgresMigrationPlan } from '@fabrika/platform-node';
|
|
2
|
+
export declare function postgresMigrations(dir?: string): PostgresMigration[];
|
|
3
|
+
export declare function postgresMigrationPlan(migrations?: readonly PostgresMigration[]): PostgresMigrationPlan;
|
|
4
|
+
export declare function applyMigrations(db: PostgresDatabase, migrations?: readonly PostgresMigration[]): Promise<string[]>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type EmailProviderRegistry, type EmailSender } from '@fabrika/email';
|
|
2
|
+
import type { Env, RequestContext } from '../env';
|
|
3
|
+
/** Config that exists ONLY off Workers — the process's own knobs, not part of the service's `Env`. */
|
|
4
|
+
export interface ProcessConfig {
|
|
5
|
+
/** TCP port to listen on. */
|
|
6
|
+
port: number;
|
|
7
|
+
/**
|
|
8
|
+
* Shared secret gating the HTTP MANAGEMENT surface (`/rpc/*`). EMPTY DISABLES IT — see
|
|
9
|
+
* `rpc-http.ts`. Never logged.
|
|
10
|
+
*/
|
|
11
|
+
rpcKey: string;
|
|
12
|
+
/**
|
|
13
|
+
* Shared secret gating the PROXY mint surface (`/auth/mint/*`), which the auth proxy calls on the
|
|
14
|
+
* cold path. Separate from `rpcKey` by least privilege — the proxy is the only publicly-routed
|
|
15
|
+
* component and needs only three IAM calls: `mintToken`, `mintFromKey`, and `exchangeAuthCode`
|
|
16
|
+
* (ADR-0022), which redeems a live handoff code for an app-bound session. That third one is a real
|
|
17
|
+
* capability rather than a read, and the split is still worth it: the code is single-use,
|
|
18
|
+
* hash-only, bound to `(session, app, return URL)` and dead in two minutes, whereas the management
|
|
19
|
+
* key would additionally let a compromised edge forge audit rows for any app. EMPTY DISABLES IT.
|
|
20
|
+
* Never logged.
|
|
21
|
+
*/
|
|
22
|
+
proxyKey: string;
|
|
23
|
+
/**
|
|
24
|
+
* The secret the platform proxy sends on IAM's route (`IAM_PROXY_SECRET_VARIABLE`), proving it wrote the client-address
|
|
25
|
+
* and request-id headers. EMPTY READS THOSE HEADERS UNPROVEN, as before the deploy that writes it. Never logged.
|
|
26
|
+
*/
|
|
27
|
+
proxySecret: string;
|
|
28
|
+
}
|
|
29
|
+
/** What a composition root hands the process besides `process.env` — never an environment variable. */
|
|
30
|
+
export interface RuntimeOverrides {
|
|
31
|
+
/** Replaces `FABRIKA_EMAIL_PROVIDER`'s sender, only with `ENVIRONMENT=local`: the local stack's mail capture. */
|
|
32
|
+
readonly emailSender?: EmailSender;
|
|
33
|
+
/** The providers `FABRIKA_EMAIL_PROVIDER` may name. Defaults to the built-in ones. */
|
|
34
|
+
readonly emailProviders?: EmailProviderRegistry;
|
|
35
|
+
}
|
|
36
|
+
export interface Runtime {
|
|
37
|
+
env: Env;
|
|
38
|
+
ctx: RequestContext;
|
|
39
|
+
config: ProcessConfig;
|
|
40
|
+
/** Wait for in-flight background work, then close the connection pool. */
|
|
41
|
+
shutdown(): Promise<void>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Read `process.env`, open the Postgres pool, mount the asset directory, and return the pair of
|
|
45
|
+
* handles every shared entrypoint function takes. Everything that can refuse the boot runs before the pool opens.
|
|
46
|
+
*
|
|
47
|
+
* Fails LOUDLY and early on missing required configuration: a service that boots half-configured and
|
|
48
|
+
* then refuses logins at 3am is strictly worse than one that never came up. Nothing here ever logs a
|
|
49
|
+
* value — the database URL and the RPC key are credentials, and only their absence is reportable.
|
|
50
|
+
*/
|
|
51
|
+
export declare function createRuntime(source?: Record<string, string | undefined>, overrides?: RuntimeOverrides): Promise<Runtime>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type Runtime } from './runtime';
|
|
2
|
+
/** Build the server's fetch handler for an assembled runtime. Exported so a test can drive it directly. */
|
|
3
|
+
export declare function createFetchHandler(runtime: Runtime): (request: Request) => Promise<Response>;
|
|
4
|
+
/** Serve an assembled runtime until SIGTERM or SIGINT. A composition root with its own overrides starts here. */
|
|
5
|
+
export declare function startIamServer(runtime: Runtime): void;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { OAuthClientCredential } from '@fabrika/iam-contract';
|
|
2
|
+
import type { EstablishedClient } from './oauth';
|
|
3
|
+
import type { OAuthConfig } from './oauth-config';
|
|
4
|
+
import type { Services } from './services';
|
|
5
|
+
/**
|
|
6
|
+
* Authenticate the client of a token or revocation request (RFC 6749 §2.3). The method is the one the
|
|
7
|
+
* client's own metadata document declares, never the one the request picks: a `private_key_jwt` client
|
|
8
|
+
* that sends no assertion is refused, and a public client that sends one is refused too.
|
|
9
|
+
* `audiences` are the values an assertion's `aud` may name.
|
|
10
|
+
*/
|
|
11
|
+
export declare function authenticateOAuthClient(services: Services, config: OAuthConfig, input: {
|
|
12
|
+
clientId: string;
|
|
13
|
+
credential: OAuthClientCredential;
|
|
14
|
+
audiences: string[];
|
|
15
|
+
}): Promise<EstablishedClient | null>;
|
|
16
|
+
/**
|
|
17
|
+
* Whether a revocation request comes from its client (RFC 7009 §2.1). A confidential client authenticates as at the
|
|
18
|
+
* token endpoint. A request without an assertion only names a registered client: the token's own client binding is
|
|
19
|
+
* enough for a public client, so an unreachable metadata document never keeps a token alive. It is refused only when
|
|
20
|
+
* the document is known and declares `private_key_jwt`.
|
|
21
|
+
*/
|
|
22
|
+
export declare function authenticateRevokingClient(services: Services, config: OAuthConfig, input: {
|
|
23
|
+
clientId: string;
|
|
24
|
+
credential: OAuthClientCredential;
|
|
25
|
+
audiences: string[];
|
|
26
|
+
}): Promise<boolean>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type OAuthClientMetadataDocument } from '@fabrika/iam-contract';
|
|
2
|
+
import type { JSONWebKeySet } from 'jose';
|
|
3
|
+
import type { ManagedOAuthClient } from './oauth-config';
|
|
4
|
+
/**
|
|
5
|
+
* The Client ID Metadata Document of an operator-registered client. Callers resolve the registration
|
|
6
|
+
* first, so an unregistered client id never causes a fetch. The key is the whole registration, so a
|
|
7
|
+
* config change is never answered from the old document.
|
|
8
|
+
*/
|
|
9
|
+
export declare function clientMetadata(registration: ManagedOAuthClient): Promise<OAuthClientMetadataDocument | null>;
|
|
10
|
+
/**
|
|
11
|
+
* The public keys at a client's `jwks_uri`, which its parsed metadata document already confined to the
|
|
12
|
+
* client id's origin. `refetch` asks for a fresh copy (an assertion named an unknown `kid`); it is
|
|
13
|
+
* honoured once per `JWKS_REFETCH_INTERVAL_MS`, so assertions cannot drive fetches.
|
|
14
|
+
*/
|
|
15
|
+
export declare function clientJwks(jwksUri: string, options: {
|
|
16
|
+
refetch: boolean;
|
|
17
|
+
}): Promise<JSONWebKeySet | null>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type OAuthManagedClient, type OAuthResourceDto } from '@fabrika/iam-contract';
|
|
2
|
+
/** An operator-registered MCP client: its CIMD identity plus where IAM fetches that document. */
|
|
3
|
+
export interface ManagedOAuthClient extends OAuthManagedClient {
|
|
4
|
+
metadataUrl: string;
|
|
5
|
+
}
|
|
6
|
+
/** `OAUTH_CONFIG`, parsed once. `null` from `parseOAuthConfig` means OAuth is off. */
|
|
7
|
+
export interface OAuthConfig {
|
|
8
|
+
clients: ManagedOAuthClient[];
|
|
9
|
+
resources: OAuthResourceDto[];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Parse `OAUTH_CONFIG`. Absent or empty disables OAuth; anything malformed THROWS, so a typo fails the
|
|
13
|
+
* boot instead of quietly serving fewer clients or scopes than the operator wrote. Unknown keys are
|
|
14
|
+
* refused for the same reason.
|
|
15
|
+
*/
|
|
16
|
+
export declare function parseOAuthConfig(raw: string | undefined): OAuthConfig | null;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Env } from './env';
|
|
2
|
+
import type { Services } from './services';
|
|
3
|
+
export declare const OAUTH_METADATA_PATH = "/.well-known/oauth-authorization-server";
|
|
4
|
+
type SigningEnv = Pick<Env, 'FABRIKA_IAM_SIGNING_KEYS' | 'ENVIRONMENT'>;
|
|
5
|
+
/** The OAuth authorization server's public surface. With `OAUTH_CONFIG` unset every path is 404. */
|
|
6
|
+
export declare function handleOAuth(request: Request, services: Services, env: SigningEnv, requestId: string): Promise<Response>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type KeyGrant, type PermissionEntry } from '@fabrika/auth-core';
|
|
2
|
+
import type { OAuthAuthorizationRequest, OAuthClientMetadataDocument, OAuthResourceDto, OAuthRevocationRequest, OAuthTokenRequest, OAuthTokenResponse } from '@fabrika/iam-contract';
|
|
3
|
+
import { type OAuthGrantRow, type PrincipalRow, type SessionRow } from './db';
|
|
4
|
+
import type { Env } from './env';
|
|
5
|
+
import type { ManagedOAuthClient, OAuthConfig } from './oauth-config';
|
|
6
|
+
import type { Services } from './services';
|
|
7
|
+
/** An authorization code is redeemed by the client's back end within seconds of the redirect. */
|
|
8
|
+
export declare const OAUTH_CODE_TTL_SECONDS = 60;
|
|
9
|
+
type SigningEnv = Pick<Env, 'FABRIKA_IAM_SIGNING_KEYS' | 'ENVIRONMENT'>;
|
|
10
|
+
export interface EstablishedClient {
|
|
11
|
+
registration: ManagedOAuthClient;
|
|
12
|
+
metadata: OAuthClientMetadataDocument;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Resolve a client and its redirect URI. Until this succeeds nothing may be redirected to
|
|
16
|
+
* `redirect_uri`. An unregistered client id is refused before any metadata fetch.
|
|
17
|
+
*/
|
|
18
|
+
export declare function establishClient(config: OAuthConfig, clientId: string, redirectUri: string): Promise<EstablishedClient | null>;
|
|
19
|
+
/** Record the consent and return the plaintext authorization code — the only time it exists. */
|
|
20
|
+
export declare function grantAuthorization(services: Services, input: {
|
|
21
|
+
request: OAuthAuthorizationRequest;
|
|
22
|
+
resource: OAuthResourceDto;
|
|
23
|
+
scopes: string[];
|
|
24
|
+
session: SessionRow;
|
|
25
|
+
requestId: string;
|
|
26
|
+
}): Promise<string>;
|
|
27
|
+
export type OAuthTokenOutcome = {
|
|
28
|
+
ok: true;
|
|
29
|
+
body: OAuthTokenResponse;
|
|
30
|
+
} | {
|
|
31
|
+
ok: false;
|
|
32
|
+
error: 'invalid_grant';
|
|
33
|
+
};
|
|
34
|
+
/** Redeem a code or rotate a refresh token for a client `authenticateOAuthClient` established. */
|
|
35
|
+
export declare function exchangeOAuthToken(services: Services, env: SigningEnv, client: EstablishedClient, input: OAuthTokenRequest, requestId: string): Promise<OAuthTokenOutcome>;
|
|
36
|
+
/** RFC 7009: revoking either token kind revokes its grant. An unknown or foreign token is a silent no-op. */
|
|
37
|
+
export declare function revokeOAuthToken(services: Services, env: SigningEnv, input: OAuthRevocationRequest, requestId: string): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Everything a grant needs to still mean something, checked at every code exchange and refresh: the
|
|
40
|
+
* grant live, its client and resource still configured, the IAM session it was given under live and
|
|
41
|
+
* usable, the principal an active user. The permissions are resolved live, never from the consent.
|
|
42
|
+
*/
|
|
43
|
+
export declare function grantAuthority(services: Services, grant: OAuthGrantRow, now: number): Promise<{
|
|
44
|
+
principal: PrincipalRow;
|
|
45
|
+
scopes: string[];
|
|
46
|
+
permissions: PermissionEntry[];
|
|
47
|
+
expiresAt: number | null;
|
|
48
|
+
} | null>;
|
|
49
|
+
/** The union of the scopes' grants, or null when a scope is no longer configured. */
|
|
50
|
+
export declare function scopeCeiling(resource: OAuthResourceDto, scopes: readonly string[]): KeyGrant[] | null;
|
|
51
|
+
export {};
|