saaslayer 0.4.1 → 0.4.2
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/bin/saaslayer.js +91 -6
- package/package.json +2 -2
- package/src/api-client.js +3 -2
- package/src/commands/foundation.js +5 -3
- package/src/commands/hooks.js +4 -9
- package/src/commands/release-manifest.js +3 -1
- package/src/commands/settings.js +2 -0
- package/src/commands/sms.js +35 -4
- package/src/commands/sso.js +913 -0
- package/src/commands/users.js +7 -3
- package/src/commands/verifier-keys.js +105 -0
- package/src/login-domain.js +1 -0
- package/src/release-manifest.js +30 -7
- package/src/secret-sink.js +77 -0
- package/src/sms/registration-fields.js +1 -1
- package/src/sso-plan.js +21 -0
- package/src/user-service-instance.js +30 -1
- package/src/users-api.js +3 -2
- package/templates/saaslayer-foundation-region.yml +10 -2
- package/templates/saaslayer-foundation.yml +33 -5
package/src/commands/users.js
CHANGED
|
@@ -108,8 +108,9 @@ const ADMIN_COMMANDS = ['create', 'get', 'list', 'update', 'disable', 'enable',
|
|
|
108
108
|
const USAGE = `usage: saaslayer users <${['export', 'import', ...ADMIN_COMMANDS].join('|')}> … (see saaslayer --help)`
|
|
109
109
|
|
|
110
110
|
/**
|
|
111
|
-
* @typedef {{ stdin?: NodeJS.ReadableStream, log?: (line: string) => void, fetch?: typeof fetch,
|
|
111
|
+
* @typedef {{ stdin?: NodeJS.ReadableStream, log?: (line: string) => void, warn?: (line: string) => void, fetch?: typeof fetch,
|
|
112
112
|
* exchange?: typeof exchangeIamToken, discover?: typeof discoverDeployment, sleep?: (ms: number) => Promise<void> }} AdminDeps
|
|
113
|
+
* warn = where warnings go (default stderr), apart from the printed JSON
|
|
113
114
|
* @typedef {ReturnType<typeof usersApi>} UsersApi
|
|
114
115
|
*/
|
|
115
116
|
|
|
@@ -206,7 +207,8 @@ function updateRequest(attrs) {
|
|
|
206
207
|
* Create a user (a durable operation). --password-stdin gives a permanent password (password initialization: never
|
|
207
208
|
* prod); --delivery invitation mails a temporary one. Re-running the same command replays the same operation (the
|
|
208
209
|
* default Idempotency-Key is derived from the email). A running operation is waited for; a failed component is an
|
|
209
|
-
* error that says to run the same command again, which resumes it.
|
|
210
|
+
* error that says to run the same command again, which resumes it. A warning (e.g. the email's domain signs in through
|
|
211
|
+
* SSO) is printed to stderr and listed in the output; the user is created all the same.
|
|
210
212
|
* @param {UsersApi} api @param {string[]} args @param {Record<string, any>} flags @param {Required<Pick<AdminDeps, 'stdin'|'log'>> & AdminDeps} deps
|
|
211
213
|
*/
|
|
212
214
|
async function create(api, args, flags, deps) {
|
|
@@ -239,7 +241,9 @@ async function create(api, args, flags, deps) {
|
|
|
239
241
|
const op = result.operation
|
|
240
242
|
throw new Error([`users create: operation ${op.id} is ${op.status}; run the same command again to resume it`, ...ops.formatOperation(op).slice(1)].join('\n'))
|
|
241
243
|
}
|
|
242
|
-
|
|
244
|
+
const warnings = result.warnings || []
|
|
245
|
+
for (const w of warnings) (deps.warn || console.error)(`warning: ${w.detail}`)
|
|
246
|
+
return { result, output: { suid: result.user && result.user.id, ...(result.user ? result.user.attributes : {}), operation: result.operation.id, ...(warnings.length ? { warnings: warnings.map((w) => `${w.code}: ${w.detail}`) } : {}) } }
|
|
243
247
|
}
|
|
244
248
|
|
|
245
249
|
/**
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// `saaslayer keys create|list|revoke`: one user-service instance's customer verifier keys, through the control plane's
|
|
2
|
+
// instance proxy (/api/deployments/{id}/services/{ref}/verifier-keys), as the owner's own deployment login of that instance
|
|
3
|
+
// (`saaslayer login --deployment`). A created key is never printed: it goes only to an SSM SecureString in your AWS account
|
|
4
|
+
// (--to-ssm) or a new 0600 file (--to-file), and a key that cannot be stored is revoked.
|
|
5
|
+
'use strict'
|
|
6
|
+
const { resolveInstanceProxy, instanceCall } = require('../user-service-instance')
|
|
7
|
+
const { openSink, writeSecret, discardSink, scrubbed, sinkName, destinationText } = require('../secret-sink')
|
|
8
|
+
|
|
9
|
+
const USAGE = 'usage: saaslayer keys <create|list|revoke> … (see saaslayer --help)'
|
|
10
|
+
const SCOPES = ['trusted-clients', 'token-status']
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @typedef {{ keyId: string, scope: string, status: string, createdAt: string, createdBy: string, revokedAt: string|null, revokedBy: string|null }} VerifierKeyView
|
|
14
|
+
* @typedef {import('../secret-sink').SinkDeps} Deps
|
|
15
|
+
* @typedef {import('../secret-sink').Destination} Destination
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/** @param {Record<string, any>} attrs @returns {VerifierKeyView} */
|
|
19
|
+
const viewOf = (attrs) => {
|
|
20
|
+
const { key, ...view } = attrs
|
|
21
|
+
return /** @type {VerifierKeyView} */ (view)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** @param {VerifierKeyView} k */
|
|
25
|
+
function describe(k) {
|
|
26
|
+
const revoked = k.revokedAt ? `, revoked ${k.revokedAt} by ${k.revokedBy}` : ''
|
|
27
|
+
return `${k.keyId} ${k.scope} ${k.status} created ${k.createdAt} by ${k.createdBy}${revoked}`
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* `keys create --scope S (--to-ssm NAME | --to-file PATH)`: the key travels from the response straight to its sink.
|
|
32
|
+
* @param {Record<string, any>} flags @param {Deps} deps
|
|
33
|
+
* @returns {Promise<{ verifierKey: VerifierKeyView, destination: Destination }>}
|
|
34
|
+
*/
|
|
35
|
+
async function create(flags, deps) {
|
|
36
|
+
if (!SCOPES.includes(flags.scope)) throw new Error(`--scope must be ${SCOPES.join(' or ')}`)
|
|
37
|
+
const sink = openSink(flags, 'a verifier key')
|
|
38
|
+
/** @type {string} */
|
|
39
|
+
let key = ''
|
|
40
|
+
try {
|
|
41
|
+
const scope = await resolveInstanceProxy(flags, 'verifier-keys')
|
|
42
|
+
const doc = await instanceCall('POST', scope.path, { data: { type: 'verifier-keys', attributes: { scope: flags.scope } } }, flags, scope)
|
|
43
|
+
key = String(doc.data.attributes.key || '')
|
|
44
|
+
const verifierKey = viewOf(doc.data.attributes)
|
|
45
|
+
let destination
|
|
46
|
+
try {
|
|
47
|
+
if (!key) throw new Error('the answer held no key')
|
|
48
|
+
destination = await writeSecret(sink, key, { region: scope.deployment.region, description: `SaaSLayer verifier key ${verifierKey.keyId} (${verifierKey.scope}) for ${scope.service} of ${scope.deployment.deploymentId}` }, flags, deps)
|
|
49
|
+
} catch (err) {
|
|
50
|
+
// A key nobody holds must not stay active.
|
|
51
|
+
discardSink(sink)
|
|
52
|
+
const where = sinkName(sink)
|
|
53
|
+
let revoked = 'it was revoked, so nothing holds a lost key'
|
|
54
|
+
try {
|
|
55
|
+
await instanceCall('DELETE', `${scope.path}/${encodeURIComponent(verifierKey.keyId)}`, undefined, flags, scope)
|
|
56
|
+
} catch {
|
|
57
|
+
revoked = `revoking it failed too: run saaslayer keys revoke ${verifierKey.keyId}`
|
|
58
|
+
}
|
|
59
|
+
throw new Error(`could not store verifier key ${verifierKey.keyId} in ${where} (${/** @type {Error} */ (err).message}); ${revoked}`)
|
|
60
|
+
}
|
|
61
|
+
const result = { verifierKey, destination }
|
|
62
|
+
if (flags.json) {
|
|
63
|
+
console.log(JSON.stringify(result, null, 2))
|
|
64
|
+
return result
|
|
65
|
+
}
|
|
66
|
+
console.log(`created verifier key ${verifierKey.keyId} (${verifierKey.scope}) for ${scope.service} of ${scope.deployment.deploymentId}: written to ${destinationText(destination)}; it is never shown`)
|
|
67
|
+
return result
|
|
68
|
+
} catch (err) {
|
|
69
|
+
discardSink(sink)
|
|
70
|
+
throw scrubbed(/** @type {Error} */ (err).message, key)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** `keys list`: ids, scopes and states (a key is never listed). @param {Record<string, any>} flags */
|
|
75
|
+
async function list(flags) {
|
|
76
|
+
const scope = await resolveInstanceProxy(flags, 'verifier-keys')
|
|
77
|
+
const doc = await instanceCall('GET', scope.path, undefined, flags, scope)
|
|
78
|
+
const keys = (doc.data || []).map((/** @type {{ attributes: Record<string, any> }} */ d) => viewOf(d.attributes))
|
|
79
|
+
if (flags.json) console.log(JSON.stringify(keys, null, 2))
|
|
80
|
+
else console.log(keys.length ? keys.map(describe).join('\n') : `no verifier keys on ${scope.service} of ${scope.deployment.deploymentId}`)
|
|
81
|
+
return keys
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** `keys revoke <keyId>`: refused from its next request. @param {string|undefined} keyId @param {Record<string, any>} flags */
|
|
85
|
+
async function revoke(keyId, flags) {
|
|
86
|
+
if (!keyId) throw new Error('usage: saaslayer keys revoke <keyId> [--env E] [--service REF]')
|
|
87
|
+
const scope = await resolveInstanceProxy(flags, 'verifier-keys')
|
|
88
|
+
const doc = await instanceCall('DELETE', `${scope.path}/${encodeURIComponent(keyId)}`, undefined, flags, scope)
|
|
89
|
+
const k = viewOf(doc.data.attributes)
|
|
90
|
+
if (flags.json) console.log(JSON.stringify(k, null, 2))
|
|
91
|
+
else console.log(`verifier key ${k.keyId} (${k.scope}) of ${scope.service} on ${scope.deployment.deploymentId} revoked: its next request is refused`)
|
|
92
|
+
return k
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* @param {string|undefined} sub @param {string[]} positional @param {Record<string, any>} flags @param {Deps} [deps]
|
|
97
|
+
*/
|
|
98
|
+
async function keysCommand(sub, positional, flags, deps = {}) {
|
|
99
|
+
if (sub === 'create') return create(flags, deps)
|
|
100
|
+
if (sub === 'list') return list(flags)
|
|
101
|
+
if (sub === 'revoke') return revoke(positional[0], flags)
|
|
102
|
+
throw new Error(USAGE)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
module.exports = { keysCommand }
|
package/src/login-domain.js
CHANGED
|
@@ -51,6 +51,7 @@ function refusalError(refused, breaks, oldHost) {
|
|
|
51
51
|
const lines = [
|
|
52
52
|
...breaks.providerRedirects.map(({ provider, redirectUri }) => ` - ${provider} redirect URI ${redirectUri}`),
|
|
53
53
|
...breaks.appCallbacks.map((url) => ` - app callback ${url}`),
|
|
54
|
+
...(breaks.ssoRedirects || []).map(({ protocol, url }) => ` - every SSO connection's ${protocol === 'saml' ? 'SAML ACS URL' : 'OIDC redirect URI'} ${url}`),
|
|
54
55
|
` - apps built with SAASLAYER_HOSTED_LOGIN_URL=https://${host} (saaslayer env export) need a rebuild`,
|
|
55
56
|
` - hosted-UI sessions on ${host} sign in once more`,
|
|
56
57
|
' - the issuer does not change',
|
package/src/release-manifest.js
CHANGED
|
@@ -10,6 +10,9 @@ const { SEMVER } = require('./versions')
|
|
|
10
10
|
const MANIFEST_SCHEMA_VERSION = 1
|
|
11
11
|
// The module whose service writes the permission docs direct-mode readers parse, and the setting that picks the format.
|
|
12
12
|
const PERMISSIONS_WRITER = Object.freeze({ module: 'permissions-service', permissionDocSetting: 'PermissionDocV2' })
|
|
13
|
+
// The setting that turns enterprise SSO on: with permissions-service beside it (combo A), removals commit to user-service's
|
|
14
|
+
// live account status, which direct-mode readers must enforce (compatibility.permissions.sso).
|
|
15
|
+
const SSO_CAPABILITY = Object.freeze({ module: 'user-service', setting: 'EnableSso' })
|
|
13
16
|
|
|
14
17
|
const COMMIT_SHA = /^[0-9a-f]{40}$/
|
|
15
18
|
const SHA256 = /^[0-9a-f]{64}$/
|
|
@@ -27,7 +30,7 @@ function directModeContract() {
|
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
/**
|
|
30
|
-
* @typedef {
|
|
33
|
+
* @typedef {import('../../permissions-engine-core/src/direct-mode-contract.js').WriterRelease} WriterRelease
|
|
31
34
|
* @typedef {{ settings: string, settingsSha256?: string }} EnvironmentRef
|
|
32
35
|
* @typedef {{ schemaVersion: 1, name?: string,
|
|
33
36
|
* bundle: { revision: string, version?: string, modules: Record<string, { settingsContractSha256: string }> },
|
|
@@ -104,10 +107,11 @@ function validateManifest(doc) {
|
|
|
104
107
|
if (writer !== undefined) {
|
|
105
108
|
const valid = isObject(writer) && isPositiveInt(writer.decisionEngineContract) && isObject(writer.writes)
|
|
106
109
|
&& isPositiveInt(writer.writes.permissionDoc) && isPositiveInt(writer.writes.registrySnapshot)
|
|
107
|
-
if (!valid) problems.push('compatibility.permissions must be { decisionEngineContract, writes: { permissionDoc, registrySnapshot } } (positive integers)')
|
|
110
|
+
if (!valid) problems.push('compatibility.permissions must be { decisionEngineContract, writes: { permissionDoc, registrySnapshot }, sso? } (positive integers)')
|
|
108
111
|
else {
|
|
109
|
-
onlyFields(writer, ['decisionEngineContract', 'writes'], 'compatibility.permissions.', problems)
|
|
112
|
+
onlyFields(writer, ['decisionEngineContract', 'writes', 'sso'], 'compatibility.permissions.', problems)
|
|
110
113
|
onlyFields(writer.writes, ['permissionDoc', 'registrySnapshot'], 'compatibility.permissions.writes.', problems)
|
|
114
|
+
if (writer.sso !== undefined && !isObject(writer.sso)) problems.push('compatibility.permissions.sso must be an object (checked by the direct-mode preflight)')
|
|
111
115
|
}
|
|
112
116
|
}
|
|
113
117
|
}
|
|
@@ -197,14 +201,23 @@ const short = (sha) => (sha ? sha.slice(0, 7) : '—')
|
|
|
197
201
|
*/
|
|
198
202
|
const permissionDocFormatFor = (value) => (String(value) === 'true' ? 2 : 1)
|
|
199
203
|
|
|
204
|
+
/** Whether an EnableSso value turns SSO on. @param {unknown} value */
|
|
205
|
+
const ssoOn = (value) => String(value) === 'true'
|
|
206
|
+
|
|
200
207
|
/**
|
|
201
|
-
* What a permissions-service deployment at this engine contract writes, given its PermissionDocV2 value
|
|
208
|
+
* What a permissions-service deployment at this engine contract writes, given its PermissionDocV2 value, and with the
|
|
209
|
+
* deployment's user-service EnableSso on (combo A), the account-status and SSO claim contracts its direct readers must enforce.
|
|
202
210
|
* @param {unknown} permissionDocV2
|
|
211
|
+
* @param {unknown} [enableSso] user-service EnableSso
|
|
203
212
|
* @returns {WriterRelease}
|
|
204
213
|
*/
|
|
205
|
-
function permissionsWriterRelease(permissionDocV2) {
|
|
206
|
-
const { DECISION_ENGINE_CONTRACT, READABLE_FORMATS } = directModeContract()
|
|
207
|
-
return {
|
|
214
|
+
function permissionsWriterRelease(permissionDocV2, enableSso) {
|
|
215
|
+
const { DECISION_ENGINE_CONTRACT, READABLE_FORMATS, READABLE_CONTRACTS } = directModeContract()
|
|
216
|
+
return {
|
|
217
|
+
decisionEngineContract: DECISION_ENGINE_CONTRACT,
|
|
218
|
+
writes: { permissionDoc: permissionDocFormatFor(permissionDocV2), registrySnapshot: Math.max(...READABLE_FORMATS.registrySnapshot) },
|
|
219
|
+
...(ssoOn(enableSso) ? { sso: { currentState: 'account-status', accountStatus: Math.max(...READABLE_CONTRACTS.accountStatus), claims: Math.max(...READABLE_CONTRACTS.ssoClaims) } } : {}),
|
|
220
|
+
}
|
|
208
221
|
}
|
|
209
222
|
|
|
210
223
|
/**
|
|
@@ -314,6 +327,15 @@ function preflightManifest({ manifest, env, current, targetSchemas, envPatch, re
|
|
|
314
327
|
add('readers', 'writer_format_mismatch', `${env} writes permissionDoc ${writes} (${PERMISSIONS_WRITER.module}.${name}) but the manifest declares permissionDoc ${release.writes.permissionDoc}`, `set ${PERMISSIONS_WRITER.module}.${name} for ${env} to match the tested release, or re-create the manifest`)
|
|
315
328
|
}
|
|
316
329
|
}
|
|
330
|
+
// SSO in combo A: removals commit to user-service's live account status, so the release must say so and readers are
|
|
331
|
+
// preflighted against it; an undeclared one would let a cached-doc reader pass as immediate cutoff.
|
|
332
|
+
const sso = deployed.get(SSO_CAPABILITY.module)
|
|
333
|
+
const ssoDeclared = sso && sso.settings.find((s) => s.name === SSO_CAPABILITY.setting)
|
|
334
|
+
const ssoPatch = envPatch && envPatch[SSO_CAPABILITY.module] && SSO_CAPABILITY.setting in envPatch[SSO_CAPABILITY.module] ? envPatch[SSO_CAPABILITY.module][SSO_CAPABILITY.setting] : undefined
|
|
335
|
+
const ssoRequested = ssoPatch !== undefined ? ssoPatch : ssoDeclared ? ssoDeclared.value : undefined
|
|
336
|
+
if (ssoOn(ssoRequested) && !(release.sso && release.sso.currentState === 'account-status')) {
|
|
337
|
+
add('readers', 'sso_undeclared', `${env} runs ${SSO_CAPABILITY.module}.${SSO_CAPABILITY.setting} with ${PERMISSIONS_WRITER.module} but the manifest declares no SSO current state for direct-mode readers`, 're-create the manifest from the SSO-enabled tested deployment (it records compatibility.permissions.sso)')
|
|
338
|
+
}
|
|
317
339
|
}
|
|
318
340
|
|
|
319
341
|
if (!reason && PROTECTED_ENVS.has(env)) add('reason', 'reason_required', `${env} is a protected environment: pass --reason <text>`)
|
|
@@ -329,6 +351,7 @@ function preflightManifest({ manifest, env, current, targetSchemas, envPatch, re
|
|
|
329
351
|
module.exports = {
|
|
330
352
|
MANIFEST_SCHEMA_VERSION,
|
|
331
353
|
PERMISSIONS_WRITER,
|
|
354
|
+
SSO_CAPABILITY,
|
|
332
355
|
validateManifest,
|
|
333
356
|
readManifest,
|
|
334
357
|
environmentSettings,
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// Where a secret the CLI is shown once goes (a verifier key, a setup link, a SCIM token): an SSM SecureString in the
|
|
2
|
+
// caller's AWS account (--to-ssm, their credentials) or a new 0600 file (--to-file). Never stdout, stderr or an error message.
|
|
3
|
+
'use strict'
|
|
4
|
+
const fs = require('fs')
|
|
5
|
+
const { awsCredentials } = require('./iam-session')
|
|
6
|
+
const { ssmApi } = require('./ssm-api')
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @typedef {{ kind: 'ssm', name: string } | { kind: 'file', path: string, fd: number }} Sink
|
|
10
|
+
* @typedef {{ ssm: { name: string, region: string, version: number } } | { file: { path: string } }} Destination
|
|
11
|
+
* @typedef {{ credentials?: () => { accessKeyId: string, secretAccessKey: string, sessionToken?: string }, fetch?: typeof fetch }} SinkDeps
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* An error whose message can never carry the secret, whatever produced it.
|
|
16
|
+
* @param {string} message @param {string} secret
|
|
17
|
+
*/
|
|
18
|
+
const scrubbed = (message, secret) => new Error(secret ? message.split(secret).join('[redacted]') : message)
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Where the secret goes, checked before any secret exists: exactly one of --to-ssm and --to-file. A file is created now
|
|
22
|
+
* (exclusively, 0600), so a path that cannot take the secret fails before the secret is made.
|
|
23
|
+
* @param {Record<string, any>} flags @param {string} noun what is stored, e.g. "a verifier key"
|
|
24
|
+
* @returns {Sink}
|
|
25
|
+
*/
|
|
26
|
+
function openSink(flags, noun) {
|
|
27
|
+
const ssm = typeof flags['to-ssm'] === 'string' && flags['to-ssm'] ? flags['to-ssm'] : null
|
|
28
|
+
const file = typeof flags['to-file'] === 'string' && flags['to-file'] ? flags['to-file'] : null
|
|
29
|
+
if (!ssm && !file) throw new Error(`${noun} is never printed: pass --to-ssm <parameter> or --to-file <path>`)
|
|
30
|
+
if (ssm && file) throw new Error('pass exactly one of --to-ssm or --to-file')
|
|
31
|
+
if (ssm) return { kind: 'ssm', name: ssm }
|
|
32
|
+
let fd
|
|
33
|
+
try {
|
|
34
|
+
fd = fs.openSync(/** @type {string} */ (file), 'wx', 0o600)
|
|
35
|
+
} catch (err) {
|
|
36
|
+
if (err && /** @type {{ code?: string }} */ (err).code === 'EEXIST') throw new Error(`${file} already exists: choose a new path (a secret file is never overwritten)`)
|
|
37
|
+
throw new Error(`cannot create ${file}: ${/** @type {Error} */ (err).message}`)
|
|
38
|
+
}
|
|
39
|
+
fs.fchmodSync(fd, 0o600)
|
|
40
|
+
return { kind: 'file', path: /** @type {string} */ (file), fd }
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Write the secret to its sink and answer where it went. An SSM parameter is replaced (the rotation use) in --ssm-region,
|
|
45
|
+
* else `region`.
|
|
46
|
+
* @param {Sink} sink @param {string} secret @param {{ description: string, region: string }} where
|
|
47
|
+
* @param {Record<string, any>} flags @param {SinkDeps} deps
|
|
48
|
+
* @returns {Promise<Destination>}
|
|
49
|
+
*/
|
|
50
|
+
async function writeSecret(sink, secret, where, flags, deps) {
|
|
51
|
+
if (sink.kind === 'file') {
|
|
52
|
+
fs.writeSync(sink.fd, secret)
|
|
53
|
+
fs.closeSync(sink.fd)
|
|
54
|
+
return { file: { path: sink.path } }
|
|
55
|
+
}
|
|
56
|
+
const region = flags['ssm-region'] || where.region
|
|
57
|
+
const call = ssmApi({ region, credentials: deps.credentials || (() => awsCredentials({ profile: flags.profile })), fetchImpl: deps.fetch || fetch })
|
|
58
|
+
const doc = await call('PutParameter', { Name: sink.name, Value: secret, Type: 'SecureString', Overwrite: true, Description: where.description })
|
|
59
|
+
return { ssm: { name: sink.name, region, version: doc.Version } }
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** A sink that will not hold a secret: a created file is removed. @param {Sink} sink */
|
|
63
|
+
function discardSink(sink) {
|
|
64
|
+
if (sink.kind !== 'file') return
|
|
65
|
+
try { fs.closeSync(sink.fd) } catch { /* already closed */ }
|
|
66
|
+
try { fs.unlinkSync(sink.path) } catch { /* nothing to remove */ }
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Where a sink was, for a message. @param {Sink} sink */
|
|
70
|
+
const sinkName = (sink) => (sink.kind === 'ssm' ? `SSM ${sink.name}` : sink.path)
|
|
71
|
+
|
|
72
|
+
/** Where a secret went, for a message. @param {Destination} destination */
|
|
73
|
+
const destinationText = (destination) => ('ssm' in destination
|
|
74
|
+
? `SSM SecureString ${destination.ssm.name} (version ${destination.ssm.version}) in ${destination.ssm.region}`
|
|
75
|
+
: `${destination.file.path} (0600)`)
|
|
76
|
+
|
|
77
|
+
module.exports = { openSink, writeSecret, discardSink, scrubbed, sinkName, destinationText }
|
|
@@ -67,7 +67,7 @@ const FIELDS = [
|
|
|
67
67
|
key: 'useCaseDetails', path: 'messagingUseCase.useCaseDetails', title: 'Use Case Details', type: 'TEXT', required: true,
|
|
68
68
|
derive: (answers) => `${answers.company.name} sends one-time sign-in and account verification codes by SMS to its users who sign in with their phone number. Messages are sent only when the user asks for a code.`,
|
|
69
69
|
},
|
|
70
|
-
{ key: 'optIn.category', path:
|
|
70
|
+
{ key: 'optIn.category', path: 'messagingUseCase.optInType', title: 'Opt-in type', type: 'SELECT', required: false, select: (answer, options) => matchOption(answer || DEFAULT_OPT_IN_CATEGORY, options) },
|
|
71
71
|
{ key: 'optIn.description', path: 'messagingUseCase.optInDescription', title: 'Opt-in Workflow Description', type: 'TEXT', required: true },
|
|
72
72
|
{ key: 'optIn.evidence', path: 'messagingUseCase.optInImage', title: 'Opt-in workflow image', type: 'ATTACHMENT', required: true },
|
|
73
73
|
{ key: 'samples.0', path: 'messageSamples.messageSample1', title: 'Message Sample 1', type: 'TEXT', required: true },
|
package/src/sso-plan.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// The Cognito plan an enterprise SSO deployment runs on: turning user-service EnableSso on moves its pool from Lite to
|
|
2
|
+
// Essentials (managed login), which changes what monthly active users cost; the settings commands say so.
|
|
3
|
+
'use strict'
|
|
4
|
+
|
|
5
|
+
/** What turning SSO on costs, in the words the settings commands print. */
|
|
6
|
+
const SSO_PLAN_NOTE = 'SSO deployments use the Cognito Essentials plan: native-sign-in monthly active users cost $0.015 instead of $0.0055 (10,000 free); SSO users cost $0.015 on every plan.'
|
|
7
|
+
|
|
8
|
+
/** @param {unknown} value */
|
|
9
|
+
const isOn = (value) => value === true || value === 'true'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Whether a user-service patch turns EnableSso on where it is off now.
|
|
13
|
+
* @param {Record<string, unknown>|undefined} values the patch's user-service settings
|
|
14
|
+
* @param {Record<string, { value?: unknown }>|undefined} current the deployment's user-service settings by name
|
|
15
|
+
*/
|
|
16
|
+
function turnsSsoOn(values, current) {
|
|
17
|
+
if (!values || !isOn(values.EnableSso)) return false
|
|
18
|
+
return !isOn(current && current.EnableSso && current.EnableSso.value)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = { SSO_PLAN_NOTE, turnsSsoOn }
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
// The user-service instance of a deployment a command acts on: --service names it (user-service or
|
|
2
2
|
// user-service@<instance>), else the deployment's only one. Several without --service is refused.
|
|
3
3
|
'use strict'
|
|
4
|
+
const { apiCall, jsonApiCall } = require('./api-client')
|
|
5
|
+
const { deploymentBearer } = require('./deployment-auth')
|
|
6
|
+
const { resolveDeployment } = require('./deployments')
|
|
4
7
|
|
|
5
8
|
const USER_SERVICE = 'user-service'
|
|
6
9
|
|
|
@@ -24,4 +27,30 @@ function chooseInstance(detail, flags) {
|
|
|
24
27
|
return instances[0]
|
|
25
28
|
}
|
|
26
29
|
|
|
27
|
-
|
|
30
|
+
/**
|
|
31
|
+
* The deployment (from --env/--region), its chosen user-service instance and the control plane's instance proxy path for
|
|
32
|
+
* one of its resources (/api/deployments/{id}/services/{ref}/{resource}).
|
|
33
|
+
* @param {Record<string, any>} flags @param {string} resource
|
|
34
|
+
* @returns {Promise<{ deployment: Awaited<ReturnType<typeof resolveDeployment>>, service: string, path: string }>}
|
|
35
|
+
*/
|
|
36
|
+
async function resolveInstanceProxy(flags, resource) {
|
|
37
|
+
const deployment = await resolveDeployment(flags)
|
|
38
|
+
const doc = await apiCall('GET', `/api/deployments/${encodeURIComponent(deployment.deploymentId)}`, undefined, flags)
|
|
39
|
+
const service = refOf(/** @type {any} */ (chooseInstance({ deploymentId: deployment.deploymentId, ...doc.data.attributes }, flags)))
|
|
40
|
+
const path = `/api/deployments/${encodeURIComponent(deployment.deploymentId)}/services/${encodeURIComponent(service)}/${resource}`
|
|
41
|
+
return { deployment, service, path }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* A call to the instance proxy as the owner's session of that instance: the deployment login of the addressed deployment
|
|
46
|
+
* and user-service instance (`user-service` is the default one), selected by --as when several exist. Never printed.
|
|
47
|
+
* @param {string} method @param {string} path @param {unknown} body @param {Record<string, any>} flags
|
|
48
|
+
* @param {{ service: string, deployment: { deploymentId: string } }} scope
|
|
49
|
+
*/
|
|
50
|
+
async function instanceCall(method, path, body, flags, scope) {
|
|
51
|
+
const instance = scope.service.includes('@') ? scope.service.slice(scope.service.indexOf('@') + 1) : 'default'
|
|
52
|
+
const session = await deploymentBearer({ deployment: scope.deployment.deploymentId, as: flags.as, 'user-service-instance': instance })
|
|
53
|
+
return jsonApiCall(method, path, body, flags, { headers: { 'X-SaaSLayer-Deployment-Token': session } })
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
module.exports = { chooseInstance, refOf, resolveInstanceProxy, instanceCall }
|
package/src/users-api.js
CHANGED
|
@@ -90,12 +90,13 @@ function usersApi(target, { fetch: fetchImpl = fetch } = {}) {
|
|
|
90
90
|
* Create a user as a durable operation. 201 created, 200 replayed or already provisioned, 202 unfinished (follow the
|
|
91
91
|
* operation, or retry with the same key and body). A password needs users:set-password and EnablePasswordInitialization.
|
|
92
92
|
* @param {CreateAttributes} attributes @param {string} idempotencyKey
|
|
93
|
-
*
|
|
93
|
+
* warnings = notes on the created user (e.g. EMAIL_DOMAIN_USES_SSO), never a refusal.
|
|
94
|
+
* @returns {Promise<{ status: number, user: User|null, operation: Operation, warnings: Array<{ code: string, detail: string }> }>}
|
|
94
95
|
*/
|
|
95
96
|
async create(attributes, idempotencyKey) {
|
|
96
97
|
const attrs = Object.fromEntries(Object.entries(attributes).filter(([, v]) => v !== undefined))
|
|
97
98
|
const { status, body } = await call('POST', '/api/users', { headers: { 'idempotency-key': idempotencyKey }, body: { data: { attributes: attrs } } })
|
|
98
|
-
return { status, user: body.data ? toUser(body.data) : null, operation: body.meta && body.meta.operation }
|
|
99
|
+
return { status, user: body.data ? toUser(body.data) : null, operation: body.meta && body.meta.operation, warnings: (body.meta && body.meta.warnings) || [] }
|
|
99
100
|
},
|
|
100
101
|
/**
|
|
101
102
|
* A create without an Idempotency-Key, to learn whether the caller may create with a supplied suid without writing:
|
|
@@ -61,6 +61,14 @@ Parameters:
|
|
|
61
61
|
The account's SMS sending number in this region: none, a toll-free number (sends once its registration is
|
|
62
62
|
approved), or a simulator number (dev only; delivers to AWS simulator destinations). Set by saaslayer sms setup and
|
|
63
63
|
moved back to none only by saaslayer sms release.
|
|
64
|
+
SmsHelpMessage:
|
|
65
|
+
Type: String
|
|
66
|
+
MinLength: 1
|
|
67
|
+
MaxLength: 160
|
|
68
|
+
Default: 'Account verification and sign-in codes. Msg and data rates may apply. Reply STOP to opt out.'
|
|
69
|
+
Description: >-
|
|
70
|
+
The number's automatic reply when someone texts HELP (carriers expect the sender's name, a contact and how to opt
|
|
71
|
+
out, in one SMS). Set by saaslayer sms setup --help-message; the default is the generic reply.
|
|
64
72
|
|
|
65
73
|
Conditions:
|
|
66
74
|
HasEmailSenderDomain: !Not [!Equals [!Ref EmailSenderDomain, '']]
|
|
@@ -73,7 +81,7 @@ Mappings:
|
|
|
73
81
|
# saaslayer-foundation: major = breaking change (resource replaced/removed), minor = additive, patch = docs.
|
|
74
82
|
Meta:
|
|
75
83
|
FoundationRegion:
|
|
76
|
-
Version: '1.
|
|
84
|
+
Version: '1.3.0'
|
|
77
85
|
|
|
78
86
|
Resources:
|
|
79
87
|
# Shared deployment-artifact bucket. Serverless namespaces every deploy under
|
|
@@ -156,7 +164,7 @@ Resources:
|
|
|
156
164
|
NumberCapabilities: [SMS]
|
|
157
165
|
MandatoryKeywords:
|
|
158
166
|
HELP:
|
|
159
|
-
Message:
|
|
167
|
+
Message: !Ref SmsHelpMessage
|
|
160
168
|
STOP:
|
|
161
169
|
Message: 'You are unsubscribed and will receive no further messages from this number.'
|
|
162
170
|
# The account's default sender; named senders, if any are added, carry their own saaslayer:sender value.
|
|
@@ -136,7 +136,7 @@ Mappings:
|
|
|
136
136
|
# patch = comments/docs/no behavior change
|
|
137
137
|
Meta:
|
|
138
138
|
Foundation:
|
|
139
|
-
Version: '8.
|
|
139
|
+
Version: '8.4.0'
|
|
140
140
|
|
|
141
141
|
Resources:
|
|
142
142
|
# The shared deployment-artifact bucket moved OUT of this account-global stack into the per-region
|
|
@@ -340,6 +340,17 @@ Resources:
|
|
|
340
340
|
Condition:
|
|
341
341
|
StringEquals:
|
|
342
342
|
aws:ResourceTag/managed-by: saaslayer-deployer
|
|
343
|
+
# Custom login domain (user-service UserPoolCustomDomain): Cognito serves it from a CloudFront distribution
|
|
344
|
+
# AWS owns and does not tag, and refuses CreateUserPoolDomain unless the caller may UpdateDistribution on '*'.
|
|
345
|
+
# CalledVia keeps the grant to requests Cognito makes for this role.
|
|
346
|
+
- Effect: Allow
|
|
347
|
+
Action:
|
|
348
|
+
- cloudfront:UpdateDistribution
|
|
349
|
+
Resource: '*'
|
|
350
|
+
Condition:
|
|
351
|
+
ForAnyValue:StringEquals:
|
|
352
|
+
aws:CalledVia:
|
|
353
|
+
- cognito-idp.amazonaws.com
|
|
343
354
|
# managed-by unlocks the deploy role's tag-scoped pool actions, so it can never be added to a pool
|
|
344
355
|
# that does not already carry it (e.g. a customer pool brought in by an import).
|
|
345
356
|
- Effect: Deny
|
|
@@ -777,12 +788,19 @@ Resources:
|
|
|
777
788
|
# Lambda manages the federated IdPs; the PreSignUp/stitching + account Lambdas link/disable
|
|
778
789
|
# providers, set passwords, and delete users. The boundary is the ceiling, so it must allow
|
|
779
790
|
# every action the managed roles use (their inline policies scope the resources).
|
|
780
|
-
|
|
781
|
-
-
|
|
782
|
-
|
|
791
|
+
# Create/Delete/Describe/UpdateIdentityProvider, as one pattern (the template is at CloudFormation's
|
|
792
|
+
# inline size limit). Enterprise SSO (user-service EnableSso, foundation 8.4.0) also manages each
|
|
793
|
+
# connection's dedicated app client (Create/Delete/Describe/UpdateUserPoolClient) and lists both for
|
|
794
|
+
# reconciliation, on the instance's own pool (its role names that pool). Also each SSO client's
|
|
795
|
+
# managed-login branding (Create/Delete/Describe/DescribeByClient/Update) and the login domains' version.
|
|
796
|
+
- cognito-idp:*IdentityProvider
|
|
797
|
+
- cognito-idp:*ManagedLoginBranding*
|
|
798
|
+
- cognito-idp:*UserPoolClient
|
|
799
|
+
- cognito-idp:UpdateUserPoolDomain
|
|
800
|
+
- cognito-idp:ListIdentityProviders
|
|
801
|
+
- cognito-idp:ListUserPoolClients
|
|
783
802
|
- cognito-idp:GetUserPoolMfaConfig
|
|
784
803
|
- cognito-idp:ListUsers
|
|
785
|
-
- cognito-idp:UpdateIdentityProvider
|
|
786
804
|
- dynamodb:BatchGetItem
|
|
787
805
|
- dynamodb:BatchWriteItem
|
|
788
806
|
# TransactWriteItems ConditionCheck items (permissions-service audit writes check erasure markers).
|
|
@@ -917,6 +935,9 @@ Resources:
|
|
|
917
935
|
- cloudformation:UpdateTerminationProtection
|
|
918
936
|
- cloudformation:DeleteChangeSet
|
|
919
937
|
- cloudformation:DeleteStack
|
|
938
|
+
# A module stack left in UPDATE_ROLLBACK_FAILED: the deployer continues its rollback (never skipping
|
|
939
|
+
# a resource), so the stack accepts updates again (8.4.0).
|
|
940
|
+
- cloudformation:ContinueUpdateRollback
|
|
920
941
|
- cloudformation:Describe*
|
|
921
942
|
- cloudformation:Get*
|
|
922
943
|
# Drift gate (update runs refuse to apply over out-of-band edits):
|
|
@@ -1072,6 +1093,13 @@ Resources:
|
|
|
1072
1093
|
Action:
|
|
1073
1094
|
- lambda:UpdateFunctionConfiguration
|
|
1074
1095
|
Resource: !Sub arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${StackNamePrefix}*
|
|
1096
|
+
# Seed re-apply: with SSO on, the user-service seed asks its deployed restApi to re-apply each SSO
|
|
1097
|
+
# connection's Cognito runtime (a direct invocation). Managed-prefix restApi functions only.
|
|
1098
|
+
- Sid: SeedInvokeRestApi
|
|
1099
|
+
Effect: Allow
|
|
1100
|
+
Action:
|
|
1101
|
+
- lambda:InvokeFunction
|
|
1102
|
+
Resource: !Sub arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${StackNamePrefix}*-restApi
|
|
1075
1103
|
# Post-deploy SEED data-plane: after a module deploys, the deployer runs its seed
|
|
1076
1104
|
# script under this role to make the deployment usable — bootstrap the tenant, the
|
|
1077
1105
|
# designated first admin's deployment-administrator binding (and an explicit recovery's
|