saaslayer 0.0.2 → 0.0.7

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.
@@ -1,6 +1,13 @@
1
1
  # SaaSLayer host-account bootstrap. Installed once per host (customer) account; grants the
2
2
  # SaaSLayer control plane the minimum access needed to deploy and support SaaSLayer modules.
3
3
  #
4
+ # SOURCE OF TRUTH — edit THIS file only. packages/cli/templates/saaslayer-foundation.yml is an
5
+ # auto-synced copy (run `npm run sync-template` from packages/cli). `npm test` fails on drift.
6
+ #
7
+ # NAMING (tbrme.13.19): the CloudFormation LOGICAL ids below stay SaaSLayer* (internal, unchanged), while the
8
+ # physical RoleName/ManagedPolicyName values are now sl-foundation-{deploy-role,cfn-exec-role,support-ro-role,
9
+ # managed-boundary} (+ saaslayer-org-vending-role in account-vending-access). Prose below names the roles by logical id.
10
+ #
4
11
  # SECURITY REVIEWER SUMMARY
5
12
  #
6
13
  # This template creates one S3 bucket, one permissions-boundary managed policy, and three IAM roles:
@@ -10,7 +17,9 @@
10
17
  # ExternalId. It can drive the CloudFormation lifecycle of stacks whose names start with
11
18
  # StackNamePrefix (default "sl-"), read/write the deployment artifact buckets, and pass exactly
12
19
  # one role (SaaSLayerCloudFormationExecutionRole) to CloudFormation. It cannot create IAM
13
- # resources or touch anything outside the managed stack namespace directly.
20
+ # resources or touch anything outside the managed stack namespace directly. Its only
21
+ # sts:AssumeRole grant is into a module stack's own data-migration role
22
+ # (role/${StackNamePrefix}*-migrate), whose policy limits it to that service's tables.
14
23
  #
15
24
  # 2. SaaSLayerCloudFormationExecutionRole — assumable ONLY by the CloudFormation service, never
16
25
  # cross-account. CloudFormation uses it to create/update/delete the resources declared by
@@ -38,11 +47,9 @@
38
47
  # support role, external-id enforcement, wildcard justification audit).
39
48
  AWSTemplateFormatVersion: '2010-09-09'
40
49
  Description: >-
41
- SaaSLayer host-account bootstrap: deployment artifact bucket, CloudFormation execution role for
42
- approved SaaSLayer module templates, permissions boundary for module-created IAM roles, a
43
- cross-account deployment role restricted to SaaSLayer-prefixed stacks, and a cross-account
44
- read-only support role. Both cross-account roles require an external ID and trust only the
45
- SaaSLayer control-plane account supplied as a parameter.
50
+ SaaSLayer foundation stack: grants the SaaSLayer control plane scoped, external-ID-gated access
51
+ to deploy and support SaaSLayer modules in this account. Installed once per account. Details:
52
+ https://saaslayer.com/docs/account-access
46
53
 
47
54
  Parameters:
48
55
  ControlPlaneAccountId:
@@ -63,6 +70,12 @@ Parameters:
63
70
  Description: >-
64
71
  Prefix for SaaSLayer-managed CloudFormation stacks. The deployment role can only operate on
65
72
  stacks whose names start with this prefix.
73
+ OrgId:
74
+ Type: String
75
+ Default: ''
76
+ Description: >-
77
+ SaaSLayer org this account is connected to. Informational only — never used in a policy or
78
+ trust decision. Surfaced in Outputs so support can identify the account from the stack alone.
66
79
  EnableEmailInbound:
67
80
  Type: String
68
81
  AllowedValues: ['true', 'false']
@@ -70,27 +83,43 @@ Parameters:
70
83
  Description: >-
71
84
  When 'true', grant the SES receipt-rule provisioning + inbound-mail runtime permissions that
72
85
  email-inbound-service needs. Default 'false' so host accounts that do NOT run email-inbound are
73
- not over-permissioned for SES. The deployer sets this per host based on the services it hosts.
86
+ not over-permissioned for SES. Set per host via `cplane accounts enable-capability <host> ses`.
87
+ EnableTenantEdge:
88
+ Type: String
89
+ AllowedValues: ['true', 'false']
90
+ Default: 'false'
91
+ Description: >-
92
+ When 'true', grant the CloudFront distribution + edge-Function permissions the NATIVE
93
+ single-tenant edge (epic f55t, Model B) provisions in this account. Default 'false' so host
94
+ accounts that route through the shared edge are not granted CloudFront write. Set per host via
95
+ `cplane accounts enable-capability <host> tenant-edge`.
96
+ WARNING (rollout order): a host ALREADY running the native edge must have this enabled BEFORE
97
+ its foundation is redeployed at >= 1.1.0, or the redeploy strips the perms its live edge needs.
74
98
 
75
99
  Conditions:
100
+ # Capability gates. Each maps 1:1 to an entry in @saaslayer/foundation-contract (packages/
101
+ # foundation-contract/src/index.ts), which is what the CLI and the deployer read; a param here with
102
+ # no registry entry (or vice versa) fails that package's contract test.
76
103
  # Gate email-inbound-service's SES permissions so they exist only on host accounts that run it.
