saaslayer 0.3.0 → 0.4.1

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.
Files changed (65) hide show
  1. package/README.md +199 -18
  2. package/bin/saaslayer.js +335 -62
  3. package/package.json +3 -2
  4. package/src/aws-sigv4.js +74 -26
  5. package/src/commands/access-admins.js +2 -2
  6. package/src/commands/admin-allowlist.js +23 -3
  7. package/src/commands/api-keys.js +83 -0
  8. package/src/commands/audit.js +77 -0
  9. package/src/commands/aws.js +355 -82
  10. package/src/commands/binding-handoff.js +174 -0
  11. package/src/commands/bindings.js +111 -0
  12. package/src/commands/catalog.js +30 -3
  13. package/src/commands/deploy.js +49 -11
  14. package/src/commands/env-export.js +58 -0
  15. package/src/commands/first-admin.js +15 -4
  16. package/src/commands/foundation.js +75 -117
  17. package/src/commands/hooks.js +271 -0
  18. package/src/commands/integration-credentials.js +1 -1
  19. package/src/commands/lifecycle.js +149 -24
  20. package/src/commands/login-domain.js +259 -0
  21. package/src/commands/permission-orgs.js +80 -0
  22. package/src/commands/release-manifest.js +17 -8
  23. package/src/commands/service-principals.js +42 -5
  24. package/src/commands/settings.js +21 -5
  25. package/src/commands/sms-registration.js +182 -0
  26. package/src/commands/sms.js +178 -0
  27. package/src/commands/social.js +265 -0
  28. package/src/commands/support-staff.js +72 -0
  29. package/src/commands/users-management.js +2 -20
  30. package/src/commands/users.js +56 -11
  31. package/src/commands/versions.js +61 -0
  32. package/src/connection-proof.js +41 -0
  33. package/src/deployments.js +14 -2
  34. package/src/foundation-change-set.js +180 -0
  35. package/src/foundation-home.js +121 -0
  36. package/src/foundation-template.js +51 -10
  37. package/src/foundation-trust-write.js +379 -0
  38. package/src/iam-session.js +14 -8
  39. package/src/login-domain.js +138 -0
  40. package/src/login-methods.js +118 -0
  41. package/src/module-catalog.js +3 -2
  42. package/src/release-manifest.js +11 -4
  43. package/src/scope.js +3 -1
  44. package/src/settings.js +85 -13
  45. package/src/sms/number.js +37 -0
  46. package/src/sms/registration-fields.js +167 -0
  47. package/src/sms/registration-validate.js +151 -0
  48. package/src/sms/registration.js +216 -0
  49. package/src/sms/release.js +55 -0
  50. package/src/sms/scope.js +86 -0
  51. package/src/sms/status.js +181 -0
  52. package/src/ssm-api.js +31 -0
  53. package/src/trust-entries.js +350 -0
  54. package/src/user-service-instance.js +27 -0
  55. package/src/users-api.js +55 -8
  56. package/src/users-import/checkpoint.js +76 -0
  57. package/src/users-import/import.js +233 -24
  58. package/src/versions.js +80 -0
  59. package/templates/bootstrap/saaslayer-bootstrap-permission-set-inline-policy.json +148 -0
  60. package/templates/bootstrap/saaslayer-bootstrap-policy-email-sender.json +22 -0
  61. package/templates/bootstrap/saaslayer-bootstrap-policy-sms-number.json +22 -0
  62. package/templates/bootstrap/saaslayer-bootstrap-policy.json +114 -0
  63. package/templates/bootstrap/saaslayer-bootstrap-trust-policy.json +18 -0
  64. package/templates/saaslayer-foundation-region.yml +45 -1
  65. package/templates/saaslayer-foundation.yml +759 -309
@@ -10,27 +10,46 @@
10
10
  #
11
11
  # SECURITY REVIEWER SUMMARY
12
12
  #
13
- # This template creates one S3 bucket, one permissions-boundary managed policy, and three IAM roles:
13
+ # This template creates one S3 bucket, one permissions-boundary managed policy, one managed policy attached to the
14
+ # execution role (sl-foundation-cfn-exec-policy), and three IAM roles:
14
15
  #
15
- # 1. SaaSLayerDeploymentRole — the only cross-account WRITE entry point. Assumable solely by the
16
- # SaaSLayer control-plane account (ControlPlaneAccountId parameter) and only with the shared
17
- # ExternalId. It can drive the CloudFormation lifecycle of stacks whose names start with
16
+ # 1. SaaSLayerDeploymentRole — the only cross-account WRITE entry point. Its trust is rendered from
17
+ # the TrustEntries parameter: one statement per managing control plane, each naming only that
18
+ # control plane's account, its deploy identity role (aws:PrincipalArn) and its trust identifiers
19
+ # (sts:ExternalId). It can drive the CloudFormation lifecycle of stacks whose names start with
18
20
  # StackNamePrefix (default "sl-"), read/write the deployment artifact buckets, update the
19
21
  # configuration of StackNamePrefix functions (credential hot-swap), and pass exactly
20
22
  # one role (SaaSLayerCloudFormationExecutionRole) to CloudFormation. It cannot create IAM
21
- # resources or touch anything outside the managed stack namespace directly. Its only
23
+ # resources. Its direct writes reach only StackNamePrefix-named resources (stacks, buckets, tables,
24
+ # functions, log groups, secrets) or resources carrying managed-by=saaslayer-deployer (user pools,
25
+ # KMS keys, ACM certificates, API Gateway custom domains and REST API stages, native-edge CloudFront
26
+ # distributions); it creates certificates, custom domains and distributions only carrying that tag.
27
+ # It may import resources into a stack only through the
28
+ # retained-resource adoption change set (saaslayer-adopt-*) and only the types adoption handles. It
29
+ # also writes /saaslayer/deployment/* SSM parameters (deployment handoff values). Its only
22
30
  # sts:AssumeRole grant is into a module stack's own data-migration role
23
- # (role/${StackNamePrefix}*-migrate), whose policy limits it to that service's tables.
31
+ # (role/${StackNamePrefix}*-migrate), whose policy limits it to that service's tables. It may read
32
+ # exactly one SSM parameter under /saaslayer/foundation: connection-authorizers (below).
24
33
  #
25
34
  # 2. SaaSLayerCloudFormationExecutionRole — assumable ONLY by the CloudFormation service, never
26
35
  # cross-account. CloudFormation uses it to create/update/delete the resources declared by
27
36
  # approved SaaSLayer module templates. Its permissions are the provisioning verbs derived from
28
- # the module resource inventory (see per-statement comments below). Because only
29
- # SaaSLayerDeploymentRole can pass this role, it is reachable exclusively through the audited
30
- # stack lifecycle above.
37
+ # the module resource inventory (see per-statement comments below). Buckets, tables, functions,
38
+ # topics, KMS aliases, IAM roles/policies, SMS configuration sets, alarms, dashboards, event buses
39
+ # and rules, log groups, schedules, SSM parameters, queues and CloudFront functions are scoped to
40
+ # StackNamePrefix names (the alarm-to-queue grants sit in sl-foundation-cfn-exec-policy, attached
41
+ # to this role); user pools, identity pools, KMS keys, CloudFront distributions and secrets to
42
+ # resources carrying managed-by=saaslayer-deployer (created only carrying it, and managed-by can never
43
+ # be added to a user pool that lacks it); API Gateway to the API paths (never custom domains,
44
+ # mappings, the account or VPC links). CloudFront origin access controls (id ARNs, no condition keys)
45
+ # still take Resource '*', as do the Cognito log-delivery verbs and the identity pool role
46
+ # attachment, which take no resource.
47
+ # Because only SaaSLayerDeploymentRole can pass this role, it is reachable exclusively through the
48
+ # audited stack lifecycle above.
31
49
  #
32
50
  # 3. SaaSLayerSupportReadOnlyRole — a separate cross-account READ-ONLY role for SaaSLayer support
33
- # staff. Same account + ExternalId trust gate as the deployment role, plus an enforced
51
+ # staff. Trust rendered from TrustEntries like the deployment role (each control plane's support
52
+ # identity role + trust identifiers), plus an enforced
34
53
  # "saaslayer-support-*" session-name pattern so every assumption is attributable in CloudTrail.
35
54
  # It carries only Get/List/Describe verbs, is tag-scoped to resources carrying
36
55
  # managed-by=saaslayer-deployer where IAM supports resource-tag conditions, and deliberately
@@ -38,6 +57,15 @@
38
57
  # values, no Secrets Manager secret values, no function code downloads). An explicit Deny
39
58
  # (DenySecretValueReads) covers the /saaslayer/deployment/* SecureStrings and their KMS decrypt.
40
59
  #
60
+ # SaaSLayerConnectionAuthorizers is an SSM String parameter publishing ConnectionAuthorizerArns and the
61
+ # control-plane ids in TrustEntries, so a control plane can read who may authorize connections through
62
+ # the deployment role. It holds no secret.
63
+ #
64
+ # TRUST RENDERING: CloudFormation cannot parse JSON, so the SaaSLayer CLI renders the trust statements
65
+ # from TrustEntries into this template before submitting it: each entry role's Statement line below is a
66
+ # single-line JSON flow sequence (empty here, filled at deploy time), and the SSM value's controlPlanes
67
+ # literal is filled the same way. Trust-only edits replace only those lines of the INSTALLED template.
68
+ #
41
69
  # SaaSLayerManagedResourceBoundary is a permissions boundary attached to every IAM role that
42
70
  # SaaSLayer module templates create: whatever a module role's own policy says, its effective
43
71
  # runtime permissions can never exceed this boundary.
@@ -46,11 +74,11 @@
46
74
  # deploymentId, customerId, and moduleName for inventory and audit.
47
75
  #
48
76
  # Contract tests for this template live at tests/bootstrap.test.js (read-only guarantee for the
49
- # support role, external-id enforcement, wildcard justification audit).
77
+ # support role, rendered trust-statement enforcement, wildcard justification audit).
50
78
  AWSTemplateFormatVersion: '2010-09-09'
51
79
  Description: >-
52
- SaaSLayer foundation stack: grants the SaaSLayer control plane scoped, external-ID-gated access
53
- to deploy and support SaaSLayer modules in this account. Installed once per account. Details:
80
+ SaaSLayer foundation stack: grants each managing SaaSLayer control plane listed in TrustEntries scoped,
81
+ trust-identifier-gated access to deploy and support SaaSLayer modules in this account. Installed once per account. Details:
54
82
  https://saaslayer.com/docs/account-access
55
83
 
56
84
  Parameters:
@@ -58,45 +86,38 @@ Parameters:
58
86
  Type: String
59
87
  AllowedPattern: '^[0-9]{12}$'
60
88
  Description: >-
61
- AWS account ID that runs the SaaSLayer deployer control plane. This is the only account the
62
- cross-account roles in this template trust.
63
- ExternalId:
89
+ Initial control-plane AWS account ID (informational). TrustEntries determines each control plane's trust.
90
+ TrustEntries:
64
91
  Type: String
