@aglyn/tenant-data-admin 1.0.0-beta.263 → 1.0.0-beta.264
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aglyn/tenant-data-admin",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.264",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"homepage": "https://aglyn.com",
|
|
6
6
|
"repository": {
|
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
"./package.json": "./package.json"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@aglyn/aglyn": "1.0.0-beta.
|
|
29
|
-
"@aglyn/shared-util-email": "1.0.0-beta.
|
|
30
|
-
"@aglyn/shared-util-fbserver": "1.0.0-beta.
|
|
31
|
-
"@aglyn/shared-util-first-touch": "1.0.0-beta.
|
|
32
|
-
"@aglyn/shared-util-http": "1.0.0-beta.
|
|
33
|
-
"@aglyn/shared-util-tools": "1.0.0-beta.
|
|
28
|
+
"@aglyn/aglyn": "1.0.0-beta.264",
|
|
29
|
+
"@aglyn/shared-util-email": "1.0.0-beta.264",
|
|
30
|
+
"@aglyn/shared-util-fbserver": "1.0.0-beta.264",
|
|
31
|
+
"@aglyn/shared-util-first-touch": "1.0.0-beta.264",
|
|
32
|
+
"@aglyn/shared-util-http": "1.0.0-beta.264",
|
|
33
|
+
"@aglyn/shared-util-tools": "1.0.0-beta.264",
|
|
34
34
|
"@msgpack/msgpack": "^3.1.3",
|
|
35
35
|
"@swc/helpers": "0.5.23",
|
|
36
36
|
"sharp": "^0.35.5",
|
|
@@ -42,17 +42,26 @@ export declare function ssoRequiredDomains(env?: Record<string, string | undefin
|
|
|
42
42
|
*
|
|
43
43
|
* For accounts that cannot use the IdP at all because someone outside the
|
|
44
44
|
* company has to sign in with them: the demo login an app store reviewer is
|
|
45
|
-
* given, for example
|
|
46
|
-
* exception is named and can be
|
|
45
|
+
* given, for example, or an automated sign-up check that creates a new
|
|
46
|
+
* plus-addressed account on every run. Every exception is named and can be
|
|
47
|
+
* read back from configuration:
|
|
47
48
|
*
|
|
48
49
|
* ```
|
|
49
|
-
* AGLYN_SSO_EXEMPT_EMAILS="reviewer@example.com"
|
|
50
|
+
* AGLYN_SSO_EXEMPT_EMAILS="reviewer@example.com ops+signup-canary*@example.com"
|
|
50
51
|
* ```
|
|
51
52
|
*
|
|
53
|
+
* An entry is an exact address, or one mailbox's plus tag followed by `*`,
|
|
54
|
+
* which also admits every address that extends that tag on the same domain.
|
|
55
|
+
* The `*` is accepted only as the last character of the local part and only
|
|
56
|
+
* after a `+`, so no entry can exempt a whole mailbox or a whole domain; any
|
|
57
|
+
* other entry with a `*` is dropped.
|
|
58
|
+
*
|
|
52
59
|
* Comma or whitespace separated, compared lower-cased. Empty by default.
|
|
53
60
|
*/
|
|
54
61
|
export declare const SSO_EXEMPT_EMAILS_ENV = "AGLYN_SSO_EXEMPT_EMAILS";
|
|
55
62
|
export declare function parseSsoExemptEmails(raw: string | null | undefined): ReadonlySet<string>;
|
|
63
|
+
/** Whether an address is named by one of the parsed exemption entries. */
|
|
64
|
+
export declare function isSsoExemptEmail(email: string | null | undefined, exempt: ReadonlySet<string>): boolean;
|
|
56
65
|
export declare function ssoExemptEmails(env?: Record<string, string | undefined>): ReadonlySet<string>;
|
|
57
66
|
export type SsoDomainVerdict =
|
|
58
67
|
/** Domain is not governed. Any pool is fine — this is most of the world. */
|
|
@@ -122,23 +122,56 @@ export const SSO_REQUIRED_DOMAINS_ENV = 'AGLYN_SSO_REQUIRED_DOMAINS';
|
|
|
122
122
|
*
|
|
123
123
|
* For accounts that cannot use the IdP at all because someone outside the
|
|
124
124
|
* company has to sign in with them: the demo login an app store reviewer is
|
|
125
|
-
* given, for example
|
|
126
|
-
* exception is named and can be
|
|
125
|
+
* given, for example, or an automated sign-up check that creates a new
|
|
126
|
+
* plus-addressed account on every run. Every exception is named and can be
|
|
127
|
+
* read back from configuration:
|
|
127
128
|
*
|
|
128
129
|
* ```
|
|
129
|
-
* AGLYN_SSO_EXEMPT_EMAILS="reviewer@example.com"
|
|
130
|
+
* AGLYN_SSO_EXEMPT_EMAILS="reviewer@example.com ops+signup-canary*@example.com"
|
|
130
131
|
* ```
|
|
131
132
|
*
|
|
133
|
+
* An entry is an exact address, or one mailbox's plus tag followed by `*`,
|
|
134
|
+
* which also admits every address that extends that tag on the same domain.
|
|
135
|
+
* The `*` is accepted only as the last character of the local part and only
|
|
136
|
+
* after a `+`, so no entry can exempt a whole mailbox or a whole domain; any
|
|
137
|
+
* other entry with a `*` is dropped.
|
|
138
|
+
*
|
|
132
139
|
* Comma or whitespace separated, compared lower-cased. Empty by default.
|
|
133
140
|
*/ export const SSO_EXEMPT_EMAILS_ENV = 'AGLYN_SSO_EXEMPT_EMAILS';
|
|
134
141
|
export function parseSsoExemptEmails(raw) {
|
|
135
142
|
const emails = new Set();
|
|
136
143
|
for (const entry of String(raw != null ? raw : '').split(/[,\s]+/)){
|
|
137
144
|
const email = entry.trim().toLowerCase();
|
|
138
|
-
|
|
145
|
+
const at = email.lastIndexOf('@');
|
|
146
|
+
if (at <= 0 || at === email.length - 1) continue;
|
|
147
|
+
if (email.slice(at + 1).includes('*')) continue;
|
|
148
|
+
const local = email.slice(0, at);
|
|
149
|
+
const star = local.indexOf('*');
|
|
150
|
+
if (star !== -1) {
|
|
151
|
+
const plus = local.indexOf('+');
|
|
152
|
+
// One trailing `*`, after a non-empty plus tag: `name+tag*`.
|
|
153
|
+
if (star !== local.length - 1 || plus <= 0 || plus >= star - 1) continue;
|
|
154
|
+
}
|
|
155
|
+
emails.add(email);
|
|
139
156
|
}
|
|
140
157
|
return emails;
|
|
141
158
|
}
|
|
159
|
+
/** Whether an address is named by one of the parsed exemption entries. */ export function isSsoExemptEmail(email, exempt) {
|
|
160
|
+
const address = String(email != null ? email : '').trim().toLowerCase();
|
|
161
|
+
if (!address) return false;
|
|
162
|
+
if (exempt.has(address)) return true;
|
|
163
|
+
const at = address.lastIndexOf('@');
|
|
164
|
+
if (at <= 0) return false;
|
|
165
|
+
const local = address.slice(0, at);
|
|
166
|
+
const domain = address.slice(at + 1);
|
|
167
|
+
for (const entry of exempt){
|
|
168
|
+
if (!entry.endsWith(`*@${domain}`)) continue;
|
|
169
|
+
if (local.startsWith(entry.slice(0, entry.length - domain.length - 2))) {
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
142
175
|
export function ssoExemptEmails(env = process.env) {
|
|
143
176
|
return parseSsoExemptEmails(env[SSO_EXEMPT_EMAILS_ENV]);
|
|
144
177
|
}
|
|
@@ -153,7 +186,7 @@ export function ssoExemptEmails(env = process.env) {
|
|
|
153
186
|
* so a spec can drive every combination directly, and so the audit view and
|
|
154
187
|
* the enforcement path can never disagree about what the policy says.
|
|
155
188
|
*/ export function evaluateSsoDomainPolicy(identity, domains = ssoRequiredDomains(), exempt = ssoExemptEmails()) {
|
|
156
|
-
var _identity_tenantId
|
|
189
|
+
var _identity_tenantId;
|
|
157
190
|
const domain = domainOf(identity.email);
|
|
158
191
|
const tenantId = (_identity_tenantId = identity.tenantId) != null ? _identity_tenantId : null;
|
|
159
192
|
// Exact-match lookup, never a suffix test: `notaglyn.com` ends with
|
|
@@ -195,7 +228,7 @@ export function ssoExemptEmails(env = process.env) {
|
|
|
195
228
|
reviewable: true
|
|
196
229
|
};
|
|
197
230
|
}
|
|
198
|
-
if (
|
|
231
|
+
if (isSsoExemptEmail(identity.email, exempt)) {
|
|
199
232
|
return {
|
|
200
233
|
verdict: 'allow-exempt',
|
|
201
234
|
refused: false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../../libs/tenant/data/admin/src/lib/server/sso-domain-policy.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Workspace-domain SSO policy (AGL-1993).\n *\n * **The rule is about a DOMAIN, not about staff.** An `@aglyn.com` address is a\n * Google Workspace identity, and Workspace is what enforces MFA, disables an\n * account at offboarding, and lets an admin revoke a session. An `@aglyn.com`\n * address that signs in through a project-pool password or a consumer Google\n * account has none of that: it looks like a company identity and is governed\n * like a personal one. That gap is the whole reason this module exists.\n *\n * ## Staff is a SEPARATE axis and this module never reads it\n *\n * Staff may be granted to anybody — SSO or not, `@aglyn.com` or not, project\n * pool or any GCIP tenant including a *customer's*. Nothing here consults the\n * `staff` claim, and `sso-domain-policy.spec.ts` pins that by evaluating every\n * staff permutation and asserting the verdict does not move. The two axes are\n * independent; conflating them would turn a narrow domain control into an\n * accidental SSO mandate for staff, which is explicitly not the policy.\n *\n * These all remain valid, and each has a test:\n *\n * | identity | staff | verdict |\n * | ------------------------------------------ | ----- | ------------------------- |\n * | `@aglyn.com` in the designated tenant | yes | allowed |\n * | personal address, project pool (break-glass)| yes | allowed — permanent design|\n * | personal address, project pool | no | allowed |\n * | SSO identity in a CUSTOMER org's tenant | yes | allowed |\n * | `@aglyn.com` in the PROJECT pool | any | **refused** when enforced |\n *\n * Only the last row is what the switch exists for.\n *\n * ## How this differs from `sso-enforcement.ts`\n *\n * {@link enforceSsoSignInMethods} (AGL-1128/1129) strips non-IdP providers from\n * accounts that are ALREADY INSIDE a tenant. It cannot see an identity that\n * never joined the tenant at all — a project-pool `@aglyn.com` account is\n * invisible to every tenant sweep, by construction. Measured on aglyn-main on\n * 2026-08-18: two such accounts existed, one of them holding a live\n * `google.com` provider. This module covers that outside-the-tenant half.\n *\n * ## Shape note: deliberately NOT a discriminated union\n *\n * `strictNullChecks` is off repo-wide, which defeats boolean-discriminant\n * narrowing — a spec can read the wrong arm of a union and pass silently. So\n * the decision is ONE flat interface with a string `verdict`, and specs assert\n * the literal. There is no arm to read by mistake.\n */\n\n/**\n * ## Self-hosting: this policy is CONFIGURATION, never a compiled-in constant\n *\n * Aglyn ships in two shapes — the Aglyn-operated SaaS, and self-hosted installs\n * on the operator's own Firebase project. `aglyn.com` is *our* Workspace\n * domain; a self-hoster has their own domain, their own IdP, or none at all.\n * Baking our domain in would make the rule dead weight for them at best and a\n * lockout at worst, so the governed set is read from configuration and is\n * **empty by default**.\n *\n * Empty means the rule does nothing. That is simultaneously the correct\n * behaviour for a fresh self-host install and the correct OFF state for us —\n * one default serving both, rather than a special case for either.\n *\n * Format — `domain=tenantId`, comma or whitespace separated:\n *\n * ```\n * AGLYN_SSO_REQUIRED_DOMAINS=\"aglyn.com=aglyn-org-y5v14\"\n * ```\n *\n * A map rather than a bare list because \"must use SSO\" is meaningless without\n * naming WHOSE SSO: the point is IdP lifecycle control, which only the tenant\n * wired to that domain's SAML provider delivers.\n */\nimport { PLATFORM_BRAND_NAME } from '@aglyn/aglyn/app-utils/platform-brand'\n\n/**\n * The block below runs in two places: here, at the session mint, and in the\n * `cloud/functions` account-creation blocking function, which refuses the\n * account before it exists. `cloud/functions` is a plain npm package that can\n * import only firebase-admin and firebase-functions, so it holds a verbatim\n * copy (`cloud/functions/src/sso-domain-policy.ts`), and\n * `apps/console/specs/sso-domain-creation-wiring.spec.ts` fails if the two\n * differ by a single character. Change it here, then copy the region across.\n */\n// #region sso-domain-policy\nexport const SSO_REQUIRED_DOMAINS_ENV = 'AGLYN_SSO_REQUIRED_DOMAINS'\n\nexport type SsoRequiredDomains = Readonly<Record<string, string>>\n\n/**\n * Parse the configured domain→tenant map. Total: anything unparseable is\n * dropped rather than throwing, because this sits on the authentication path\n * and a malformed env var must not take sign-in down. A dropped entry fails\n * OPEN (the domain is simply ungoverned), which is the safe direction for a\n * rule whose only power is to refuse.\n */\nexport function parseSsoRequiredDomains(\n raw: string | null | undefined,\n): SsoRequiredDomains {\n const map: Record<string, string> = {}\n for (const pair of String(raw ?? '').split(/[,\\s]+/)) {\n if (!pair) continue\n const eq = pair.indexOf('=')\n if (eq <= 0) continue\n const domain = pair.slice(0, eq).trim().toLowerCase()\n const tenantId = pair.slice(eq + 1).trim()\n if (!domain || !tenantId) continue\n map[domain] = tenantId\n }\n return map\n}\n\n/**\n * The operator's SSO-required domains. Empty unless configured — see above.\n */\nexport function ssoRequiredDomains(\n env: Record<string, string | undefined> = process.env,\n): SsoRequiredDomains {\n return parseSsoRequiredDomains(env[SSO_REQUIRED_DOMAINS_ENV])\n}\n\n/**\n * Addresses on a governed domain that may still sign in OUTSIDE its tenant.\n *\n * For accounts that cannot use the IdP at all because someone outside the\n * company has to sign in with them: the demo login an app store reviewer is\n * given, for example. Exact addresses only, never a pattern, so every\n * exception is named and can be read back from configuration:\n *\n * ```\n * AGLYN_SSO_EXEMPT_EMAILS=\"reviewer@example.com\"\n * ```\n *\n * Comma or whitespace separated, compared lower-cased. Empty by default.\n */\nexport const SSO_EXEMPT_EMAILS_ENV = 'AGLYN_SSO_EXEMPT_EMAILS'\n\nexport function parseSsoExemptEmails(\n raw: string | null | undefined,\n): ReadonlySet<string> {\n const emails = new Set<string>()\n for (const entry of String(raw ?? '').split(/[,\\s]+/)) {\n const email = entry.trim().toLowerCase()\n if (email.includes('@')) emails.add(email)\n }\n return emails\n}\n\nexport function ssoExemptEmails(\n env: Record<string, string | undefined> = process.env,\n): ReadonlySet<string> {\n return parseSsoExemptEmails(env[SSO_EXEMPT_EMAILS_ENV])\n}\n\nexport type SsoDomainVerdict =\n /** Domain is not governed. Any pool is fine — this is most of the world. */\n | 'allow-ungoverned'\n /** Governed domain, signed in through the tenant we designated for it. */\n | 'allow-designated-tenant'\n /**\n * Governed domain, signed in through SOME tenant, but not the designated\n * one. Allowed — they did use SSO, and refusing would invent a restriction\n * nobody asked for — but surfaced so a staff-access review can see it.\n */\n | 'allow-foreign-tenant'\n /**\n * Governed domain, no tenant, but the address is named in\n * {@link SSO_EXEMPT_EMAILS_ENV}. Allowed and reviewable.\n */\n | 'allow-exempt'\n /**\n * Governed domain with NO tenant at all: a project-pool password or consumer\n * Google sign-in. The only refusal this policy ever produces.\n */\n | 'refuse-sso-required'\n\nexport interface SsoDomainDecision {\n verdict: SsoDomainVerdict\n /**\n * Whether enforcement WOULD refuse this identity. Independent of whether\n * enforcement is currently switched on — {@link ssoDomainEnforcementEnabled}\n * decides that — so the same evaluation can drive both an audit in\n * report-only mode and the refusal once the switch is flipped.\n */\n refused: boolean\n /** Lower-cased domain, or null when the identity has no email address. */\n domain: string | null\n /** Tenant this domain is required to use, or null when ungoverned. */\n requiredTenantId: string | null\n /** Tenant the identity actually signed in through; null = project pool. */\n tenantId: string | null\n /** Worth a human look even though it is allowed (foreign-tenant case). */\n reviewable: boolean\n}\n\nexport interface SsoDomainIdentity {\n /** The identity's email address. Absent/empty is treated as ungoverned. */\n email?: string | null\n /**\n * GCIP tenant the identity signed in through — `decoded.firebase?.tenant`,\n * or a `PooledUserRecord.tenantId`. Null/undefined means the project pool.\n *\n * Never inferred and never defaulted to a hard-coded tenant: a uid is only\n * unique WITHIN a pool, and assuming one is how a lookup silently lands on\n * the wrong record.\n */\n tenantId?: string | null\n}\n\n/** The domain part of an address, lower-cased. Null when there isn't one. */\nexport function domainOf(email: string | null | undefined): string | null {\n const address = String(email ?? '').trim().toLowerCase()\n const at = address.lastIndexOf('@')\n if (at < 0 || at === address.length - 1) return null\n return address.slice(at + 1)\n}\n\n/**\n * Decide the policy for one identity. Pure and total — no Firebase, no env —\n * so a spec can drive every combination directly, and so the audit view and\n * the enforcement path can never disagree about what the policy says.\n */\nexport function evaluateSsoDomainPolicy(\n identity: SsoDomainIdentity,\n domains: SsoRequiredDomains = ssoRequiredDomains(),\n exempt: ReadonlySet<string> = ssoExemptEmails(),\n): SsoDomainDecision {\n const domain = domainOf(identity.email)\n const tenantId = identity.tenantId ?? null\n // Exact-match lookup, never a suffix test: `notaglyn.com` ends with\n // `aglyn.com`, and a suffix test would refuse an unrelated company's staff.\n const requiredTenantId = domain\n ? (Object.prototype.hasOwnProperty.call(domains, domain)\n ? domains[domain]\n : null)\n : null\n\n if (!requiredTenantId) {\n // Ungoverned: a personal address, a customer's address, anything not on\n // the list. Includes the permanent break-glass account by construction\n // rather than by special case — see the staff-access doc.\n return {\n verdict: 'allow-ungoverned',\n refused: false,\n domain,\n requiredTenantId: null,\n tenantId,\n reviewable: false,\n }\n }\n\n if (tenantId === requiredTenantId) {\n return {\n verdict: 'allow-designated-tenant',\n refused: false,\n domain,\n requiredTenantId,\n tenantId,\n reviewable: false,\n }\n }\n\n if (tenantId) {\n // A governed address inside somebody else's tenant. They authenticated\n // through an IdP, so the hole this policy closes is not open here — but\n // the IdP is not one Aglyn controls, so it is flagged for review.\n return {\n verdict: 'allow-foreign-tenant',\n refused: false,\n domain,\n requiredTenantId,\n tenantId,\n reviewable: true,\n }\n }\n\n if (exempt.has(String(identity.email ?? '').trim().toLowerCase())) {\n return {\n verdict: 'allow-exempt',\n refused: false,\n domain,\n requiredTenantId,\n tenantId: null,\n reviewable: true,\n }\n }\n\n return {\n verdict: 'refuse-sso-required',\n refused: true,\n domain,\n requiredTenantId,\n tenantId: null,\n reviewable: true,\n }\n}\n\n/**\n * THE ENFORCEMENT SWITCH — ships OFF.\n *\n * Off means `evaluateSsoDomainPolicy` still computes `refused`, and callers\n * still record it, but nobody is turned away. That is deliberate: the audit\n * trail accumulates under the real rule before the rule bites, so flipping the\n * switch holds no surprises.\n *\n * Opt-in by exact string. Anything else — unset, empty, `false`, `0`, a typo —\n * is OFF. A security control that switches itself on through a misspelling is\n * a control that can lock people out through a misspelling.\n *\n * Note both halves must be set for anything to happen: this switch AND a\n * non-empty {@link SSO_REQUIRED_DOMAINS_ENV}. A self-host install that sets\n * only this switch still governs nothing.\n *\n * **Precondition for flipping it — written down so it is not re-litigated:**\n * 1. SSO staff access verified working through a REAL sign-in (not a token\n * inspection): a staff account reaches `/admin/*` via the SAML tenant.\n * 2. Every identity on a governed domain has been migrated into its tenant,\n * retired, or named in {@link SSO_EXEMPT_EMAILS_ENV}. An automation or\n * reviewer account is the one that bites without warning: nobody is\n * watching a sign-in page when it fails.\n *\n * A second staff identity is NOT a precondition: the permanent break-glass\n * account is on an ungoverned domain, so this rule can never refuse it.\n */\nexport const SSO_DOMAIN_ENFORCEMENT_ENV = 'AGLYN_SSO_DOMAIN_ENFORCEMENT'\n\nexport function ssoDomainEnforcementEnabled(\n env: Record<string, string | undefined> = process.env,\n): boolean {\n return env[SSO_DOMAIN_ENFORCEMENT_ENV] === 'on'\n}\n\n/**\n * Whether an account about to be CREATED must be refused. Same switch, same\n * domains, same exemptions as the session mint, so an address the mint would\n * turn away is never created in the first place, and an address it admits\n * is never refused here.\n */\nexport function ssoDomainCreationRefused(\n identity: SsoDomainIdentity,\n env: Record<string, string | undefined> = process.env,\n): boolean {\n if (!ssoDomainEnforcementEnabled(env)) return false\n return evaluateSsoDomainPolicy(\n identity,\n ssoRequiredDomains(env),\n ssoExemptEmails(env),\n ).refused\n}\n// #endregion sso-domain-policy\n\n/**\n * What the refused person is told. Names the fix, not the mechanism.\n *\n * `PLATFORM_BRAND_NAME`, not a literal (AGL-2214). Everything else in this\n * module is careful that the RULE is configuration rather than a compiled-in\n * assumption about Aglyn — and then the one string a refused person actually\n * reads named us anyway. A self-hoster who governs their own domain would\n * have turned their own staff away in our name.\n *\n * Byte-identical for a deployment that has not renamed itself.\n */\nexport const SSO_DOMAIN_REFUSAL_MESSAGE =\n `Sign in with your ${PLATFORM_BRAND_NAME} Workspace account ` +\n '(Single sign-on). Accounts on this domain cannot use a password or ' +\n 'personal Google sign-in.'\n\n/**\n * The refusal a caller should return, or null to carry on.\n *\n * Returns null whenever the switch is off, so wiring this into an\n * authentication path is inert until the account owner flips it — the call site is live,\n * the consequence is not.\n */\nexport function ssoDomainRefusal(\n identity: SsoDomainIdentity,\n env: Record<string, string | undefined> = process.env,\n): { decision: SsoDomainDecision; response: Response } | null {\n const decision = evaluateSsoDomainPolicy(\n identity,\n ssoRequiredDomains(env),\n ssoExemptEmails(env),\n )\n if (!decision.refused) return null\n if (!ssoDomainEnforcementEnabled(env)) return null\n return {\n decision,\n response: Response.json(\n {\n error: SSO_DOMAIN_REFUSAL_MESSAGE,\n reason: 'sso-domain-required',\n domain: decision.domain,\n },\n { status: 403 },\n ),\n }\n}\n\nexport default evaluateSsoDomainPolicy\n"],"names":["PLATFORM_BRAND_NAME","SSO_REQUIRED_DOMAINS_ENV","parseSsoRequiredDomains","raw","map","pair","String","split","eq","indexOf","domain","slice","trim","toLowerCase","tenantId","ssoRequiredDomains","env","process","SSO_EXEMPT_EMAILS_ENV","parseSsoExemptEmails","emails","Set","entry","email","includes","add","ssoExemptEmails","domainOf","address","at","lastIndexOf","length","evaluateSsoDomainPolicy","identity","domains","exempt","requiredTenantId","Object","prototype","hasOwnProperty","call","verdict","refused","reviewable","has","SSO_DOMAIN_ENFORCEMENT_ENV","ssoDomainEnforcementEnabled","ssoDomainCreationRefused","SSO_DOMAIN_REFUSAL_MESSAGE","ssoDomainRefusal","decision","response","Response","json","error","reason","status"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8CC,GAED;;;;;;;;;;;;;;;;;;;;;;;CAuBC,GACD,SAASA,mBAAmB,QAAQ,wCAAuC;AAE3E;;;;;;;;CAQC,GACD,4BAA4B;AAC5B,OAAO,MAAMC,2BAA2B,6BAA4B;AAIpE;;;;;;CAMC,GACD,OAAO,SAASC,wBACdC,GAA8B;IAE9B,MAAMC,MAA8B,CAAC;IACrC,KAAK,MAAMC,QAAQC,OAAOH,cAAAA,MAAO,IAAII,KAAK,CAAC,UAAW;QAC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4BAA4B9B,MAAM,OAAO;IAC9C,OAAOgB,wBACLC,UACAlB,mBAAmBC,MACnBU,gBAAgBV,MAChB0B,OAAO;AACX;AACA,+BAA+B;AAE/B;;;;;;;;;;CAUC,GACD,OAAO,MAAMM,6BACX,CAAC,kBAAkB,EAAEhD,oBAAoB,mBAAmB,CAAC,GAC7D,wEACA,2BAA0B;AAE5B;;;;;;CAMC,GACD,OAAO,SAASiD,iBACdhB,QAA2B,EAC3BjB,MAA0CC,QAAQD,GAAG;IAErD,MAAMkC,WAAWlB,wBACfC,UACAlB,mBAAmBC,MACnBU,gBAAgBV;IAElB,IAAI,CAACkC,SAASR,OAAO,EAAE,OAAO;IAC9B,IAAI,CAACI,4BAA4B9B,MAAM,OAAO;IAC9C,OAAO;QACLkC;QACAC,UAAUC,SAASC,IAAI,CACrB;YACEC,OAAON;YACPO,QAAQ;YACR7C,QAAQwC,SAASxC,MAAM;QACzB,GACA;YAAE8C,QAAQ;QAAI;IAElB;AACF;AAEA,eAAexB,wBAAuB"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../libs/tenant/data/admin/src/lib/server/sso-domain-policy.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Workspace-domain SSO policy (AGL-1993).\n *\n * **The rule is about a DOMAIN, not about staff.** An `@aglyn.com` address is a\n * Google Workspace identity, and Workspace is what enforces MFA, disables an\n * account at offboarding, and lets an admin revoke a session. An `@aglyn.com`\n * address that signs in through a project-pool password or a consumer Google\n * account has none of that: it looks like a company identity and is governed\n * like a personal one. That gap is the whole reason this module exists.\n *\n * ## Staff is a SEPARATE axis and this module never reads it\n *\n * Staff may be granted to anybody — SSO or not, `@aglyn.com` or not, project\n * pool or any GCIP tenant including a *customer's*. Nothing here consults the\n * `staff` claim, and `sso-domain-policy.spec.ts` pins that by evaluating every\n * staff permutation and asserting the verdict does not move. The two axes are\n * independent; conflating them would turn a narrow domain control into an\n * accidental SSO mandate for staff, which is explicitly not the policy.\n *\n * These all remain valid, and each has a test:\n *\n * | identity | staff | verdict |\n * | ------------------------------------------ | ----- | ------------------------- |\n * | `@aglyn.com` in the designated tenant | yes | allowed |\n * | personal address, project pool (break-glass)| yes | allowed — permanent design|\n * | personal address, project pool | no | allowed |\n * | SSO identity in a CUSTOMER org's tenant | yes | allowed |\n * | `@aglyn.com` in the PROJECT pool | any | **refused** when enforced |\n *\n * Only the last row is what the switch exists for.\n *\n * ## How this differs from `sso-enforcement.ts`\n *\n * {@link enforceSsoSignInMethods} (AGL-1128/1129) strips non-IdP providers from\n * accounts that are ALREADY INSIDE a tenant. It cannot see an identity that\n * never joined the tenant at all — a project-pool `@aglyn.com` account is\n * invisible to every tenant sweep, by construction. Measured on aglyn-main on\n * 2026-08-18: two such accounts existed, one of them holding a live\n * `google.com` provider. This module covers that outside-the-tenant half.\n *\n * ## Shape note: deliberately NOT a discriminated union\n *\n * `strictNullChecks` is off repo-wide, which defeats boolean-discriminant\n * narrowing — a spec can read the wrong arm of a union and pass silently. So\n * the decision is ONE flat interface with a string `verdict`, and specs assert\n * the literal. There is no arm to read by mistake.\n */\n\n/**\n * ## Self-hosting: this policy is CONFIGURATION, never a compiled-in constant\n *\n * Aglyn ships in two shapes — the Aglyn-operated SaaS, and self-hosted installs\n * on the operator's own Firebase project. `aglyn.com` is *our* Workspace\n * domain; a self-hoster has their own domain, their own IdP, or none at all.\n * Baking our domain in would make the rule dead weight for them at best and a\n * lockout at worst, so the governed set is read from configuration and is\n * **empty by default**.\n *\n * Empty means the rule does nothing. That is simultaneously the correct\n * behaviour for a fresh self-host install and the correct OFF state for us —\n * one default serving both, rather than a special case for either.\n *\n * Format — `domain=tenantId`, comma or whitespace separated:\n *\n * ```\n * AGLYN_SSO_REQUIRED_DOMAINS=\"aglyn.com=aglyn-org-y5v14\"\n * ```\n *\n * A map rather than a bare list because \"must use SSO\" is meaningless without\n * naming WHOSE SSO: the point is IdP lifecycle control, which only the tenant\n * wired to that domain's SAML provider delivers.\n */\nimport { PLATFORM_BRAND_NAME } from '@aglyn/aglyn/app-utils/platform-brand'\n\n/**\n * The block below runs in two places: here, at the session mint, and in the\n * `cloud/functions` account-creation blocking function, which refuses the\n * account before it exists. `cloud/functions` is a plain npm package that can\n * import only firebase-admin and firebase-functions, so it holds a verbatim\n * copy (`cloud/functions/src/sso-domain-policy.ts`), and\n * `apps/console/specs/sso-domain-creation-wiring.spec.ts` fails if the two\n * differ by a single character. Change it here, then copy the region across.\n */\n// #region sso-domain-policy\nexport const SSO_REQUIRED_DOMAINS_ENV = 'AGLYN_SSO_REQUIRED_DOMAINS'\n\nexport type SsoRequiredDomains = Readonly<Record<string, string>>\n\n/**\n * Parse the configured domain→tenant map. Total: anything unparseable is\n * dropped rather than throwing, because this sits on the authentication path\n * and a malformed env var must not take sign-in down. A dropped entry fails\n * OPEN (the domain is simply ungoverned), which is the safe direction for a\n * rule whose only power is to refuse.\n */\nexport function parseSsoRequiredDomains(\n raw: string | null | undefined,\n): SsoRequiredDomains {\n const map: Record<string, string> = {}\n for (const pair of String(raw ?? '').split(/[,\\s]+/)) {\n if (!pair) continue\n const eq = pair.indexOf('=')\n if (eq <= 0) continue\n const domain = pair.slice(0, eq).trim().toLowerCase()\n const tenantId = pair.slice(eq + 1).trim()\n if (!domain || !tenantId) continue\n map[domain] = tenantId\n }\n return map\n}\n\n/**\n * The operator's SSO-required domains. Empty unless configured — see above.\n */\nexport function ssoRequiredDomains(\n env: Record<string, string | undefined> = process.env,\n): SsoRequiredDomains {\n return parseSsoRequiredDomains(env[SSO_REQUIRED_DOMAINS_ENV])\n}\n\n/**\n * Addresses on a governed domain that may still sign in OUTSIDE its tenant.\n *\n * For accounts that cannot use the IdP at all because someone outside the\n * company has to sign in with them: the demo login an app store reviewer is\n * given, for example, or an automated sign-up check that creates a new\n * plus-addressed account on every run. Every exception is named and can be\n * read back from configuration:\n *\n * ```\n * AGLYN_SSO_EXEMPT_EMAILS=\"reviewer@example.com ops+signup-canary*@example.com\"\n * ```\n *\n * An entry is an exact address, or one mailbox's plus tag followed by `*`,\n * which also admits every address that extends that tag on the same domain.\n * The `*` is accepted only as the last character of the local part and only\n * after a `+`, so no entry can exempt a whole mailbox or a whole domain; any\n * other entry with a `*` is dropped.\n *\n * Comma or whitespace separated, compared lower-cased. Empty by default.\n */\nexport const SSO_EXEMPT_EMAILS_ENV = 'AGLYN_SSO_EXEMPT_EMAILS'\n\nexport function parseSsoExemptEmails(\n raw: string | null | undefined,\n): ReadonlySet<string> {\n const emails = new Set<string>()\n for (const entry of String(raw ?? '').split(/[,\\s]+/)) {\n const email = entry.trim().toLowerCase()\n const at = email.lastIndexOf('@')\n if (at <= 0 || at === email.length - 1) continue\n if (email.slice(at + 1).includes('*')) continue\n const local = email.slice(0, at)\n const star = local.indexOf('*')\n if (star !== -1) {\n const plus = local.indexOf('+')\n // One trailing `*`, after a non-empty plus tag: `name+tag*`.\n if (star !== local.length - 1 || plus <= 0 || plus >= star - 1) continue\n }\n emails.add(email)\n }\n return emails\n}\n\n/** Whether an address is named by one of the parsed exemption entries. */\nexport function isSsoExemptEmail(\n email: string | null | undefined,\n exempt: ReadonlySet<string>,\n): boolean {\n const address = String(email ?? '').trim().toLowerCase()\n if (!address) return false\n if (exempt.has(address)) return true\n const at = address.lastIndexOf('@')\n if (at <= 0) return false\n const local = address.slice(0, at)\n const domain = address.slice(at + 1)\n for (const entry of exempt) {\n if (!entry.endsWith(`*@${domain}`)) continue\n if (local.startsWith(entry.slice(0, entry.length - domain.length - 2))) {\n return true\n }\n }\n return false\n}\n\nexport function ssoExemptEmails(\n env: Record<string, string | undefined> = process.env,\n): ReadonlySet<string> {\n return parseSsoExemptEmails(env[SSO_EXEMPT_EMAILS_ENV])\n}\n\nexport type SsoDomainVerdict =\n /** Domain is not governed. Any pool is fine — this is most of the world. */\n | 'allow-ungoverned'\n /** Governed domain, signed in through the tenant we designated for it. */\n | 'allow-designated-tenant'\n /**\n * Governed domain, signed in through SOME tenant, but not the designated\n * one. Allowed — they did use SSO, and refusing would invent a restriction\n * nobody asked for — but surfaced so a staff-access review can see it.\n */\n | 'allow-foreign-tenant'\n /**\n * Governed domain, no tenant, but the address is named in\n * {@link SSO_EXEMPT_EMAILS_ENV}. Allowed and reviewable.\n */\n | 'allow-exempt'\n /**\n * Governed domain with NO tenant at all: a project-pool password or consumer\n * Google sign-in. The only refusal this policy ever produces.\n */\n | 'refuse-sso-required'\n\nexport interface SsoDomainDecision {\n verdict: SsoDomainVerdict\n /**\n * Whether enforcement WOULD refuse this identity. Independent of whether\n * enforcement is currently switched on — {@link ssoDomainEnforcementEnabled}\n * decides that — so the same evaluation can drive both an audit in\n * report-only mode and the refusal once the switch is flipped.\n */\n refused: boolean\n /** Lower-cased domain, or null when the identity has no email address. */\n domain: string | null\n /** Tenant this domain is required to use, or null when ungoverned. */\n requiredTenantId: string | null\n /** Tenant the identity actually signed in through; null = project pool. */\n tenantId: string | null\n /** Worth a human look even though it is allowed (foreign-tenant case). */\n reviewable: boolean\n}\n\nexport interface SsoDomainIdentity {\n /** The identity's email address. Absent/empty is treated as ungoverned. */\n email?: string | null\n /**\n * GCIP tenant the identity signed in through — `decoded.firebase?.tenant`,\n * or a `PooledUserRecord.tenantId`. Null/undefined means the project pool.\n *\n * Never inferred and never defaulted to a hard-coded tenant: a uid is only\n * unique WITHIN a pool, and assuming one is how a lookup silently lands on\n * the wrong record.\n */\n tenantId?: string | null\n}\n\n/** The domain part of an address, lower-cased. Null when there isn't one. */\nexport function domainOf(email: string | null | undefined): string | null {\n const address = String(email ?? '').trim().toLowerCase()\n const at = address.lastIndexOf('@')\n if (at < 0 || at === address.length - 1) return null\n return address.slice(at + 1)\n}\n\n/**\n * Decide the policy for one identity. Pure and total — no Firebase, no env —\n * so a spec can drive every combination directly, and so the audit view and\n * the enforcement path can never disagree about what the policy says.\n */\nexport function evaluateSsoDomainPolicy(\n identity: SsoDomainIdentity,\n domains: SsoRequiredDomains = ssoRequiredDomains(),\n exempt: ReadonlySet<string> = ssoExemptEmails(),\n): SsoDomainDecision {\n const domain = domainOf(identity.email)\n const tenantId = identity.tenantId ?? null\n // Exact-match lookup, never a suffix test: `notaglyn.com` ends with\n // `aglyn.com`, and a suffix test would refuse an unrelated company's staff.\n const requiredTenantId = domain\n ? (Object.prototype.hasOwnProperty.call(domains, domain)\n ? domains[domain]\n : null)\n : null\n\n if (!requiredTenantId) {\n // Ungoverned: a personal address, a customer's address, anything not on\n // the list. Includes the permanent break-glass account by construction\n // rather than by special case — see the staff-access doc.\n return {\n verdict: 'allow-ungoverned',\n refused: false,\n domain,\n requiredTenantId: null,\n tenantId,\n reviewable: false,\n }\n }\n\n if (tenantId === requiredTenantId) {\n return {\n verdict: 'allow-designated-tenant',\n refused: false,\n domain,\n requiredTenantId,\n tenantId,\n reviewable: false,\n }\n }\n\n if (tenantId) {\n // A governed address inside somebody else's tenant. They authenticated\n // through an IdP, so the hole this policy closes is not open here — but\n // the IdP is not one Aglyn controls, so it is flagged for review.\n return {\n verdict: 'allow-foreign-tenant',\n refused: false,\n domain,\n requiredTenantId,\n tenantId,\n reviewable: true,\n }\n }\n\n if (isSsoExemptEmail(identity.email, exempt)) {\n return {\n verdict: 'allow-exempt',\n refused: false,\n domain,\n requiredTenantId,\n tenantId: null,\n reviewable: true,\n }\n }\n\n return {\n verdict: 'refuse-sso-required',\n refused: true,\n domain,\n requiredTenantId,\n tenantId: null,\n reviewable: true,\n }\n}\n\n/**\n * THE ENFORCEMENT SWITCH — ships OFF.\n *\n * Off means `evaluateSsoDomainPolicy` still computes `refused`, and callers\n * still record it, but nobody is turned away. That is deliberate: the audit\n * trail accumulates under the real rule before the rule bites, so flipping the\n * switch holds no surprises.\n *\n * Opt-in by exact string. Anything else — unset, empty, `false`, `0`, a typo —\n * is OFF. A security control that switches itself on through a misspelling is\n * a control that can lock people out through a misspelling.\n *\n * Note both halves must be set for anything to happen: this switch AND a\n * non-empty {@link SSO_REQUIRED_DOMAINS_ENV}. A self-host install that sets\n * only this switch still governs nothing.\n *\n * **Precondition for flipping it — written down so it is not re-litigated:**\n * 1. SSO staff access verified working through a REAL sign-in (not a token\n * inspection): a staff account reaches `/admin/*` via the SAML tenant.\n * 2. Every identity on a governed domain has been migrated into its tenant,\n * retired, or named in {@link SSO_EXEMPT_EMAILS_ENV}. An automation or\n * reviewer account is the one that bites without warning: nobody is\n * watching a sign-in page when it fails.\n *\n * A second staff identity is NOT a precondition: the permanent break-glass\n * account is on an ungoverned domain, so this rule can never refuse it.\n */\nexport const SSO_DOMAIN_ENFORCEMENT_ENV = 'AGLYN_SSO_DOMAIN_ENFORCEMENT'\n\nexport function ssoDomainEnforcementEnabled(\n env: Record<string, string | undefined> = process.env,\n): boolean {\n return env[SSO_DOMAIN_ENFORCEMENT_ENV] === 'on'\n}\n\n/**\n * Whether an account about to be CREATED must be refused. Same switch, same\n * domains, same exemptions as the session mint, so an address the mint would\n * turn away is never created in the first place, and an address it admits\n * is never refused here.\n */\nexport function ssoDomainCreationRefused(\n identity: SsoDomainIdentity,\n env: Record<string, string | undefined> = process.env,\n): boolean {\n if (!ssoDomainEnforcementEnabled(env)) return false\n return evaluateSsoDomainPolicy(\n identity,\n ssoRequiredDomains(env),\n ssoExemptEmails(env),\n ).refused\n}\n// #endregion sso-domain-policy\n\n/**\n * What the refused person is told. Names the fix, not the mechanism.\n *\n * `PLATFORM_BRAND_NAME`, not a literal (AGL-2214). Everything else in this\n * module is careful that the RULE is configuration rather than a compiled-in\n * assumption about Aglyn — and then the one string a refused person actually\n * reads named us anyway. A self-hoster who governs their own domain would\n * have turned their own staff away in our name.\n *\n * Byte-identical for a deployment that has not renamed itself.\n */\nexport const SSO_DOMAIN_REFUSAL_MESSAGE =\n `Sign in with your ${PLATFORM_BRAND_NAME} Workspace account ` +\n '(Single sign-on). Accounts on this domain cannot use a password or ' +\n 'personal Google sign-in.'\n\n/**\n * The refusal a caller should return, or null to carry on.\n *\n * Returns null whenever the switch is off, so wiring this into an\n * authentication path is inert until the account owner flips it — the call site is live,\n * the consequence is not.\n */\nexport function ssoDomainRefusal(\n identity: SsoDomainIdentity,\n env: Record<string, string | undefined> = process.env,\n): { decision: SsoDomainDecision; response: Response } | null {\n const decision = evaluateSsoDomainPolicy(\n identity,\n ssoRequiredDomains(env),\n ssoExemptEmails(env),\n )\n if (!decision.refused) return null\n if (!ssoDomainEnforcementEnabled(env)) return null\n return {\n decision,\n response: Response.json(\n {\n error: SSO_DOMAIN_REFUSAL_MESSAGE,\n reason: 'sso-domain-required',\n domain: decision.domain,\n },\n { status: 403 },\n ),\n }\n}\n\nexport default evaluateSsoDomainPolicy\n"],"names":["PLATFORM_BRAND_NAME","SSO_REQUIRED_DOMAINS_ENV","parseSsoRequiredDomains","raw","map","pair","String","split","eq","indexOf","domain","slice","trim","toLowerCase","tenantId","ssoRequiredDomains","env","process","SSO_EXEMPT_EMAILS_ENV","parseSsoExemptEmails","emails","Set","entry","email","at","lastIndexOf","length","includes","local","star","plus","add","isSsoExemptEmail","exempt","address","has","endsWith","startsWith","ssoExemptEmails","domainOf","evaluateSsoDomainPolicy","identity","domains","requiredTenantId","Object","prototype","hasOwnProperty","call","verdict","refused","reviewable","SSO_DOMAIN_ENFORCEMENT_ENV","ssoDomainEnforcementEnabled","ssoDomainCreationRefused","SSO_DOMAIN_REFUSAL_MESSAGE","ssoDomainRefusal","decision","response","Response","json","error","reason","status"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8CC,GAED;;;;;;;;;;;;;;;;;;;;;;;CAuB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