77
104
  EmailInboundEnabled: !Equals [!Ref EnableEmailInbound, 'true']
105
+ # Gate the native tenant-edge CloudFront permissions to hosts that actually run a native edge.
106
+ TenantEdgeEnabled: !Equals [!Ref EnableTenantEdge, 'true']
107
+
108
+ Mappings:
109
+ # Foundation template version (semver). BUMP on every change so support can tell which bootstrap an
110
+ # account runs (surfaced via the FoundationVersion / SaaSLayerAccountRef Outputs). Bump rules:
111
+ # major = breaking trust/permission-contract change (role renamed, permission removed) — account must re-bootstrap
112
+ # minor = additive capability (new resource-type perms, new optional param) — safe, no re-bootstrap
113
+ # patch = comments/docs/no behavior change
114
+ Meta:
115
+ Foundation:
116
+ Version: '5.9.0'
78
117
 
79
118
  Resources:
80
- # Private, encrypted bucket for packaged module templates and lambda artifacts uploaded by the
81
- # deployer. Only the deployment role reads/writes it (see saaslayer-stack-lifecycle below).
82
- DeploymentArtifactBucket:
83
- Type: AWS::S3::Bucket
84
- Properties:
85
- PublicAccessBlockConfiguration:
86
- BlockPublicAcls: true
87
- BlockPublicPolicy: true
88
- IgnorePublicAcls: true
89
- RestrictPublicBuckets: true
90
- BucketEncryption:
91
- ServerSideEncryptionConfiguration:
92
- - ServerSideEncryptionByDefault:
93
- SSEAlgorithm: AES256
119
+ # The shared deployment-artifact bucket moved OUT of this account-global stack into the per-region
120
+ # saaslayer-foundation-<region> stack (bead .30): S3 is regional and this IAM stack cannot deploy per-region.
121
+ # The deploy role reaches that bucket (sl-artifacts-<token>-<region>) through the ${StackNamePrefix}* grant
122
+ # in saaslayer-stack-lifecycle below, same as every other managed bucket.
94
123
 
95
124
  # Service role CloudFormation assumes while creating/updating/deleting resources declared by
96
125
  # approved SaaSLayer module templates. Not assumable by any AWS account — only the CloudFormation
@@ -102,7 +131,7 @@ Resources:
102
131
  SaaSLayerCloudFormationExecutionRole:
103
132
  Type: AWS::IAM::Role
104
133
  Properties:
105
- RoleName: SaaSLayerCloudFormationExecutionRole
134
+ RoleName: sl-foundation-cfn-exec-role
106
135
  AssumeRolePolicyDocument:
107
136
  Version: '2012-10-17'
108
137
  Statement:
@@ -136,6 +165,9 @@ Resources:
136
165
  - cloudwatch:EnableAlarmActions
137
166
  - cloudwatch:GetDashboard
138
167
  - cloudwatch:ListDashboards
168
+ # DetectStackDrift reads alarm tags; without this, drift checks on the ops alarms
169
+ # 403 and block every UPDATE (fail-closed drift gate).
170
+ - cloudwatch:ListTagsForResource
139
171
  - cloudwatch:PutDashboard
140
172
  - cloudwatch:PutMetricAlarm
141
173
  - cloudwatch:TagResource
@@ -208,18 +240,10 @@ Resources:
208
240
  - events:RemoveTargets
209
241
  - events:TagResource
210
242
  - events:UntagResource
211
- # IAM role/policy lifecycle for the roles module templates declare (lambda
212
- # execution roles, scheduler roles). Runtime permissions of created roles are
213
- # capped by SaaSLayerManagedResourceBoundary.
214
- - iam:CreatePolicy
215
- - iam:CreatePolicyVersion
216
- - iam:CreateRole
217
- - iam:DeletePolicy
218
- - iam:DeletePolicyVersion
219
- - iam:DeleteRole
220
- - iam:DeleteRolePolicy
221
- - iam:DetachRolePolicy
222
- - iam:AttachRolePolicy
243
+ # IAM read-only introspection during changeset execution. Mutating IAM verbs
244
+ # (Create/Delete/Update/Attach/Pass/Tag) are prefix-scoped in dedicated
245
+ # statements below — never Resource '*' — and CreateRole additionally requires
246
+ # SaaSLayerManagedResourceBoundary so no created role can exceed the boundary.
223
247
  - iam:GetPolicy
224
248
  - iam:GetPolicyVersion
225
249
  - iam:GetRole
@@ -228,30 +252,38 @@ Resources:
228
252
  - iam:ListEntitiesForPolicy
229
253
  - iam:ListPolicyVersions
230
254
  - iam:ListRolePolicies