65
- NoEcho: true
92
+ MaxLength: 4096
66
93
  Description: >-
67
- External ID required when assuming SaaSLayerDeploymentRole or SaaSLayerSupportReadOnlyRole.
68
- Shared out-of-band during onboarding; assume-role calls without it are denied.
94
+ JSON v1 entries: controlPlaneId, principalAccountId, trustIdentifiers, deployCallerArns, supportCallerArns. The CLI renders trust; identifiers are ExternalIds, not secrets.
95
+ ConnectionAuthorizerArns:
96
+ Type: CommaDelimitedList
97
+ Description: >-
98
+ Path-less IAM principal ARNs allowed to authorize org connections. Defaults to the installer; changes require an explicit authorizer update.
69
99
  StackNamePrefix:
70
100
  Type: String
71
101
  Default: sl-
72
102
  Description: >-
73
- Prefix for SaaSLayer-managed CloudFormation stacks. The deployment role can only operate on
74
- stacks whose names start with this prefix.
103
+ The deployment role manages only CloudFormation stacks starting with this prefix.
75
104
  OrgId:
76
105
  Type: String
77
106
  Default: ''
78
107
  Description: >-
79
- SaaSLayer org this account is connected to. Informational only — never used in a policy or
80
- trust decision. Surfaced in Outputs so support can identify the account from the stack alone.
108
+ Connected SaaSLayer org (informational output only; never used for authorization).
81
109
  EnableEmailInbound:
82
110
  Type: String
83
111
  AllowedValues: ['true', 'false']
84
112
  Default: 'false'
85
113
  Description: >-
86
- When 'true', grant the SES receipt-rule provisioning + inbound-mail runtime permissions that
87
- email-inbound-service needs. Default 'false' so host accounts that do NOT run email-inbound are
88
- not over-permissioned for SES. Set per host via `cplane accounts enable-capability <host> ses`.
114
+ Inbound SES permissions for email-inbound-service. Enable only on inbound-mail hosts: cplane accounts enable-capability <host> ses.
89
115
  EnableTenantEdge:
90
116
  Type: String
91
117
  AllowedValues: ['true', 'false']
92
118
  Default: 'false'
93
119
  Description: >-
94
- When 'true', grant the CloudFront distribution + edge-Function permissions the NATIVE
95
- single-tenant edge (epic f55t, Model B) provisions in this account. Default 'false' so host
96
- accounts that route through the shared edge are not granted CloudFront write. Set per host via
97
- `cplane accounts enable-capability <host> tenant-edge`.
98
- WARNING (rollout order): a host ALREADY running the native edge must have this enabled BEFORE
99
- its foundation is redeployed at >= 1.1.0, or the redeploy strips the perms its live edge needs.
120
+ Native single-tenant edge CloudFront permissions. Enable: cplane accounts enable-capability <host> tenant-edge. Existing native-edge hosts must enable this before foundation >= 1.1.0 redeploy to preserve permissions.
100
121
 
101
122
  Conditions:
102
123
  # Capability gates. Each maps 1:1 to an entry in @saaslayer/foundation-contract (packages/
@@ -115,7 +136,7 @@ Mappings:
115
136
  # patch = comments/docs/no behavior change
116
137
  Meta:
117
138
  Foundation:
118
- Version: '6.0.0'
139
+ Version: '8.3.0'
119
140
 
120
141
  Resources:
121
142
  # The shared deployment-artifact bucket moved OUT of this account-global stack into the per-region
@@ -141,6 +162,8 @@ Resources:
141
162
  Principal:
142
163
  Service: cloudformation.amazonaws.com
143
164
  Action: sts:AssumeRole
165
+ ManagedPolicyArns:
166
+ - !Ref SaaSLayerCloudFormationExecutionPolicy
144
167
  Policies:
145
168
  - PolicyName: saaslayer-approved-template-execution
146
169
  PolicyDocument:
@@ -149,99 +172,54 @@ Resources:
149
172
  # Provisioning verbs per service. Several AWS create/list APIs only accept
150
173
  # Resource '*'; resource-name namespacing work to tighten this is tracked in
151
174
  # docs/permissions-hardening.md.
175
+ # Services scoped by the managed name prefix or the managed-by tag have their own statements below
176
+ # (alarms, event buses and rules, log groups, schedules, parameters and queues in
177
+ # sl-foundation-cfn-exec-policy). What stays on Resource '*' is reads, creates that take no resource
178
+ # ARN, verbs AWS defines with no resource type, and services not yet scoped (UNSCOPED_PENDING_ON_STAR
179
+ # in tests/bootstrap.test.js, which may only shrink).
152
180
  - Effect: Allow
153
181
  Action:
154
- # API Gateway IAM actions are bare HTTP verbs against untyped resource paths;
155
- # REST API provisioning (methods, resources, deployments, stages, authorizers)
156
- # exercises all of them. Justified service wildcard (tests/bootstrap.test.js).
157
- - apigateway:*
158
182
  # Stack introspection while executing changesets (read-only verbs).
159
183
  - cloudformation:Describe*
160
184
  - cloudformation:Get*
161
185
  - cloudformation:List*
162
- # CloudWatch alarm + dashboard lifecycle for module observability resources.
163
- - cloudwatch:DeleteAlarms
164
- - cloudwatch:DeleteDashboards
186
+ # CloudWatch alarm + dashboard reads for module observability resources. Lifecycle:
187
+ # sl-foundation-cfn-exec-policy (managed prefix).
165
188
  - cloudwatch:DescribeAlarms
166
- - cloudwatch:DisableAlarmActions
167
- - cloudwatch:EnableAlarmActions
168
189
  - cloudwatch:GetDashboard
169
190
  - cloudwatch:ListDashboards
170
191
  # DetectStackDrift reads alarm tags; without this, drift checks on the ops alarms
171
192
  # 403 and block every UPDATE (fail-closed drift gate).
172
193
  - cloudwatch:ListTagsForResource
173
- - cloudwatch:PutDashboard
174
- - cloudwatch:PutMetricAlarm
175
- - cloudwatch:TagResource
176
- - cloudwatch:UntagResource
177
- # CloudFront distribution + origin-access-control lifecycle for static-site modules
178
- # (rbac-admin-ui: private S3 origin + OAC). CreateDistribution/OAC cannot be
179
- # resource-scoped, so these sit in the Resource:'*' statement. CreateInvalidation
180
- # busts the edge cache when a redeploy uploads a new SPA build.
181
- - cloudfront:CreateDistribution
194
+ # Origin access control lifecycle for static-site modules (frontend-hosting, permissions-admin-ui:
195
+ # private S3 origin + OAC): *OriginAccessControl is its Create/Get/Update/Delete (template size). An OAC
196
+ # ARN carries an id and AWS defines no condition key for it, so neither a name nor a tag can scope it.
197
+ # CreateInvalidation busts the edge cache when a redeploy uploads a new SPA build. Distribution
198
+ # lifecycle: tag-scoped statements below.
199
+ - cloudfront:*OriginAccessControl
182
200
  - cloudfront:CreateInvalidation
183
- - cloudfront:CreateOriginAccessControl
184
- - cloudfront:DeleteDistribution
185
- - cloudfront:DeleteOriginAccessControl
186
- - cloudfront:GetDistribution
187
- - cloudfront:GetDistributionConfig
188
- - cloudfront:GetOriginAccessControl
201
+ - cloudfront:GetDistribution*
189
202
  - cloudfront:ListTagsForResource
190
- - cloudfront:TagResource
191
- - cloudfront:UntagResource
192
- - cloudfront:UpdateDistribution
193
- - cloudfront:UpdateOriginAccessControl
194
- # SNS topic lifecycle: module stacks create an ops-alarms topic that
195
- # alarms publish to (lean health checks). Full lifecycle so
196
- # CloudFormation can create/read/tag/delete the managed topics.
197
- - sns:CreateTopic
198
- - sns:DeleteTopic
199
- - sns:GetTopicAttributes
200
- - sns:SetTopicAttributes
201
- - sns:Subscribe
202
- - sns:Unsubscribe
203
- - sns:ListSubscriptionsByTopic
204
- - sns:TagResource
205
- - sns:UntagResource
206
- # Cognito identity pool + user pool lifecycle (user-service module). Their
207
- # CloudFormation handlers exercise a broad, shifting action set; kept as
208
- # justified service wildcards until enumerated (docs/permissions-hardening.md).
209
- - cognito-identity:*
210
- - cognito-idp:*
211
- # DynamoDB table lifecycle (provisioning verbs only — no item read/write).
212
- - dynamodb:CreateTable
213
- - dynamodb:DeleteTable
214
- - dynamodb:DescribeContinuousBackups
215
- - dynamodb:DescribeContributorInsights
216
- - dynamodb:DescribeTable
217
- - dynamodb:DescribeTimeToLive
218
- - dynamodb:ListTagsOfResource
219
- - dynamodb:TagResource
220
- - dynamodb:UntagResource
221
- - dynamodb:UpdateContinuousBackups
222
- - dynamodb:UpdateContributorInsights
223
- - dynamodb:UpdateTable
224
- - dynamodb:UpdateTimeToLive
203
+ # Identity pool calls that take no pool ARN: the pool list and the role attachment (user-service
204
+ # IdentityPoolRoleAttachment). Pool lifecycle: tag-scoped statements below.
205
+ - cognito-identity:ListIdentityPools
206
+ - cognito-identity:SetIdentityPoolRoles
207
+ # User-pool reads that take no resource ARN.
208
+ - cognito-idp:DescribeUserPoolDomain
209
+ - cognito-idp:ListUserPools
225
210
  # EventBridge custom event bus lifecycle (module event buses) + rule lifecycle for
226
211
  # scheduled Lambdas (serverless `schedule` events generate AWS::Events::Rule — e.g.
227
212
  # rbac-service's event-delivery poller). DescribeRule/PutRule/*Targets are required
228
- # or the rule CREATE fails with AccessDenied.
229
- - events:CreateEventBus
230
- - events:DeleteEventBus
231
- - events:DeleteRule
213
+ # or the rule CREATE fails with AccessDenied. Reads here; lifecycle: sl-foundation-cfn-exec-policy.
232
214
  - events:DescribeEventBus
233
215
  - events:DescribeRule
234
- - events:DisableRule
235
- - events:EnableRule
236
216
  - events:ListTagsForResource
237
217
  - events:ListTargetsByRule
238
- - events:PutPermission
239
- - events:PutRule
240
- - events:PutTargets
241
- - events:RemovePermission
242
- - events:RemoveTargets
243
- - events:TagResource
244
- - events:UntagResource
218
+ # EarlyValidation runs a KMS::Alias name-conflict check on change-set creation; without
219
+ # ListAliases it reports a (non-fatal) "not allowed to check if resource already exists"
220
+ # FAIL in the console Hooks view and can't detect a real alias collision. Enumeration API,
221
+ # no resource-level scoping (monorepo-pcren). Key and alias lifecycle: tag/prefix-scoped statements below.
222
+ - kms:ListAliases
245
223
  # IAM read-only introspection during changeset execution. Mutating IAM verbs
