-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverless.yml
278 lines (261 loc) · 7.84 KB
/
serverless.yml
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
service: okta-hooks
frameworkVersion: '3'
configValidationMode: error
plugins:
- serverless-webpack
provider:
name: aws
runtime: nodejs18.x
stage: ${env:ENVIRONMENT}
region: us-east-1
vpc:
securityGroupIds:
- sg-888294ed
subnetIds:
- subnet-f2c2dfda # us-east-1a
- subnet-1508db62 # us-east-1b
- subnet-3fd94266 # us-east-1c
stackTags:
Name: ${env:PROJECT_NAME}-${self:custom.environmentMap.${env:ENVIRONMENT}}
owner: [email protected]
application: ${env:PROJECT_NAME}
env: ${self:custom.environmentMap.${env:ENVIRONMENT}}
managed_by: serverless-framework
function: lambda
iam:
role:
statements:
- Effect: Allow
Action:
- SNS:Publish
- SNS:Subscribe
Resource:
Ref: OktaEventsSNSTopic
- Effect: Allow
Action:
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
- dynamodb:BatchWriteItem
Resource:
- Fn::GetAtt: [ OktaRestrictedDomainsTable, Arn ]
layers:
- arn:aws:lambda:us-east-1:072686360478:layer:node-16_14_2:1
environment: ${file(env.js)}
package:
individually: true
patterns:
- '!.webpack/**'
- '!test/**'
- '!**/*.test.js'
- '!.deployment/**'
custom:
webpack:
webpackConfig: ./webpack.config.js
includeModules: true
packager: yarn
excludeFiles: '**/*.test.js'
excludeRegex: \.ts|test|\.map
environmentMap:
production: prod
staging: stage
development: dev
lab: lab
resources:
extensions:
IamRoleLambdaExecution:
Properties:
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole
- arn:aws:iam::aws:policy/service-role/AWSLambdaENIManagementAccess
VerificationAlbListenerRule2:
Properties:
# serverless framework only allows a single header condition, we handle all verification conditions here
Conditions:
- Field: path-pattern
Values:
- /events
- Field: http-request-method
HttpRequestMethodConfig:
Values:
- GET
- Field: http-header
HttpHeaderConfig:
HttpHeaderName: Authorization
Values:
- ${env:OKTA_SHARED_SECRET}
- Field: http-header
HttpHeaderConfig:
HttpHeaderName: X-Okta-Verification-Challenge
Values:
- ?*
Resources:
OktaLoadBalancer:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
Name: okta-hooks-${env:ENVIRONMENT}-alb
Type: application
Scheme: internet-facing
IpAddressType: ipv4
SecurityGroups:
- sg-888294ed
Subnets:
- subnet-f5c2dfdd # us-east-1a
- subnet-2808db5f # us-east-1b
- subnet-9eda41c7 # us-east-1c
LoadBalancerAttributes:
- Key: access_logs.s3.enabled
Value: true
- Key: access_logs.s3.bucket
Value: cru-alb-logs
- Key: access_logs.s3.prefix
Value: okta-hooks/${env:ENVIRONMENT}
OktaLoadBalancerListener:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
LoadBalancerArn:
Ref: OktaLoadBalancer
Certificates:
- CertificateArn: "arn:aws:acm:us-east-1:056154071827:certificate/dc6b7f6b-5d69-4382-9585-26c641e6b12b"
DefaultActions:
- Type: fixed-response
Order: 1
FixedResponseConfig:
StatusCode: 403
ContentType: application/json
MessageBody: '{"error": "Forbidden"}'
Port: 443
Protocol: HTTPS
OktaEventsSNSTopic:
Type: AWS::SNS::Topic
Properties:
DisplayName: Okta Events
TopicName: ${self:service}-${env:ENVIRONMENT}-lifecycle-events
OktaRestrictedDomainsTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: ${self:service}-${env:ENVIRONMENT}-restricted-domains
AttributeDefinitions:
- AttributeName: DomainName
AttributeType: S
KeySchema:
- AttributeName: DomainName
KeyType: HASH
BillingMode: PAY_PER_REQUEST
functions:
registration:
handler: hooks/inline/registration.handler
memorySize: 128
timeout: 5
description: Registration hook to generate a new GUID and prevent signup with restricted domain.
environment:
DYNAMODB_RESTRICTED_DOMAINS:
Ref: OktaRestrictedDomainsTable
events:
- alb:
listenerArn:
Ref: OktaLoadBalancerListener
priority: 1
conditions:
header:
name: Authorization
values:
- ${env:OKTA_SHARED_SECRET}
method:
- POST
path: /registration
verification:
handler: hooks/event/verification.handler
memorySize: 128
timeout: 5
description: Event hook Verification
events:
- alb:
listenerArn:
Ref: OktaLoadBalancerListener
priority: 2
conditions: # conditions required here but overwritten in Resources block.
path: /events
events:
handler: hooks/event/events.handler
memorySize: 128
timeout: 5
description: Event hook for all okta events
environment:
SNS_OKTA_EVENTS_ARN:
Ref: OktaEventsSNSTopic
events:
- alb:
listenerArn:
Ref: OktaLoadBalancerListener
priority: 3
conditions:
header:
name: Authorization
values:
- ${env:OKTA_SHARED_SECRET}
method:
- POST
path: /events
userLifecycleCreate:
handler: sns/user/lifecycle/create.handler
description: Handle all `user.lifecycle.create` okta events
memorySize: 256
timeout: 12
events:
- sns:
arn: !Ref OktaEventsSNSTopic
topicName: ${self:service}-${env:ENVIRONMENT}-lifecycle-events
filterPolicy:
eventType:
- user.lifecycle.create
userLifecycleStatusChange:
handler: sns/user/lifecycle/status-change.handler
description: Handles all `user.lifecycle.deactivated` and `user.lifecycle.reactivate` okta events
memorySize: 128
timeout: 6
events:
- sns:
arn: !Ref OktaEventsSNSTopic
topicName: ${self:service}-${env:ENVIRONMENT}-lifecycle-events
filterPolicy:
eventType:
- user.lifecycle.deactivate
- user.lifecycle.reactivate
userAccountUpdateProfile:
handler: sns/user/account/update-profile.handler
description: Handle all `user.account.update_profile` okta events
memorySize: 256
timeout: 12
events:
- sns:
arn: !Ref OktaEventsSNSTopic
topicName: ${self:service}-${env:ENVIRONMENT}-lifecycle-events
filterPolicy:
eventType:
- user.account.update_profile
syncRestrictedDomains:
handler: schedule/sync-restricted-domains.handler
description: Sync list of restricted domains from Google Sheet
memorySize: 1024
timeout: 120
environment:
DYNAMODB_RESTRICTED_DOMAINS:
Ref: OktaRestrictedDomainsTable
events:
# Run daily at 12:00a and 12:00p UTC
- schedule: cron(0 0,12 * * ? *)
syncMissingOktaUsers:
handler: schedule/sync-missing-okta-users.handler
description: Query okta users missing Global Registry IDs and enqueue to SNS to re-sync them.
memorySize: 1024
timeout: 120
environment:
SNS_OKTA_EVENTS_ARN:
Ref: OktaEventsSNSTopic
events:
# Run every 30 minutes.
- schedule: cron(0/30 * * * ? *)