-
Notifications
You must be signed in to change notification settings - Fork 142
/
Copy pathop-scim-bridge.yaml
589 lines (589 loc) · 17.9 KB
/
op-scim-bridge.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
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
AWSTemplateFormatVersion: 2010-09-09
Description: >-
Deploys 1Password SCIM Bridge on AWS Fargate in an Amazon ECS cluster. Includes ALB, ACM certificate, AWS secret,
security groups, and IAM role resources. Optionally creates Route 53 records and a VPC with 2 public subnets,
internet gateway, and route table.
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Parameters:
- VPCID
- VPCCIDR
- PublicSubnets
- Route53HostedZoneID
- ProvisioningVolume
- DomainName
- SCIMBridgeVersion
- scimsession
- Label:
default: Workspace configuration (only for customers integrating with Google Workspace)
Parameters:
- WorkspaceCredentials
- WorkspaceActor
ParameterLabels:
VPCID:
default: VPC ID
VPCCIDR:
default: VPC CIDR
PublicSubnets:
default: Public subnets
Route53HostedZoneID:
default: Route 53 hosted zone
ProvisioningVolume:
default: Provisioning volume
DomainName:
default: 1Password SCIM Bridge domain name
SCIMBridgeVersion:
default: 1Password SCIM Bridge version
WorkspaceCredentials:
default: Service account key
WorkspaceActor:
default: Actor
Parameters:
VPCID:
Type: String
Description: >-
(Optional) ID of an existing VPC to use for your SCIM bridge. If empty, a new VPC and two public subnets will be
created.
VPCCIDR:
Type: String
Default: 10.0.0.0/16
Description: A CIDR block for the VPC. Required if VPCID is empty; ignored if specifying a VPCID.
PublicSubnets:
Type: CommaDelimitedList
Description: (Optional) A comma-separated list of two or more public subnets in the specified VPC.
ConstraintDescription: >-
must be a list of at least two existing subnets associated a unique availability zone in the specified VPC
Route53HostedZoneID:
Type: String
Description: >-
(Optional) The Route 53 hosted zone in which to create DNS records for ACM validation and the ALB endpoint. If
empty, these records must be created in your DNS provider.
ProvisioningVolume:
Type: String
Description: >-
The expected volume of provisioning activity. Use base for provisioning less than 1,000 users, high for up to
5,000 users, or very-high for more than 5,000 users.
Default: base
AllowedValues:
- base
- high
- very-high
ConstraintDescription: must be base, high, or very-high
DomainName:
Type: String
Default: scim.example.com
Description: >-
A fully qualified domain name for your SCIM bridge.
scimsession:
Type: String
Description: >-
The plain text contents of the scimsession file created during the automated user provisioning setup in your
1Password account.
MinLength: 1
ConstraintDescription: must not be empty
NoEcho: true
SCIMBridgeVersion:
Type: String
Default: v2.9.9
Description: >-
The tag of the 1Password SCIM Bridge image to pull from Docker Hub.
WorkspaceCredentials:
Type: String
Default: ""
Description: >-
The plain text contents of the key file associated with the service account for Google Workspace.
NoEcho: true
WorkspaceActor:
Type: String
Default: ""
Description: >-
The email address of the Google Workspace administrator that the service account is acting on behalf of.
Rules:
ValidateWorkspaceConfig:
RuleCondition: !Not
- Fn::EachMemberEquals:
- - !Ref WorkspaceCredentials
- !Ref WorkspaceActor
- ""
Assertions:
- Assert: !Not [!Equals [!Ref WorkspaceCredentials, ""]]
AssertDescription: >-
The service account key is required to connect to Google Workspace.
- Assert: !Not [!Equals [!Ref WorkspaceActor, ""]]
AssertDescription: >-
The actor email is required to connect to Google Workspace.
Mappings:
CpuScale:
base:
SCIMBridge: 128
Redis: 128
Task: 256
high:
SCIMBridge: 512
Redis: 128
Task: 1024
very-high:
SCIMBridge: 1024
Redis: 128
Task: 2048
MemoryScale:
base:
SCIMBridge: 512
Redis: 512
Task: 1024
high:
SCIMBridge: 1024
Redis: 512
Task: 2048
very-high:
SCIMBridge: 1024
Redis: 512
Task: 4096
Conditions:
CreateVPC: !Equals [!Ref VPCID, ""]
CreateRoute53Records: !Not [!Equals [!Ref Route53HostedZoneID, ""]]
OutputDNSRecordContent: !Not [Condition: CreateRoute53Records]
UsingGoogleWorkspace: !Not
- !Or
- !Equals [!Ref WorkspaceCredentials, ""]
- !Equals [!Ref WorkspaceActor, ""]
Resources:
scimsessionSecret:
Type: AWS::SecretsManager::Secret
Properties:
SecretString: !Ref scimsession
WorkspaceCredentialsSecret:
Type: AWS::SecretsManager::Secret
Condition: UsingGoogleWorkspace
Properties:
SecretString: !Ref WorkspaceCredentials
WorkspaceSettingsSecret:
Type: AWS::SecretsManager::Secret
Condition: UsingGoogleWorkspace
Properties:
SecretString: !Sub |-
{
"actor":"${WorkspaceActor}",
"bridgeAddress":"https://${DomainName}"
}
ECSCluster:
Type: AWS::ECS::Cluster
DependsOn: ExecutionRole
Properties:
CapacityProviders:
- FARGATE
DefaultCapacityProviderStrategy:
- CapacityProvider: FARGATE
Weight: 1
ECSTaskDefinition:
Type: AWS::ECS::TaskDefinition
Properties:
Family: op-scim-bridge
RequiresCompatibilities:
- FARGATE
NetworkMode: awsvpc
Cpu: !FindInMap
- CpuScale
- !Ref ProvisioningVolume
- Task
Memory: !FindInMap
- MemoryScale
- !Ref ProvisioningVolume
- Task
ExecutionRoleArn: !GetAtt ExecutionRole.Arn
TaskRoleArn: !Ref TaskRole
RuntimePlatform:
CpuArchitecture: ARM64
OperatingSystemFamily: LINUX
Volumes:
- Name: secrets
ContainerDefinitions:
- Name: mount-secrets
Essential: false
Image: amazon/aws-cli
MountPoints:
- ContainerPath: /aws
SourceVolume: secrets
Environment:
- Name: SCIMSESSION_ARN
Value: !Ref scimsessionSecret
- !If
- UsingGoogleWorkspace
- Name: WORKSPACE_CREDENTIALS_ARN
Value: !Ref WorkspaceCredentialsSecret
- !Ref AWS::NoValue
- !If
- UsingGoogleWorkspace
- Name: WORKSPACE_SETTINGS_ARN
Value: !Ref WorkspaceSettingsSecret
- !Ref AWS::NoValue
EntryPoint:
- /bin/bash
- -c
Command:
- !Join
- " "
- - >-
aws secretsmanager get-secret-value
--secret-id $SCIMSESSION_ARN --query SecretString --output text
> scimsession
- !If
- UsingGoogleWorkspace
- >-
&& aws secretsmanager get-secret-value
--secret-id $WORKSPACE_CREDENTIALS_ARN --query SecretString --output text
> workspace-credentials.json
&& aws secretsmanager get-secret-value
--secret-id $WORKSPACE_SETTINGS_ARN --query SecretString --output text
> workspace-settings.json
- !Ref AWS::NoValue
LogConfiguration:
LogDriver: awslogs
Options:
awslogs-region: !Ref AWS::Region
awslogs-group: !Ref LogGroup
awslogs-stream-prefix: !Ref LogStream
- Name: op-scim-bridge
Cpu: !FindInMap
- CpuScale
- !Ref ProvisioningVolume
- SCIMBridge
Memory: !FindInMap
- MemoryScale
- !Ref ProvisioningVolume
- SCIMBridge
Image: !Sub 1password/scim:${SCIMBridgeVersion}
User: opuser:opuser
PortMappings: [ContainerPort: 3002]
DependsOn:
- ContainerName: mount-secrets
Condition: SUCCESS
- ContainerName: redis
Condition: HEALTHY
MountPoints:
- ContainerPath: /home/opuser/.op
SourceVolume: secrets
LogConfiguration:
LogDriver: awslogs
Options:
awslogs-region: !Ref AWS::Region
awslogs-group: !Ref LogGroup
awslogs-stream-prefix: !Ref LogStream
- Name: redis
Cpu: !FindInMap
- CpuScale
- !Ref ProvisioningVolume
- Redis
Memory: !FindInMap
- MemoryScale
- !Ref ProvisioningVolume
- Redis
Image: redis
User: redis:redis
Command:
- --maxmemory 256mb
- --maxmemory-policy volatile-lru
- --save ""
PortMappings: [ContainerPort: 6379]
HealthCheck:
Command:
- CMD-SHELL
- redis-cli ping | grep PONG
LogConfiguration:
LogDriver: awslogs
Options:
awslogs-region: !Ref AWS::Region
awslogs-group: !Ref LogGroup
awslogs-stream-prefix: !Ref LogStream
LogGroup:
Type: AWS::Logs::LogGroup
LogStream:
Type: AWS::Logs::LogStream
Properties:
LogGroupName: !Ref LogGroup
ECSService:
Type: AWS::ECS::Service
DependsOn: HTTPSListener
Properties:
Cluster: !Ref ECSCluster
TaskDefinition: !Ref ECSTaskDefinition
DesiredCount: 1
HealthCheckGracePeriodSeconds: 60
LaunchType: FARGATE
NetworkConfiguration:
AwsvpcConfiguration:
AssignPublicIp: ENABLED
Subnets: !If
- CreateVPC
- [!Ref PublicSubnet1, !Ref PublicSubnet2]
- !Ref PublicSubnets
SecurityGroups:
- !Ref ServiceSecurityGroup
LoadBalancers:
- ContainerName: op-scim-bridge
ContainerPort: 3002
TargetGroupArn: !Ref TargetGroup
TargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
HealthCheckIntervalSeconds: 10
HealthCheckPath: /ping
Matcher:
HttpCode: 200,301,302
HealthCheckTimeoutSeconds: 5
UnhealthyThresholdCount: 2
HealthyThresholdCount: 2
Port: 3002
Protocol: HTTP
TargetGroupAttributes:
- Key: deregistration_delay.timeout_seconds
Value: 60
TargetType: ip
VpcId: !If [CreateVPC, !Ref VPC, !Ref VPCID]
LoadBalancer:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
Scheme: internet-facing
Subnets: !If
- CreateVPC
- [!Ref PublicSubnet1, !Ref PublicSubnet2]
- !Ref PublicSubnets
SecurityGroups:
- !Ref LoadBalancerSecurityGroup
LoadBalancerSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: >-
Allow public HTTPS ingress to the load balancer from the identity
provider, restrict egress to the VPC for 1Password SCIM Bridge
VpcId: !If [CreateVPC, !Ref VPC, !Ref VPCID]
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 443
ToPort: 443
CidrIp: 0.0.0.0/0
SecurityGroupEgress:
- IpProtocol: tcp
FromPort: 3002
ToPort: 3002
CidrIp: !If
- CreateVPC
- !GetAtt VPC.CidrBlock
- 0.0.0.0/0
ServiceSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: >-
Restrict ingress to ECS Service from load balancer, allow egress to
1Password.com for 1Password SCIM Bridge.
VpcId: !If [CreateVPC, !Ref VPC, !Ref VPCID]
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 3002
ToPort: 3002
SourceSecurityGroupId: !Ref LoadBalancerSecurityGroup
SecurityGroupEgress:
- IpProtocol: tcp
FromPort: 443
ToPort: 443
CidrIp: 0.0.0.0/0
HTTPSListener:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
DefaultActions:
- Type: forward
TargetGroupArn: !Ref TargetGroup
LoadBalancerArn: !Ref LoadBalancer
Port: 443
Protocol: HTTPS
Certificates:
- CertificateArn: !Ref TLSCertificate
SslPolicy: ELBSecurityPolicy-TLS13-1-2-2021-06
ExecutionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Sid: ""
Effect: Allow
Principal:
Service:
- ecs-tasks.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: inlined_managed_policy
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource:
- arn:aws:logs:*:*:*
DNSRecord:
Condition: CreateRoute53Records
Type: AWS::Route53::RecordSet
Properties:
HostedZoneId: !Ref Route53HostedZoneID
Comment: DNS record pointing to load balancer for 1Password SCIM Bridge
Name: !Ref DomainName
Type: A
AliasTarget:
DNSName: !GetAtt LoadBalancer.DNSName
HostedZoneId: !GetAtt LoadBalancer.CanonicalHostedZoneID
TLSCertificate:
Type: AWS::CertificateManager::Certificate
Properties:
DomainName: !Ref DomainName
ValidationMethod: DNS
DomainValidationOptions: !If
- CreateRoute53Records
- - DomainName: !Ref DomainName
HostedZoneId: !Ref Route53HostedZoneID
- !Ref AWS::NoValue
TaskRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- ecs-tasks.amazonaws.com
Action:
- sts:AssumeRole
Path: /
Policies:
- PolicyName: cloudwatch_logging
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource: "*"
- PolicyName: vpc_access
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- ec2:CreateNetworkInterface
- ec2:DescribeNetworkInterfaces
- ec2:DeleteNetworkInterface
Resource: "*"
- PolicyName: secrets_manager_policy
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- secretsmanager:GetSecretValue
Resource:
- !Ref scimsessionSecret
- !If
- UsingGoogleWorkspace
- !Ref WorkspaceCredentialsSecret
- !Ref AWS::NoValue
- !If
- UsingGoogleWorkspace
- !Ref WorkspaceSettingsSecret
- !Ref AWS::NoValue
VPC:
Condition: CreateVPC
Type: AWS::EC2::VPC
Properties:
CidrBlock: !Ref VPCCIDR
EnableDnsHostnames: true
EnableDnsSupport: true
PublicSubnet1:
Type: AWS::EC2::Subnet
Condition: CreateVPC
Properties:
AvailabilityZone:
Fn::Select:
- 0
- Fn::GetAZs: !Ref AWS::Region
VpcId: !Ref VPC
CidrBlock:
Fn::Select:
- 0
- Fn::Cidr:
- !GetAtt VPC.CidrBlock
- 16
- 12
PublicSubnet2:
Type: AWS::EC2::Subnet
Condition: CreateVPC
Properties:
AvailabilityZone:
Fn::Select:
- 1
- Fn::GetAZs: !Ref AWS::Region
VpcId: !Ref VPC
CidrBlock:
Fn::Select:
- 1
- Fn::Cidr:
- !GetAtt VPC.CidrBlock
- 16
- 12
InternetGateway:
Condition: CreateVPC
Type: AWS::EC2::InternetGateway
GatewayAttachment:
Condition: CreateVPC
Type: AWS::EC2::VPCGatewayAttachment
Properties:
VpcId: !Ref VPC
InternetGatewayId: !Ref InternetGateway
RouteTable:
Condition: CreateVPC
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
Route:
Condition: CreateVPC
Type: AWS::EC2::Route
DependsOn: GatewayAttachment
Properties:
RouteTableId: !Ref RouteTable
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref InternetGateway
PublicSubnet1RouteTableAssociation:
Condition: CreateVPC
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref PublicSubnet1
RouteTableId: !Ref RouteTable
PublicSubnet2RouteTableAssociation:
Condition: CreateVPC
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref PublicSubnet2
RouteTableId: !Ref RouteTable
Outputs:
CNAMEName:
Condition: OutputDNSRecordContent
Description: >-
Name of a DNS record to point to the load balancer. Use with CNAMEValue to create a CNAME record in your DNS
provider.
Value: !Sub ${DomainName}.
CNAMEValue:
Condition: OutputDNSRecordContent
Description: >-
Value of a DNS record to point to the load balancer. Use with CNAMEName to create a public CNAME record in your
DNS provider.
Value: !Sub ${LoadBalancer.DNSName}.
SCIMBridgeURL:
Description: >-
The URL for your SCIM bridge. Use this and your bearer token to connect
your identity provider to 1Password.
Value: !Sub https://${DomainName}