246
224
  # (Create/Delete/Update/Attach/Pass/Tag) are prefix-scoped in dedicated
247
225
  # statements below — never Resource '*' — and CreateRole additionally requires
@@ -254,202 +232,284 @@ Resources:
254
232
  - iam:ListEntitiesForPolicy
255
233
  - iam:ListPolicyVersions
256
234
  - iam:ListRolePolicies
257
- # KMS customer-managed key + alias lifecycle. rbac-service provisions an
258
- # EventDeliveryKey (AWS::KMS::Key, rotation on) + alias for webhook payload
259
- # encryption; CreateKey mandates Resource '*', and TagResource on the new key
260
- # is required or CloudFormation fails with UnauthorizedTaggingOperation.
261
- - kms:CreateAlias
262
- - kms:CreateKey
263
- # EarlyValidation runs a KMS::Alias name-conflict check on change-set creation; without
264
- # ListAliases it reports a (non-fatal) "not allowed to check if resource already exists"
265
- # FAIL in the console Hooks view and can't detect a real alias collision. Enumeration API,
266
- # no resource-level scoping (monorepo-pcren).
267
- - kms:ListAliases
268
- # Grant + data-plane actions: a resource encrypted with a customer CMK (email-inbound's
269
- # InboundTable via DynamoDB SSE-KMS) makes the service create a grant AND
270
- # decrypt/generate data keys against the CMK during provisioning — without these the
271
- # table create fails AccessDenied (kms:CreateGrant, then kms:Decrypt/GenerateDataKey).
272
- - kms:CreateGrant
273
- - kms:Decrypt
274
- - kms:DeleteAlias
275
- - kms:DescribeKey
276
- - kms:DisableKeyRotation
277
- - kms:EnableKeyRotation
278
- - kms:Encrypt
279
- - kms:GenerateDataKey
280
- - kms:GenerateDataKeyWithoutPlaintext
281
- - kms:GetKeyPolicy
282
- - kms:GetKeyRotationStatus
283
- - kms:ListGrants
284
- - kms:ListResourceTags
285
- - kms:PutKeyPolicy
286
- - kms:ReEncryptFrom
287
- - kms:ReEncryptTo
288
- - kms:RevokeGrant
289
- - kms:ScheduleKeyDeletion
290
- - kms:TagResource
291
- - kms:UntagResource
292
- - kms:UpdateAlias
293
- # Lambda function/layer/alias/event-source lifecycle. lambda:InvokeFunction is
294
- # required because module templates use CloudFormation custom resources
295
- # (Custom::Delay in user-service) that CloudFormation invokes during deploys.
296
- - lambda:AddPermission
235
+ # Lambda calls that take no function ARN (event-source-mapping create, account and list reads).
236
+ # Function lifecycle: the managed-prefix statement below.
297
237
  - lambda:CreateEventSourceMapping
298
- - lambda:CreateFunction
299
- - lambda:DeleteEventSourceMapping
300
- - lambda:DeleteFunction
301
- - lambda:DeleteFunctionConcurrency
302
- - lambda:DeleteFunctionEventInvokeConfig
303
- - lambda:DeleteLayerVersion
304
- - lambda:DeleteProvisionedConcurrencyConfig
305
238
  - lambda:GetAccountSettings
306
- - lambda:GetAlias
307
239
  - lambda:GetEventSourceMapping
308
- - lambda:GetFunction
309
- - lambda:GetFunctionCodeSigningConfig
310
- - lambda:GetFunctionConcurrency
311
- - lambda:GetFunctionConfiguration
312
- - lambda:GetFunctionEventInvokeConfig
313
- - lambda:GetLayerVersion
314
- - lambda:GetPolicy
315
- - lambda:GetProvisionedConcurrencyConfig
316
- - lambda:GetRuntimeManagementConfig
317
- - lambda:InvokeFunction
318
- - lambda:ListAliases
319
240
  - lambda:ListEventSourceMappings
320
241
  - lambda:ListFunctions
321
242
  - lambda:ListLayerVersions
322
- - lambda:ListTags
323
- - lambda:ListVersionsByFunction
324
- - lambda:PublishLayerVersion
325
- - lambda:PublishVersion
326
- - lambda:PutFunctionCodeSigningConfig
327
- - lambda:PutFunctionConcurrency
328
- - lambda:PutFunctionEventInvokeConfig
329
- - lambda:PutProvisionedConcurrencyConfig
330
- - lambda:RemovePermission
331
- - lambda:TagResource
332
- - lambda:UntagResource
333
- - lambda:UpdateAlias
334
- - lambda:UpdateEventSourceMapping
335
- - lambda:UpdateFunctionCode
336
- - lambda:UpdateFunctionConfiguration
337
- # Log group lifecycle for module functions/services. The LogDelivery and
243
+ # Log group reads for module functions/services. The LogDelivery and
338
244
  # resource-policy verbs support AWS::Cognito::LogDeliveryConfiguration
339
- # (user-service auth event logging).
245
+ # (user-service auth event logging) and take no resource ARN. Log group and metric filter
246
+ # (billing-service ops alarms on its log events) lifecycle: sl-foundation-cfn-exec-policy.
340
247
  - logs:CreateLogDelivery
341
- - logs:CreateLogGroup
342
- - logs:CreateLogStream
343
248
  - logs:DeleteLogDelivery
344
- - logs:DeleteLogGroup
345
- - logs:DeleteLogStream
346
- - logs:DeleteRetentionPolicy
347
249
  - logs:DescribeIndexPolicies
348
250
  - logs:DescribeLogGroups
349
251
  - logs:DescribeLogStreams
252
+ - logs:DescribeMetricFilters
350
253
  - logs:DescribeResourcePolicies
351
254
  - logs:GetLogDelivery
352
255
  - logs:ListLogDeliveries
353
256
  - logs:ListTagsForResource
354
- - logs:PutDestination
355
- - logs:PutDestinationPolicy
356
- - logs:PutLogEvents
357
257
  - logs:PutResourcePolicy
358
- - logs:PutRetentionPolicy
359
- - logs:TagLogGroup
360
- - logs:TagResource
361
- - logs:UntagLogGroup
362
- - logs:UntagResource
363
258
  - logs:UpdateLogDelivery
364
- # EventBridge Scheduler lifecycle for module-declared schedules (rbac-core
365
- # delegation expiry uses schedules; runtime CRUD is granted via the boundary).
366
- - scheduler:CreateSchedule
367
- - scheduler:CreateScheduleGroup
368
- - scheduler:DeleteSchedule
369
- - scheduler:DeleteScheduleGroup
259
+ # EventBridge Scheduler reads for module-declared schedules (rbac-core
260
+ # delegation expiry uses schedules; runtime CRUD is granted via the boundary). Lifecycle:
261
+ # sl-foundation-cfn-exec-policy.
370
262
  - scheduler:GetSchedule
371
263
  - scheduler:GetScheduleGroup
372
264
  - scheduler:ListTagsForResource
373
- - scheduler:TagResource
374
- - scheduler:UntagResource
375
- - scheduler:UpdateSchedule
376
- # Secrets Manager secret lifecycle (AWS::SecretsManager::Secret in modules).
377
- # No GetSecretValue: this role provisions secrets, it cannot read their values.
378
- - secretsmanager:CreateSecret
379
- - secretsmanager:DeleteResourcePolicy
380
- - secretsmanager:DeleteSecret
265
+ # Secret metadata reads. Lifecycle: tag-scoped statements below.
381
266
  - secretsmanager:DescribeSecret
382
267
  - secretsmanager:GetResourcePolicy