231
- - iam:PassRole
232
- - iam:PutRolePolicy
233
- - iam:SetDefaultPolicyVersion
234
- - iam:TagPolicy
235
- - iam:TagRole
236
- - iam:UntagPolicy
237
- - iam:UntagRole
238
- - iam:UpdateAssumeRolePolicy
239
- - iam:UpdateRole
240
- - iam:UpdateRoleDescription
241
255
  # KMS customer-managed key + alias lifecycle. rbac-service provisions an
242
256
  # EventDeliveryKey (AWS::KMS::Key, rotation on) + alias for webhook payload
243
257
  # encryption; CreateKey mandates Resource '*', and TagResource on the new key
244
258
  # is required or CloudFormation fails with UnauthorizedTaggingOperation.
245
259
  - kms:CreateAlias
246
260
  - kms:CreateKey
261
+ # EarlyValidation runs a KMS::Alias name-conflict check on change-set creation; without
262
+ # ListAliases it reports a (non-fatal) "not allowed to check if resource already exists"
263
+ # FAIL in the console Hooks view and can't detect a real alias collision. Enumeration API,
264
+ # no resource-level scoping (monorepo-pcren).
265
+ - kms:ListAliases
266
+ # Grant + data-plane actions: a resource encrypted with a customer CMK (email-inbound's
267
+ # InboundTable via DynamoDB SSE-KMS) makes the service create a grant AND
268
+ # decrypt/generate data keys against the CMK during provisioning — without these the
269
+ # table create fails AccessDenied (kms:CreateGrant, then kms:Decrypt/GenerateDataKey).
270
+ - kms:CreateGrant
271
+ - kms:Decrypt
247
272
  - kms:DeleteAlias
248
273
  - kms:DescribeKey
249
274
  - kms:DisableKeyRotation
250
275
  - kms:EnableKeyRotation
276
+ - kms:Encrypt
277
+ - kms:GenerateDataKey
278
+ - kms:GenerateDataKeyWithoutPlaintext
251
279
  - kms:GetKeyPolicy
252
280
  - kms:GetKeyRotationStatus
281
+ - kms:ListGrants
253
282
  - kms:ListResourceTags
254
283
  - kms:PutKeyPolicy
284
+ - kms:ReEncryptFrom
285
+ - kms:ReEncryptTo
286
+ - kms:RevokeGrant
255
287
  - kms:ScheduleKeyDeletion
256
288
  - kms:TagResource
257
289
  - kms:UntagResource
@@ -416,6 +448,80 @@ Resources:
416
448
  - sqs:TagQueue
417
449
  - sqs:UntagQueue
418
450
  Resource: '*'
451
+ # Mutating IAM verbs are scoped to the managed-resource prefix (StackNamePrefix) so
452
+ # the exec role can only create/modify SaaSLayer module roles + customer-managed
453
+ # policies — never a pre-existing account role, and never the control-plane primitives
454
+ # (named SaaSLayer*, outside the prefix). CreateRole additionally requires the
455
+ # boundary, so no created role can exceed it even if a template attaches an admin policy.
456
+ - Effect: Allow
457
+ Action:
458
+ - iam:CreateRole
459
+ Resource: !Sub arn:${AWS::Partition}:iam::${AWS::AccountId}:role/${StackNamePrefix}*
460
+ Condition:
461
+ StringEquals:
462
+ iam:PermissionsBoundary: !Ref SaaSLayerManagedResourceBoundary
463
+ - Effect: Allow
464
+ Action:
465
+ - iam:DeleteRole
466
+ - iam:UpdateRole
467
+ - iam:UpdateRoleDescription
468
+ - iam:UpdateAssumeRolePolicy
469
+ - iam:PutRolePolicy
470
+ - iam:DeleteRolePolicy
471
+ - iam:AttachRolePolicy
472
+ - iam:DetachRolePolicy
473
+ - iam:TagRole
474
+ - iam:UntagRole
475
+ - iam:PassRole
476
+ Resource: !Sub arn:${AWS::Partition}:iam::${AWS::AccountId}:role/${StackNamePrefix}*
477
+ - Effect: Allow
478
+ Action:
479
+ - iam:CreatePolicy
480
+ - iam:CreatePolicyVersion
481
+ - iam:DeletePolicy
482
+ - iam:DeletePolicyVersion
483
+ - iam:SetDefaultPolicyVersion
484
+ - iam:TagPolicy
485
+ - iam:UntagPolicy
486
+ Resource: !Sub arn:${AWS::Partition}:iam::${AWS::AccountId}:policy/${StackNamePrefix}*
487
+ # Self-protecting Deny (defense-in-depth): the exec role can never mutate the
488
+ # permissions boundary or the three bootstrap roles, even though prefix scoping
489
+ # already excludes their SaaSLayer* names. An explicit Deny overrides any Allow.
490
+ - Effect: Deny
491
+ Action:
492
+ - iam:CreatePolicyVersion
493
+ - iam:SetDefaultPolicyVersion
494
+ - iam:DeletePolicy
495
+ - iam:DeletePolicyVersion
496
+ - iam:DeleteRole
497
+ - iam:PutRolePolicy
498
+ - iam:DeleteRolePolicy
499
+ - iam:AttachRolePolicy
500
+ - iam:DetachRolePolicy
501
+ - iam:UpdateAssumeRolePolicy
502
+ - iam:UpdateRole
503
+ Resource:
504
+ - !Ref SaaSLayerManagedResourceBoundary
505
+ - !Sub arn:${AWS::Partition}:iam::${AWS::AccountId}:role/sl-foundation-cfn-exec-role
506
+ - !Sub arn:${AWS::Partition}:iam::${AWS::AccountId}:role/sl-foundation-deploy-role
507
+ - !Sub arn:${AWS::Partition}:iam::${AWS::AccountId}:role/sl-foundation-support-ro-role
508
+ # Tenant-edge B (native single-tenant edge, epic f55t): CFN-driven Model B stands up a
509
+ # CloudFront distro + prefix-strip Function IN this account for
510
+ # {slug}.saaslayer-cloud.com/{service}. Only on hosts that run a native edge
511
+ # (EnableTenantEdge=true); the shared-edge path needs none of it.
512
+ - Fn::If:
513
+ - TenantEdgeEnabled
514
+ - Effect: Allow
515
+ Action:
516
+ - cloudfront:CreateFunction
517
+ - cloudfront:PublishFunction
518
+ - cloudfront:UpdateFunction
519
+ - cloudfront:DescribeFunction
520
+ - cloudfront:GetFunction
521
+ - cloudfront:ListFunctions
522
+ - cloudfront:ListDistributions
523
+ Resource: '*'
524
+ - !Ref AWS::NoValue
419
525
  # SES receipt rule set/rule provisioning — only on hosts that run email-inbound
