-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtemplate.yaml
More file actions
652 lines (610 loc) · 26.8 KB
/
Copy pathtemplate.yaml
File metadata and controls
652 lines (610 loc) · 26.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: >
iPad Claude Code — browser terminal running Claude Code in per-user AWS Lambda
MicroVMs, with Cognito auth and per-user S3 Files home directories.
# ─────────────────────────────────────────────────────────────────────────────
# Layout of this template:
# Parameters — deploy-time knobs (region-derived values, image name)
# Networking — VPC, NAT, subnets, NFS security group
# Storage — S3 buckets + the S3 Files filesystem/mount targets
# Identity — Cognito user pool + the IAM roles
# Compute — token-vending Lambda + API Gateway (Cognito-authorized)
# Frontend — S3 origin + CloudFront
# Egress — Lambda network connector (VPC egress for the MicroVMs)
# Outputs — everything deploy.sh / the frontend need
#
# IAM policy precedence (per the project convention): SAM policy templates first,
# then AWS managed policies, then inline. The token Lambda's permissions
# (SSM write, s3files access-point CRUD, microvm lifecycle, PassRole) have no
# matching policy template, so they are necessarily inline.
# ─────────────────────────────────────────────────────────────────────────────
Parameters:
ImageName:
Type: String
Default: ipad-claude-v2
Description: Name of the Lambda MicroVM image (built out-of-band by deploy.sh).
Globals:
Function:
Runtime: nodejs24.x
Architectures: [arm64]
Timeout: 30
MemorySize: 256
Resources:
# ── Networking ──────────────────────────────────────────────────────────────
Vpc:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.0.0.0/16
EnableDnsSupport: true
EnableDnsHostnames: true
Tags: [{ Key: Name, Value: ipad-claude-vpc }]
InternetGateway:
Type: AWS::EC2::InternetGateway
IgwAttachment:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
VpcId: !Ref Vpc
InternetGatewayId: !Ref InternetGateway
PublicSubnet1:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref Vpc
CidrBlock: 10.0.0.0/24
AvailabilityZone: !Select [0, !GetAZs ""]
MapPublicIpOnLaunch: true
PublicSubnet2:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref Vpc
CidrBlock: 10.0.1.0/24
AvailabilityZone: !Select [1, !GetAZs ""]
MapPublicIpOnLaunch: true
PrivateSubnet1:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref Vpc
CidrBlock: 10.0.2.0/24
AvailabilityZone: !Select [0, !GetAZs ""]
PrivateSubnet2:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref Vpc
CidrBlock: 10.0.3.0/24
AvailabilityZone: !Select [1, !GetAZs ""]
PublicRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref Vpc
PublicRoute:
Type: AWS::EC2::Route
DependsOn: IgwAttachment
Properties:
RouteTableId: !Ref PublicRouteTable
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref InternetGateway
PublicSubnet1RouteAssoc:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties: { RouteTableId: !Ref PublicRouteTable, SubnetId: !Ref PublicSubnet1 }
PublicSubnet2RouteAssoc:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties: { RouteTableId: !Ref PublicRouteTable, SubnetId: !Ref PublicSubnet2 }
NatEip:
Type: AWS::EC2::EIP
Properties: { Domain: vpc }
NatGateway:
Type: AWS::EC2::NatGateway
Properties:
AllocationId: !GetAtt NatEip.AllocationId
SubnetId: !Ref PublicSubnet1
PrivateRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref Vpc
PrivateRoute:
Type: AWS::EC2::Route
Properties:
RouteTableId: !Ref PrivateRouteTable
DestinationCidrBlock: 0.0.0.0/0
NatGatewayId: !Ref NatGateway
PrivateSubnet1RouteAssoc:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties: { RouteTableId: !Ref PrivateRouteTable, SubnetId: !Ref PrivateSubnet1 }
PrivateSubnet2RouteAssoc:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties: { RouteTableId: !Ref PrivateRouteTable, SubnetId: !Ref PrivateSubnet2 }
# NFS (2049) within the VPC — S3 Files mount targets live behind this.
NfsSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Allow NFS traffic for S3 Files mount targets
VpcId: !Ref Vpc
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 2049
ToPort: 2049
CidrIp: 10.0.0.0/16
# ── Storage ─────────────────────────────────────────────────────────────────
# Workspace bucket backs the S3 Files filesystem (per-user home directories).
# Versioning is required by S3 Files. Retained so homes survive a stack delete.
WorkspaceBucket:
Type: AWS::S3::Bucket
DeletionPolicy: Retain
UpdateReplacePolicy: Retain
Properties:
PublicAccessBlockConfiguration:
{ BlockPublicAcls: true, BlockPublicPolicy: true, IgnorePublicAcls: true, RestrictPublicBuckets: true }
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault: { SSEAlgorithm: AES256 }
VersioningConfiguration: { Status: Enabled }
ArtifactBucket:
Type: AWS::S3::Bucket
DeletionPolicy: Retain
UpdateReplacePolicy: Retain
Properties:
PublicAccessBlockConfiguration:
{ BlockPublicAcls: true, BlockPublicPolicy: true, IgnorePublicAcls: true, RestrictPublicBuckets: true }
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault: { SSEAlgorithm: AES256 }
VersioningConfiguration: { Status: Enabled }
FrontendBucket:
Type: AWS::S3::Bucket
Properties:
PublicAccessBlockConfiguration:
{ BlockPublicAcls: true, BlockPublicPolicy: true, IgnorePublicAcls: true, RestrictPublicBuckets: true }
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault: { SSEAlgorithm: AES256 }
# Role S3 Files assumes to sync the bucket + manage its change-detection rules.
# Inline: this is a service-linked-style trust policy with no policy-template equivalent.
S3FilesRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal: { Service: elasticfilesystem.amazonaws.com }
Action: sts:AssumeRole
Condition:
StringEquals: { aws:SourceAccount: !Ref AWS::AccountId }
ArnLike: { aws:SourceArn: !Sub "arn:aws:s3files:${AWS::Region}:${AWS::AccountId}:file-system/*" }
Policies:
- PolicyName: BucketAccess
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action: [s3:ListBucket, s3:ListBucketVersions]
Resource: !GetAtt WorkspaceBucket.Arn
Condition: { StringEquals: { aws:ResourceAccount: !Ref AWS::AccountId } }
- Effect: Allow
Action:
- s3:AbortMultipartUpload
- s3:DeleteObject
- s3:DeleteObjectVersion
- s3:GetObject
- s3:GetObjectVersion
- s3:List*
- s3:PutObject
- s3:PutObjectAcl
Resource: !Sub "${WorkspaceBucket.Arn}/*"
Condition: { StringEquals: { aws:ResourceAccount: !Ref AWS::AccountId } }
- Effect: Allow
Action: [events:DeleteRule, events:DisableRule, events:EnableRule, events:PutRule, events:PutTargets, events:RemoveTargets]
Resource: arn:aws:events:*:*:rule/DO-NOT-DELETE-S3-Files*
Condition: { StringEquals: { events:ManagedBy: elasticfilesystem.amazonaws.com } }
- Effect: Allow
Action: [events:DescribeRule, events:ListRuleNamesByTarget, events:ListRules, events:ListTargetsByRule]
Resource: arn:aws:events:*:*:rule/*
# S3 Files filesystem (NFS over the workspace bucket) + a mount target per AZ.
S3FilesFileSystem:
Type: AWS::S3Files::FileSystem
Properties:
Bucket: !GetAtt WorkspaceBucket.Arn
RoleArn: !GetAtt S3FilesRole.Arn
AcceptBucketWarning: true
S3FilesMountTarget1:
Type: AWS::S3Files::MountTarget
Properties:
FileSystemId: !GetAtt S3FilesFileSystem.FileSystemId
SubnetId: !Ref PrivateSubnet1
SecurityGroups: [!Ref NfsSecurityGroup]
S3FilesMountTarget2:
Type: AWS::S3Files::MountTarget
Properties:
FileSystemId: !GetAtt S3FilesFileSystem.FileSystemId
SubnetId: !Ref PrivateSubnet2
SecurityGroups: [!Ref NfsSecurityGroup]
# ── Identity ────────────────────────────────────────────────────────────────
# Admin-created users only — no self-signup.
UserPool:
Type: AWS::Cognito::UserPool
DeletionPolicy: Retain
UpdateReplacePolicy: Retain
Properties:
UserPoolName: ipad-claude-users
AdminCreateUserConfig: { AllowAdminCreateUserOnly: true }
UsernameAttributes: [email]
AutoVerifiedAttributes: [email]
AccountRecoverySetting:
RecoveryMechanisms: [{ Name: verified_email, Priority: 1 }]
Policies:
PasswordPolicy:
MinimumLength: 12
RequireLowercase: true
RequireUppercase: true
RequireNumbers: true
RequireSymbols: false
Schema:
- Name: email
AttributeDataType: String
Required: true
Mutable: false
UserPoolClient:
Type: AWS::Cognito::UserPoolClient
Properties:
UserPoolId: !Ref UserPool
ClientName: ipad-claude-web
GenerateSecret: false
ExplicitAuthFlows: [ALLOW_USER_PASSWORD_AUTH, ALLOW_USER_SRP_AUTH, ALLOW_REFRESH_TOKEN_AUTH]
AccessTokenValidity: 1
IdTokenValidity: 1
RefreshTokenValidity: 30
TokenValidityUnits: { AccessToken: hours, IdToken: hours, RefreshToken: days }
# MicroVM build role — reads the image artifact from S3.
# AWS managed policy for basic Lambda logging, inline for the artifact read.
MicroVmBuildRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal: { Service: lambda.amazonaws.com }
Action: sts:AssumeRole
Condition: { StringEquals: { aws:SourceAccount: !Ref AWS::AccountId } }
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
Policies:
- PolicyName: ArtifactRead
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action: [s3:GetObject, s3:GetObjectVersion]
Resource: !Sub "${ArtifactBucket.Arn}/*"
- Effect: Allow
Action: s3:ListBucket
Resource: !GetAtt ArtifactBucket.Arn
# Permissions boundary for roles created FROM INSIDE the sandbox. The
# execution role may create/manage IAM roles only if the new role carries
# this boundary, and the boundary caps every such role at sandbox level —
# so the sandbox can deploy full stacks (SAM/CDK role creation included)
# but can never mint anything more privileged than itself, create IAM
# users/access keys, or tamper with the boundary. The statements here
# deliberately mirror the execution role's ScopedIamWrites policy so that
# roles created by created roles are capped identically (self-propagating).
# Name is fixed (not stack-derived) because the in-VM CLAUDE.md briefing
# must be able to state the ARN statically — repo convention, same as the
# hardcoded /ipad-claude/* SSM prefix and function name.
SandboxPermissionsBoundary:
Type: AWS::IAM::ManagedPolicy
Properties:
ManagedPolicyName: ipad-claude-sandbox-boundary
Description: Caps IAM roles created from inside the sandbox at sandbox privilege level.
PolicyDocument:
Version: "2012-10-17"
Statement:
# Broad service access, PowerUserAccess-shaped.
- Sid: Services
Effect: Allow
NotAction: [iam:*, organizations:*, account:*]
Resource: "*"
- Sid: IamRead
Effect: Allow
Action: [iam:Get*, iam:List*, iam:SimulatePrincipalPolicy, iam:SimulateCustomPolicy]
Resource: "*"
- Sid: PassRole
Effect: Allow
Action: iam:PassRole
Resource: !Sub "arn:aws:iam::${AWS::AccountId}:role/*"
- Sid: BoundedRoleWrites
Effect: Allow
Action: [iam:CreateRole, iam:PutRolePolicy, iam:DeleteRolePolicy, iam:AttachRolePolicy, iam:DetachRolePolicy, iam:PutRolePermissionsBoundary]
Resource: !Sub "arn:aws:iam::${AWS::AccountId}:role/*"
Condition:
StringEquals:
iam:PermissionsBoundary: !Sub "arn:aws:iam::${AWS::AccountId}:policy/ipad-claude-sandbox-boundary"
- Sid: RoleLifecycle
Effect: Allow
Action: [iam:DeleteRole, iam:UpdateRole, iam:UpdateRoleDescription, iam:UpdateAssumeRolePolicy, iam:TagRole, iam:UntagRole, iam:CreateServiceLinkedRole]
Resource: "*"
- Sid: ManagePolicies
Effect: Allow
Action: [iam:CreatePolicy, iam:DeletePolicy, iam:CreatePolicyVersion, iam:DeletePolicyVersion, iam:SetDefaultPolicyVersion, iam:TagPolicy, iam:UntagPolicy]
Resource: !Sub "arn:aws:iam::${AWS::AccountId}:policy/*"
- Sid: InstanceProfiles
Effect: Allow
Action: [iam:CreateInstanceProfile, iam:DeleteInstanceProfile, iam:AddRoleToInstanceProfile, iam:RemoveRoleFromInstanceProfile, iam:TagInstanceProfile, iam:UntagInstanceProfile]
Resource: !Sub "arn:aws:iam::${AWS::AccountId}:instance-profile/*"
- Sid: DenyBoundaryTamper
Effect: Deny
Action: [iam:CreatePolicyVersion, iam:DeletePolicy, iam:DeletePolicyVersion, iam:SetDefaultPolicyVersion]
Resource: !Sub "arn:aws:iam::${AWS::AccountId}:policy/ipad-claude-sandbox-boundary"
- Sid: DenyBoundaryRemoval
Effect: Deny
Action: iam:DeleteRolePermissionsBoundary
Resource: "*"
- Sid: DenyTouchSandboxInfra
Effect: Deny
Action: iam:*
Resource: !Sub "arn:aws:iam::${AWS::AccountId}:role/ipad-claude-*"
# MicroVM execution role — the credential the sandbox operates with.
# AWS managed PowerUserAccess (full service access minus IAM/Orgs), plus
# inline Bedrock + S3 Files client-mount permissions, plus boundary-gated
# IAM writes (ScopedIamWrites) so `sam deploy` / CDK work from inside the
# sandbox without granting open-ended IAM. See README SECURITY.
MicroVmExecutionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal: { Service: lambda.amazonaws.com }
Action: sts:AssumeRole
Condition: { StringEquals: { aws:SourceAccount: !Ref AWS::AccountId } }
ManagedPolicyArns:
- arn:aws:iam::aws:policy/PowerUserAccess
Policies:
- PolicyName: BedrockAndS3Files
PolicyDocument:
Version: "2012-10-17"
Statement:
# The models are `us.anthropic.*` cross-region inference profiles.
# Invoking one needs BOTH the inference-profile ARN (in the deploy
# region) AND the underlying foundation-model ARNs in every region
# the US profile can route to (us-east-1 / us-east-2 / us-west-2).
# This is redundant while PowerUserAccess is attached, but makes the
# README's "scope PowerUserAccess down" advice actually safe.
- Effect: Allow
Action: [bedrock:InvokeModel, bedrock:InvokeModelWithResponseStream]
Resource:
- !Sub "arn:aws:bedrock:${AWS::Region}:${AWS::AccountId}:inference-profile/us.anthropic.claude-*"
- arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-*
- arn:aws:bedrock:us-east-2::foundation-model/anthropic.claude-*
- arn:aws:bedrock:us-west-2::foundation-model/anthropic.claude-*
- Effect: Allow
Action: [s3files:ClientMount, s3files:ClientWrite]
Resource: "*"
- Effect: Allow
Action: [s3:GetObject, s3:GetObjectVersion, s3:PutObject, s3:DeleteObject, s3:ListBucket]
Resource: [!GetAtt WorkspaceBucket.Arn, !Sub "${WorkspaceBucket.Arn}/*"]
# IAM writes for in-sandbox deploys (sam deploy, CDK, etc.), gated by
# the permissions boundary: any role created from the sandbox MUST
# carry SandboxPermissionsBoundary, which caps it at sandbox level and
# propagates the same cap to roles it creates in turn. Escalation
# paths are closed: no boundary-free role writes, no IAM users or
# access keys (never granted), no editing/removing the boundary, no
# touching the sandbox's own ipad-claude-* roles.
- PolicyName: ScopedIamWrites
PolicyDocument:
Version: "2012-10-17"
Statement:
- Sid: IamRead
Effect: Allow
Action: [iam:Get*, iam:List*, iam:SimulatePrincipalPolicy, iam:SimulateCustomPolicy]
Resource: "*"
- Sid: PassRole
Effect: Allow
Action: iam:PassRole
Resource: !Sub "arn:aws:iam::${AWS::AccountId}:role/*"
- Sid: BoundedRoleWrites
Effect: Allow
Action: [iam:CreateRole, iam:PutRolePolicy, iam:DeleteRolePolicy, iam:AttachRolePolicy, iam:DetachRolePolicy, iam:PutRolePermissionsBoundary]
Resource: !Sub "arn:aws:iam::${AWS::AccountId}:role/*"
Condition:
StringEquals:
iam:PermissionsBoundary: !Ref SandboxPermissionsBoundary
- Sid: RoleLifecycle
Effect: Allow
Action: [iam:DeleteRole, iam:UpdateRole, iam:UpdateRoleDescription, iam:UpdateAssumeRolePolicy, iam:TagRole, iam:UntagRole, iam:CreateServiceLinkedRole]
Resource: "*"
- Sid: ManagePolicies
Effect: Allow
Action: [iam:CreatePolicy, iam:DeletePolicy, iam:CreatePolicyVersion, iam:DeletePolicyVersion, iam:SetDefaultPolicyVersion, iam:TagPolicy, iam:UntagPolicy]
Resource: !Sub "arn:aws:iam::${AWS::AccountId}:policy/*"
- Sid: InstanceProfiles
Effect: Allow
Action: [iam:CreateInstanceProfile, iam:DeleteInstanceProfile, iam:AddRoleToInstanceProfile, iam:RemoveRoleFromInstanceProfile, iam:TagInstanceProfile, iam:UntagInstanceProfile]
Resource: !Sub "arn:aws:iam::${AWS::AccountId}:instance-profile/*"
- Sid: DenyBoundaryTamper
Effect: Deny
Action: [iam:CreatePolicyVersion, iam:DeletePolicy, iam:DeletePolicyVersion, iam:SetDefaultPolicyVersion]
Resource: !Ref SandboxPermissionsBoundary
- Sid: DenyBoundaryRemoval
Effect: Deny
Action: iam:DeleteRolePermissionsBoundary
Resource: "*"
- Sid: DenyTouchSandboxInfra
Effect: Deny
Action: iam:*
Resource: !Sub "arn:aws:iam::${AWS::AccountId}:role/ipad-claude-*"
# ── Compute: token-vending Lambda + API ──────────────────────────────────────
TokenApi:
Type: AWS::Serverless::Api
Properties:
StageName: prod
Cors:
AllowOrigin: "'*'"
AllowMethods: "'GET,DELETE,OPTIONS'"
AllowHeaders: "'Content-Type,Authorization'"
Auth:
DefaultAuthorizer: CognitoAuthorizer
# Do NOT gate the CORS preflight (OPTIONS) behind the authorizer — the
# browser sends OPTIONS without a token, so it must stay public.
AddDefaultAuthorizerToCorsPreflight: false
Authorizers:
CognitoAuthorizer:
UserPoolArn: !GetAtt UserPool.Arn
TokenFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: ipad-claude-token-vend
CodeUri: functions/token-vend/
Handler: index.handler
Environment:
Variables:
ALLOWED_ORIGINS: "*"
IMAGE_ARN: !Sub "arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:microvm-image:${ImageName}"
EXECUTION_ROLE_ARN: !GetAtt MicroVmExecutionRole.Arn
NETWORK_CONNECTOR_ARN: !GetAtt VpcEgressConnector.Arn
S3_FILES_FS_ID: !GetAtt S3FilesFileSystem.FileSystemId
WORKSPACE_BUCKET_ARN: !GetAtt WorkspaceBucket.Arn
Policies:
# SAM policy templates first:
- SSMParameterWithSlashPrefixReadPolicy: { ParameterName: /ipad-claude/* }
# Then inline for permissions with no policy-template equivalent:
- Statement:
- Sid: SsmWritePerUserState
Effect: Allow
Action: [ssm:PutParameter, ssm:GetParameter]
Resource: !Sub "arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/ipad-claude/*"
- Sid: PerUserAccessPoints
Effect: Allow
Action: [s3files:CreateAccessPoint, s3files:GetAccessPoint, s3files:ListAccessPoints, s3files:DeleteAccessPoint]
Resource: "*"
- Sid: MicroVmLifecycle
Effect: Allow
Action: lambda:*
Resource: "*"
Condition: { StringEquals: { aws:RequestedRegion: !Ref AWS::Region } }
- Sid: PassExecutionRole
Effect: Allow
Action: iam:PassRole
Resource: !GetAtt MicroVmExecutionRole.Arn
Events:
GetToken:
Type: Api
Properties:
RestApiId: !Ref TokenApi
Path: /token
Method: get
TerminateVm:
Type: Api
Properties:
RestApiId: !Ref TokenApi
Path: /token
Method: delete
# ── Frontend: S3 + CloudFront ─────────────────────────────────────────────────
FrontendOac:
Type: AWS::CloudFront::OriginAccessControl
Properties:
OriginAccessControlConfig:
Name: !Sub "${AWS::StackName}-frontend-oac"
OriginAccessControlOriginType: s3
SigningBehavior: always
SigningProtocol: sigv4
FrontendDistribution:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
Comment: iPad Claude Code frontend
Enabled: true
DefaultRootObject: index.html
Origins:
- Id: frontend-s3
DomainName: !GetAtt FrontendBucket.RegionalDomainName
OriginAccessControlId: !Ref FrontendOac
S3OriginConfig: { OriginAccessIdentity: "" }
DefaultCacheBehavior:
TargetOriginId: frontend-s3
ViewerProtocolPolicy: redirect-to-https
AllowedMethods: [GET, HEAD, OPTIONS]
# Managed-CachingDisabled — the frontend injects live config, don't cache it.
CachePolicyId: 4135ea2d-6df8-44a3-9df3-4b5a84be39ad
CustomErrorResponses:
- { ErrorCode: 403, ResponseCode: 200, ResponsePagePath: /index.html }
- { ErrorCode: 404, ResponseCode: 200, ResponsePagePath: /index.html }
# Bucket policy: allow only this CloudFront distribution (via OAC) to read.
FrontendBucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref FrontendBucket
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal: { Service: cloudfront.amazonaws.com }
Action: s3:GetObject
Resource: !Sub "${FrontendBucket.Arn}/*"
Condition:
StringEquals:
AWS:SourceArn: !Sub "arn:aws:cloudfront::${AWS::AccountId}:distribution/${FrontendDistribution}"
# ── Egress: Lambda network connector (VPC egress for MicroVMs) ────────────────
NetworkConnectorOperatorRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service: [lambda.amazonaws.com, network-connectors.lambda.amazonaws.com]
Action: sts:AssumeRole
Policies:
- PolicyName: EniManagement
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action: ec2:CreateNetworkInterface
Resource:
- arn:aws:ec2:*:*:network-interface/*
- arn:aws:ec2:*:*:subnet/*
- arn:aws:ec2:*:*:security-group/*
- Effect: Allow
Action: ec2:CreateTags
Resource: arn:aws:ec2:*:*:network-interface/*
Condition:
StringEquals: { ec2:ManagedResourceOperator: network-connectors.lambda.amazonaws.com }
VpcEgressConnector:
Type: AWS::Lambda::NetworkConnector
Properties:
Name: ipad-claude-vpc-egress
Configuration:
VpcEgressConfiguration:
SubnetIds: [!Ref PrivateSubnet1, !Ref PrivateSubnet2]
SecurityGroupIds: [!Ref NfsSecurityGroup]
NetworkProtocol: IPv4
AssociatedComputeResourceTypes: [MicroVm]
OperatorRole: !GetAtt NetworkConnectorOperatorRole.Arn
Outputs:
TokenApiUrl:
Description: Token-vending API endpoint.
Value: !Sub "https://${TokenApi}.execute-api.${AWS::Region}.amazonaws.com/prod/token"
UserPoolId:
Value: !Ref UserPool
UserPoolClientId:
Value: !Ref UserPoolClient
FrontendUrl:
Value: !Sub "https://${FrontendDistribution.DomainName}"
FrontendBucketName:
Value: !Ref FrontendBucket
ArtifactBucketName:
Value: !Ref ArtifactBucket
WorkspaceBucketName:
Value: !Ref WorkspaceBucket
CloudFrontDistributionId:
Value: !Ref FrontendDistribution
BuildRoleArn:
Value: !GetAtt MicroVmBuildRole.Arn
ExecutionRoleArn:
Value: !GetAtt MicroVmExecutionRole.Arn
NetworkConnectorArn:
Value: !GetAtt VpcEgressConnector.Arn
S3FilesFileSystemId:
Value: !GetAtt S3FilesFileSystem.FileSystemId