383
- - secretsmanager:PutResourcePolicy
268
+ # SSM parameter reads for module configuration exports (AWS::SSM::Parameter). Lifecycle:
269
+ # sl-foundation-cfn-exec-policy.
270
+ - ssm:DescribeParameters
271
+ - ssm:GetParameter
272
+ - ssm:GetParameters
273
+ - ssm:GetParametersByPath
274
+ - ssm:ListTagsForResource
275
+ # SQS queue reads. Lifecycle: sl-foundation-cfn-exec-policy.
276
+ - sqs:GetQueueAttributes
277
+ - sqs:ListQueueTags
278
+ Resource: '*'
279
+ # API Gateway IAM actions are bare HTTP verbs against untyped resource paths; REST, HTTP and
280
+ # WebSocket API provisioning (methods, resources, deployments, stages, authorizers, routes,
281
+ # integrations) exercises all of them. Justified service wildcard (tests/bootstrap.test.js), limited
282
+ # to the API paths and their tags: no module declares a custom domain, base path / API mapping, the
283
+ # account CloudWatch role, a VPC link or a usage plan, so those paths are out of reach. API ids
284
+ # carry no name, and osls tags HTTP APIs only on request, so no prefix or tag condition applies here.
285
+ - Effect: Allow
286
+ Action:
287
+ - apigateway:*
288
+ Resource:
289
+ - !Sub arn:${AWS::Partition}:apigateway:*::/restapis
290
+ - !Sub arn:${AWS::Partition}:apigateway:*::/restapis/*
291
+ - !Sub arn:${AWS::Partition}:apigateway:*::/apis
292
+ - !Sub arn:${AWS::Partition}:apigateway:*::/apis/*
293
+ - !Sub arn:${AWS::Partition}:apigateway:*::/tags/*
294
+ # Cognito user and identity pools (user-service), CloudFront distributions (frontend-hosting,
295
+ # permissions-admin-ui) and secrets (user-service's PasswordlessMagicLinkHmacSecret, named by CloudFormation
296
+ # <LogicalId>-<random>, outside the managed prefix). Pool and distribution ARNs carry ids and the secret's name
297
+ # is not ours, so the managed-by tag scopes all four: created only carrying managed-by=saaslayer-deployer
298
+ # (user-service sets it in UserPoolTags, IdentityPoolTags and the secret's Tags; the modules' stack tags reach
299
+ # distributions and secrets), then changed only while they carry it. The pool and distribution create APIs take no resource
300
+ # ARN. Tags at create need TagResource with the request carrying managed-by; that grant could also stamp
301
+ # managed-by on an existing distribution, identity pool or secret, which this role reaches only through its
302
+ # own stacks (imports are limited to the adoption change set). User pools are guarded by the Deny below.
303
+ - Effect: Allow
304
+ Action:
305
+ - cloudfront:CreateDistribution
306
+ - cloudfront:TagResource
307
+ - cognito-identity:CreateIdentityPool
308
+ - cognito-identity:TagResource
309
+ - cognito-idp:CreateUserPool
310
+ - secretsmanager:CreateSecret
311
+ - secretsmanager:TagResource
312
+ Resource: '*'
313
+ Condition:
314
+ StringEquals:
315
+ aws:RequestTag/managed-by: saaslayer-deployer
316
+ # Each action matches only its own service's ARNs. The pool CloudFormation handlers exercise a broad,
317
+ # shifting action set, so the service wildcards stay, limited to tagged pools. No GetSecretValue: this role
318
+ # provisions secrets, it cannot read their values. *TagResource is TagResource and UntagResource.
319
+ - Effect: Allow
320
+ Action:
321
+ - cloudfront:*TagResource
322
+ - cloudfront:DeleteDistribution
323
+ - cloudfront:UpdateDistribution
324
+ - cognito-identity:*
325
+ - cognito-idp:*
326
+ # Secret verbs as globs (inline policy and template size): *Replica* is RemoveRegionsFromReplication,
327
+ # ReplicateSecretToRegions and StopReplicationToReplica; Update* is UpdateSecret and
328
+ # UpdateSecretVersionStage.
329
+ - secretsmanager:*Replica*
330
+ - secretsmanager:*TagResource
331
+ - secretsmanager:DeleteSecret
384
332
  - secretsmanager:PutSecretValue
385
- - secretsmanager:RemoveRegionsFromReplication
386
- - secretsmanager:ReplicateSecretToRegions
387
333
  - secretsmanager:RestoreSecret
388
- - secretsmanager:StopReplicationToReplica
389
- - secretsmanager:TagResource
390
- - secretsmanager:UntagResource
391
- - secretsmanager:UpdateSecret
392
- - secretsmanager:UpdateSecretVersionStage
393
- # S3 bucket lifecycle + bucket configuration for module buckets, plus object
394
- # read/write used while CloudFormation stages template artifacts.
334
+ - secretsmanager:Update*
335
+ Resource:
336
+ - !Sub arn:${AWS::Partition}:cloudfront::${AWS::AccountId}:distribution/*
337
+ - !Sub arn:${AWS::Partition}:cognito-identity:*:${AWS::AccountId}:identitypool/*
338
+ - !Sub arn:${AWS::Partition}:cognito-idp:*:${AWS::AccountId}:userpool/*
339
+ - !Sub arn:${AWS::Partition}:secretsmanager:*:${AWS::AccountId}:secret:*
340
+ Condition:
341
+ StringEquals:
342
+ aws:ResourceTag/managed-by: saaslayer-deployer
343
+ # managed-by unlocks the deploy role's tag-scoped pool actions, so it can never be added to a pool
344
+ # that does not already carry it (e.g. a customer pool brought in by an import).
345
+ - Effect: Deny
346
+ Action:
347
+ - cognito-idp:TagResource
348
+ Resource: '*'
349
+ Condition:
350
+ ForAnyValue:StringEquals:
351
+ aws:TagKeys:
352
+ - managed-by
353
+ 'Null':
354
+ aws:ResourceTag/managed-by: 'true'
355
+ # DynamoDB table lifecycle (provisioning verbs only — no item read/write). Every module table is
356
+ # ${stackName}-<suffix>, under the managed prefix.
357
+ - Effect: Allow
358
+ Action:
359
+ - dynamodb:CreateTable
360
+ - dynamodb:DeleteTable
361
+ - dynamodb:Describe*
362
+ - dynamodb:ListTagsOfResource
363
+ - dynamodb:TagResource
364
+ - dynamodb:UntagResource
365
+ - dynamodb:UpdateContinuousBackups
366
+ - dynamodb:UpdateContributorInsights
367
+ - dynamodb:UpdateTable
368
+ - dynamodb:UpdateTimeToLive
369
+ # The wildcard also covers the tables' indexes (table/<name>/index/<index>).
370
+ Resource: !Sub arn:${AWS::Partition}:dynamodb:*:${AWS::AccountId}:table/${StackNamePrefix}*
371
+ # KMS customer-managed key + alias lifecycle. rbac-service provisions an
372
+ # EventDeliveryKey (AWS::KMS::Key, rotation on) + alias for webhook payload
373
+ # encryption; CreateKey mandates Resource '*', and TagResource on the new key
374
+ # is required or CloudFormation fails with UnauthorizedTaggingOperation. A key carries no name,
375
+ # so the managed-by tag (a stack tag) scopes it: CreateKey and its tags-at-create need the request
376
+ # to carry managed-by; every other key call needs a key that already carries it.
377
+ - Effect: Allow
378
+ Action:
379
+ - kms:CreateKey
380
+ Resource: '*'
381
+ Condition:
382
+ StringEquals:
383
+ aws:RequestTag/managed-by: saaslayer-deployer
384
+ - Effect: Allow
385
+ Action:
386
+ - kms:TagResource
387
+ Resource: !Sub arn:${AWS::Partition}:kms:*:${AWS::AccountId}:key/*
388
+ Condition:
389
+ StringEquals:
390
+ aws:RequestTag/managed-by: saaslayer-deployer
391
+ # GlobalTable's provider reads the AWS-managed DynamoDB key when SSEEnabled is true without a CMK.
392
+ # AWS-managed keys cannot carry our resource tag; allow metadata only, for this service alias only.
393
+ - Effect: Allow
394
+ Action:
395
+ - kms:DescribeKey
396
+ Resource: !Sub arn:${AWS::Partition}:kms:*:${AWS::AccountId}:key/*
397
+ Condition:
398
+ ForAnyValue:StringEquals:
399
+ kms:ResourceAliases:
400
+ - alias/aws/dynamodb
401
+ # Grant + data-plane actions: a resource encrypted with a customer CMK (email-inbound's
402
+ # InboundTable via DynamoDB SSE-KMS) makes the service create a grant AND
403
+ # decrypt/generate data keys against the CMK during provisioning — without these the
404
+ # table create fails AccessDenied (kms:CreateGrant, then kms:Decrypt/GenerateDataKey).
405
+ # Alias verbs authorize against both the alias (next statement) and its key (here).
406
+ - Effect: Allow
407
+ Action:
408
+ - kms:*Alias
409
+ - kms:CreateGrant
410
+ - kms:Decrypt
411
+ - kms:DescribeKey
412
+ - kms:DisableKeyRotation
413
+ - kms:EnableKeyRotation
414
+ - kms:Encrypt
415
+ - kms:GenerateDataKey*
416
+ - kms:Get*
417
+ - kms:List*
418
+ - kms:PutKeyPolicy
419
+ - kms:ReEncrypt*
420
+ - kms:RevokeGrant
421
+ - kms:ScheduleKeyDeletion
422
+ - kms:TagResource
423
+ - kms:UntagResource
424
+ Resource: !Sub arn:${AWS::Partition}:kms:*:${AWS::AccountId}:key/*
425
+ Condition:
426
+ StringEquals:
427
+ aws:ResourceTag/managed-by: saaslayer-deployer
428
+ - Effect: Allow
429
+ Action:
430
+ - kms:*Alias
431
+ Resource: !Sub arn:${AWS::Partition}:kms:*:${AWS::AccountId}:alias/${StackNamePrefix}*
432
+ # Lambda function/layer/alias/event-source lifecycle. lambda:InvokeFunction is
433
+ # required because module templates use CloudFormation custom resources
434
+ # (Custom::Delay in user-service) that CloudFormation invokes during deploys. Every module
435
+ # function is ${stackName}-<fn> or (email-inbound's pinned custom-resource functions)
436
+ # sl-email-inbound-<stage>-<fn>, under the managed prefix.
437
+ - Effect: Allow
438
+ Action:
439
+ # Get/List/Delete/Put/Update as globs (inline policy size, as for buckets); the resources below
440
+ # keep them on managed-prefix functions and layers.
441
+ - lambda:AddPermission
442
+ - lambda:CreateFunction
443
+ - lambda:Delete*
444
+ - lambda:Get*
445
+ - lambda:InvokeFunction
446
+ - lambda:List*
447
+ - lambda:PublishLayerVersion
448
+ - lambda:PublishVersion
449
+ - lambda:Put*
450
+ - lambda:RemovePermission
451
+ - lambda:TagResource
452
+ - lambda:UntagResource
453
+ - lambda:Update*
454
+ Resource:
455
+ - !Sub arn:${AWS::Partition}:lambda:*:${AWS::AccountId}:function:${StackNamePrefix}*
456
+ - !Sub arn:${AWS::Partition}:lambda:*:${AWS::AccountId}:layer:${StackNamePrefix}*
457
+ # Event source mappings are addressed by id; lambda:FunctionArn limits them to managed-prefix functions.
458
+ - Effect: Allow
459
+ Action:
460
+ - lambda:DeleteEventSourceMapping
461
+ - lambda:UpdateEventSourceMapping
462
+ Resource: !Sub arn:${AWS::Partition}:lambda:*:${AWS::AccountId}:event-source-mapping:*
463
+ Condition:
464
+ ArnLike:
465
+ lambda:FunctionArn: !Sub arn:${AWS::Partition}:lambda:*:${AWS::AccountId}:function:${StackNamePrefix}*
466
+ # Stack tags reach event source mappings; Lambda's tag calls take no lambda:FunctionArn condition. A
467
+ # mapping's tags grant nothing anywhere in this account.
468
+ - Effect: Allow
469
+ Action:
470
+ - lambda:ListTags
471
+ - lambda:TagResource
472
+ - lambda:UntagResource
473
+ Resource: !Sub arn:${AWS::Partition}:lambda:*:${AWS::AccountId}:event-source-mapping:*
474
+ # S3 bucket lifecycle + bucket configuration for module buckets, plus object
475
+ # read/write used while CloudFormation stages template artifacts. Every module bucket, the shared
476
+ # artifacts bucket and the framework's auto-named deployment bucket start with the managed prefix.
477
+ - Effect: Allow
478
+ Action:
479
+ # Bucket configuration verbs as globs (the role's inline policy is near IAM's 10,240-character
480
+ # limit); the resources below keep them on managed-prefix buckets.
395
481
  - s3:CreateBucket
396
- - s3:DeleteBucket
397
- - s3:DeleteBucketPolicy
398
- - s3:DeleteBucketWebsite
482
+ - s3:DeleteBucket*
399
483
  - s3:DeleteObject
400
484
  - s3:GetAccelerateConfiguration
401
- - s3:GetBucketAcl
402
- - s3:GetBucketCORS
403
- - s3:GetBucketLocation
404
- - s3:GetBucketLogging
405
- - s3:GetBucketNotification
406
- - s3:GetBucketObjectLockConfiguration
407
- - s3:GetBucketOwnershipControls
408
- - s3:GetBucketPolicy
409
- - s3:GetBucketPublicAccessBlock
410
- - s3:GetBucketTagging
411
- - s3:GetBucketVersioning
412
- - s3:GetBucketWebsite
485
+ - s3:GetBucket*
413
486
  - s3:GetEncryptionConfiguration
414
487
  - s3:GetLifecycleConfiguration
415
488
  - s3:GetObject
416
489
  - s3:ListBucket
417
490
  - s3:PutAccelerateConfiguration
418
- - s3:PutBucketAcl
419
- - s3:PutBucketCORS
420
- - s3:PutBucketLogging
421
- - s3:PutBucketNotification
422
- - s3:PutBucketObjectLockConfiguration
423
- - s3:PutBucketOwnershipControls
424
- - s3:PutBucketPolicy
425
- - s3:PutBucketPublicAccessBlock
426
- - s3:PutBucketTagging
427
- - s3:PutBucketVersioning
428
- - s3:PutBucketWebsite
491
+ - s3:PutBucket*
429
492
  - s3:PutEncryptionConfiguration
430
493
  - s3:PutLifecycleConfiguration
431
494
  - s3:PutObject
432
495
  - s3:PutObjectAcl
433
- # SSM parameter lifecycle for module configuration exports (AWS::SSM::Parameter).
434
- - ssm:AddTagsToResource
435
- - ssm:DeleteParameter
436
- - ssm:DeleteParameters
437
- - ssm:DescribeParameters
438
- - ssm:GetParameter
439
- - ssm:GetParameters
440
- - ssm:GetParametersByPath
441
- - ssm:ListTagsForResource
442
- - ssm:PutParameter
443
- - ssm:RemoveTagsFromResource
444
- # SQS queue lifecycle (provisioning verbs only — no message send/receive).
445
- - sqs:CreateQueue
446
- - sqs:DeleteQueue
447
- - sqs:GetQueueAttributes
448
- - sqs:ListQueueTags
449
- - sqs:SetQueueAttributes
450
- - sqs:TagQueue
451
- - sqs:UntagQueue
452
- Resource: '*'
496
+ # The wildcard also covers the buckets' objects (<bucket>/<key>).
497
+ Resource: !Sub arn:${AWS::Partition}:s3:::${StackNamePrefix}*
498
+ # SNS topic lifecycle: module stacks create an ops-alarms topic that
499
+ # alarms publish to (lean health checks). Full lifecycle so
500
+ # CloudFormation can create/read/tag/delete the managed topics (${stackName}-ops-alarms).
501
+ - Effect: Allow
502
+ Action:
503
+ - sns:CreateTopic
504
+ - sns:DeleteTopic
505
+ - sns:GetTopicAttributes
506
+ - sns:SetTopicAttributes
507
+ - sns:Subscribe
508
+ - sns:Unsubscribe
509
+ - sns:ListSubscriptionsByTopic
510
+ - sns:TagResource
511
+ - sns:UntagResource
512
+ Resource: !Sub arn:${AWS::Partition}:sns:*:${AWS::AccountId}:${StackNamePrefix}*
453
513
  # Mutating IAM verbs are scoped to the managed-resource prefix (StackNamePrefix) so
454
514
  # the exec role can only create/modify SaaSLayer module roles + customer-managed
455
515
  # policies — never a pre-existing account role, and never the control-plane primitives
@@ -486,6 +546,17 @@ Resources:
486
546
  - iam:TagPolicy
487
547
  - iam:UntagPolicy
488
548
  Resource: !Sub arn:${AWS::Partition}:iam::${AWS::AccountId}:policy/${StackNamePrefix}*
549
+ # Cognito email through SES (user-service CognitoEmailSenderArn → DEVELOPER email): on the first such
550
+ # user pool in an account, Cognito creates its email service-linked role with these credentials
551
+ # (UPDATE failed AccessDenied "allow 'email.cognito-idp.amazonaws.com' to call iam:CreateServiceLinkedRole").
552
+ # Scoped to exactly that service and role path.
553
+ - Effect: Allow
554
+ Action:
555
+ - iam:CreateServiceLinkedRole
556
+ Resource: 'arn:aws:iam::*:role/aws-service-role/email.cognito-idp.amazonaws.com/*'
557
+ Condition:
558
+ StringEquals:
559
+ iam:AWSServiceName: email.cognito-idp.amazonaws.com
489
560
  # Self-protecting Deny (defense-in-depth): the exec role can never mutate the
490
561
  # permissions boundary or the three bootstrap roles, even though prefix scoping
491
562
  # already excludes their SaaSLayer* names. An explicit Deny overrides any Allow.
@@ -504,6 +575,7 @@ Resources:
504
575
  - iam:UpdateRole
505
576
  Resource:
506
577
  - !Ref SaaSLayerManagedResourceBoundary
578
+ - !Ref SaaSLayerCloudFormationExecutionPolicy
507
579
  - !Sub arn:${AWS::Partition}:iam::${AWS::AccountId}:role/sl-foundation-cfn-exec-role
508
580
  - !Sub arn:${AWS::Partition}:iam::${AWS::AccountId}:role/sl-foundation-deploy-role
509
581
  - !Sub arn:${AWS::Partition}:iam::${AWS::AccountId}:role/sl-foundation-support-ro-role
@@ -516,14 +588,22 @@ Resources:
516
588
  - Effect: Allow
517
589
  Action:
518
590
  - cloudfront:CreateFunction
519
- - cloudfront:PublishFunction
520
- - cloudfront:UpdateFunction
521
591
  - cloudfront:DescribeFunction
522
592
  - cloudfront:GetFunction
523
593
  - cloudfront:ListFunctions
524
594
  - cloudfront:ListDistributions
525
595
  Resource: '*'
526
596
  - !Ref AWS::NoValue
597
+ # Function ARNs carry the function name; every edge function is named under the managed prefix
598
+ # (frontend-hosting ${stackName}-<region code>-f, the native edge's sl-strip-<slug>).
599
+ - Fn::If:
600
+ - TenantEdgeEnabled
601
+ - Effect: Allow
602
+ Action:
603
+ - cloudfront:PublishFunction
604
+ - cloudfront:UpdateFunction
605
+ Resource: !Sub arn:${AWS::Partition}:cloudfront::${AWS::AccountId}:function/${StackNamePrefix}*
606
+ - !Ref AWS::NoValue
527
607
  # SES receipt rule set/rule provisioning — only on hosts that run email-inbound
528
608
  # (EnableEmailInbound=true). Identity verification (VerifyDomainIdentity/DKIM) runs
529
609
  # CP-side in the domain-service, never from the tenant account.
@@ -543,6 +623,33 @@ Resources:
543
623
  - ses:DescribeReceiptRule
544
624
  Resource: '*'
545
625
  - !Ref AWS::NoValue
626
+ # Phone sign-in SMS (user-service phone pools): the AWS::SMSVOICE::ConfigurationSet
627
+ # (${stackName}-phoneSms, under the managed prefix) and its AWS::SMSVOICE::ProtectConfiguration
628
+ # (country rule set; AWS-generated id, so not name-scopable). Lifecycle + tag verbs only: no
629
+ # sending, no account-default protect, spend limit, origination identity or registration changes.
630
+ - Effect: Allow
631
+ Action:
632
+ - sms-voice:AssociateProtectConfiguration
633
+ - sms-voice:CreateConfigurationSet
634
+ - sms-voice:CreateProtectConfiguration
635
+ - sms-voice:DeleteConfigurationSet
636
+ - sms-voice:DeleteProtectConfiguration
637
+ - sms-voice:DisassociateProtectConfiguration
638
+ - sms-voice:GetProtectConfigurationCountryRuleSet
639
+ - sms-voice:ListTagsForResource
640
+ - sms-voice:TagResource
641
+ - sms-voice:UntagResource
642
+ - sms-voice:UpdateProtectConfiguration
643
+ - sms-voice:UpdateProtectConfigurationCountryRuleSet
644
+ Resource:
645
+ - !Sub arn:${AWS::Partition}:sms-voice:*:${AWS::AccountId}:configuration-set/${StackNamePrefix}*
646
+ - !Sub arn:${AWS::Partition}:sms-voice:*:${AWS::AccountId}:protect-configuration/*
647
+ # The SMS resources' read handlers enumerate with Describe*, which take no resource scope.
648
+ - Effect: Allow
649
+ Action:
650
+ - sms-voice:DescribeConfigurationSets
651
+ - sms-voice:DescribeProtectConfigurations
652
+ Resource: '*'
546
653
  # Module templates use the AWS::LanguageExtensions transform; CloudFormation
547
654
  # requires CreateChangeSet on the transform pseudo-resource to expand it.
548
655
  - Effect: Allow
@@ -550,6 +657,89 @@ Resources:
550
657
  - cloudformation:CreateChangeSet
551
658
  Resource: !Sub arn:${AWS::Partition}:cloudformation:${AWS::Region}:aws:transform/LanguageExtensions
552
659
 
660
+ # Managed-prefix lifecycle grants of SaaSLayerCloudFormationExecutionRole that do not fit its inline policy (IAM caps a
661
+ # role's inline policies at 10,240 characters in total). Attached to that role only; the role's self-protecting Deny
662
+ # keeps it from changing this policy.
663
+ SaaSLayerCloudFormationExecutionPolicy:
664
+ Type: AWS::IAM::ManagedPolicy
665
+ Properties:
666
+ ManagedPolicyName: sl-foundation-cfn-exec-policy
667
+ Description: Managed-prefix lifecycle of module alarms, event buses and rules, log groups, schedules, parameters and queues.
668
+ PolicyDocument:
669
+ Version: '2012-10-17'
670
+ Statement:
671
+ # Alarm, dashboard, EventBridge bus and rule, log group, schedule, SSM parameter and queue lifecycle. Every
672
+ # module names these from its stack name: alarms ${stackName}-<alarm>, buses ${stackName}-<purpose>, rules
673
+ # ${stackName}-<fn> (unnamed schedule rules get CloudFormation's <stackName>-<LogicalId>-<random>), the schedule
674
+ # group ${stackName}, parameters /${stackName}/..., queues ${stackName}-<purpose>. Log groups are
675
+ # /aws/lambda/<function> (every function is under the managed prefix) and /aws/cognito/${stackName}-logs.
676
+ - Effect: Allow
677
+ Action:
678
+ - cloudwatch:DeleteAlarms
679
+ - cloudwatch:DeleteDashboards
680
+ - cloudwatch:DisableAlarmActions
681
+ - cloudwatch:EnableAlarmActions
682
+ - cloudwatch:PutDashboard
683
+ - cloudwatch:PutMetricAlarm
684
+ - cloudwatch:TagResource
685
+ - cloudwatch:UntagResource
686
+ - events:CreateEventBus
687
+ - events:DeleteEventBus
688
+ - events:DeleteRule
689
+ - events:DisableRule
690
+ - events:EnableRule
691
+ - events:PutRule
692
+ - events:PutTargets
693
+ - events:RemoveTargets
694
+ - events:TagResource
695
+ - events:UntagResource
696
+ - logs:CreateLogGroup
697
+ - logs:CreateLogStream
698
+ - logs:DeleteLogGroup
699
+ - logs:DeleteLogStream
700
+ - logs:DeleteMetricFilter
701
+ - logs:DeleteRetentionPolicy
702
+ - logs:PutDestination
703
+ - logs:PutDestinationPolicy
704
+ - logs:PutLogEvents
705
+ - logs:PutMetricFilter
706
+ - logs:PutRetentionPolicy
707
+ - logs:TagLogGroup
708
+ - logs:TagResource
709
+ - logs:UntagLogGroup
710
+ - logs:UntagResource
711
+ - scheduler:CreateSchedule
712
+ - scheduler:CreateScheduleGroup
713
+ - scheduler:DeleteSchedule
714
+ - scheduler:DeleteScheduleGroup
715
+ - scheduler:TagResource
716
+ - scheduler:UntagResource
717
+ - scheduler:UpdateSchedule
718
+ - ssm:AddTagsToResource
719
+ - ssm:DeleteParameter
720
+ - ssm:DeleteParameters
721
+ - ssm:PutParameter
722
+ - ssm:RemoveTagsFromResource
723
+ - sqs:CreateQueue
724
+ - sqs:DeleteQueue
725
+ - sqs:SetQueueAttributes
726
+ - sqs:TagQueue
727
+ - sqs:UntagQueue
728
+ # Each action matches only its own service's ARNs, so one statement carries every service.
729
+ Resource:
730
+ - !Sub arn:${AWS::Partition}:cloudwatch:*:${AWS::AccountId}:alarm:${StackNamePrefix}*
731
+ - !Sub arn:${AWS::Partition}:cloudwatch::${AWS::AccountId}:dashboard/${StackNamePrefix}*
732
+ - !Sub arn:${AWS::Partition}:events:*:${AWS::AccountId}:event-bus/${StackNamePrefix}*
733
+ - !Sub arn:${AWS::Partition}:events:*:${AWS::AccountId}:event-busv2/${StackNamePrefix}*
734
+ - !Sub arn:${AWS::Partition}:events:*:${AWS::AccountId}:rule/${StackNamePrefix}*
735
+ - !Sub arn:${AWS::Partition}:logs:*:${AWS::AccountId}:log-group:/aws/lambda/${StackNamePrefix}*
736
+ - !Sub arn:${AWS::Partition}:logs:*:${AWS::AccountId}:log-group:/aws/cognito/${StackNamePrefix}*
737
+ - !Sub arn:${AWS::Partition}:logs:*:${AWS::AccountId}:destination:${StackNamePrefix}*
738
+ - !Sub arn:${AWS::Partition}:scheduler:*:${AWS::AccountId}:schedule-group/${StackNamePrefix}*
739
+ - !Sub arn:${AWS::Partition}:scheduler:*:${AWS::AccountId}:schedule/${StackNamePrefix}*
740
+ - !Sub arn:${AWS::Partition}:ssm:*:${AWS::AccountId}:parameter/${StackNamePrefix}*
741
+ - !Sub arn:${AWS::Partition}:sqs:*:${AWS::AccountId}:${StackNamePrefix}*
742
+
553
743
  # Permissions boundary attached to every IAM role created by SaaSLayer module templates (the
554
744
  # deployer passes this policy's ARN into each module deploy). A module role's effective runtime
555
745
  # permissions are the INTERSECTION of its own policy and this boundary, so even a template bug
@@ -595,6 +785,8 @@ Resources:
595
785
  - cognito-idp:UpdateIdentityProvider
596
786
  - dynamodb:BatchGetItem
597
787
  - dynamodb:BatchWriteItem
788
+ # TransactWriteItems ConditionCheck items (permissions-service audit writes check erasure markers).
789
+ - dynamodb:ConditionCheckItem
598
790
  - dynamodb:DeleteItem
599
791
  - dynamodb:DescribeStream
600
792
  - dynamodb:DescribeTable
@@ -672,6 +864,13 @@ Resources:
672
864
  - ses:SendEmail
673
865
  Resource:
674
866
  - !Sub arn:${AWS::Partition}:ses:*:${AWS::AccountId}:identity/*
867
+ # Phone sign-in SMS: Cognito sends through a user-service phone pool's SMS caller role. Send only; the
868
+ # role's own policy scopes it to its configuration set and origination identity.
869
+ - Effect: Allow
870
+ Action:
871
+ - sms-voice:SendTextMessage
872
+ Resource:
873
+ - !Sub arn:${AWS::Partition}:sms-voice:*:${AWS::AccountId}:*
675
874
  # SES runtime (forward/notify sends + the active-rule-set custom resource) — only on hosts
676
875
  # that run email-inbound. Receiving into S3 is granted to the ses.amazonaws.com service
677
876
  # principal by the module's bucket policy, not here.
@@ -687,8 +886,9 @@ Resources:
687
886
  Resource: '*'
688
887
  - !Ref AWS::NoValue
689
888
 
690
- # Cross-account WRITE entry point for the SaaSLayer control plane. Trust is double-gated: only
691
- # the control-plane account, and only with the shared external ID. Every mutating grant is scoped
889
+ # Cross-account WRITE entry point for the managing SaaSLayer control planes. Trust is rendered from
890
+ # TrustEntries: per control plane, only its account, only its deploy identity role (aws:PrincipalArn) and
891
+ # only with its trust identifier (sts:ExternalId). Every mutating grant is scoped
692
892
  # to the SaaSLayer stack namespace (StackNamePrefix) or the deployment artifact buckets; resource
693
893
  # creation itself always happens through CloudFormation with the execution role above.
694
894
  SaaSLayerDeploymentRole:
@@ -697,14 +897,7 @@ Resources:
697
897
  RoleName: sl-foundation-deploy-role
698
898
  AssumeRolePolicyDocument:
699
899
  Version: '2012-10-17'
700
- Statement:
701
- - Effect: Allow
702
- Principal:
703
- AWS: !Sub arn:aws:iam::${ControlPlaneAccountId}:root
704
- Action: sts:AssumeRole
705
- Condition:
706
- StringEquals:
707
- sts:ExternalId: !Ref ExternalId
900
+ Statement: []
708
901
  Policies:
709
902
  - PolicyName: saaslayer-stack-lifecycle
710
903
  PolicyDocument:
@@ -731,6 +924,37 @@ Resources:
731
924
  - cloudformation:DetectStackDrift
732
925
  - cloudformation:DetectStackResourceDrift
733
926
  Resource: !Sub arn:aws:cloudformation:${AWS::Region}:${AWS::AccountId}:stack/${StackNamePrefix}*
927
+ # Resource import (foundation 8.0.0): only the retained-resource adoption path imports
928
+ # (src/retained-adoption.ts, change set saaslayer-adopt-<runId>), and only the resource types it
929
+ # adopts. CloudFormation has no change-set-type condition key; cloudformation:ImportResourceTypes is
930
+ # present exactly when a change set imports.
931
+ - Sid: DenyImportsOutsideAdoption
932
+ Effect: Deny
933
+ Action:
934
+ - cloudformation:CreateChangeSet
935
+ Resource: '*'
936
+ Condition:
937
+ 'Null':
938
+ cloudformation:ImportResourceTypes: 'false'
939
+ StringNotLike:
940
+ cloudformation:ChangeSetName: saaslayer-adopt-*
941
+ - Sid: DenyImportOfUnadoptableTypes
942
+ Effect: Deny
943
+ Action:
944
+ - cloudformation:CreateChangeSet
945
+ Resource: '*'
946
+ Condition:
947
+ ForAnyValue:StringNotEquals:
948
+ cloudformation:ImportResourceTypes:
949
+ - AWS::DynamoDB::Table
950
+ - AWS::DynamoDB::GlobalTable
951
+ - AWS::Cognito::UserPool
952
+ - AWS::Cognito::UserPoolClient
953
+ - AWS::Cognito::UserPoolGroup
954
+ - AWS::Cognito::IdentityPool
955
+ - AWS::S3::Bucket
956
+ - AWS::KMS::Key
957
+ - AWS::SecretsManager::Secret
734
958
  # Actions the API cannot scope to a stack ARN: ValidateTemplate, and the
735
959
  # drift-detection status poll which operates on a detection id, not a stack.
736
960
  - Effect: Allow
@@ -738,6 +962,14 @@ Resources:
738
962
  - cloudformation:ValidateTemplate
739
963
  - cloudformation:DescribeStackDriftDetectionStatus
740
964
  Resource: '*'
965
+ # Connection authorization metadata (ADR 0005 §4): the control plane reads who may authorize
966
+ # SaaSLayer connections to this account through this role. Exactly one parameter, in this
967
+ # stack's (home) region; it holds role ARNs and control-plane ids, no secret.
968
+ - Sid: ReadConnectionAuthorizers
969
+ Effect: Allow
970
+ Action:
971
+ - ssm:GetParameter
972
+ Resource: !Sub arn:${AWS::Partition}:ssm:${AWS::Region}:${AWS::AccountId}:parameter/saaslayer/foundation/connection-authorizers
741
973
  # The single permitted pass-role path: this role may hand CloudFormation exactly one
742
974
  # execution role. It cannot pass any other role in the account.
743
975
  - Effect: Allow
@@ -769,17 +1001,12 @@ Resources:
769
1001
  - !Sub arn:aws:s3:::${StackNamePrefix}*
770
1002
  - !Sub arn:aws:s3:::${StackNamePrefix}*/*
