saaslayer 0.4.2 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -6
- package/src/commands/operations.js +1 -1
- package/src/commands/users-management.js +2 -2
- package/src/users-import/ids.js +1 -1
- package/vendor/config/login-domain.js +213 -0
- package/vendor/discovery/index.d.mts +109 -0
- package/vendor/discovery/index.mjs +409 -0
- package/vendor/ids/index.d.ts +21 -0
- package/vendor/ids/index.js +237 -0
- package/vendor/migrations/backups.js +118 -0
- package/vendor/migrations/child.js +78 -0
- package/vendor/migrations/credentials.js +103 -0
- package/vendor/migrations/errors.js +30 -0
- package/vendor/migrations/exec-child.js +78 -0
- package/vendor/migrations/gate.js +51 -0
- package/vendor/migrations/index.js +30 -0
- package/vendor/migrations/inventory.js +92 -0
- package/vendor/migrations/log.js +14 -0
- package/vendor/migrations/release.js +45 -0
- package/vendor/migrations/report.js +129 -0
- package/vendor/migrations/rules.js +104 -0
- package/vendor/migrations/run.js +311 -0
- package/vendor/migrations/session-policy.js +37 -0
- package/vendor/migrations/step-guard.js +82 -0
- package/vendor/operations/activity.d.ts +21 -0
- package/vendor/operations/activity.js +126 -0
- package/vendor/operations/index.d.ts +60 -0
- package/vendor/operations/index.js +471 -0
- package/vendor/permissions-engine-core/account-status.js +270 -0
- package/vendor/permissions-engine-core/delegation.js +174 -0
- package/vendor/permissions-engine-core/direct-mode-contract.js +237 -0
- package/vendor/permissions-engine-core/sso-claims.js +206 -0
- package/vendor/user-management/cognito/emails/token-registry.js +48 -0
- package/vendor/user-management/email/validate.js +207 -0
- package/vendor/user-management/extensibility/hook-contract.js +720 -0
- package/vendor/user-management/extensibility/safe-webhook.js +85 -0
- package/vendor/user-management/identity/admission.js +215 -0
- package/vendor/user-management/identity/attr.js +27 -0
- package/vendor/user-management/identity/attribute-registry.js +115 -0
- package/vendor/user-management/identity/email.js +25 -0
- package/vendor/user-management/identity/ensure-suid.js +74 -0
- package/vendor/user-management/identity/pointers.js +192 -0
- package/vendor/user-management/identity/stitch-provider.js +275 -0
- package/vendor/user-management/management/apply-request.js +227 -0
- package/vendor/user-management/management/core-profile.js +110 -0
- package/vendor/user-management/management/index.js +23 -0
- package/vendor/user-management/management/purposes.js +94 -0
- package/vendor/user-management/management/registry.js +569 -0
- package/vendor/user-management/store/table.js +332 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "saaslayer",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "SaaSLayer CLI — onboard an account (init) and register a service's permissions manifest.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"bin": {
|
|
@@ -41,18 +41,17 @@
|
|
|
41
41
|
"access": "public"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
|
-
"test": "node scripts/sync-template.js --check && node scripts/sync-vendor.js --check && node bin/saaslayer.js --help >/dev/null && node test/credentials.test.js && node test/multi-account.test.js && node test/aws.test.js && node test/api-client-refresh.test.js && node test/update.test.js && node test/versions.test.js && node test/migrations-approve.test.js && node test/service-add.test.js && node test/service-remove.test.js && node test/destroy.test.js && node test/settings.test.js && node test/login-methods.test.js && node test/settings-login-domain.test.js && node test/login-domain.test.js && node test/env-compare.test.js && node test/release-manifest.test.js && node test/operations.test.js && node test/projects.test.js && node test/activity.test.js && node test/integration-credentials.test.js && node test/users-management.test.js && node test/deploy.test.js && node test/module-catalog.test.js && node test/stacks.test.js && node test/catalog.test.js && node test/catalog-registry.test.js && node test/permissions-inspect.test.js && node test/permissions-commands.test.js && node test/iam.test.js && node test/machine-trust.test.js && node test/access-admins.test.js && node test/support-staff.test.js && node test/permission-orgs.test.js && node test/first-admin.test.js && node test/social.test.js && node test/hooks.test.js && node test/verifier-keys.test.js && node test/sso.test.js && node test/service-principals.test.js && node test/package-files.test.js && node test/users-export.test.js && node test/users-import.test.js && node test/users-import-checkpoint.test.js && node test/users-import-profiles.test.js && node test/users.test.js && node test/users-api.test.js && node test/migrate.test.js && node test/foundation-template.test.js && node test/trust-entries.test.js && node test/foundation-home.test.js && node test/foundation.test.js && node test/foundation-change-set.test.js && node test/foundation-trust-write.test.js && node test/connection-proof.test.js && node test/aws-connect.test.js && node test/bootstrap-policy.test.js && node test/aws-rotate-trust.test.js && node test/sms-setup.test.js && node test/sms-release.test.js && node test/scope.test.js && node test/discovery.test.js && node test/credential-profiles.test.js && node test/login-challenges.test.js && node test/login-prompt.test.js && node test/control-plane-url.test.js && node test/signup.test.js && node test/org-members.test.js && node test/sms-register.test.js && node test/sms-status.test.js && echo ok && node test/id-token-auth.test.js && node test/trust-policies.test.js && node test/api-keys.test.js && node test/bindings.test.js && node test/binding-handoff.test.js && node test/env-export.test.js && node test/audit-erase.test.js",
|
|
44
|
+
"test": "node scripts/sync-template.js --check && node scripts/sync-vendor.js --check && node bin/saaslayer.js --help >/dev/null && node test/credentials.test.js && node test/multi-account.test.js && node test/aws.test.js && node test/api-client-refresh.test.js && node test/update.test.js && node test/versions.test.js && node test/migrations-approve.test.js && node test/service-add.test.js && node test/service-remove.test.js && node test/destroy.test.js && node test/settings.test.js && node test/login-methods.test.js && node test/settings-login-domain.test.js && node test/login-domain.test.js && node test/env-compare.test.js && node test/release-manifest.test.js && node test/operations.test.js && node test/projects.test.js && node test/activity.test.js && node test/integration-credentials.test.js && node test/users-management.test.js && node test/deploy.test.js && node test/module-catalog.test.js && node test/stacks.test.js && node test/catalog.test.js && node test/catalog-registry.test.js && node test/permissions-inspect.test.js && node test/permissions-commands.test.js && node test/iam.test.js && node test/machine-trust.test.js && node test/access-admins.test.js && node test/support-staff.test.js && node test/permission-orgs.test.js && node test/first-admin.test.js && node test/social.test.js && node test/hooks.test.js && node test/verifier-keys.test.js && node test/sso.test.js && node test/service-principals.test.js && node test/package-files.test.js && node test/pack-release.test.js && node test/vendor-user-management.test.js && node test/users-export.test.js && node test/users-import.test.js && node test/users-import-checkpoint.test.js && node test/users-import-profiles.test.js && node test/users.test.js && node test/users-api.test.js && node test/migrate.test.js && node test/foundation-template.test.js && node test/trust-entries.test.js && node test/foundation-home.test.js && node test/foundation.test.js && node test/foundation-change-set.test.js && node test/foundation-trust-write.test.js && node test/connection-proof.test.js && node test/aws-connect.test.js && node test/bootstrap-policy.test.js && node test/aws-rotate-trust.test.js && node test/sms-setup.test.js && node test/sms-release.test.js && node test/scope.test.js && node test/discovery.test.js && node test/credential-profiles.test.js && node test/login-challenges.test.js && node test/login-prompt.test.js && node test/control-plane-url.test.js && node test/signup.test.js && node test/org-members.test.js && node test/sms-register.test.js && node test/sms-status.test.js && echo ok && node test/id-token-auth.test.js && node test/trust-policies.test.js && node test/api-keys.test.js && node test/bindings.test.js && node test/binding-handoff.test.js && node test/env-export.test.js && node test/audit-erase.test.js",
|
|
45
45
|
"sync-template": "node scripts/sync-template.js",
|
|
46
46
|
"sync-template:check": "node scripts/sync-template.js --check",
|
|
47
47
|
"prepublishOnly": "node scripts/sync-template.js",
|
|
48
|
-
"release:patch": "npm version patch && npm publish",
|
|
49
|
-
"release:minor": "npm version minor && npm publish",
|
|
50
|
-
"release:major": "npm version major && npm publish",
|
|
51
48
|
"test:ddb": "node test/migrate.ddb.test.js",
|
|
52
49
|
"prepack": "node scripts/sync-vendor.js",
|
|
53
|
-
"sync-vendor": "node scripts/sync-vendor.js"
|
|
50
|
+
"sync-vendor": "node scripts/sync-vendor.js",
|
|
51
|
+
"pack:release": "node scripts/pack-release.js"
|
|
54
52
|
},
|
|
55
53
|
"dependencies": {
|
|
54
|
+
"@aws-sdk/client-cognito-identity-provider": "^3.1053.0",
|
|
56
55
|
"@aws-sdk/client-dynamodb": "^3.700.0",
|
|
57
56
|
"@aws-sdk/client-pinpoint-sms-voice-v2": "^3.1147.0",
|
|
58
57
|
"@aws-sdk/client-sts": "^3.1058.0",
|
|
@@ -8,7 +8,7 @@ const { apiCall } = require('../api-client')
|
|
|
8
8
|
const { resolveDeployment } = require('../deployments')
|
|
9
9
|
|
|
10
10
|
// The monorepo source, for running the CLI from a checkout before vendor/ is synced (the published package carries
|
|
11
|
-
// vendor/operations, synced
|
|
11
|
+
// vendor/operations, synced by pack:release).
|
|
12
12
|
const MONOREPO_OPERATIONS = path.join(__dirname, '../../../operations/src')
|
|
13
13
|
|
|
14
14
|
/** A module of the operations package (index by default; activity for the activity feed). @param {string} [file] */
|
|
@@ -10,13 +10,13 @@ const { ssmApi } = require('../ssm-api')
|
|
|
10
10
|
const { awsCredentials } = require('../iam-session')
|
|
11
11
|
|
|
12
12
|
// The monorepo source, for running the CLI from a checkout before vendor/ is synced (the published package carries
|
|
13
|
-
// vendor/user-management, synced
|
|
13
|
+
// vendor/user-management, synced by pack:release).
|
|
14
14
|
const MONOREPO_MANAGEMENT = path.join(__dirname, '../../../../services/user-service/src/management')
|
|
15
15
|
|
|
16
16
|
/** The user-service management package: registry, purposes and the request flow its seed also runs. */
|
|
17
17
|
function loadManagement() {
|
|
18
18
|
try {
|
|
19
|
-
return require('../../vendor/user-management')
|
|
19
|
+
return require('../../vendor/user-management/management')
|
|
20
20
|
} catch (err) {
|
|
21
21
|
if (err && err.code !== 'MODULE_NOT_FOUND') throw err
|
|
22
22
|
return require(MONOREPO_MANAGEMENT)
|
package/src/users-import/ids.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
const path = require('path')
|
|
5
5
|
|
|
6
6
|
// The monorepo source, for running the CLI from a checkout before vendor/ is synced. Resolved at runtime because it
|
|
7
|
-
// is never shipped: the published package carries vendor/ids (synced
|
|
7
|
+
// is never shipped: the published package carries vendor/ids (synced by pack:release).
|
|
8
8
|
const MONOREPO_IDS = path.join(__dirname, '../../../ids/src')
|
|
9
9
|
|
|
10
10
|
function loadIds() {
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
// Hosted-login domain change rules (ADR 0007 E8): which writes change the login host a user-service advertises
|
|
2
|
+
// (ActiveLoginDomain), what is registered against that host (the break list), the refusal unless it is a handoff, and
|
|
3
|
+
// the deployer-owned login-domain settings a user settings write may not name.
|
|
4
|
+
'use strict'
|
|
5
|
+
|
|
6
|
+
/** The user-service setting that names a custom hosted-login domain ('' = none provisioned). */
|
|
7
|
+
const LOGIN_DOMAIN_SETTING = 'CustomCognitoDomainName'
|
|
8
|
+
/** The user-service setting that chooses the advertised login domain: opaque (the prefix domain, default) | custom. */
|
|
9
|
+
const ACTIVE_LOGIN_DOMAIN_SETTING = 'ActiveLoginDomain'
|
|
10
|
+
/** The refusal code the CLI, the control-plane API and the deployer share. */
|
|
11
|
+
const LOGIN_DOMAIN_HANDOFF_REQUIRED = 'LOGIN_DOMAIN_HANDOFF_REQUIRED'
|
|
12
|
+
/** The user-service settings only the deployer writes (saaslayer login-domain): a user settings write is refused. */
|
|
13
|
+
const LOGIN_DOMAIN_MANAGED_SETTINGS = ['CustomCognitoDomainName', 'CustomCognitoDomainCertificateArn', 'ActiveLoginDomain']
|
|
14
|
+
/** The refusal code for a user settings write of a deployer-owned login-domain setting. */
|
|
15
|
+
const LOGIN_DOMAIN_MANAGED_SETTING = 'LOGIN_DOMAIN_MANAGED_SETTING'
|
|
16
|
+
/** The refusal code for an update that would move a custom domain held in the prefix domain resource. */
|
|
17
|
+
const LOGIN_DOMAIN_MIGRATION_REQUIRED = 'LOGIN_DOMAIN_MIGRATION_REQUIRED'
|
|
18
|
+
const USER_SERVICE = 'user-service'
|
|
19
|
+
// Federated identity providers whose console registration holds https://<login host>/oauth2/idpresponse.
|
|
20
|
+
const SOCIAL_PROVIDERS = [['Google', 'EnableGoogleLogin'], ['Facebook', 'EnableFacebookLogin'], ['Amazon', 'EnableAmazonLogin'], ['Apple', 'EnableAppleLogin']]
|
|
21
|
+
const UNKNOWN_HOST = 'the current login domain'
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @typedef {{ providerRedirects: Array<{ provider: string, redirectUri: string }>, appCallbacks: string[],
|
|
25
|
+
* ssoRedirects?: Array<{ protocol: 'saml'|'oidc', url: string }> }} LoginDomainBreaks ssoRedirects: with enterprise SSO on,
|
|
26
|
+
* what every SSO connection's identity provider registers against the login host (SAML ACS URL, OIDC redirect URI)
|
|
27
|
+
* @typedef {{ service: string, fromHost: string|null, toHost: string|null, confirmDomain: string, reason: string, breaks: LoginDomainBreaks }} LoginDomainHandoff
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
const isTrue = (/** @type {unknown} */ value) => value === true || value === 'true'
|
|
31
|
+
const csv = (/** @type {unknown} */ value) => String(value ?? '').split(',').map((item) => item.trim()).filter(Boolean)
|
|
32
|
+
const plural = (/** @type {number} */ count, /** @type {string} */ noun) => `${count} ${noun}${count === 1 ? '' : 's'}`
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A login domain as a comparable host: no scheme, path, trailing dot or case; '' for the opaque default (empty/null).
|
|
36
|
+
* @param {unknown} value
|
|
37
|
+
* @returns {string}
|
|
38
|
+
*/
|
|
39
|
+
function normalizeLoginDomain(value) {
|
|
40
|
+
if (value === undefined || value === null) return ''
|
|
41
|
+
return String(value).trim().toLowerCase().replace(/^https?:\/\//, '').replace(/\/.*$/, '').replace(/\.$/, '')
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The hosted-login host of an opaque Cognito prefix domain in the pool's region.
|
|
46
|
+
* @param {string} prefix the UserPoolDomain prefix (sl-<token>-auth)
|
|
47
|
+
* @param {string} region
|
|
48
|
+
* @returns {string}
|
|
49
|
+
*/
|
|
50
|
+
function opaqueLoginHost(prefix, region) {
|
|
51
|
+
return `${prefix}.auth.${region}.amazoncognito.com`
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** The module a parameter-map key (a service ref like user-service@public) names. @param {string} ref */
|
|
55
|
+
const moduleOf = (ref) => String(ref).split('@')[0]
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The custom domain a user-service ref advertises: its custom name while ActiveLoginDomain=custom, else '' (the opaque
|
|
59
|
+
* prefix domain). A provisioned custom name with ActiveLoginDomain=opaque (the default) is not advertised.
|
|
60
|
+
* @param {Record<string, unknown>|undefined|null} values the ref's settings
|
|
61
|
+
* @returns {string}
|
|
62
|
+
*/
|
|
63
|
+
function activeLoginDomain(values) {
|
|
64
|
+
if (!values || values[ACTIVE_LOGIN_DOMAIN_SETTING] !== 'custom') return ''
|
|
65
|
+
return normalizeLoginDomain(values[LOGIN_DOMAIN_SETTING])
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The login-domain changes a write makes on a standing deployment: each user-service ref whose advertised domain
|
|
70
|
+
* (activeLoginDomain of the stored settings with the write applied; null resets to the default) differs from the
|
|
71
|
+
* stored one. Activate and deactivate are changes; provisioning a custom name while opaque stays advertised,
|
|
72
|
+
* certificate-only and same-host writes are not.
|
|
73
|
+
* @param {{ parameters?: Record<string, Record<string, unknown>|undefined>|null, stored?: Record<string, Record<string, unknown>|undefined> }} input
|
|
74
|
+
* @returns {Array<{ service: string, from: string, to: string }>} from/to are custom domains, '' for the opaque default
|
|
75
|
+
*/
|
|
76
|
+
function loginDomainChanges({ parameters, stored = {} }) {
|
|
77
|
+
const changes = []
|
|
78
|
+
for (const [service, values] of Object.entries(parameters || {})) {
|
|
79
|
+
if (moduleOf(service) !== USER_SERVICE || !values) continue
|
|
80
|
+
const current = stored[service] || {}
|
|
81
|
+
const next = { ...current, ...values }
|
|
82
|
+
for (const [name, value] of Object.entries(values)) if (value === null) delete next[name]
|
|
83
|
+
const from = activeLoginDomain(current)
|
|
84
|
+
const to = activeLoginDomain(next)
|
|
85
|
+
if (from !== to) changes.push({ service, from, to })
|
|
86
|
+
}
|
|
87
|
+
return changes
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The deployer-owned login-domain settings a settings write names, per user-service ref, in request order.
|
|
92
|
+
* @param {Record<string, Record<string, unknown>|undefined>|null|undefined} parameters
|
|
93
|
+
* @returns {Array<{ service: string, setting: string }>}
|
|
94
|
+
*/
|
|
95
|
+
function managedLoginDomainSettings(parameters) {
|
|
96
|
+
return Object.entries(parameters || {})
|
|
97
|
+
.filter(([service, values]) => moduleOf(service) === USER_SERVICE && values)
|
|
98
|
+
.flatMap(([service, values]) => Object.keys(/** @type {Record<string, unknown>} */ (values))
|
|
99
|
+
.filter((setting) => LOGIN_DOMAIN_MANAGED_SETTINGS.includes(setting))
|
|
100
|
+
.map((setting) => ({ service, setting })))
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Refuse a settings write that names a deployer-owned login-domain setting (422 LOGIN_DOMAIN_MANAGED_SETTING).
|
|
105
|
+
* @param {Record<string, Record<string, unknown>|undefined>|null|undefined} parameters
|
|
106
|
+
*/
|
|
107
|
+
function refuseManagedLoginDomainSettings(parameters) {
|
|
108
|
+
const [first] = managedLoginDomainSettings(parameters)
|
|
109
|
+
if (!first) return
|
|
110
|
+
throw Object.assign(new Error(`${first.setting} is set by saaslayer login-domain`), {
|
|
111
|
+
statusCode: 422, code: LOGIN_DOMAIN_MANAGED_SETTING, service: first.service, setting: first.setting,
|
|
112
|
+
})
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* What is registered against the current login host and breaks when it changes: each enabled social provider's
|
|
117
|
+
* redirect URI and the app callback and logout URLs whose sign-in starts there, and with enterprise SSO on (EnableSso) the
|
|
118
|
+
* SAML ACS URL and OIDC redirect URI every SSO connection's identity provider registers. The issuer is not on the list: it
|
|
119
|
+
* names the user pool, not the domain (nor is the SAML entity id). Passkeys are not either: their ceremonies run on the app
|
|
120
|
+
* page against PasswordlessRelyingPartyId, never on the hosted-login host.
|
|
121
|
+
* @param {Record<string, unknown>} settings the ref's current settings
|
|
122
|
+
* @param {string|null} oldHost
|
|
123
|
+
* @returns {LoginDomainBreaks}
|
|
124
|
+
*/
|
|
125
|
+
function loginDomainBreaks(settings, oldHost) {
|
|
126
|
+
const host = oldHost || UNKNOWN_HOST
|
|
127
|
+
const providerRedirects = isTrue(settings.EnableSocialProviders)
|
|
128
|
+
? SOCIAL_PROVIDERS.filter(([, flag]) => isTrue(settings[flag])).map(([provider]) => ({ provider, redirectUri: `https://${host}/oauth2/idpresponse` }))
|
|
129
|
+
: []
|
|
130
|
+
const appCallbacks = [...new Set([...csv(settings.AllowedCallbackUrls), ...csv(settings.AllowedLogoutUrls)])]
|
|
131
|
+
if (!isTrue(settings.EnableSso)) return { providerRedirects, appCallbacks }
|
|
132
|
+
/** @type {Array<{ protocol: 'saml'|'oidc', url: string }>} */
|
|
133
|
+
const ssoRedirects = [{ protocol: 'saml', url: `https://${host}/saml2/idpresponse` }, { protocol: 'oidc', url: `https://${host}/oauth2/idpresponse` }]
|
|
134
|
+
return { providerRedirects, appCallbacks, ssoRedirects }
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* The refusal title: what breaks, and the flags that make the change an explicit handoff.
|
|
139
|
+
* @param {{ oldHost: string|null, breaks: LoginDomainBreaks }} input
|
|
140
|
+
* @returns {string}
|
|
141
|
+
*/
|
|
142
|
+
function loginDomainRefusalMessage({ oldHost, breaks }) {
|
|
143
|
+
const host = oldHost || UNKNOWN_HOST
|
|
144
|
+
const counts = [plural(breaks.providerRedirects.length, 'provider redirect'), plural(breaks.appCallbacks.length, 'app callback')]
|
|
145
|
+
if (breaks.ssoRedirects && breaks.ssoRedirects.length) counts.push('every SSO connection\'s SAML ACS URL and OIDC redirect')
|
|
146
|
+
const listed = counts.length > 2 ? `${counts.slice(0, -1).join(', ')} and ${counts[counts.length - 1]}` : counts.join(' and ')
|
|
147
|
+
return `changing the login domain breaks ${listed} registered against ${host}; pass --confirm-domain ${oldHost || '<current login domain>'} --reason`
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Admit one login-domain change only as an explicit handoff: `domainHandoff` (the acknowledged break list) with the
|
|
152
|
+
* current host typed as `confirmDomain` and a written `reason`. Anything missing, or a typed domain that is not the
|
|
153
|
+
* current host, is refused (409 LOGIN_DOMAIN_HANDOFF_REQUIRED). With an unknown current host (null) only the inputs
|
|
154
|
+
* are checked; the caller that knows the host decides. Returns the acknowledgement to record.
|
|
155
|
+
* @param {{ service: string, oldHost: string|null, newHost: string|null, settings: Record<string, unknown>, domainHandoff: unknown }} input
|
|
156
|
+
* @returns {LoginDomainHandoff}
|
|
157
|
+
*/
|
|
158
|
+
function admitLoginDomainHandoff({ service, oldHost, newHost, settings, domainHandoff }) {
|
|
159
|
+
const breaks = loginDomainBreaks(settings, oldHost)
|
|
160
|
+
const refuse = (/** @type {string} */ suffix = '') => Object.assign(new Error(`${loginDomainRefusalMessage({ oldHost, breaks })}${suffix}`), {
|
|
161
|
+
statusCode: 409, code: LOGIN_DOMAIN_HANDOFF_REQUIRED, service, setting: ACTIVE_LOGIN_DOMAIN_SETTING,
|
|
162
|
+
})
|
|
163
|
+
if (!domainHandoff || typeof domainHandoff !== 'object') throw refuse()
|
|
164
|
+
const { confirmDomain, reason } = /** @type {{ confirmDomain?: unknown, reason?: unknown }} */ (domainHandoff)
|
|
165
|
+
const confirmed = typeof confirmDomain === 'string' ? normalizeLoginDomain(confirmDomain) : ''
|
|
166
|
+
if (!confirmed || typeof reason !== 'string' || !reason.trim()) throw refuse()
|
|
167
|
+
if (oldHost && confirmed !== oldHost) throw refuse(`; ${confirmed} is not the current login domain`)
|
|
168
|
+
return { service, fromHost: oldHost, toHost: newHost, confirmDomain: confirmed, reason: reason.trim(), breaks }
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* The completion checklist for an accepted handoff: the confirmation is an acknowledgement, and the change is complete
|
|
173
|
+
* only when the new host serves and every listed redirect and callback is updated and verified. Apps that baked the old
|
|
174
|
+
* host from `saaslayer env export` need a rebuild, and hosted-UI sessions on the old host sign in once more.
|
|
175
|
+
* @param {LoginDomainHandoff} handoff
|
|
176
|
+
* @returns {string[]}
|
|
177
|
+
*/
|
|
178
|
+
function loginDomainChecklist({ fromHost, toHost, breaks }) {
|
|
179
|
+
const to = toHost || 'the new login domain'
|
|
180
|
+
const from = fromHost || UNKNOWN_HOST
|
|
181
|
+
return [
|
|
182
|
+
`login domain ${from} → ${to}`,
|
|
183
|
+
...breaks.providerRedirects.map(({ provider, redirectUri }) => `update the ${provider} redirect URI ${redirectUri} to https://${to}/oauth2/idpresponse`),
|
|
184
|
+
...breaks.appCallbacks.map((url) => `point the app at ${url} to sign in at https://${to}`),
|
|
185
|
+
...(breaks.ssoRedirects && breaks.ssoRedirects.length
|
|
186
|
+
? [`in every SSO connection's identity provider, register https://${to}/saml2/idpresponse (SAML ACS URL) or https://${to}/oauth2/idpresponse (OIDC redirect URI) beside https://${from}/saml2/idpresponse or https://${from}/oauth2/idpresponse, and keep the old one until the switch is verified (GET /api/sso/connections/{id}/service-provider shows each connection's); the SAML entity id urn:amazon:cognito:sp:<user pool id> does not change`]
|
|
187
|
+
: []),
|
|
188
|
+
`rebuild apps built with SAASLAYER_HOSTED_LOGIN_URL=https://${from} (saaslayer env export) so they sign in at https://${to}`,
|
|
189
|
+
`add https://${to} to each app's Content-Security-Policy connect-src and form-action before the switch (the widget posts tokens there and sign-in forms submit there; a blocked request fails with a generic error); keep https://${from} until the switch is verified`,
|
|
190
|
+
`hosted-UI sessions on ${from} end: users sign in once more at ${to}`,
|
|
191
|
+
'the issuer does not change: tokens keep the same iss (https://cognito-idp.<region>.amazonaws.com/<user pool id>)',
|
|
192
|
+
`the change is complete only when ${to} serves sign-in and every redirect and callback above is updated and verified`,
|
|
193
|
+
]
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
module.exports = {
|
|
197
|
+
LOGIN_DOMAIN_SETTING,
|
|
198
|
+
ACTIVE_LOGIN_DOMAIN_SETTING,
|
|
199
|
+
LOGIN_DOMAIN_HANDOFF_REQUIRED,
|
|
200
|
+
LOGIN_DOMAIN_MANAGED_SETTINGS,
|
|
201
|
+
LOGIN_DOMAIN_MANAGED_SETTING,
|
|
202
|
+
LOGIN_DOMAIN_MIGRATION_REQUIRED,
|
|
203
|
+
normalizeLoginDomain,
|
|
204
|
+
activeLoginDomain,
|
|
205
|
+
opaqueLoginHost,
|
|
206
|
+
loginDomainChanges,
|
|
207
|
+
managedLoginDomainSettings,
|
|
208
|
+
refuseManagedLoginDomainSettings,
|
|
209
|
+
loginDomainBreaks,
|
|
210
|
+
loginDomainRefusalMessage,
|
|
211
|
+
admitLoginDomainHandoff,
|
|
212
|
+
loginDomainChecklist,
|
|
213
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// Types for @saaslayer/discovery: the versioned deployment discovery document and the functions that build, decode,
|
|
2
|
+
// fetch and select it.
|
|
3
|
+
|
|
4
|
+
export declare const DISCOVERY_CONTRACT_VERSION: 2
|
|
5
|
+
/** The contract versions this reader decodes, oldest first. */
|
|
6
|
+
export declare const SUPPORTED_DISCOVERY_VERSIONS: ReadonlyArray<number>
|
|
7
|
+
|
|
8
|
+
export interface DiscoveryOutputSpec {
|
|
9
|
+
field: string
|
|
10
|
+
module: 'user-service' | 'permissions-service'
|
|
11
|
+
output: string
|
|
12
|
+
required: boolean
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export declare const DISCOVERY_OUTPUTS: ReadonlyArray<DiscoveryOutputSpec>
|
|
16
|
+
export declare const DISCOVERY_FIELDS: ReadonlyArray<keyof DeploymentDiscovery>
|
|
17
|
+
/** The environment variables a consumer configures from a discovery document, in print order. */
|
|
18
|
+
export declare const DISCOVERY_ENV_VARS: ReadonlyArray<{
|
|
19
|
+
name: string
|
|
20
|
+
field: 'userPoolId' | 'clientId' | 'region' | 'issuer' | 'jwksUrl' | 'usersApiBase' | 'permissionsApiBase' | 'hostedLoginUrl'
|
|
21
|
+
}>
|
|
22
|
+
|
|
23
|
+
export interface DeploymentDiscovery {
|
|
24
|
+
contractVersion: number
|
|
25
|
+
deploymentId: string
|
|
26
|
+
/** The release revision (commit) the deployment runs. */
|
|
27
|
+
revision: string | null
|
|
28
|
+
region: string
|
|
29
|
+
userPoolId: string
|
|
30
|
+
clientId: string
|
|
31
|
+
/** The `iss` of the deployment's ID tokens. */
|
|
32
|
+
issuer: string
|
|
33
|
+
/** Accepted `aud` values (the deployment's app clients). */
|
|
34
|
+
audience: string[]
|
|
35
|
+
jwksUrl: string
|
|
36
|
+
/** Hosted sign-in (OAuth2 authorization server) base URL. */
|
|
37
|
+
hostedLoginUrl: string
|
|
38
|
+
usersApiBase: string
|
|
39
|
+
permissionsApiBase: string
|
|
40
|
+
/** null when passwordless is off. */
|
|
41
|
+
passwordlessApiBase: string | null
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface ModuleOutputsRecord {
|
|
45
|
+
moduleName: string | null
|
|
46
|
+
serviceInstance?: string | null
|
|
47
|
+
outputs?: Record<string, unknown>
|
|
48
|
+
publicOutputs?: Record<string, unknown>
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface DiscoveryInstances {
|
|
52
|
+
'user-service'?: string
|
|
53
|
+
'permissions-service'?: string
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export type DiscoveryTarget =
|
|
57
|
+
| {
|
|
58
|
+
url: string
|
|
59
|
+
/**
|
|
60
|
+
* Opt-in runtime refresh: look the document up again at most once per this many seconds (e.g. 900), keeping the
|
|
61
|
+
* last-known-good document through a discovery outage. Absent: looked up once and kept.
|
|
62
|
+
*/
|
|
63
|
+
refreshSeconds?: number
|
|
64
|
+
}
|
|
65
|
+
| { apiBase: string; deploymentId: string; instances?: DiscoveryInstances }
|
|
66
|
+
|
|
67
|
+
export type DeploymentDiscoveryErrorCode =
|
|
68
|
+
| 'MODULE_NOT_DEPLOYED' | 'OUTPUT_MISSING' | 'INVALID_OUTPUT' | 'NOT_PUBLIC' | 'INVALID_DOCUMENT'
|
|
69
|
+
| 'UNSUPPORTED_CONTRACT' | 'NOT_FOUND' | 'AMBIGUOUS' | 'UNAVAILABLE'
|
|
70
|
+
|
|
71
|
+
export declare class DeploymentDiscoveryError extends Error {
|
|
72
|
+
constructor(code: string, message: string, extra?: { output?: string; status?: number })
|
|
73
|
+
code: DeploymentDiscoveryErrorCode | string
|
|
74
|
+
/** The missing or invalid output, as `<module>[@<instance>].<Output>`. */
|
|
75
|
+
output?: string
|
|
76
|
+
status?: number
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export declare function deploymentDiscoveryFromModules(input: {
|
|
80
|
+
deploymentId: string
|
|
81
|
+
region?: string | null
|
|
82
|
+
revision?: string | null
|
|
83
|
+
modules: ModuleOutputsRecord[]
|
|
84
|
+
instances?: DiscoveryInstances
|
|
85
|
+
}): DeploymentDiscovery
|
|
86
|
+
|
|
87
|
+
export declare function assertPublicDiscovery<T extends Record<string, unknown>>(doc: T): T
|
|
88
|
+
export declare function decodeDeploymentDiscovery(raw: unknown): DeploymentDiscovery
|
|
89
|
+
/** Throws unless the document decodes under the oldest supported reader; returns it unchanged. */
|
|
90
|
+
export declare function assertPublishableDiscovery<T>(raw: T): T
|
|
91
|
+
export declare function deploymentDiscoveryUrl(target: DiscoveryTarget): string
|
|
92
|
+
export declare function fetchDeploymentDiscovery(target: DiscoveryTarget, options?: { fetch?: typeof fetch }): Promise<DeploymentDiscovery>
|
|
93
|
+
/**
|
|
94
|
+
* A discovery document looked up at first use and kept; with `refreshSeconds`, refreshed in the background at most once
|
|
95
|
+
* per interval, keeping last-known-good through an outage. A first lookup with nothing to fall back on throws
|
|
96
|
+
* `UNAVAILABLE`. `now` is the clock in milliseconds (default Date.now).
|
|
97
|
+
*/
|
|
98
|
+
export declare function createDiscoverySource(
|
|
99
|
+
target: DiscoveryTarget,
|
|
100
|
+
options?: { fetch?: typeof fetch; now?: () => number },
|
|
101
|
+
): { get(): Promise<DeploymentDiscovery> }
|
|
102
|
+
export declare function selectDeployment<T extends { deploymentId: string; customerSlug?: string | null; customerId?: string | null; environment?: string | null; region?: string | null }>(
|
|
103
|
+
rows: T[],
|
|
104
|
+
query: { project: string; environment: string; region?: string },
|
|
105
|
+
): T
|
|
106
|
+
/** A discovery document as environment variables (DISCOVERY_ENV_VARS, in order). */
|
|
107
|
+
export declare function discoveryEnv(doc: DeploymentDiscovery): Record<string, string>
|
|
108
|
+
/** A discovery document as dotenv `KEY=value` lines, quoting only values that need it. */
|
|
109
|
+
export declare function discoveryDotenv(doc: DeploymentDiscovery): string
|