-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtemplate.yaml
277 lines (261 loc) · 7.49 KB
/
template.yaml
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
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: >
ETH2 Validator BLS Key Generator
Globals:
Function:
Timeout: 120
Parameters:
SigningProfileVersionArnParameter:
Type: String
Description: Lambda Code Signing Profile ARN
Default: ""
Resources:
VPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.200.0.0/16
EnableDnsSupport: true
EnableDnsHostnames: true
Tags:
- Key: Name
Value: "secure-keygen-vpc"
Metadata:
cfn_nag:
rules_to_suppress:
- id: W60
reason: "Only Lambda is deployed on this VPC. No need for flow log"
PrivateSubnet:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
AvailabilityZone: !Select [ 1, !GetAZs '' ]
CidrBlock: 10.200.0.0/24
MapPublicIpOnLaunch: false
PrivateRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
PrivateSubnetRouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref PrivateRouteTable
SubnetId: !Ref PrivateSubnet
LambdaSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Validator Lambda Security Group
VpcId: !Ref VPC
SecurityGroupEgress:
- IpProtocol: tcp
FromPort: 443
ToPort: 443
CidrIp: 0.0.0.0/0
Description: Allow to all destinations
Metadata:
cfn_nag:
rules_to_suppress:
- id: W5
reason: "Lambda function need to interact with other AWS services"
EndpointSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: VPC Endpoint Security Group
VpcId: !Ref VPC
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 443
ToPort: 443
CidrIp: !GetAtt VPC.CidrBlock
Description: Allow from VPC
SecurityGroupEgress:
- IpProtocol: tcp
FromPort: 443
ToPort: 443
CidrIp: !GetAtt VPC.CidrBlock
Description: Allow to VPC
KMSEndpoint:
Type: AWS::EC2::VPCEndpoint
Properties:
VpcEndpointType: Interface
ServiceName: !Sub 'com.amazonaws.${AWS::Region}.kms'
PrivateDnsEnabled: true
VpcId: !Ref VPC
SubnetIds:
- !Ref PrivateSubnet
SecurityGroupIds:
- !Ref EndpointSecurityGroup
S3Endpoint:
Type: AWS::EC2::VPCEndpoint
Properties:
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal: '*'
Action:
- 's3:*'
Resource:
- '*'
RouteTableIds:
- !Ref PrivateRouteTable
ServiceName: !Sub 'com.amazonaws.${AWS::Region}.s3'
VpcId: !Ref VPC
DynamoDBEndpoint:
Type: AWS::EC2::VPCEndpoint
Properties:
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal: '*'
Action:
- 'dynamodb:BatchWriteItem'
- 'dynamodb:DeleteItem'
- 'dynamodb:DescribeTable'
- 'dynamodb:PutItem'
- 'dynamodb:UpdateItem'
Resource:
- '*'
RouteTableIds:
- !Ref PrivateRouteTable
ServiceName: !Sub 'com.amazonaws.${AWS::Region}.dynamodb'
VpcId: !Ref VPC
ValidatorKeyGenFunction:
Type: AWS::Serverless::Function
Properties:
PackageType: Zip
CodeUri: secure_keygen/
Handler: app.lambda_handler
Runtime: python3.9
MemorySize: 1024
CodeSigningConfigArn: !Ref SignedFunctionCodeSigningConfig
ReservedConcurrentExecutions: 1
VpcConfig:
SecurityGroupIds:
- !Ref LambdaSecurityGroup
SubnetIds:
- !Ref PrivateSubnet
Environment:
Variables:
KMS_KEY_ARN:
Fn::GetAtt:
- Key
- Arn
DDB_TABLE_NAME:
Ref: ValidatorKeysTable
LOG_LEVEL: "DEBUG"
Architectures:
- x86_64
Policies:
- Version: "2012-10-17"
Statement:
- Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Effect: Allow
Resource: !Sub 'arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/*'
- Action:
- kms:Encrypt
- kms:GenerateDataKey*
- kms:ReEncrypt*
Effect: Allow
Resource:
Fn::GetAtt:
- Key
- Arn
- Action:
- dynamodb:BatchWriteItem
- dynamodb:DeleteItem
- dynamodb:DescribeTable
- dynamodb:PutItem
- dynamodb:UpdateItem
Effect: Allow
Resource:
- Fn::GetAtt:
- ValidatorKeysTable
- Arn
Metadata:
cfn_nag:
rules_to_suppress:
- id: W89
reason: "False positive - https://github.com/stelligent/cfn_nag/issues/601"
# CodeSigningConfig drift detection not supported:
# https://github.com/aws-cloudformation/cloudformation-coverage-roadmap/issues/954
SignedFunctionCodeSigningConfig:
Type: AWS::Lambda::CodeSigningConfig
Properties:
Description: "Code Signing for ValidatorKeyGenFunction"
AllowedPublishers:
SigningProfileVersionArns:
- !Ref SigningProfileVersionArnParameter
CodeSigningPolicies:
UntrustedArtifactOnDeployment: "Enforce"
ValidatorKeysTable:
Type: AWS::DynamoDB::Table
Properties:
KeySchema:
- AttributeName: web3signer_uuid
KeyType: HASH
- AttributeName: pubkey
KeyType: RANGE
AttributeDefinitions:
- AttributeName: web3signer_uuid
AttributeType: S
- AttributeName: pubkey
AttributeType: S
PointInTimeRecoverySpecification:
PointInTimeRecoveryEnabled: true
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
SSESpecification:
SSEEnabled: true
BillingMode: PROVISIONED
UpdateReplacePolicy: Delete
DeletionPolicy: Delete
Key:
Type: AWS::KMS::Key
Properties:
KeyPolicy:
Statement:
- Action:
- "kms:Create*"
- "kms:Describe*"
- "kms:Enable*"
- "kms:Encrypt"
- "kms:List*"
- "kms:Put*"
- "kms:Update*"
- "kms:Revoke*"
- "kms:Disable*"
- "kms:Get*"
- "kms:Delete*"
- "kms:ScheduleKeyDeletion"
- "kms:CancelKeyDeletion"
- "kms:GenerateDataKey*"
- "kms:TagResource"
- "kms:UntagResource"
# - "kms:Decrypt" # Uncomment to debug
Effect: Allow
Principal:
AWS: !Sub 'arn:${AWS::Partition}:iam::${AWS::AccountId}:root'
Resource: "*"
Version: "2012-10-17"
EnableKeyRotation: true
UpdateReplacePolicy: Delete
DeletionPolicy: Delete
Outputs:
ValidatorKeyGenFunction:
Description: "Lambda Function ARN"
Value: !GetAtt ValidatorKeyGenFunction.Arn
ValidatorKeyGenFunctionIamRole:
Description: "Implicit IAM Role created for function"
Value: !GetAtt ValidatorKeyGenFunctionRole.Arn
ValidatorKeysTable:
Description: "DynamoDB Table Arn"
Value: !GetAtt ValidatorKeysTable.Arn
Key:
Description: "KMS Key"
Value: !GetAtt Key.Arn