771
1003
  # Deploy tooling introspection after stack operations complete: stack enumeration
772
- # (ListStacks has no resource scoping), API Gateway lifecycle calls the Serverless
773
- # tooling makes outside CloudFormation, and lambda version/alias inspection.
1004
+ # (ListStacks has no resource scoping) and lambda version/alias inspection. The API Gateway
1005
+ # calls the Serverless tooling and the domain-service make outside CloudFormation are below.
774
1006
  - Effect: Allow
775
1007
  Action:
776
1008
  - cloudformation:ListStacks
777
1009
  - cloudformation:ListStackResources
778
- - apigateway:DELETE
779
- - apigateway:GET
780
- - apigateway:PATCH
781
- - apigateway:POST
782
- - apigateway:PUT
783
1010
  - lambda:GetAlias
784
1011
  - lambda:GetFunction
785
1012
  - lambda:GetFunctionConfiguration
@@ -787,6 +1014,56 @@ Resources:
787
1014
  - lambda:ListTags
788
1015
  - lambda:ListVersionsByFunction
789
1016
  Resource: '*'
1017
+ # API Gateway outside CloudFormation (foundation 8.0.0). Reads stay open: osls finds the module's REST
1018
+ # API by name in GET /restapis, and the domain-service probes GET /apis/<id> and lists /domainnames.
1019
+ - Sid: ApiGatewayReads
1020
+ Effect: Allow
1021
+ Action:
1022
+ - apigateway:GET
1023
+ Resource: !Sub arn:${AWS::Partition}:apigateway:*::/*
1024
+ # The domain-service creates a custom domain (v1 or v2) only carrying managed-by=saaslayer-deployer.
1025
+ - Sid: CreateManagedDomains
1026
+ Effect: Allow
1027
+ Action:
1028
+ - apigateway:POST
1029
+ Resource: !Sub arn:${AWS::Partition}:apigateway:*::/domainnames
1030
+ Condition:
1031
+ StringEquals:
1032
+ aws:RequestTag/managed-by: saaslayer-deployer
1033
+ # Base path / API mappings and deletes reach only domains carrying managed-by: a customer's own
1034
+ # domain of the same name (a swallowed create Conflict) or a vanity host the deployer did not create
1035
+ # is refused. Mappings take the tags of their domain for authorization.
1036
+ - Sid: ManagedDomainChanges
1037
+ Effect: Allow
1038
+ Action:
1039
+ - apigateway:DELETE
1040
+ - apigateway:PATCH
1041
+ - apigateway:POST
1042
+ Resource: !Sub arn:${AWS::Partition}:apigateway:*::/domainnames/*
1043
+ Condition:
1044
+ StringEquals:
1045
+ aws:ResourceTag/managed-by: saaslayer-deployer
1046
+ # osls's post-deploy stage update (REST modules with tags): create/update the stage of a REST API that
1047
+ # carries managed-by (stack tags reach the RestApi; a stage takes its API's tags for authorization).
1048
+ - Sid: ManagedRestApiStages
1049
+ Effect: Allow
1050
+ Action:
1051
+ - apigateway:PATCH
1052
+ - apigateway:POST
1053
+ Resource:
1054
+ - !Sub arn:${AWS::Partition}:apigateway:*::/restapis/*/stages
1055
+ - !Sub arn:${AWS::Partition}:apigateway:*::/restapis/*/stages/*
1056
+ Condition:
1057
+ StringEquals:
1058
+ aws:ResourceTag/managed-by: saaslayer-deployer
1059
+ # ...and set the stage's tags. The /tags resource takes no resource-tag condition; API Gateway also
1060
+ # requires PATCH on the tagged resource itself, which ManagedRestApiStages grants only on managed stages.
1061
+ - Sid: ApiGatewayStageTags
1062
+ Effect: Allow
1063
+ Action:
1064
+ - apigateway:DELETE
1065
+ - apigateway:PUT
1066
+ Resource: !Sub arn:${AWS::Partition}:apigateway:*::/tags/*
790
1067
  # Env-mode credential hot-swap: revoke/rotate updates a managed function's environment directly
791
1068
  # (UpdateFunctionConfiguration with RevisionId, read back with GetFunctionConfiguration above) instead
792
1069
  # of a stack deploy. Managed-prefix functions only.
@@ -810,8 +1087,9 @@ Resources:
810
1087
  - cognito-idp:AdminUpdateUserAttributes
811
1088
  - cognito-idp:ListUsers
812
1089
  # Scoped to SaaSLayer-managed pools by tag — the seed can never touch the customer's
813
- # own Cognito pools. Module stacks tag the pool managed-by:saaslayer-deployer (CFN
814
- # propagates stack tags), so it is tagged before the post-deploy seed runs.
1090
+ # own Cognito pools. user-service creates the pool with managed-by:saaslayer-deployer in its
1091
+ # explicit UserPoolTags (stack tags do not reach user pools), so it is tagged before the
1092
+ # post-deploy seed runs, and the execution role cannot add managed-by to any other pool.
815
1093
  Resource: !Sub arn:aws:cognito-idp:${AWS::Region}:${AWS::AccountId}:userpool/*
816
1094
  Condition:
817
1095
  StringEquals:
@@ -825,6 +1103,8 @@ Resources:
825
1103
  - dynamodb:DeleteItem
826
1104
  - dynamodb:Query
827
1105
  - dynamodb:BatchWriteItem
1106
+ # Audit transactions (permissions seed) carry ConditionCheck items on erasure markers.
1107
+ - dynamodb:ConditionCheckItem
828
1108
  # Teardown cleanup: a table with DeletionPolicy:Retain survives `serverless remove`, so the
829
1109
  # deployer's module-runner deletes those retained sl-* tables directly after the stack is gone
830
1110
  # (deleteStackOwnedTables) — else a same-named recreate collides. Scoped to sl-* tables only.
@@ -849,6 +1129,105 @@ Resources:
849
1129
  - logs:DeleteLogGroup
850
1130
  Resource:
851
1131
  - !Sub arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/${StackNamePrefix}*
1132
+ # Recovery inventory (ADR 0006 §2.2, foundation 6.5.0): before a destroy removes anything, the deployer
1133
+ # describes every stateful resource of the module stacks to write the deployment's recovery record.
1134
+ # Metadata reads only — never a secret or parameter value. Tables, buckets and secrets are managed-prefix
1135
+ # scoped; a module's KMS key is addressed by an id the prefix does not cover, so it is scoped to the account.
1136
+ - Sid: RecoveryInventoryScopedReads
1137
+ Effect: Allow
1138
+ Action:
1139
+ - dynamodb:DescribeTable
1140
+ - dynamodb:DescribeContinuousBackups
1141
+ - s3:GetBucketVersioning
1142
+ - secretsmanager:DescribeSecret
1143
+ - kms:DescribeKey
1144
+ Resource:
1145
+ - !Sub arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${StackNamePrefix}*
1146
+ - !Sub arn:aws:s3:::${StackNamePrefix}*
1147
+ - !Sub arn:aws:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:${StackNamePrefix}*
1148
+ - !Sub arn:aws:kms:${AWS::Region}:${AWS::AccountId}:key/*
1149
+ # Pool and app-client reads, limited to SaaSLayer-managed pools by tag like the seed's admin actions.
1150
+ - Sid: RecoveryInventoryPoolReads
1151
+ Effect: Allow
1152
+ Action:
1153
+ - cognito-idp:DescribeUserPool
1154
+ - cognito-idp:DescribeUserPoolClient
1155
+ Resource: !Sub arn:aws:cognito-idp:${AWS::Region}:${AWS::AccountId}:userpool/*
1156
+ Condition:
1157
+ StringEquals:
1158
+ aws:ResourceTag/managed-by: saaslayer-deployer
1159
+ # Identity pool reads (foundation 7.2.0): this account and region only, metadata (name) only. No tag condition,
1160
+ # so a retain never refuses on an identity pool its stack tags did not reach; the purge delete stays tag-limited.
1161
+ - Sid: RecoveryInventoryIdentityPoolReads
1162
+ Effect: Allow
1163
+ Action:
1164
+ - cognito-identity:DescribeIdentityPool
1165
+ Resource: !Sub arn:aws:cognito-identity:${AWS::Region}:${AWS::AccountId}:identitypool/*
1166
+ # DescribeUserPoolDomain and DescribeParameters support no resource-level scoping.
1167
+ - Sid: RecoveryInventoryUnscopedReads
1168
+ Effect: Allow
1169
+ Action:
1170
+ - cognito-idp:DescribeUserPoolDomain
1171
+ - ssm:DescribeParameters
1172
+ Resource: '*'
1173
+ # Purge (ADR 0006 §2.1, foundation 7.1.0): a delete destroy, or the purge of a retired deployment, deletes
1174
+ # what the deployment kept in custody, item by item from its recorded inventory: the backups of its tables,
1175
+ # its own buckets (emptied with the object grants above), its Secrets Manager secrets with no recovery
1176
+ # window, and its user pools (domain first, deletion protection off), app clients, identity pools (7.2.0) and
1177
+ # KMS keys. Tables, buckets and secrets are managed-prefix scoped; pools and keys are limited to
1178
+ # SaaSLayer-managed ones by tag.
1179
+ - Sid: PurgeScopedDeletes
1180
+ Effect: Allow
1181
+ Action:
1182
+ - dynamodb:DeleteBackup
1183
+ - s3:DeleteBucket
1184
+ - secretsmanager:DeleteSecret
1185
+ Resource:
1186
+ - !Sub arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${StackNamePrefix}*/backup/*
1187
+ - !Sub arn:aws:s3:::${StackNamePrefix}*
1188
+ - !Sub arn:aws:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:${StackNamePrefix}*
1189
+ - Sid: PurgeManagedPoolsAndKeys
1190
+ Effect: Allow
1191
+ Action:
1192
+ - cognito-idp:DeleteUserPool
1193
+ - cognito-idp:DeleteUserPoolClient
1194
+ - cognito-idp:DeleteUserPoolDomain
1195
+ - cognito-idp:UpdateUserPool
1196
+ - cognito-identity:DeleteIdentityPool
1197
+ - kms:ScheduleKeyDeletion
1198
+ Resource:
1199
+ - !Sub arn:aws:cognito-idp:${AWS::Region}:${AWS::AccountId}:userpool/*
1200
+ - !Sub arn:aws:cognito-identity:${AWS::Region}:${AWS::AccountId}:identitypool/*
1201
+ - !Sub arn:aws:kms:${AWS::Region}:${AWS::AccountId}:key/*
1202
+ Condition:
1203
+ StringEquals:
1204
+ aws:ResourceTag/managed-by: saaslayer-deployer
1205
+ # Adopt (ADR 0006 §2.2 step 5, foundation 7.2.0): once a retained user pool is imported back, every user is
1206
+ # signed out (AdminUserGlobalSignOut, listed with ListUsers) so refresh tokens issued before the retain stop
1207
+ # working. Limited to SaaSLayer-managed pools by tag; no user data is read or written beyond usernames.
1208
+ - Sid: AdoptSessionRevocation
1209
+ Effect: Allow
1210
+ Action:
1211
+ - cognito-idp:ListUsers
1212
+ - cognito-idp:AdminUserGlobalSignOut
1213
+ Resource: !Sub arn:aws:cognito-idp:${AWS::Region}:${AWS::AccountId}:userpool/*
1214
+ Condition:
1215
+ StringEquals:
1216
+ aws:ResourceTag/managed-by: saaslayer-deployer
1217
+ # ListBackups supports no resource-level scoping; the purge lists only its own tables' backups by name.
1218
+ - Sid: PurgeBackupListing
1219
+ Effect: Allow
1220
+ Action:
1221
+ - dynamodb:ListBackups
1222
+ Resource: '*'
1223
+ # Login-domain quota (foundation 7.4.0): Cognito allows 4 custom domains per account and region, so before
1224
+ # a deployment gets a branded login host the deployer counts the account's user pools in the region.
1225
+ # Read-only (pool ids and names); ListUserPools supports no resource-level scoping.
1226
+ - Sid: LoginDomainQuotaRead
1227
+ Effect: Allow
1228
+ Action:
1229
+ - cognito-idp:ListUserPools
1230
+ Resource: '*'
852
1231
  # Data migrations (@saaslayer/migrations): hop into a service stack's own migrate role; the
853
1232
  # role's own policy limits it to that service's tables. Its trust is account root + an
854
1233
  # aws:PrincipalArn condition, which delegates to this identity policy, so the grant is required.
@@ -857,8 +1236,8 @@ Resources:
857
1236
  Resource: !Sub arn:${AWS::Partition}:iam::${AWS::AccountId}:role/${StackNamePrefix}*-migrate
858
1237
  # Domain-mapping (D1.0, monorepo-88mn.3): the domain-service assumes this role to issue an ACM
859
1238
  # cert for the tenant's {slug}.saaslayer-cloud.com names, then attach an API-GW regional custom
860
- # domain — the apigateway create/read/update/delete verbs are ALREADY granted above (Resource
861
- # '*'), so only ACM is added here. Scoped to certs tagged managed-by=saaslayer-deployer so this
1239
+ # domain — the apigateway create/map/delete verbs are granted above (CreateManagedDomains,
1240
+ # ManagedDomainChanges), so only ACM is added here. Scoped to certs tagged managed-by=saaslayer-deployer so this
862
1241
  # role can only touch certs it created; RequestCertificate has no resource-level ARN, so the
863
1242
  # request-tag condition is the only guard. Regional custom domains do NOT need a service-linked
864
1243
  # role; add iam:CreateServiceLinkedRole for apigateway ONLY if domain-iam-spike.sh (D1.0a) proves it.
@@ -904,6 +1283,9 @@ Resources:
904
1283
  - Effect: Allow
905
1284
  Action:
906
1285
  - ssm:GetParameter
1286
+ # User-service's first-admin seed reads the endpoint and scoped service key in
1287
+ # one GetParameters call. Keep that batch read in the same deployment namespace.
1288
+ - ssm:GetParameters
907
1289
  - ssm:PutParameter
908
1290
  # DeleteParameter: the destroy/teardown phase clears the handoff params (they are written
909
1291
  # by PutParameter, NOT CloudFormation, so a stack delete leaves them behind) — M4b.
@@ -929,28 +1311,54 @@ Resources:
929
1311
  - TenantEdgeEnabled
930
1312
  - Effect: Allow
931
1313
  Action:
932
- - cloudfront:CreateDistribution
933
1314
  - cloudfront:GetDistribution
934
1315
  - cloudfront:GetDistributionConfig
935
- - cloudfront:UpdateDistribution
936
1316
  - cloudfront:ListDistributions
937
- - cloudfront:TagResource
938
1317
  - cloudfront:CreateFunction
939
- - cloudfront:PublishFunction
940
- - cloudfront:UpdateFunction
941
1318
  - cloudfront:DescribeFunction
942
1319
  - cloudfront:GetFunction
943
1320
  - cloudfront:ListFunctions
944
- # Native/B teardown (teardownNativeEdge runs via THIS DeploymentRole, direct SDK): delete
945
- # the per-tenant distro + strip Function on destroy. Without these the B teardown leaks.
1321
+ Resource: '*'
1322
+ - !Ref AWS::NoValue
1323
+ # The distro is created and tagged only with the request carrying managed-by (CreateDistributionWithTags;
1324
+ # provision and teardown tag the distro they find by its {slug} alias before changing it), and updated (the
1325
+ # teardown's disable) and deleted (native/B teardown) only while it carries managed-by.
1326
+ - Fn::If:
1327
+ - TenantEdgeEnabled
1328
+ - Effect: Allow
1329
+ Action:
1330
+ - cloudfront:CreateDistribution
1331
+ - cloudfront:TagResource
1332
+ Resource: '*'
1333
+ Condition:
1334
+ StringEquals:
1335
+ aws:RequestTag/managed-by: saaslayer-deployer
1336
+ - !Ref AWS::NoValue
1337
+ - Fn::If:
1338
+ - TenantEdgeEnabled
1339
+ - Effect: Allow
1340
+ Action:
946
1341
  - cloudfront:DeleteDistribution
1342
+ - cloudfront:UpdateDistribution
1343
+ Resource: !Sub arn:${AWS::Partition}:cloudfront::${AWS::AccountId}:distribution/*
1344
+ Condition:
1345
+ StringEquals:
1346
+ aws:ResourceTag/managed-by: saaslayer-deployer
1347
+ - !Ref AWS::NoValue
1348
+ # The strip Function is sl-strip-<slug>, under the managed prefix; its ARN carries the name.
1349
+ - Fn::If:
1350
+ - TenantEdgeEnabled
1351
+ - Effect: Allow
1352
+ Action:
1353
+ - cloudfront:PublishFunction
1354
+ - cloudfront:UpdateFunction
947
1355
  - cloudfront:DeleteFunction
948
- Resource: '*'
1356
+ Resource: !Sub arn:${AWS::Partition}:cloudfront::${AWS::AccountId}:function/${StackNamePrefix}*
949
1357
  - !Ref AWS::NoValue
950
1358
 
951
1359
  # Cross-account READ-ONLY role for SaaSLayer support staff to diagnose managed deployments
952
- # without the deployment role's write power. Trust matches the deployment role (control-plane
953
- # account + external ID) and additionally pins the session name to saaslayer-support-* so each
1360
+ # without the deployment role's write power. Trust is rendered like the deployment role's (per
1361
+ # control plane: its account, its support identity role and its trust identifier) and additionally pins the session name to saaslayer-support-* so each
954
1362
  # assumption is attributable in CloudTrail. Grants carry only Get/List/Describe verbs — enforced
955
1363
  # by tests/bootstrap.test.js — and exclude all data-plane reads: no S3 object reads, no DynamoDB
956
1364
  # item reads, no SSM parameter values, no Secrets Manager secret values, no function code downloads.
@@ -964,16 +1372,7 @@ Resources:
964
1372
  RoleName: sl-foundation-support-ro-role
965
1373
  AssumeRolePolicyDocument:
966
1374
  Version: '2012-10-17'
967
- Statement:
968
- - Effect: Allow
969
- Principal:
970
- AWS: !Sub arn:aws:iam::${ControlPlaneAccountId}:root
971
- Action: sts:AssumeRole
972
- Condition:
973
- StringEquals:
974
- sts:ExternalId: !Ref ExternalId
975
- StringLike:
976
- sts:RoleSessionName: saaslayer-support-*
1375
+ Statement: []
977
1376
  Policies:
978
1377
  - PolicyName: saaslayer-support-read-only
979
1378
  PolicyDocument:
@@ -997,6 +1396,12 @@ Resources:
997
1396
  Action:
998
1397
  - cloudformation:ListStacks
999
1398
  Resource: '*'
1399
+ # Foundation home: the foundation roles' aws:cloudformation:stack-id tag names this account
1400
+ # stack and so its home region, which foundation discovery reads before DescribeStacks.
1401
+ - Effect: Allow
1402
+ Action:
1403
+ - iam:ListRoleTags
1404
+ Resource: !Sub arn:${AWS::Partition}:iam::${AWS::AccountId}:role/sl-foundation-*
1000
1405
  # Configuration reads scoped by resource tag: these services support the
1001
1406
  # aws:ResourceTag condition key, and every SaaSLayer-deployed resource carries
1002
1407
  # managed-by=saaslayer-deployer via stack tags. Untagged (customer) resources
@@ -1043,6 +1448,34 @@ Resources:
1043
1448
  - logs:GetLogGroupFields
1044
1449
  - logs:GetLogRecord
1045
1450
  Resource: !Sub arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/${StackNamePrefix}*:*
1451
+ # Phone sign-in SMS readiness (read-only): account tier + spend limit, origination identities and
1452
+ # their registrations, a sandbox account's verified destination numbers, and the read-back of a phone
1453
+ # pool's configuration set + protect country rules. Account-level facts that carry no deployer tag,
1454
+ # so not tag-scoped.
1455
+ - Effect: Allow
1456
+ Action:
1457
+ - sms-voice:DescribeAccountAttributes
1458
+ - sms-voice:DescribeConfigurationSets
1459
+ - sms-voice:DescribePhoneNumbers
1460
+ - sms-voice:DescribePools
1461
+ - sms-voice:DescribeProtectConfigurations
1462
+ - sms-voice:DescribeRegistrations
1463
+ - sms-voice:DescribeSenderIds
1464
+ - sms-voice:DescribeSpendLimits
1465
+ - sms-voice:DescribeVerifiedDestinationNumbers
1466
+ - sms-voice:GetProtectConfigurationCountryRuleSet
1467
+ Resource: '*'
1468
+ # Recovery email readiness (read-only), checked before a recovery cutover: the account's SES sending status
1469
+ # (production access, sending enabled) and whether a sender identity is verified for sending. Account-level
1470
+ # facts that carry no deployer tag, so not tag-scoped; identity reads stay within this account.
1471
+ - Effect: Allow
1472
+ Action:
1473
+ - ses:GetAccount
1474
+ Resource: '*'
1475
+ - Effect: Allow
1476
+ Action:
1477
+ - ses:GetEmailIdentity
1478
+ Resource: !Sub arn:${AWS::Partition}:ses:*:${AWS::AccountId}:identity/*
1046
1479
  # Alarm/dashboard state for module observability. CloudWatch alarms support
1047
1480
  # aws:ResourceTag; DescribeAlarms is an enumeration API evaluated per-alarm.
1048
1481
  - Effect: Allow
@@ -1068,12 +1501,29 @@ Resources:
1068
1501
  kms:ViaService: ssm.*.amazonaws.com
1069
1502
  kms:EncryptionContext:PARAMETER_ARN: !Sub arn:${AWS::Partition}:ssm:*:${AWS::AccountId}:parameter/saaslayer/deployment/*
1070
1503
 
1504
+ # Connection authorization metadata (ADR 0005 §4), in this stack's (home) region: who may authorize
1505
+ # SaaSLayer org connections (ConnectionAuthorizerArns) and which control planes hold trust entries.
1506
+ # The controlPlanes literal (the line after "controlPlanes") is rendered from TrustEntries by the CLI.
1507
+ SaaSLayerConnectionAuthorizers:
1508
+ Type: AWS::SSM::Parameter
1509
+ Properties:
1510
+ Name: /saaslayer/foundation/connection-authorizers
1511
+ Type: String
1512
+ Description: SaaSLayer connection authorizers and managing control planes of this account (no secret).
1513
+ Value: !Join
1514
+ - ''
1515
+ - - '{"v":1,"connectionAuthorizerArns":["'
1516
+ - !Join ['","', !Ref ConnectionAuthorizerArns]
1517
+ - '"],"controlPlanes":'
1518
+ - '[]'
1519
+ - '}'
1520
+
1071
1521
  Outputs:
1072
1522
  DeploymentRoleArn:
1073
- Description: Cross-account deployment role the SaaSLayer control plane assumes (external ID required).
1523
+ Description: Cross-account deployment role the managing SaaSLayer control planes assume (trust identifier required).
1074
1524
  Value: !GetAtt SaaSLayerDeploymentRole.Arn
1075
1525
  SupportReadOnlyRoleArn:
1076
- Description: Cross-account read-only role SaaSLayer support staff assume for diagnostics (external ID required).
1526
+ Description: Cross-account read-only role SaaSLayer support staff assume for diagnostics (trust identifier required).
1077
1527
  Value: !GetAtt SaaSLayerSupportReadOnlyRole.Arn
1078
1528
  CloudFormationExecutionRoleArn:
1079
1529
  Description: Service role CloudFormation uses to provision approved SaaSLayer module stacks; not assumable cross-account.