420
526
  # (EnableEmailInbound=true). Identity verification (VerifyDomainIdentity/DKIM) runs
421
527
  # CP-side in the domain-service, never from the tenant account.
@@ -428,6 +534,9 @@ Resources:
428
534
  - ses:CreateReceiptRule
429
535
  - ses:DeleteReceiptRule
430
536
  - ses:UpdateReceiptRule
537
+ # CFN's AWS::SES::ReceiptRule calls SetReceiptRulePosition to (re)order a rule via its
538
+ # `After` property on UPDATE — without it a rule reorder 403s + wedges the stack.
539
+ - ses:SetReceiptRulePosition
431
540
  - ses:DescribeReceiptRuleSet
432
541
  - ses:DescribeReceiptRule
433
542
  Resource: '*'
@@ -449,20 +558,34 @@ Resources:
449
558
  SaaSLayerManagedResourceBoundary:
450
559
  Type: AWS::IAM::ManagedPolicy
451
560
  Properties:
452
- ManagedPolicyName: SaaSLayerManagedResourceBoundary
561
+ ManagedPolicyName: sl-foundation-managed-boundary
453
562
  Description: Maximum runtime permissions for IAM roles created by SaaSLayer managed stacks.
454
563
  PolicyDocument:
455
564
  Version: '2012-10-17'
456
565
  Statement:
457
566
  - Effect: Allow
458
567
  Action:
568
+ # Invitation registration creates the invited account after mailbox proof (user-service).
569
+ - cognito-idp:AdminCreateUser
570
+ - cognito-idp:AdminDeleteUser
459
571
  - cognito-idp:AdminDeleteUserAttributes
572
+ - cognito-idp:AdminDisableProviderForUser
460
573
  - cognito-idp:AdminGetUser
574
+ - cognito-idp:AdminLinkProviderForUser
461
575
  - cognito-idp:AdminListGroupsForUser
462
576
  - cognito-idp:AdminSetUserMFAPreference
577
+ - cognito-idp:AdminSetUserPassword
463
578
  - cognito-idp:AdminUpdateUserAttributes
579
+ # Social login + identity stitching (epic monorepo-24667): the idpResource custom-resource
580
+ # Lambda manages the federated IdPs; the PreSignUp/stitching + account Lambdas link/disable
581
+ # providers, set passwords, and delete users. The boundary is the ceiling, so it must allow
582
+ # every action the managed roles use (their inline policies scope the resources).
583
+ - cognito-idp:CreateIdentityProvider
584
+ - cognito-idp:DeleteIdentityProvider
585
+ - cognito-idp:DescribeIdentityProvider
464
586
  - cognito-idp:GetUserPoolMfaConfig
465
587
  - cognito-idp:ListUsers
588
+ - cognito-idp:UpdateIdentityProvider
466
589
  - dynamodb:BatchGetItem
467
590
  - dynamodb:BatchWriteItem
468
591
  - dynamodb:DeleteItem
@@ -486,6 +609,9 @@ Resources:
486
609
  - lambda:InvokeFunction
487
610
  - logs:CreateLogGroup
488
611
  - logs:CreateLogStream
612
+ # Cognito validates a user-import job's logs role for DescribeLogStreams before it starts the job
613
+ # (user-service UserImportLogsRole; `saaslayer users import`).
614
+ - logs:DescribeLogStreams
489
615
  - logs:PutLogEvents
