@fabrika/iam 0.0.0-stage → 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 +70 -5
- 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,86 @@
|
|
|
1
|
+
import { type Locale } from '@fabrika/auth-core';
|
|
2
|
+
import type { InstallationBrand } from '@fabrika/proxy-core/brand';
|
|
3
|
+
import type { AppPresentationRow } from './repositories/app-schema';
|
|
4
|
+
import type { Services } from './services';
|
|
5
|
+
/**
|
|
6
|
+
* The application a page or an e-mail is for, as IAM names it: the language, the display name, and where a completed
|
|
7
|
+
* action lands. `app: null` is IAM's own page, in the reader's language else the installation's.
|
|
8
|
+
*/
|
|
9
|
+
export interface AppPresentation {
|
|
10
|
+
readonly app: string | null;
|
|
11
|
+
/** The language of the page or the mail (`chooseLocale`). */
|
|
12
|
+
readonly locale: Locale;
|
|
13
|
+
/**
|
|
14
|
+
* The reader's own language when this page or mail knows one: stored for the flow, or named by its link. The links
|
|
15
|
+
* and forms it builds carry it (`appQuery`), so the next page keeps it; null when the words follow the application.
|
|
16
|
+
*/
|
|
17
|
+
readonly personLocale: Locale | null;
|
|
18
|
+
readonly displayName: string | null;
|
|
19
|
+
/** The app's first registered return origin (Control registers one, its public origin), or null for none. */
|
|
20
|
+
readonly landing: string | null;
|
|
21
|
+
/**
|
|
22
|
+
* The installation's client logo, which every page draws in place of the fabrika mark, or null for the mark. It is
|
|
23
|
+
* the installation's and not the application's; it rides here because every page already takes its presentation.
|
|
24
|
+
* An e-mail does not show it.
|
|
25
|
+
*/
|
|
26
|
+
readonly brand: InstallationBrand | null;
|
|
27
|
+
}
|
|
28
|
+
/** The installation's words with no logo, for an e-mail. A page takes `installationPresentation`, which reads the brand. */
|
|
29
|
+
export declare const INSTALLATION_PRESENTATION: AppPresentation;
|
|
30
|
+
/**
|
|
31
|
+
* Who reads a page or a mail, beside the application it is for. `request` is the page's own: its `?locale=`, the
|
|
32
|
+
* remembered language and its `Accept-Language` pick words; a mail has none. `locale` is the person's own language as
|
|
33
|
+
* IAM stored it for this flow (an invitation's, a password action's, a principal's), which beats every other source.
|
|
34
|
+
*/
|
|
35
|
+
export interface Reader {
|
|
36
|
+
readonly request?: Request | null;
|
|
37
|
+
readonly locale?: string | null;
|
|
38
|
+
/**
|
|
39
|
+
* The brand a caller already holds, a request's earlier presentation's or `null` for an e-mail, which shows none;
|
|
40
|
+
* given, the brand is not read again.
|
|
41
|
+
*/
|
|
42
|
+
readonly brand?: InstallationBrand | null;
|
|
43
|
+
}
|
|
44
|
+
/** The presentation of IAM's own page, in the reader's language (else the installation's) and with its logo. */
|
|
45
|
+
export declare function installationPresentation(services: Services, reader: Reader): Promise<AppPresentation>;
|
|
46
|
+
/**
|
|
47
|
+
* The presentation of `app`, which is a hint from a query or a form, or a stored row's app. It names an application only
|
|
48
|
+
* when IAM knows one by that id — a reconciled locale or display name, or a registered return origin — and is the
|
|
49
|
+
* installation's otherwise. It decides words and the landing, never authority: the landing is a registered origin, so a
|
|
50
|
+
* forged `app` can only pick another registered application's language and address. The language is the reader's
|
|
51
|
+
* where one is known, else the application's (`chooseLocale`).
|
|
52
|
+
*/
|
|
53
|
+
export declare function presentationFor(services: Services, app: string | null, reader: Reader): Promise<AppPresentation>;
|
|
54
|
+
/** `presentation` in the person's own `locale`, when there is one; unchanged for none. */
|
|
55
|
+
export declare function withPersonLocale(presentation: AppPresentation, locale: Locale | null): AppPresentation;
|
|
56
|
+
/** A stored row read back: a locale IAM no longer speaks, or a name the rule refuses, counts as not declared. */
|
|
57
|
+
export declare function parsePresentation(row: AppPresentationRow | null): {
|
|
58
|
+
locale: Locale | null;
|
|
59
|
+
displayName: string | null;
|
|
60
|
+
};
|
|
61
|
+
/** The URL a completed action sends the browser to inside the app, or null when the app has no registered origin. */
|
|
62
|
+
export declare function landingUrl(presentation: AppPresentation): string | null;
|
|
63
|
+
/** The installation's console: the registered origin of the first admin audience that has one, or null for none. */
|
|
64
|
+
export declare function installationConsole(services: Services): Promise<string | null>;
|
|
65
|
+
/**
|
|
66
|
+
* Where a browser lands when nothing names its destination — a sign-in, a sign-out or a completed action of no
|
|
67
|
+
* application: the installation's console, whose proxy then signs the browser in through the normal handoff. IAM's
|
|
68
|
+
* own origin serves no page at `/`, and on Zerops the proxy answers it with 403. Without a registered console it is
|
|
69
|
+
* IAM's sign-in page.
|
|
70
|
+
*/
|
|
71
|
+
export declare function installationLanding(services: Services): Promise<string>;
|
|
72
|
+
/**
|
|
73
|
+
* The origin off IAM where a completed action of `presentation` lands, which its page's `form-action` must admit:
|
|
74
|
+
* the application's own, else the console. Null when it lands on IAM's own sign-in page.
|
|
75
|
+
*/
|
|
76
|
+
export declare function actionLandingOrigin(services: Services, presentation: AppPresentation): Promise<string | null>;
|
|
77
|
+
/**
|
|
78
|
+
* The query a link or a form carries so the next page speaks for the same application and in the same person's
|
|
79
|
+
* language: `?app=` and, where the reader's own language is known, `locale=`. Empty for neither.
|
|
80
|
+
*/
|
|
81
|
+
export declare function appQuery(presentation: AppPresentation): string;
|
|
82
|
+
/**
|
|
83
|
+
* The query that carries only the reader's own language (`?locale=`), for a link or a form to a page whose application
|
|
84
|
+
* travels elsewhere: IAM's sign-in, whose `?app=` names a handoff. Empty when the words follow the application.
|
|
85
|
+
*/
|
|
86
|
+
export declare function localeQuery(presentation: AppPresentation): string;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { AuthContext, FetchService, RequestExecutionContext } from '@fabrika/app';
|
|
2
|
+
import type { ResolvedAdmin } from './admin/router';
|
|
3
|
+
import type { Env } from './env';
|
|
4
|
+
import { type IamServiceOptions } from './service';
|
|
5
|
+
import { type Services } from './services';
|
|
6
|
+
export interface IamAppContext {
|
|
7
|
+
readonly env: Env;
|
|
8
|
+
readonly request: Request;
|
|
9
|
+
readonly exec: RequestExecutionContext;
|
|
10
|
+
readonly services: Services;
|
|
11
|
+
readonly requestId: string;
|
|
12
|
+
/** What this composition's ingress says the client is, or `null` when it cannot see one. */
|
|
13
|
+
readonly clientAddress: string | null;
|
|
14
|
+
auth: AuthContext;
|
|
15
|
+
admin: ResolvedAdmin | null;
|
|
16
|
+
}
|
|
17
|
+
export interface IamAppOptions {
|
|
18
|
+
/** Shared secret for the process-only management transport. Empty disables the surface. */
|
|
19
|
+
readonly rpcKey?: string;
|
|
20
|
+
/** Shared secret for the process-only proxy mint transport. Empty disables the surface. */
|
|
21
|
+
readonly proxyKey?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Mount the membership transport (`src/membership-http.ts`) for applications that have no IAM service binding. Each
|
|
24
|
+
* call is authenticated by its application's own key, not by a composition secret.
|
|
25
|
+
*/
|
|
26
|
+
readonly membershipTransport?: boolean;
|
|
27
|
+
/** Process liveness is mounted explicitly because the public Worker does not expose it. */
|
|
28
|
+
readonly health?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* The ONE header this composition's ingress overwrites with the observed client address. Omitted
|
|
31
|
+
* means this installation cannot see its clients and keeps only the account and deployment-wide
|
|
32
|
+
* buckets — never a guess. See `src/client-address.ts`.
|
|
33
|
+
*/
|
|
34
|
+
readonly clientAddressHeader?: string;
|
|
35
|
+
/**
|
|
36
|
+
* The ONE header this composition's ingress overwrites with its own correlation id. Omitted means
|
|
37
|
+
* every request gets a generated id. See `src/request-id.ts`.
|
|
38
|
+
*/
|
|
39
|
+
readonly requestIdHeader?: string;
|
|
40
|
+
/**
|
|
41
|
+
* The secret the proxy sends in `PROXY_SECRET_HEADER` to prove it wrote the two headers above. Set, a request without
|
|
42
|
+
* it keys on `UNPROVEN_CLIENT_ADDRESS` and gets a generated id; omitted or empty, the headers are read as they arrive.
|
|
43
|
+
* See `src/proxy-proof.ts`.
|
|
44
|
+
*/
|
|
45
|
+
readonly proxySecret?: string;
|
|
46
|
+
}
|
|
47
|
+
/** The service contract this composition serves: a switched-off transport has no row (`IamServiceOptions`). */
|
|
48
|
+
export declare function iamServiceOptions(options: IamAppOptions): IamServiceOptions;
|
|
49
|
+
/**
|
|
50
|
+
* Build IAM as a runtime-neutral service: `serveService` over IAM's service contract, which is also what the
|
|
51
|
+
* platform proxy decides from on Zerops. Every row authenticates itself.
|
|
52
|
+
*
|
|
53
|
+
* The native Cloudflare service-binding RPC remains on the WorkerEntrypoint. The optional HTTP
|
|
54
|
+
* transports are mounted by the Bun composition because their shared-secret boundary is process-only.
|
|
55
|
+
*/
|
|
56
|
+
export declare function createIamApp(options?: IamAppOptions): FetchService<Env>;
|
|
57
|
+
/**
|
|
58
|
+
* The bare application, with no composition options at all — routing only. Neither entrypoint serves
|
|
59
|
+
* it: `src/index.ts` and `src/node/server.ts` each build their own, because each has to name the one
|
|
60
|
+
* headers its own ingress guarantees (see `IamAppOptions.clientAddressHeader` and `requestIdHeader`).
|
|
61
|
+
*/
|
|
62
|
+
export declare const iamApp: FetchService<Env>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cookie (de)serialization for the auth flow. Minimal — only what login/callback/logout need:
|
|
3
|
+
* a `Set-Cookie` builder and a single-cookie reader off the `Cookie` header.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* There is deliberately **no `domain` option**. Every cookie this service writes is host-only: the
|
|
7
|
+
* login cookie belongs to IAM's host and an app's session is written on the app's own host by its
|
|
8
|
+
* proxy ([ADR-0023](../../../../docs/decisions/0023-one-session-per-host.md)). `SESSION_COOKIE` also
|
|
9
|
+
* carries the `__Host-` prefix, which makes a browser refuse any cookie of that name that names a
|
|
10
|
+
* `Domain` — so the option could not do anything but break the cookie it was applied to.
|
|
11
|
+
*/
|
|
12
|
+
export interface CookieOptions {
|
|
13
|
+
/** Lifetime in seconds. Omit for a session cookie; 0 to expire immediately. */
|
|
14
|
+
maxAge?: number;
|
|
15
|
+
httpOnly?: boolean;
|
|
16
|
+
secure?: boolean;
|
|
17
|
+
sameSite?: 'Lax' | 'Strict' | 'None';
|
|
18
|
+
path?: string;
|
|
19
|
+
}
|
|
20
|
+
/** Build a `Set-Cookie` value. */
|
|
21
|
+
export declare function serializeCookie(name: string, value: string, opts?: CookieOptions): string;
|
|
22
|
+
/**
|
|
23
|
+
* A `Set-Cookie` that immediately expires `name` (logout / one-shot cookie cleanup). `Secure` is
|
|
24
|
+
* unconditional for the same reason it is on the way in: a deletion must satisfy the same attribute
|
|
25
|
+
* rules as the cookie it replaces, or the browser keeps the original.
|
|
26
|
+
*/
|
|
27
|
+
export declare function clearCookie(name: string, opts?: Pick<CookieOptions, 'path'>): string;
|
|
28
|
+
/** Read a single cookie value out of a raw `Cookie` header. Returns null when absent. */
|
|
29
|
+
export declare function readCookie(header: string | null, name: string): string | null;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Why a browser-facing auth request is refused. The page words it in the request's language; a refusal of a handoff
|
|
3
|
+
* names the address it refused, because that is what an operator can act on.
|
|
4
|
+
*/
|
|
5
|
+
export type AuthFailure = {
|
|
6
|
+
readonly kind: 'no_return_address';
|
|
7
|
+
} | {
|
|
8
|
+
readonly kind: 'no_handoff_proof';
|
|
9
|
+
} | {
|
|
10
|
+
readonly kind: 'unregistered_origin';
|
|
11
|
+
readonly origin: string;
|
|
12
|
+
} | {
|
|
13
|
+
readonly kind: 'password_disabled';
|
|
14
|
+
} | {
|
|
15
|
+
readonly kind: 'oidc_disabled';
|
|
16
|
+
} | {
|
|
17
|
+
readonly kind: 'cross_origin';
|
|
18
|
+
} | {
|
|
19
|
+
readonly kind: 'malformed_form';
|
|
20
|
+
} | {
|
|
21
|
+
readonly kind: 'login_unavailable';
|
|
22
|
+
} | {
|
|
23
|
+
readonly kind: 'logout_unavailable';
|
|
24
|
+
} | {
|
|
25
|
+
readonly kind: 'oidc_invalid_state';
|
|
26
|
+
} | {
|
|
27
|
+
readonly kind: 'oidc_exchange_failed';
|
|
28
|
+
} | {
|
|
29
|
+
readonly kind: 'oidc_invalid_id_token';
|
|
30
|
+
} | {
|
|
31
|
+
readonly kind: 'not_admitted';
|
|
32
|
+
}
|
|
33
|
+
/** The browser holds no login of a principal that may enrol a terminal. */
|
|
34
|
+
| {
|
|
35
|
+
readonly kind: 'terminal_enrolment_not_allowed';
|
|
36
|
+
} | {
|
|
37
|
+
readonly kind: 'terminal_enrolment_unavailable';
|
|
38
|
+
}
|
|
39
|
+
/** A terminal identification completed by another browser, twice, too late, or after its login ended. */
|
|
40
|
+
| {
|
|
41
|
+
readonly kind: 'terminal_completion_refused';
|
|
42
|
+
}
|
|
43
|
+
/** A refusal of the principal resolution; `reason` is its fixed code, never what the caller sent. */
|
|
44
|
+
| {
|
|
45
|
+
readonly kind: 'login_refused';
|
|
46
|
+
readonly reason: string;
|
|
47
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { type Services } from '../services';
|
|
2
|
+
import type { AuthFailure } from './failure';
|
|
3
|
+
/**
|
|
4
|
+
* A session handoff in flight ([ADR-0023](../../../../docs/decisions/0023-one-session-per-host.md)):
|
|
5
|
+
* which app the browser came from and where it goes back to. `null` means a login that started on
|
|
6
|
+
* IAM's own host and stays there.
|
|
7
|
+
*/
|
|
8
|
+
export interface Handoff {
|
|
9
|
+
app: string;
|
|
10
|
+
returnUrl: string;
|
|
11
|
+
state: string;
|
|
12
|
+
challenge: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* What `?app=` + `?redirect=` turned out to be. `none` is a login with no app at all; `refused`
|
|
16
|
+
* carries the failure of a hard 400.
|
|
17
|
+
*/
|
|
18
|
+
type HandoffReading = {
|
|
19
|
+
kind: 'none';
|
|
20
|
+
} | {
|
|
21
|
+
kind: 'handoff';
|
|
22
|
+
handoff: Handoff;
|
|
23
|
+
} | {
|
|
24
|
+
kind: 'refused';
|
|
25
|
+
failure: AuthFailure;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Read `?app=` + `?redirect=` as a handoff, validating the return URL against what that app has
|
|
29
|
+
* registered.
|
|
30
|
+
*
|
|
31
|
+
* **Two outcomes once an app is named**: the registry contains the return address and the browser
|
|
32
|
+
* gets a code, or it does not and this is a `400` that names the address. There is no third path —
|
|
33
|
+
* ADR-0023 retired the shared session cookie, so a handoff is the ONLY way a session reaches an app's
|
|
34
|
+
* host and an app whose registry does not cover its own origin cannot log anyone in. Answering that
|
|
35
|
+
* with a fallback would produce a login that succeeds and lands somewhere the browser has no session,
|
|
36
|
+
* i.e. a loop with nothing logged anywhere; answering with the address is what an operator can act on.
|
|
37
|
+
*
|
|
38
|
+
* `none` survives only for a login with no `?app=` at all — someone opening IAM's own login page.
|
|
39
|
+
*/
|
|
40
|
+
export declare function readHandoff(services: Services, app: string | null, redirect: string | null, state: string | null, challenge: string | null): Promise<HandoffReading>;
|
|
41
|
+
/** The handoff a reading carries, or null — after the caller has already answered a `refused`. */
|
|
42
|
+
export declare function handoffOf(reading: HandoffReading): Handoff | null;
|
|
43
|
+
/**
|
|
44
|
+
* What a login page or an OIDC flight should carry as its return address: the handoff's validated
|
|
45
|
+
* destination when there is one, otherwise an address on IAM's own origin (`safeRedirect`), or null
|
|
46
|
+
* for none, which `issueSession` answers with the installation's landing.
|
|
47
|
+
*/
|
|
48
|
+
export declare function handoffRedirectOr(handoff: Handoff | null, raw: string | null, services: Services): string | null;
|
|
49
|
+
/**
|
|
50
|
+
* What the login page needs to know about where its submission lands: a handoff's app id and proof,
|
|
51
|
+
* which it carries in hidden fields, and the origin off IAM its `form-action` must admit — the
|
|
52
|
+
* handoff's destination, or the console for a login with no return address. Both origins are
|
|
53
|
+
* REGISTERED ones: the handoff's is taken from the return URL `readHandoff` resolved, so it is the
|
|
54
|
+
* same value the 302 will use and never a caller's spelling.
|
|
55
|
+
*/
|
|
56
|
+
export declare function loginDestinationFields(services: Services, handoff: Handoff | null, redirect: string | null): Promise<{
|
|
57
|
+
app?: string;
|
|
58
|
+
redirectOrigin?: string;
|
|
59
|
+
handoffState?: string;
|
|
60
|
+
handoffChallenge?: string;
|
|
61
|
+
}>;
|
|
62
|
+
/** Issue the code and build the URL of the app's own callback. */
|
|
63
|
+
export declare function handoffLocation(services: Services, handoff: Handoff, parentSessionId: string): Promise<string>;
|
|
64
|
+
/** IAM's own sign-in page for the same handoff, which signs a browser in afresh and then continues it. */
|
|
65
|
+
export declare function handoffLoginUrl(services: Services, handoff: Handoff): string;
|
|
66
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type Config } from '../services';
|
|
2
|
+
/**
|
|
3
|
+
* Open-redirect guard for a `?redirect=` that stays on IAM: accept only an absolute URL on IAM's OWN
|
|
4
|
+
* origin, and answer null for anything else, which the caller sends to the installation's landing
|
|
5
|
+
* (`installationLanding`). Prevents `/auth/login?redirect=https://evil.example` from bouncing a
|
|
6
|
+
* logged-in user out.
|
|
7
|
+
*
|
|
8
|
+
* It used to also admit the configured session-cookie domain and, locally, any `*.localhost` — the
|
|
9
|
+
* allowlist for the shared cookie's reach. ADR-0023 retired that cookie, so **the return-origin
|
|
10
|
+
* registry is now the only authority on sending a browser to another host**, and it is consulted by
|
|
11
|
+
* `readHandoff` before this function is ever reached. Widening this back would be a second, weaker
|
|
12
|
+
* answer to the same question.
|
|
13
|
+
*
|
|
14
|
+
* The comparison is the whole origin, not the hostname: the issuer already fixes the scheme and port,
|
|
15
|
+
* so there is nothing left for a special case to decide.
|
|
16
|
+
*/
|
|
17
|
+
export declare function safeRedirect(raw: string | null, config: Config): string | null;
|
|
18
|
+
export declare function sameOrigin(request: Request, config: Config): boolean;
|
|
19
|
+
export declare function readForm(request: Request): Promise<URLSearchParams | null>;
|
|
20
|
+
export declare function stringValue(value: string | null): string | null;
|
|
21
|
+
export declare function methodNotAllowed(): Response;
|
|
22
|
+
/**
|
|
23
|
+
* Headers for a 302 out of this surface. `no-store` belongs on every one of them, not just the
|
|
24
|
+
* password pages: these are the responses that carry the 30-day session cookie and, on the handoff
|
|
25
|
+
* path, the single-use code in the `Location` itself.
|
|
26
|
+
*/
|
|
27
|
+
export declare function redirectHeaders(location: string): Headers;
|
|
28
|
+
/** Keep an untrusted value fit for an error page: printable ASCII, bounded. */
|
|
29
|
+
export declare function printable(value: string): string;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type RequestContext } from '../env';
|
|
2
|
+
import type { Services } from '../services';
|
|
3
|
+
/**
|
|
4
|
+
* `GET|POST /auth/invitations/accept`. The emailed link opens the GET page; its fragment carries the
|
|
5
|
+
* one-time token, which never reaches a server log. Accepting is a POST from that page, same-origin
|
|
6
|
+
* only, by the principal signed in HERE, on IAM's host — the mailbox's owner, proven by the token.
|
|
7
|
+
*
|
|
8
|
+
* An invitation that creates its principal (`invitationOffer`) answers that POST with a set-password form instead;
|
|
9
|
+
* its POST, with the password, creates the external principal and accepts in one transaction, then signs the browser
|
|
10
|
+
* in on IAM. Neither the GET nor the POST without a password changes anything, so a mail scanner spends nothing. A
|
|
11
|
+
* browser signed in here as anyone gets neither: it is told to sign out or use another browser profile first. An
|
|
12
|
+
* invitation whose mailbox no principal holds and whose acceptance creates none (`no_account`, a role not declared
|
|
13
|
+
* external among them) answers that the address has no account here instead of a sign-in it could not pass.
|
|
14
|
+
*
|
|
15
|
+
* The link's `?app=` picks the page's language; an accepted invitation lands on its own application's
|
|
16
|
+
* registered origin, where the application's proxy signs the browser in through the normal handoff.
|
|
17
|
+
*/
|
|
18
|
+
export declare function handleInvitation(request: Request, services: Services, ctx: RequestContext, requestId: string): Promise<Response>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AuthEnv } from './oidc-flight';
|
|
2
|
+
export declare const KNOWN_DEVICE_COOKIE = "__Host-fabrika_device";
|
|
3
|
+
/** Three session lifetimes: a regular user keeps the exemption across renewals, a lost browser drops out within a quarter. */
|
|
4
|
+
export declare const KNOWN_DEVICE_TTL_SECONDS: number;
|
|
5
|
+
export interface KnownDevice {
|
|
6
|
+
principalId: string;
|
|
7
|
+
deviceId: string;
|
|
8
|
+
}
|
|
9
|
+
/** A `Set-Cookie` naming a fresh device id for `principalId`. */
|
|
10
|
+
export declare function knownDeviceCookie(env: AuthEnv, principalId: string): Promise<string>;
|
|
11
|
+
/** The device the request's cookie proves, or null when it is absent, forged, expired or malformed. */
|
|
12
|
+
export declare function readKnownDevice(env: AuthEnv, request: Request): Promise<KnownDevice | null>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type RequestContext } from '../env';
|
|
2
|
+
import { type Services } from '../services';
|
|
3
|
+
import { type AuthEnv } from './oidc-flight';
|
|
4
|
+
export declare function handleLogin(request: Request, services: Services, env: AuthEnv, ctx: RequestContext, requestId: string): Promise<Response>;
|
|
5
|
+
/**
|
|
6
|
+
* The answer to `chooseAccountPage`. Same-origin only, and it reads the handoff and the login again. `continue` hands off
|
|
7
|
+
* from the login the browser holds now; `another` ends that login like a sign-out and returns to the sign-in page of the
|
|
8
|
+
* same handoff, whose verifier the app's proxy still holds.
|
|
9
|
+
*/
|
|
10
|
+
export declare function handleAccountChoice(request: Request, services: Services, requestId: string): Promise<Response>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { AppPresentation } from '../app-presentation';
|
|
2
|
+
import { type Env } from '../env';
|
|
3
|
+
import type { AuthFailure } from './failure';
|
|
4
|
+
/**
|
|
5
|
+
* In-flight OIDC cookie: a SIGNED token carrying state + PKCE verifier + redirect; `__Host-`, 10 min.
|
|
6
|
+
* Outside the `__Host-px_` prefix the proxy strips upstream; host-only on IAM's host, so no application receives it.
|
|
7
|
+
*/
|
|
8
|
+
export declare const OIDC_COOKIE = "__Host-fabrika_oidc";
|
|
9
|
+
export declare const OIDC_TTL_SECONDS = 600;
|
|
10
|
+
/** The only env the auth surface touches directly is the signing config — the JWKS, and the flight. */
|
|
11
|
+
export type AuthEnv = Pick<Env, 'FABRIKA_IAM_SIGNING_KEYS' | 'ENVIRONMENT'>;
|
|
12
|
+
/** The in-flight OIDC state carried between /auth/login and /auth/callback. */
|
|
13
|
+
interface Flight {
|
|
14
|
+
state: string;
|
|
15
|
+
verifier: string;
|
|
16
|
+
/** Absent for a login with no return address, which lands on the installation's landing. */
|
|
17
|
+
redirect?: string;
|
|
18
|
+
/** The handoff app, when this SSO detour started from one (ADR-0022). */
|
|
19
|
+
app?: string;
|
|
20
|
+
handoffState?: string;
|
|
21
|
+
handoffChallenge?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* SIGN the flight, with IAM's own key, and keep it in a `__Host-` cookie. Both are needed.
|
|
25
|
+
*
|
|
26
|
+
* The `state` match alone is not a CSRF check when whoever writes the cookie also writes `state`.
|
|
27
|
+
* The signature proves IAM issued the flight, but an attacker can start a login of their own and
|
|
28
|
+
* get a validly signed flight too. Cookie-tossing from any host under a shared registrable domain
|
|
29
|
+
* would plant it in the victim's browser ahead of the victim's own, and IAM would issue the victim
|
|
30
|
+
* a session for the ATTACKER'S identity. The browser refuses a `__Host-` cookie that names a
|
|
31
|
+
* `Domain`, so the prefix proves this browser's flight was set by IAM's host.
|
|
32
|
+
*/
|
|
33
|
+
export declare function encodeFlight(env: AuthEnv, flight: Flight): Promise<string>;
|
|
34
|
+
export declare function decodeFlight(env: AuthEnv, raw: string | null): Promise<Flight | null>;
|
|
35
|
+
/** The `Set-Cookie` values that spend the flight, the legacy `/auth` one included. */
|
|
36
|
+
export declare function endingFlightCookies(): string[];
|
|
37
|
+
/** A refusal page that also spends the OIDC flight — every terminal callback outcome goes through here. */
|
|
38
|
+
export declare function authFailureEndingFlight(presentation: AppPresentation, failure: AuthFailure, status: number): Response;
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type RequestContext } from '../env';
|
|
2
|
+
import { type Services } from '../services';
|
|
3
|
+
import { type Handoff } from './handoff';
|
|
4
|
+
import { type AuthEnv } from './oidc-flight';
|
|
5
|
+
export declare function handleOidcStart(request: Request, services: Services, env: AuthEnv): Promise<Response>;
|
|
6
|
+
export declare function startOidc(request: Request, services: Services, env: AuthEnv, redirect: string | null, handoff?: Handoff | null): Promise<Response>;
|
|
7
|
+
export declare function handleCallback(request: Request, services: Services, env: AuthEnv, ctx: RequestContext, requestId: string): Promise<Response>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type RequestContext } from '../env';
|
|
2
|
+
import { type PasswordActionPurpose } from '../password-db';
|
|
3
|
+
import { type Services } from '../services';
|
|
4
|
+
import type { AuthEnv } from './oidc-flight';
|
|
5
|
+
export declare function handlePasswordLogin(request: Request, services: Services, env: AuthEnv, ctx: RequestContext, clientAddress: string | null, requestId: string): Promise<Response>;
|
|
6
|
+
export declare function handleForgotPassword(request: Request, services: Services, ctx: RequestContext, clientAddress: string | null, requestId: string): Promise<Response>;
|
|
7
|
+
export declare function handlePasswordAction(request: Request, services: Services, ctx: RequestContext, purpose: PasswordActionPurpose, requestId: string): Promise<Response>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { RequestContext } from '../env';
|
|
2
|
+
import type { Services } from '../services';
|
|
3
|
+
import type { AuthEnv } from './oidc-flight';
|
|
4
|
+
/**
|
|
5
|
+
* `clientAddress` is what the composition's ingress observed, or `null` when it cannot see a client
|
|
6
|
+
* (`src/client-address.ts`). It keys the per-client abuse bucket and NOTHING else — it is never an
|
|
7
|
+
* identity, never a credential, and never stored in the clear. Defaulting to `null` is deliberate: a
|
|
8
|
+
* caller that has not been given a trustworthy coordinate gets the account and deployment-wide buckets
|
|
9
|
+
* alone, which is what existed before, rather than one keyed on a guess.
|
|
10
|
+
*
|
|
11
|
+
* `requestId` is the correlation id the composition root allowed (`src/request-id.ts`); a caller that
|
|
12
|
+
* supplies none gets a generated one, never a header read here.
|
|
13
|
+
*/
|
|
14
|
+
export declare function handleAuth(request: Request, services: Services, env: AuthEnv, ctx: RequestContext, clientAddress?: string | null, requestId?: string): Promise<Response>;
|
|
15
|
+
export { safeRedirect } from './http';
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { type AuthenticationMethod, type PrincipalRow, type SessionRow } from '../db';
|
|
2
|
+
import { type RequestContext } from '../env';
|
|
3
|
+
import { type Services } from '../services';
|
|
4
|
+
import { type Handoff } from './handoff';
|
|
5
|
+
/** The caller's IAM session, if the browser already holds a valid one on this host. */
|
|
6
|
+
export declare function currentSession(request: Request, services: Services): Promise<SessionRow | null>;
|
|
7
|
+
/** A login a handoff may continue: the browser's IAM session and its principal, an active user. */
|
|
8
|
+
export interface CurrentLogin {
|
|
9
|
+
readonly session: SessionRow;
|
|
10
|
+
readonly principal: PrincipalRow;
|
|
11
|
+
}
|
|
12
|
+
/** The caller's IAM login when its principal is an active user, else null — which signs in afresh. */
|
|
13
|
+
export declare function currentLogin(request: Request, services: Services): Promise<CurrentLogin | null>;
|
|
14
|
+
/**
|
|
15
|
+
* Open a login: the session and its `auth_log` row are written in one batch, before the answer. A login that cannot
|
|
16
|
+
* be logged opens no session and answers 503. A principal that administers at IAM, the installation or the people of
|
|
17
|
+
* an application (ADR-0058), is logged `privileged`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function issueSession(request: Request, services: Services, ctx: RequestContext, input: {
|
|
20
|
+
principalId: string;
|
|
21
|
+
idpSub?: string | null;
|
|
22
|
+
email?: string | null;
|
|
23
|
+
authenticationMethod?: AuthenticationMethod;
|
|
24
|
+
/** Where the login lands; null for no destination of its own, which is the installation's landing. */
|
|
25
|
+
redirect: string | null;
|
|
26
|
+
reason: string;
|
|
27
|
+
/** The correlation id the composition root allowed; see `src/request-id.ts`. */
|
|
28
|
+
requestId: string;
|
|
29
|
+
clearOidc?: boolean;
|
|
30
|
+
/** When set, land on the app's callback with a code instead of on `redirect` (ADR-0022). */
|
|
31
|
+
handoff?: Handoff | null;
|
|
32
|
+
}): Promise<Response>;
|
|
33
|
+
/**
|
|
34
|
+
* Answer a refused login after its `deny` row is in `auth_log`. A refusal that cannot be logged answers 503 instead,
|
|
35
|
+
* so no login attempt goes unrecorded.
|
|
36
|
+
*/
|
|
37
|
+
/** The fixed `auth_log.reason` of a refused login. A reason never carries what the caller submitted. */
|
|
38
|
+
export type LoginRefusal = 'password_invalid' | 'password_throttled' | 'password_malformed' | 'handoff_refused' | 'login_cross_origin' | 'oidc_invalid_state' | 'oidc_code_exchange_failed' | 'oidc_invalid_id_token' | 'oidc_not_admitted' | 'oidc_disabled' | 'oidc_unknown_principal' | 'oidc_external_principal' | 'local_login_refused';
|
|
39
|
+
export declare function refuseLogin(services: Services, request: Request, entry: {
|
|
40
|
+
requestId: string;
|
|
41
|
+
principalId: string | null;
|
|
42
|
+
reason: LoginRefusal;
|
|
43
|
+
}, answer: () => Response | Promise<Response>): Promise<Response>;
|
|
44
|
+
/** Whether the principal administers at IAM, the installation or the people of an application — what marks its login privileged. */
|
|
45
|
+
export declare function administersIam(services: Services, principalId: string): Promise<boolean>;
|
|
46
|
+
/**
|
|
47
|
+
* Revoke the login and clear the cookie. Same-origin only, like every other mutating form here:
|
|
48
|
+
* `px_session` is `SameSite=Lax`, so a cross-site top-level GET carried it, and because every app
|
|
49
|
+
* session hangs off this one, that single request logged the human out of every host at once.
|
|
50
|
+
* The revocation and its `logout` row in `auth_log` are one batch; one that cannot be written answers 503
|
|
51
|
+
* and leaves the session as it was.
|
|
52
|
+
*/
|
|
53
|
+
export declare function handleLogout(request: Request, services: Services, requestId: string): Promise<Response>;
|
|
54
|
+
/**
|
|
55
|
+
* End the browser's IAM login, and with it every app session derived from it. The revocation and its `logout` row are
|
|
56
|
+
* one batch; false when that batch could not be written, and the login stands. The caller checks `sameOrigin` first.
|
|
57
|
+
*/
|
|
58
|
+
export declare function endLogin(request: Request, services: Services, requestId: string): Promise<boolean>;
|
|
59
|
+
/** The 302 out of an ended login, which clears its cookie. */
|
|
60
|
+
export declare function signedOutRedirect(location: string): Response;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type AppPresentation } from '../app-presentation';
|
|
2
|
+
import type { Services } from '../services';
|
|
3
|
+
import { type Handoff } from './handoff';
|
|
4
|
+
/**
|
|
5
|
+
* The cookie that makes a browser a terminal (ADR-0067 §1). It is not a session: no proxy reads it and it authorizes no
|
|
6
|
+
* request. IAM reads it on its own host, only to start an identification.
|
|
7
|
+
*/
|
|
8
|
+
export declare const TERMINAL_COOKIE = "__Host-px_terminal";
|
|
9
|
+
/**
|
|
10
|
+
* 400 days, the longest lifetime a browser keeps (RFC 6265bis caps `Max-Age` there, and Chromium enforces it). A terminal
|
|
11
|
+
* ends when an administrator revokes it, not when a cookie expires, so it asks for the most a browser grants.
|
|
12
|
+
*/
|
|
13
|
+
export declare const TERMINAL_COOKIE_MAX_AGE_SECONDS: number;
|
|
14
|
+
/** Where an application's proxy sends a signed-out terminal's browser; the proxy's `SIGNOUT_RELEASE_PATH` names it. */
|
|
15
|
+
export declare const TERMINAL_RELEASE_PATH = "/auth/terminals/release";
|
|
16
|
+
/**
|
|
17
|
+
* `GET` renders the enrolment form to a login that may enrol; `POST` enrols. A browser without a login is sent to sign
|
|
18
|
+
* in and back here. The form and every refusal name no application, so they speak the reader's language (`readerLocale`).
|
|
19
|
+
*/
|
|
20
|
+
export declare function handleTerminalEnrolment(request: Request, services: Services, requestId: string): Promise<Response>;
|
|
21
|
+
/**
|
|
22
|
+
* Send a terminal's browser to the application to identify the person at it (ADR-0067 §2): when the browser is an
|
|
23
|
+
* enrolled terminal, the handoff's application is one of its asserters and declares an identification page. The
|
|
24
|
+
* identification holds the handoff, so IAM alone issues the code once the application names the person. Null for any
|
|
25
|
+
* other sign-in, which goes on as usual. The terminal cookie is refreshed, so a terminal in use never reaches its cap.
|
|
26
|
+
*/
|
|
27
|
+
export declare function identificationRedirect(request: Request, services: Services, handoff: Handoff, presentation: AppPresentation, requestId: string): Promise<Response | null>;
|
|
28
|
+
/**
|
|
29
|
+
* `GET /auth/terminals/complete?identification=` (ADR-0067 §3): the terminal's browser arrives here from the application
|
|
30
|
+
* after its assertion, and IAM issues the handoff's code to it. Only the browser of the identification's own terminal
|
|
31
|
+
* completes it, once, within the completion window, while the asserted login is still valid; anything else is refused
|
|
32
|
+
* and issues nothing. The code goes to the proxy's callback on the handoff's return origin, so the application never
|
|
33
|
+
* sees it, and the proxy redeems it only with the verifier it set on the browser that started the sign-in.
|
|
34
|
+
*
|
|
35
|
+
* A GET without a same-origin check, like the release: the application sends the browser here from its own host.
|
|
36
|
+
* Completing an identification the application already asserted is all a cross-site request can do.
|
|
37
|
+
*/
|
|
38
|
+
export declare function handleTerminalCompletion(request: Request, services: Services, requestId: string): Promise<Response>;
|
|
39
|
+
/**
|
|
40
|
+
* `GET /auth/terminals/release?app=&redirect=` (ADR-0067 §5): end the sessions of this browser's terminal, then return
|
|
41
|
+
* to `redirect`, which must lie in the app's registered return origins. A browser that is no terminal is only sent back.
|
|
42
|
+
*
|
|
43
|
+
* A GET without a same-origin check, unlike every other auth route that changes state: the application's proxy sends
|
|
44
|
+
* the browser here from its own sign-out, a navigation from another host. The most a cross-site request can do is end
|
|
45
|
+
* the short session of whoever stands at the terminal.
|
|
46
|
+
*/
|
|
47
|
+
export declare function handleTerminalRelease(request: Request, services: Services, requestId: string): Promise<Response>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { type PermissionEntry, type PrincipalType, type TokenPrincipalType } from '@fabrika/auth-core';
|
|
2
|
+
import type { SessionRow } from './db';
|
|
3
|
+
import type { Env } from './env';
|
|
4
|
+
import type { Config, Services } from './services';
|
|
5
|
+
/** Fixed identity of the local-dev login (`LOCAL_DEV_LOGIN`, `auth/login.ts`). */
|
|
6
|
+
export declare const LOCAL_DEV_ADMIN_ID = "local-dev-admin";
|
|
7
|
+
export declare const LOCAL_DEV_ADMIN_EMAIL = "admin@local.test";
|
|
8
|
+
/**
|
|
9
|
+
* May this session still be used, given what the installation enables NOW?
|
|
10
|
+
*
|
|
11
|
+
* **Checked at USE, not at creation, and that is the point.** Turning a method off changes what the
|
|
12
|
+
* next login may do and nothing about what was already issued. Sessions live 30 days, so an
|
|
13
|
+
* installation that moved to password-only kept honouring every OIDC login for a month — and, for the
|
|
14
|
+
* bypass, every one of those is a global admin.
|
|
15
|
+
*
|
|
16
|
+
* The bypass carries `local_dev` as its own method rather than an exemption
|
|
17
|
+
* here, so this stays a total function over the enum: a method added later has to answer the question.
|
|
18
|
+
*/
|
|
19
|
+
export declare function sessionUsable(session: Pick<SessionRow, 'authentication_method'>, config: Pick<Config, 'authentication' | 'localDevLogin'>): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Fixed identity for the SEEDED PROVISIONING KEY below. A stable `service` principal with this id is
|
|
22
|
+
* seeded into `principals` (migration `0001_init.sql`) so the audit the provisioning
|
|
23
|
+
* key drives (e.g. `iam.app.schema.reconcile`) resolves its `principal_id` FK — the prod-applied analog
|
|
24
|
+
* of the dev admin's `seed.dev.sql` row.
|
|
25
|
+
*/
|
|
26
|
+
export declare const PROVISIONING_ADMIN_ID = "provisioning-admin";
|
|
27
|
+
/** The resolved caller. `type` is absent for an ANONYMOUS credential (a share link). */
|
|
28
|
+
export interface ResolvedCaller<T extends TokenPrincipalType = PrincipalType> {
|
|
29
|
+
id: string;
|
|
30
|
+
type?: T;
|
|
31
|
+
label: string | null;
|
|
32
|
+
permissions: PermissionEntry[];
|
|
33
|
+
/** The terminal of a person's session token asserted on one (ADR-0067): its `terminal` claim's principal id. */
|
|
34
|
+
terminal?: string;
|
|
35
|
+
}
|
|
36
|
+
type CallerRefusal = {
|
|
37
|
+
ok: false;
|
|
38
|
+
reason: 'missing_token' | 'invalid_token' | 'unknown_principal' | 'disabled';
|
|
39
|
+
};
|
|
40
|
+
export type CallerResolution<T extends TokenPrincipalType = PrincipalType> = {
|
|
41
|
+
ok: true;
|
|
42
|
+
caller: ResolvedCaller<T>;
|
|
43
|
+
verifiedApp: string;
|
|
44
|
+
} | CallerRefusal;
|
|
45
|
+
type CallerEnv = Pick<Env, 'FABRIKA_IAM_SIGNING_KEYS' | 'FABRIKA_IAM_PROVISIONING_KEY' | 'ENVIRONMENT'>;
|
|
46
|
+
type CallerInput = {
|
|
47
|
+
app: string;
|
|
48
|
+
credential: string | null;
|
|
49
|
+
requestId: string;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* The caller of a management or membership operation. A workload key or token calls none: it only mints for its own
|
|
53
|
+
* application (a job's link operations resolve through `resolveLinkCaller`).
|
|
54
|
+
*/
|
|
55
|
+
export declare function resolveCaller(services: Services, env: CallerEnv, input: CallerInput): Promise<CallerResolution>;
|
|
56
|
+
/**
|
|
57
|
+
* The caller of `issueLink` or `revokeLink`: a member caller, or a job (`type: 'job'`), which IAM then holds to the link
|
|
58
|
+
* mount its current declaration names. A webhook, a public procedure or a connector key calls neither.
|
|
59
|
+
*/
|
|
60
|
+
export declare function resolveLinkCaller(services: Services, env: CallerEnv, input: CallerInput): Promise<CallerResolution<PrincipalType | 'job'>>;
|
|
61
|
+
/** A request authenticated before its token expired may finish, and audit, after it; one hour covers that. */
|
|
62
|
+
export declare const AUDIT_TOKEN_EXPIRY_GRACE_SECONDS: number;
|
|
63
|
+
/**
|
|
64
|
+
* The app an `audit` event belongs to, read from the caller's own token rather than from the event: a
|
|
65
|
+
* native access token's `aud`, or an OAuth resource token's signed `app`. Null when neither verifies.
|
|
66
|
+
* Signature, issuer and token kind are checked as strictly as anywhere; only `exp` gets
|
|
67
|
+
* `AUDIT_TOKEN_EXPIRY_GRACE_SECONDS`, because this decides where an event is filed, never what is allowed.
|
|
68
|
+
*/
|
|
69
|
+
export declare function verifiedTokenApp(services: Services, env: Pick<Env, 'FABRIKA_IAM_SIGNING_KEYS' | 'ENVIRONMENT'>, credential: string): Promise<string | null>;
|
|
70
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** The IAM application id `<app>@<env>` whose deployment holds the binding, or null for a binding that names none. */
|
|
2
|
+
export declare function bindingApp(ctx: {
|
|
3
|
+
readonly props?: unknown;
|
|
4
|
+
}): string | null;
|
|
5
|
+
/**
|
|
6
|
+
* Whether the deployer marked the binding as the application Worker's, never its proxy's. Only the proxy obtains a
|
|
7
|
+
* delegation grant (ADR-0022 rule 6); a binding without the mark is a proxy's, a platform component's, or an application
|
|
8
|
+
* Worker deployed before the mark existed.
|
|
9
|
+
*/
|
|
10
|
+
export declare function isApplicationWorkerBinding(ctx: {
|
|
11
|
+
readonly props?: unknown;
|
|
12
|
+
}): boolean;
|