490
616
  - mobiletargeting:PutEvents
491
617
  - s3:AbortMultipartUpload
@@ -505,7 +631,28 @@ Resources:
505
631
  - sqs:ReceiveMessage
506
632
  - sqs:SendMessage
507
633
  - sqs:SendMessageBatch
634
+ # Social login (epic monorepo-24667): the idpResource custom resource reads the BYO client
635
+ # secret from an SSM SecureString (/saaslayer/deployment/*); kms:Decrypt above covers the
636
+ # SecureString's aws/ssm key.
637
+ - ssm:GetParameter
508
638
  Resource: '*'
639
+ # PITR check + opt-in on-demand backup for per-service migrate roles (@saaslayer/migrations).
640
+ # Managed-prefix tables only. The boundary is account-global and the role policies do the
641
+ # regional scoping, hence dynamodb:*:.
642
+ - Effect: Allow
643
+ Action:
644
+ - dynamodb:DescribeContinuousBackups
645
+ - dynamodb:CreateBackup
646
+ - dynamodb:DescribeBackup
647
+ Resource:
648
+ - !Sub arn:${AWS::Partition}:dynamodb:*:${AWS::AccountId}:table/${StackNamePrefix}*
649
+ - !Sub arn:${AWS::Partition}:dynamodb:*:${AWS::AccountId}:table/${StackNamePrefix}*/backup/*
650
+ # Transactional email from this account's own SES identities (user-service registration codes).
651
+ - Effect: Allow
652
+ Action:
653
+ - ses:SendEmail
654
+ Resource:
655
+ - !Sub arn:${AWS::Partition}:ses:*:${AWS::AccountId}:identity/*
509
656
  # SES runtime (forward/notify sends + the active-rule-set custom resource) — only on hosts
510
657
  # that run email-inbound. Receiving into S3 is granted to the ses.amazonaws.com service
511
658
  # principal by the module's bucket policy, not here.
@@ -528,7 +675,7 @@ Resources:
528
675
  SaaSLayerDeploymentRole:
529
676
  Type: AWS::IAM::Role
530
677
  Properties:
531
- RoleName: SaaSLayerDeploymentRole
678
+ RoleName: sl-foundation-deploy-role
532
679
  AssumeRolePolicyDocument:
533
680
  Version: '2012-10-17'
534
681
  Statement:
@@ -553,6 +700,9 @@ Resources:
553
700
  - cloudformation:UpdateStack
554
701
  - cloudformation:ExecuteChangeSet
555
702
  - cloudformation:SetStackPolicy
703
+ # Protected environments (prod, staging): the deployer enables termination protection
704
+ # after a deploy and disables it before an authorized destroy.
705
+ - cloudformation:UpdateTerminationProtection
556
706
  - cloudformation:DeleteChangeSet
557
707
  - cloudformation:DeleteStack
558
708
  - cloudformation:Describe*
@@ -575,11 +725,11 @@ Resources:
575
725
  Action:
576
726
  - iam:PassRole
577
727
  Resource: !GetAtt SaaSLayerCloudFormationExecutionRole.Arn
578
- # Artifact staging: the bootstrap-created artifact bucket, the per-stack serverless
579
- # deployment buckets (sl- prefixed), and the module data buckets named from the
580
- # deployer slug (sldep*) — e.g. user-service's versioned cognito-user-backup bucket,
581
- # which teardown must empty (ListBucketVersions/DeleteObjectVersion) before the stack
582
- # can delete it, or destroy fails with AccessDenied on s3:ListBucketVersions.
728
+ # Artifact staging + data-bucket lifecycle: the shared deployment-artifact bucket
729
+ # (sl-artifacts-<token>-<region>, in the per-region foundation stack), the module data buckets
730
+ # named from the managed prefix (sl-) — e.g. user-service's versioned cognito-user-backup bucket,
731
+ # which teardown must empty (ListBucketVersions/DeleteObjectVersion) before the stack can delete
732
+ # it, or destroy fails with AccessDenied on s3:ListBucketVersions.
583
733
  - Effect: Allow
584
734
  Action:
585
735
  - s3:GetBucketLocation
@@ -591,23 +741,14 @@ Resources:
591
741
  - s3:ListBucket
592
742
  - s3:ListBucketVersions
593
743
  Resource:
594
- - !GetAtt DeploymentArtifactBucket.Arn
595
- - !Sub ${DeploymentArtifactBucket.Arn}/*
596
- - arn:aws:s3:::sl-*serverlessdeploymentbuck*
597
- - arn:aws:s3:::sl-*serverlessdeploymentbuck*/*
598
- - arn:aws:s3:::sldep*-cognito-user-backup-*
599
- - arn:aws:s3:::sldep*-cognito-user-backup-*/*
600
- # rbac-admin-ui static-site bucket: serverless-s3-sync uploads the SPA + config.json
601
- # under this role at deploy, and teardown empties it before the stack deletes it.
602
- - arn:aws:s3:::sl-*-adminui-*
603
- - arn:aws:s3:::sl-*-adminui-*/*
604
- # email-inbound-service raw-MIME + attachment buckets: SES writes inbound mail here
605
- # and teardown must empty them (ListBucketVersions/DeleteObjectVersion) before the
606
- # stack can delete them, or destroy fails with AccessDenied.
607
- - arn:aws:s3:::sl-*-email-inbound-raw-*
608
- - arn:aws:s3:::sl-*-email-inbound-raw-*/*
609
- - arn:aws:s3:::sl-*-email-inbound-attachments-*
610
- - arn:aws:s3:::sl-*-email-inbound-attachments-*/*
744
+ # ALL deployer-managed service app buckets are now OPAQUE ${StackNamePrefix}<token>-<service>
745
+ # (naming §5, T-FOUNDATION-WILDCARDS): the opaque token replaces the old per-service name
746
+ # suffixes (eml-raw/att, cognito-user-backup, adminui, manifest) AND the framework
747
+ # *serverlessdeploymentbucket*, so ONE prefix-scoped wildcard covers every one. The deploy
748
+ # role can create + empty (ListBucketVersions/DeleteObjectVersion) only buckets under the
749
+ # managed prefix — never a bare literal (D8: StackNamePrefix is customer-configurable).
750
+ - !Sub arn:aws:s3:::${StackNamePrefix}*
751
+ - !Sub arn:aws:s3:::${StackNamePrefix}*/*
611
752
  # Deploy tooling introspection after stack operations complete: stack enumeration
612
753
  # (ListStacks has no resource scoping), API Gateway lifecycle calls the Serverless
613
754
  # tooling makes outside CloudFormation, and lambda version/alias inspection.
@@ -638,8 +779,15 @@ Resources:
638
779
  - cognito-idp:AdminCreateUser
639
780
  - cognito-idp:AdminGetUser
640
781
  - cognito-idp:AdminSetUserPassword
782
+ - cognito-idp:AdminUpdateUserAttributes
641
783
  - cognito-idp:ListUsers
784
+ # Scoped to SaaSLayer-managed pools by tag — the seed can never touch the customer's
785
+ # own Cognito pools. Module stacks tag the pool managed-by:saaslayer-deployer (CFN
786
+ # propagates stack tags), so it is tagged before the post-deploy seed runs.
642
787
  Resource: !Sub arn:aws:cognito-idp:${AWS::Region}:${AWS::AccountId}:userpool/*
788
+ Condition:
789
+ StringEquals:
790
+ aws:ResourceTag/managed-by: saaslayer-deployer
643
791
  - Effect: Allow
644
792
  Action:
645
793
  - dynamodb:GetItem
@@ -647,9 +795,125 @@ Resources:
647
795
  - dynamodb:UpdateItem
648
796
  - dynamodb:Query
649
797
  - dynamodb:BatchWriteItem
798
+ # Teardown cleanup: a table with DeletionPolicy:Retain survives `serverless remove`, so the
799
+ # deployer's module-runner deletes those retained sl-* tables directly after the stack is gone
800
+ # (deleteStackOwnedTables) — else a same-named recreate collides. Scoped to sl-* tables only.
801
+ - dynamodb:DeleteTable
650
802
  Resource:
651
- - !Sub arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/rbac-*
652
- - !Sub arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/rbac-*/index/*
803
+ - !Sub arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${StackNamePrefix}*
804
+ - !Sub arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${StackNamePrefix}*/index/*
805
+ # Teardown cleanup: AWS auto-creates a /aws/lambda/<function> log group on first invocation that
806
+ # survives `serverless remove` (and even an explicit AWS::Logs::LogGroup can outlive the stack), so
807
+ # the module-runner sweeps the module's log groups after remove (like the retained-table sweep) —
808
+ # else a same-name recreate collides ("LogGroup already exists" at EarlyValidation). DescribeLogGroups
809
+ # is an enumeration (no resource scoping); DeleteLogGroup is scoped to the managed prefix (monorepo-04egp).
810
+ - Effect: Allow
811
+ Action:
812
+ - logs:DescribeLogGroups
813
+ Resource: '*'
814
+ - Effect: Allow
815
+ Action:
816
+ - logs:DeleteLogGroup
817
+ Resource:
818
+ - !Sub arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/${StackNamePrefix}*
819
+ # Data migrations (@saaslayer/migrations): hop into a service stack's own migrate role; the
820
+ # role's own policy limits it to that service's tables. Its trust is account root + an
821
+ # aws:PrincipalArn condition, which delegates to this identity policy, so the grant is required.
822
+ - Effect: Allow
823
+ Action: sts:AssumeRole
824
+ Resource: !Sub arn:${AWS::Partition}:iam::${AWS::AccountId}:role/${StackNamePrefix}*-migrate
825
+ # Domain-mapping (D1.0, monorepo-88mn.3): the domain-service assumes this role to issue an ACM
826
+ # cert for the tenant's {slug}.saaslayer-cloud.com names, then attach an API-GW regional custom
827
+ # domain — the apigateway create/read/update/delete verbs are ALREADY granted above (Resource
828
+ # '*'), so only ACM is added here. Scoped to certs tagged managed-by=saaslayer-deployer so this
829
+ # role can only touch certs it created; RequestCertificate has no resource-level ARN, so the
830
+ # request-tag condition is the only guard. Regional custom domains do NOT need a service-linked
831
+ # role; add iam:CreateServiceLinkedRole for apigateway ONLY if domain-iam-spike.sh (D1.0a) proves it.
832
+ # attachDomain (domain-service.ts) creates the API Gateway service-linked role on the FIRST
833
+ # custom domain in the account — the earlier "regional custom domains do NOT need a
834
+ # service-linked role" assumption was wrong (attachDomain AccessDenied'd on
835
+ # iam:CreateServiceLinkedRole). Scoped to the apigateway service-linked-role path only.
836
+ - Effect: Allow
837
+ Action:
838
+ - iam:CreateServiceLinkedRole
839
+ Resource: 'arn:aws:iam::*:role/aws-service-role/*apigateway.amazonaws.com/*'
840
+ Condition:
841
+ StringLike:
842
+ iam:AWSServiceName: '*apigateway.amazonaws.com'
843
+ - Effect: Allow
844
+ Action:
845
+ - acm:RequestCertificate
846
+ Resource: '*'
847
+ Condition:
848
+ StringEquals:
849
+ aws:RequestTag/managed-by: saaslayer-deployer
850
+ - Effect: Allow
851
+ Action:
852
+ - acm:DescribeCertificate
853
+ - acm:DeleteCertificate
854
+ - acm:AddTagsToCertificate
855
+ - acm:ListTagsForCertificate
856
+ Resource: '*'
857
+ Condition:
858
+ StringEquals:
859
+ aws:ResourceTag/managed-by: saaslayer-deployer
860
+ # ListCertificates has no resource-level or condition support.
861
+ - Effect: Allow
862
+ Action:
863
+ - acm:ListCertificates
864
+ Resource: '*'
865
+ # M2 vendable-key handoff (plan s7oc.9.3): the deploy role runs rbac's post-deploy SEED via
866
+ # DIRECT SDK calls (like the native-edge teardown below), and the seed writes the scoped
867
+ # onboarding endpoint (String) + service key (SecureString) into THIS deployment's SSM
868
+ # namespace for user-service to read (M4). GetParameter re-reads to honor the SSM-authoritative
869
+ # verify contract (reuse a still-valid key instead of re-minting on every deploy). Scoped to
870
+ # /saaslayer/deployment/* — the deploy role is the account's deploy agent across deployments.
871
+ - Effect: Allow
872
+ Action:
873
+ - ssm:GetParameter
874
+ - ssm:PutParameter
875
+ # DeleteParameter: the destroy/teardown phase clears the handoff params (they are written
876
+ # by PutParameter, NOT CloudFormation, so a stack delete leaves them behind) — M4b.
877
+ - ssm:DeleteParameter
878
+ Resource: !Sub arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/saaslayer/deployment/*
879
+ # Encrypt/decrypt the SecureString onboarding key through the SSM-managed default key
880
+ # (alias/aws/ssm). ViaService confines this grant to operations performed by SSM.
881
+ - Effect: Allow
882
+ Action:
883
+ - kms:Encrypt
884
+ - kms:Decrypt
885
+ - kms:GenerateDataKey
886
+ Resource: '*'
887
+ Condition:
888
+ StringEquals:
889
+ kms:ViaService: !Sub ssm.${AWS::Region}.amazonaws.com
890
+ # Tenant-edge B (native single-tenant edge, epic f55t): the deploy role provisions a CloudFront
891
+ # distro + prefix-strip Function IN this account via DIRECT SDK calls (not CloudFormation), so
892
+ # these live on the DeploymentRole (the ExecutionRole copies are for CFN-driven Model-B). No IAM
893
+ # creation here — CloudFront distros/functions don't create roles — so the role stays narrow.
894
+ # Gated on the tenant-edge capability: a host on the shared edge never needs CloudFront write.
895
+ - Fn::If:
896
+ - TenantEdgeEnabled
897
+ - Effect: Allow
898
+ Action:
899
+ - cloudfront:CreateDistribution
900
+ - cloudfront:GetDistribution
901
+ - cloudfront:GetDistributionConfig
902
+ - cloudfront:UpdateDistribution
903
+ - cloudfront:ListDistributions
904
+ - cloudfront:TagResource
905
+ - cloudfront:CreateFunction
906
+ - cloudfront:PublishFunction
907
+ - cloudfront:UpdateFunction
908
+ - cloudfront:DescribeFunction
909
+ - cloudfront:GetFunction
910
+ - cloudfront:ListFunctions
911
+ # Native/B teardown (teardownNativeEdge runs via THIS DeploymentRole, direct SDK): delete
912
+ # the per-tenant distro + strip Function on destroy. Without these the B teardown leaks.
913
+ - cloudfront:DeleteDistribution
914
+ - cloudfront:DeleteFunction
915
+ Resource: '*'
916
+ - !Ref AWS::NoValue
653
917
 
654
918
  # Cross-account READ-ONLY role for SaaSLayer support staff to diagnose managed deployments
655
919
  # without the deployment role's write power. Trust matches the deployment role (control-plane
@@ -660,7 +924,7 @@ Resources:
660
924
  SaaSLayerSupportReadOnlyRole:
661
925
  Type: AWS::IAM::Role
662
926
  Properties:
663
- RoleName: SaaSLayerSupportReadOnlyRole
927
+ RoleName: sl-foundation-support-ro-role
664
928
  AssumeRolePolicyDocument:
665
929
  Version: '2012-10-17'
666
930
  Statement:
@@ -684,7 +948,13 @@ Resources:
684
948
  - cloudformation:Describe*
685
949
  - cloudformation:Get*
686
950
  - cloudformation:ListStackResources
687
- Resource: !Sub arn:${AWS::Partition}:cloudformation:${AWS::Region}:${AWS::AccountId}:stack/${StackNamePrefix}*
951
+ Resource:
952
+ # SaaSLayer-managed module stacks (sl-*) AND the foundation stack itself
953
+ # (saaslayer-foundation / -host-bootstrap): the deployer's foundation discovery assumes
954
+ # THIS support-ro role and reads the foundation stack Outputs, so it must be in scope.
955
+ - !Sub arn:${AWS::Partition}:cloudformation:${AWS::Region}:${AWS::AccountId}:stack/${StackNamePrefix}*
956
+ - !Sub arn:${AWS::Partition}:cloudformation:${AWS::Region}:${AWS::AccountId}:stack/saaslayer-foundation*
957
+ - !Sub arn:${AWS::Partition}:cloudformation:${AWS::Region}:${AWS::AccountId}:stack/saaslayer-host-bootstrap*
688
958
  # Stack enumeration; the ListStacks API does not support resource scoping.
689
959
  - Effect: Allow
690
960
  Action:
@@ -720,20 +990,22 @@ Resources:
720
990
  Condition:
721
991
  StringEquals:
722
992
  aws:ResourceTag/managed-by: saaslayer-deployer
723
- # Log reads for diagnosing module function failures. CloudWatch Logs does not
724
- # support aws:ResourceTag conditions on these read actions, and module log group
725
- # names follow function names rather than a common prefix, so these cannot be
726
- # tag- or ARN-scoped yet. They expose log content and log-group metadata only —
727
- # no service configuration or data-plane records.
993
+ # Log-group enumeration + tag reads stay account-wide (enumeration APIs return only
994
+ # names/metadata). Log CONTENT reads are scoped to SaaSLayer module log groups
995
+ # (/aws/lambda/<StackNamePrefix>*), so support can never read the customer's own
996
+ # application logs — which routinely carry PII, bearer tokens, and secrets.
728
997
  - Effect: Allow
729
998
  Action:
730
999
  - logs:DescribeLogGroups
1000
+ - logs:ListTagsForResource
1001
+ Resource: '*'
1002
+ - Effect: Allow
1003
+ Action:
731
1004
  - logs:DescribeLogStreams
732
1005
  - logs:GetLogEvents
733
1006
  - logs:GetLogGroupFields
734
1007
  - logs:GetLogRecord
735
- - logs:ListTagsForResource
736
- Resource: '*'
1008
+ Resource: !Sub arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/${StackNamePrefix}*:*
737
1009
  # Alarm/dashboard state for module observability. CloudWatch alarms support
738
1010
  # aws:ResourceTag; DescribeAlarms is an enumeration API evaluated per-alarm.
739
1011
  - Effect: Allow
@@ -753,9 +1025,14 @@ Outputs:
753
1025
  CloudFormationExecutionRoleArn:
754
1026
  Description: Service role CloudFormation uses to provision approved SaaSLayer module stacks; not assumable cross-account.
755
1027
  Value: !GetAtt SaaSLayerCloudFormationExecutionRole.Arn
756
- DeploymentArtifactBucketName:
757
- Description: Private, encrypted bucket holding packaged SaaSLayer deployment artifacts.
758
- Value: !Ref DeploymentArtifactBucket
759
1028
  ManagedResourceBoundaryArn:
760
1029
  Description: Permissions boundary capping the runtime permissions of every IAM role created by SaaSLayer module stacks.
761
1030
  Value: !Ref SaaSLayerManagedResourceBoundary
1031
+ FoundationVersion:
1032
+ Description: Version of this foundation template installed in the account.
1033
+ Value: !FindInMap [Meta, Foundation, Version]
1034
+ SaaSLayerAccountRef:
1035
+ Description: Share this with SaaSLayer support to identify your account and foundation version.
1036
+ Value: !Sub
1037
+ - 'org=${OrgId} account=${AWS::AccountId} region=${AWS::Region} prefix=${StackNamePrefix} v=${Ver}'
1038
+ - Ver: !FindInMap [Meta, Foundation, Version]