-
Notifications
You must be signed in to change notification settings - Fork 182
/
template.yaml
764 lines (716 loc) · 27.7 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
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
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: Which pattern are we deploying? The app with secrets, the app but using existing secrets, or just the secrets.
Parameters:
- DeployPattern
- Label:
default: AWS IAM Identity Center (Successor to AWS Single Sign-On)
Parameters:
- SCIMEndpointUrl
- SCIMEndpointAccessToken
- Region
- IdentityStoreID
- Label:
default: Google Workspace Credentials
Parameters:
- GoogleAdminEmail
- GoogleCredentials
- Label:
default: Sync Configuration
Parameters:
- SyncMethod
- GoogleUserMatch
- GoogleGroupMatch
- IgnoreUsers
- IgnoreGroups
- Label:
default: "Configuration options for users_groups Mode only"
Parameters:
- IncludeGroups
- Label:
default: "Lambda Configuration"
Parameters:
- FunctionName
- LogLevel
- LogFormat
- TimeOut
- ScheduleExpression
AWS::ServerlessRepo::Application:
Name: ssosync
Description: Helping you populate AWS SSO directly with your Google Apps users.
Author: Sebastian Doell
SpdxLicenseId: Apache-2.0
# paths are relative to .aws-sam/build directory
LicenseUrl: LICENSE
ReadmeUrl: SAR.md
Labels: [serverless, sso, lambda, scim]
HomePageUrl: https://github.com/awslabs/ssosync
# Update the semantic version and run sam publish to publish a new version of your app
SemanticVersion: 1.0.0-rc.10
# best practice is to use git tags for each release and link to the version tag as your source code URL
SourceCodeUrl: https://github.com/awslabs/ssosync
Parameters:
DeployPattern:
Type: String
Description: |
App + secrets (default); you provide the values for the secrets and the everything is setup.
App only; Deploys the app and to use the secrets you provide the arn for, that exist in this account.
App for cross-account; Deploys the app and to use the secrets you provide the arn for, also requires details of the KMS key used to encrypt them.
Secrets only; Just creates the secrets.
Secrets for cross-account; Just creates the secrets, and encrypts them with a KMS key and share them with the target account.
Default: App + secrets
AllowedValues:
- App + secrets
- App only
- App for cross-account
- Secrets only
- Secrets for cross-account
CrossStackConfig:
Type: String
Description: |
[App for cross-account] this is the AppConfig from the ouputs of the Secrets for cross-account stack.
[Secrets for cross-account] this is the AWS account id into which you will be deplying the SSOSync app?
Default: ""
AllowedPattern: '(?!.*\s)|(\d{12})|(arn:aws:secretsmanager:((us(-gov)?|ap|ca|cn|eu|sa)-(central|(north|south)?(east|west)?)-\d):[0-9]{8,12}:secret:[a-zA-Z0-9/_+=.@-]{1,512})(,arn:aws:secretsmanager:((us(-gov)?|ap|ca|cn|eu|sa)-(central|(north|south)?(east|west)?)-\d):[0-9]{8,12}:secret:[a-zA-Z0-9/_+=.@-]{1,512}){5}(,arn:aws:kms:((us(-gov)?|ap|ca|cn|eu|sa)-(central|(north|south)?(east|west)?)-\d):[0-9]{12}:key/[a-zA-Z0-9/_+=.@-]{1,512})?'
FunctionName:
Type: String
Description: |
[optional] Specify the name you want to us for this deployment, if you want to trigger SSOSync as part of a pipeline or other automation this will ensure a consistent arn to call. leave empty for default behaviour.
Default: ""
AllowedPattern: '(?!.*\s)|[a-zA-Z0-9-_]{1,140}'
ScheduleExpression:
Type: String
Description: |
[optional] Schedule for trigger the execution of ssosync (see CloudWatch schedule expressions), leave empty if you want to trigger execution by another method such as AWS CodePipeline.
Default: rate(15 minutes)
AllowedPattern: '(?!.*\s)|rate\(\d{1,3} (minutes|hours|days)\)|(cron\((([0-9]|[1-5][0-9]|60)|\d\/([0-9]|[1-5][0-9]|60)|\*) (([0-9]|[1][0-9]|[2][0-3])|(\d\/([0-9]|[1][0-9]|[2][0-3]))|(([0-9]|[1][0-9]|[2][0-3])-([0-9]|[1][0-9]|[2][0-3]))|\*) (([1-9]|[1-2][0-9]|[3][0-1])|\d\/([1-9]|[1-2][0-9]|[3][0-1])|[1-5]W|L|\*|\?) (([1-9]|[1][1-2])|(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)|((JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV)-(FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC))|(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV)(,(FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)){0,11}|\d\/([0-9]|[1][0-2])|\?|\*) ((MON|TUE|WED|THU|FRI|SAT|SUN)|(MON|TUE|WED|THU|FRI|SAT)-(TUE|WED|THU|FRI|SAT|SUN)|(MON|TUE|WED|THU|FRI|SAT)(,(TUE|WED|THU|FRI|SAT|SUN)){0,6}|[1-7]L|[1-7]#[1-5]|\?|\*) ((19[7-9][0-9]|2[0-1]\d\d)|(19[7-9][0-9]|2[0-1]\d\d)-(19[7-9][0-9]|2[0-1]\d\d)|(19[7-9][0-9]|2[0-1]\d\d)(,(19[7-9][0-9]|2[0-1]\d\d))*|\*)\))'
LogLevel:
Type: String
Description: |
[required] Log level for Lambda function logging
Default: warn
AllowedValues:
- panic
- fatal
- error
- warn
- info
- debug
- trace
LogFormat:
Type: String
Description: |
[required] Log format for Lambda function logging
Default: json
AllowedValues:
- json
- text
TimeOut:
Type: Number
Description: |
[required] Timeout for the Lambda function
Default: 300
MinValue: 1
MaxValue: 900
# Secrets
GoogleCredentials:
Type: String
Description: |
Credentials to log into Google (content of credentials.json)
Default: ""
AllowedPattern: '(?!.*\s)|(\{(\s)*(".*")(\s)*:(\s)*(".*")(\s)*\})'
NoEcho: true
GoogleAdminEmail:
Type: String
Description: |
Google Admin email
Default: ""
AllowedPattern: '(?!.*\s)|(([a-zA-Z0-9.+=_-]{0,61})@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*)'
NoEcho: true
SCIMEndpointUrl:
Type: String
Description: |
AWS IAM Identity Center - SCIM Endpoint Url
Default: ""
AllowedPattern: '(?!.*\s)|(https://scim.(us(-gov)?|ap|ca|cn|eu|sa)-(central|(north|south)?(east|west)?)-([0-9]{1}).amazonaws.com/(.*)-([a-z0-9]{4})-([a-z0-9]{4})-([a-z0-9]{12})/scim/v2/?)'
SCIMEndpointAccessToken:
Type: String
Description: |
AWS IAM Identity Center - SCIM AccessToken
Default: ""
AllowedPattern: '(?!.*\s)|([0-9a-zA-Z/=+-\\]{500,620})'
NoEcho: true
Region:
Type: String
Description: |
AWS Region where AWS IAM Identity Center is enabled
Default: ""
AllowedPattern: '(?!.*\s)|(us(-gov)?|ap|ca|cn|eu|sa)-(central|(north|south)?(east|west)?)-\d'
IdentityStoreID:
Type: String
Description: |
Identifier of Identity Store in AWS IAM Identity Center
Default: ""
AllowedPattern: '(?!.*\s)|d-[1-z0-9]{10}'
GoogleUserMatch:
Type: String
Description: |
[optional] Google Workspace Users filter query parameter, a simple '*' denotes sync all users in the directory. example: 'name:John*,email:admin*', '*' or name=John Doe,email:admin*' see: https://developers.google.com/admin-sdk/directory/v1/guides/search-users, if left empty no users will be selected but if a pattern has been set for GroupMatch users that are members of the groups it matches will still be selected.
Default: ""
AllowedPattern: '(?!.*\s)|(\*)|((((name|Name|NAME)((:[a-zA-Z0-9\- ]{1,64}\*)|(=[a-zA-Z0-9\- ]{1,64})))|((email|Email|EMAIL)((:[a-zA-Z0-9.\-_]{1,64}\*)|(=([a-zA-Z0-9.\-_]{1,64})@([a-zA-Z0-9.\-]{5,260})))))(,(((name|Name|NAME)((:[a-zA-Z0-9\- ]{1,64}\*)|(=[a-zA-Z0-9\- ]{1,64})))|((email|Email|EMAIL)((:[a-zA-Z0-9.\-_]{1,64}\*)|(=([a-zA-Z0-9.\-_]{1,64})@([a-zA-Z0-9.\-]{5,260}))))))*)'
GoogleGroupMatch:
Type: String
Description: |
[optional] Google Workspace Groups filter query parameter, a simple '*' denotes sync all groups (and any users that are members of those groups). example: 'name:Admin*,email:aws-*', 'name=Admins' or '*' see: https://developers.google.com/admin-sdk/directory/v1/guides/search-groups, if left empty no groups will be selected.
Default: "*"
AllowedPattern: '(?!.*\s)|(\*)|((((name|Name|NAME)((:[a-zA-Z0-9\- ]{1,64}\*)|(=[a-zA-Z0-9\- ]{1,64})))|((email|Email|EMAIL)((:[a-zA-Z0-9.\-_]{1,64}\*)|(=([a-zA-Z0-9.\-_]{1,64})@([a-zA-Z0-9.\-]{5,260})))))(,(((name|Name|NAME)((:[a-zA-Z0-9\- ]{1,64}\*)|(=[a-zA-Z0-9\- ]{1,64})))|((email|Email|EMAIL)((:[a-zA-Z0-9.\-_]{1,64}\*)|(=([a-zA-Z0-9.\-_]{1,64})@([a-zA-Z0-9.\-]{5,260}))))))*)'
IgnoreGroups:
Type: String
Description: |
[optional] Ignore these Google Workspace groups, leave empty if not required
Default: ""
AllowedPattern: '(?!.*\s)|((([a-zA-Z0-9.\-_]{1,64})@([a-zA-Z0-9.\-]{5,260}))(,(([a-zA-Z0-9.\-_]{1,64})@([a-zA-Z0-9.\-]{5,260})))*)'
IgnoreUsers:
Type: String
Description: |
[optional] Ignore these Google Workspace users, leave empty if not required
Default: ""
AllowedPattern: '(?!.*\s)|((([a-zA-Z0-9.\-_]{1,64})@([a-zA-Z0-9.\-]{5,260}))(,(([a-zA-Z0-9.\-_]{1,64})@([a-zA-Z0-9.\-]{5,260})))*)'
IncludeGroups:
Type: String
Description: |
[optional] Include only these Google Workspace groups, leave empty if not required. (Only applicable for SyncMethod user_groups)
Default: ""
AllowedPattern: '(?!.*\s)|((([a-zA-Z0-9.\-_]{1,64})@([a-zA-Z0-9.\-]{5,260}))(,(([a-zA-Z0-9.\-_]{1,64})@([a-zA-Z0-9.\-]{5,260})))*)'
SyncMethod:
Type: String
Description: Sync method to use
Default: groups
AllowedValues:
- groups
- users_groups
Conditions:
SetFunctionName: !Not
- !Equals
- !Ref FunctionName
- ""
SetGoogleUserMatch: !And
- !Not
- !Equals
- !Ref GoogleUserMatch
- ""
- !Equals
- !Ref SyncMethod
- "groups"
SetGoogleGroupMatch: !And
- !Not
- !Equals
- !Ref GoogleGroupMatch
- ""
- !Equals
- !Ref SyncMethod
- "groups"
SetIgnoreGroups: !Not
- !Equals
- !Ref IgnoreGroups
- ""
SetIgnoreUsers: !Not
- !Equals
- !Ref IgnoreUsers
- ""
SetIncludeGroups: !And
- !Not
- !Equals
- !Ref IncludeGroups
- ""
- !Equals
- !Ref SyncMethod
- "users_groups"
OnSchedule: !Not
- !Equals
- !Ref ScheduleExpression
- ""
CreateFunction: !Or
- !Equals
- !Ref DeployPattern
- "App for cross-account"
- !Equals
- !Ref DeployPattern
- "App + secrets"
- !Equals
- !Ref DeployPattern
- "App only"
CreateSecrets: !Or
- !Equals
- !Ref DeployPattern
- "App + secrets"
- !Equals
- !Ref DeployPattern
- "Secrets only"
- !Equals
- !Ref DeployPattern
- "Secrets for cross-account"
CreateKey: !Equals
- !Ref DeployPattern
- "Secrets for cross-account"
RemoteSecrets: !Equals
- !Ref DeployPattern
- "App for cross-account"
LocalSecrets: !Or
- !Equals
- !Ref DeployPattern
- "App + secrets"
- !Equals
- !Ref DeployPattern
- "App only"
OutputFunction: !Or
- !Equals
- !Ref DeployPattern
- "App + secrets"
- !Equals
- !Ref DeployPattern
- "App only"
- !Equals
- !Ref DeployPattern
- "App for cross-account"
OutputSecrets: !Equals
- !Ref DeployPattern
- "Secrets only"
Rules:
SecretValues:
RuleCondition: !Or
- !Equals
- !Ref DeployPattern
- "App + secrets"
- !Equals
- !Ref DeployPattern
- "Secrets only"
- !Equals
- !Ref DeployPattern
- "Secrets for cross-account"
Assertions:
- Assert: !Not
- !Equals
- !Ref GoogleCredentials
- ""
AssertDescription: 'The contents of the Credentials.json is required for this deployment type.'
- Assert: !Not
- !Equals
- !Ref GoogleAdminEmail
- ""
AssertDescription: 'The email address of a directory admin is required for this deployment type.'
- Assert: !Not
- !Equals
- !Ref SCIMEndpointUrl
- ""
AssertDescription: 'The SCIM url from IAM Identity Center is required for this deployment type.'
- Assert: !Not
- !Equals
- !Ref SCIMEndpointAccessToken
- ""
AssertDescription: 'The SCIM Access Token is required for this deployment type.'
- Assert: !Not
- !Equals
- !Ref Region
- ""
AssertDescription: 'The Region in which IAM Identity Center is deployed is required for this deployment type.'
- Assert: !Not
- !Equals
- !Ref IdentityStoreID
- ""
AssertDescription: 'The Identity Store Id for IAM Identity Center is required for this deployment type.'
LocalSecrets:
RuleCondition: !Or
- !Equals
- !Ref DeployPattern
- "App + secrets"
- !Equals
- !Ref DeployPattern
- "Secrets only"
Assertions:
- Assert: !Equals
- !Ref CrossStackConfig
- ""
AssertDescription: 'Do not provide a Cross Stack Configuration for this deployment type.'
CrossSecrets:
RuleCondition: !Equals
- !Ref DeployPattern
- "Secrets for cross-account"
Assertions:
- Assert: !Not
- !Equals
- !Ref CrossStackConfig
- ""
AssertDescription: 'The AWS account id, of the account where you intend to deploy the app.'
CrossApp:
RuleCondition: !Or
- !Equals
- !Ref DeployPattern
- "App"
- !Equals
- !Ref DeployPattern
- "App for cross-account"
Assertions:
- Assert: !Equals
- !Ref GoogleCredentials
- ""
AssertDescription: 'A value for GoogleCredentials is not required for this deployment type.'
- Assert: !Equals
- !Ref GoogleAdminEmail
- ""
AssertDescription: 'A value for GoogleAdminEmail is not required for this deployment type.'
- Assert: !Equals
- !Ref SCIMEndpointUrl
- ""
AssertDescription: 'A value for SCIMEndpointUrl is not required for this deployment type.'
- Assert: !Equals
- !Ref SCIMEndpointAccessToken
- ""
AssertDescription: 'A value for SCIMEndpointAccessToken is not required for this deployment type.'
- Assert: !Equals
- !Ref Region
- ""
AssertDescription: 'A value for Region is not required for this deployment type.'
- Assert: !Equals
- !Ref IdentityStoreID
- ""
AssertDescription: 'A value for IdentityStoreID is not required for this deployment type.'
- Assert: !Not
- !Equals
- !Ref CrossStackConfig
- ""
AssertDescription: 'AppConfig copied from the outputs of the secrets stack is required for this deployment type.'
Resources:
SSOSyncRoleLocal:
Type: AWS::IAM::Role
Condition: LocalSecrets
Properties:
RoleName: SSOSyncAppRole
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Action:
- sts:AssumeRole
Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Path: /
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AWSLambdaExecute
Policies:
- PolicyName: SSOSyncAppPolicy
PolicyDocument:
Version: '2012-10-17'
Statement:
- Sid: SSMGetParameterPolicy
Effect: Allow
Action:
- "secretsmanager:Get*"
Resource:
- !If [CreateSecrets, !Ref SecretGoogleCredentials, !Select [0, !Split [',', !Ref CrossStackConfig]]]
- !If [CreateSecrets, !Ref SecretGoogleAdminEmail, !Select [1, !Split [',', !Ref CrossStackConfig]]]
- !If [CreateSecrets, !Ref SecretSCIMEndpoint, !Select [2, !Split [',', !Ref CrossStackConfig]]]
- !If [CreateSecrets, !Ref SecretSCIMAccessToken, !Select [3, !Split [',', !Ref CrossStackConfig]]]
- !If [CreateSecrets, !Ref SecretRegion, !Select [4, !Split [',', !Ref CrossStackConfig]]]
- !If [CreateSecrets, !Ref SecretIdentityStoreID, !Select [5, !Split [',', !Ref CrossStackConfig]]]
- Sid: IdentityStoreAccesPolicy
Effect: Allow
Action:
- "identitystore:DeleteUser"
- "identitystore:CreateGroup"
- "identitystore:CreateGroupMembership"
- "identitystore:ListGroups"
- "identitystore:ListUsers"
- "identitystore:ListGroupMemberships"
- "identitystore:IsMemberInGroups"
- "identitystore:GetGroupMembershipId"
- "identitystore:DeleteGroupMembership"
- "identitystore:DeleteGroup"
Resource:
- "*"
- Sid: CodePipelinePolicy
Effect: Allow
Action:
- codepipeline:PutJobSuccessResult
- codepipeline:PutJobFailureResult
Resource: "*"
SSOSyncRoleRemote:
Type: AWS::IAM::Role
Condition: RemoteSecrets
Properties:
RoleName: SSOSyncAppRole
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Action:
- sts:AssumeRole
Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Path: /
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AWSLambdaExecute
Policies:
- PolicyName: SSOSyncAppPolicy
PolicyDocument:
Version: '2012-10-17'
Statement:
- Sid: SSMGetParameterPolicy
Effect: Allow
Action:
- "secretsmanager:Get*"
Resource:
- !Select [0, !Split [',', !Ref CrossStackConfig]] # GoogleCredentials
- !Select [1, !Split [',', !Ref CrossStackConfig]] # GoogleAdminEmail
- !Select [2, !Split [',', !Ref CrossStackConfig]] # SCIMEndpointUrl
- !Select [3, !Split [',', !Ref CrossStackConfig]] # SCIMEndpointAccessToken
- !Select [4, !Split [',', !Ref CrossStackConfig]] # Region
- !Select [5, !Split [',', !Ref CrossStackConfig]] # IdentityStoreID
- Sid: KMSDecryptPolicy
Effect: Allow
Action:
- kms:Decrypt
Resource:
- !Select [6, !Split [',', !Ref CrossStackConfig]] # KMSSecret
- Sid: IdentityStoreAccesPolicy
Effect: Allow
Action:
- "identitystore:DeleteUser"
- "identitystore:CreateGroup"
- "identitystore:CreateGroupMembership"
- "identitystore:ListGroups"
- "identitystore:ListUsers"
- "identitystore:ListGroupMemberships"
- "identitystore:IsMemberInGroups"
- "identitystore:GetGroupMembershipId"
- "identitystore:DeleteGroupMembership"
- "identitystore:DeleteGroup"
Resource:
- "*"
- Sid: CodePipelinePolicy
Effect: Allow
Action:
- codepipeline:PutJobSuccessResult
- codepipeline:PutJobFailureResult
Resource: "*"
SSOSyncFunction:
Type: AWS::Serverless::Function
Condition: CreateFunction
Properties:
FunctionName: !If [SetFunctionName, !Ref FunctionName, !Ref AWS::NoValue]
Description: "An instance of ssosync deplyed from the Serverless Application Repository, for details see http://https://github.com/awslabs/ssosync"
Role: !If [RemoteSecrets, !GetAtt SSOSyncRoleRemote.Arn, !GetAtt SSOSyncRoleLocal.Arn]
Runtime: provided.al2
Handler: bootstrap
Architectures:
- arm64
Timeout: !Ref TimeOut
ReservedConcurrentExecutions: 1
Environment:
Variables:
LOG_LEVEL: !Ref LogLevel
LOG_FORMAT: !Ref LogFormat
GOOGLE_CREDENTIALS: !If [CreateSecrets, !Ref SecretGoogleCredentials, !Select [0, !Split [',', !Ref CrossStackConfig]]]
GOOGLE_ADMIN: !If [CreateSecrets, !Ref SecretGoogleAdminEmail, !Select [1, !Split [',', !Ref CrossStackConfig]]]
SCIM_ENDPOINT: !If [CreateSecrets, !Ref SecretSCIMEndpoint, !Select [2, !Split [',', !Ref CrossStackConfig]]]
SCIM_ACCESS_TOKEN: !If [CreateSecrets, !Ref SecretSCIMAccessToken, !Select [3, !Split [',', !Ref CrossStackConfig]]]
REGION: !If [CreateSecrets, !Ref SecretRegion, !Select [4, !Split [',', !Ref CrossStackConfig]]]
IDENTITY_STORE_ID: !If [CreateSecrets, !Ref SecretIdentityStoreID, !Select [5, !Split [',', !Ref CrossStackConfig]]]
USER_MATCH: !If [SetGoogleUserMatch, !Ref GoogleUserMatch, !Ref AWS::NoValue]
GROUP_MATCH: !If [SetGoogleGroupMatch, !Ref GoogleGroupMatch, !Ref AWS::NoValue]
SYNC_METHOD: !Ref SyncMethod
IGNORE_GROUPS: !If [SetIgnoreGroups, !Ref IgnoreGroups, !Ref AWS::NoValue]
IGNORE_USERS: !If [SetIgnoreUsers, !Ref IgnoreUsers, !Ref AWS::NoValue]
INCLUDE_GROUPS: !If [SetIncludeGroups, !Ref IncludeGroups, !Ref AWS::NoValue]
Events:
SyncScheduledEvent:
Type: Schedule
Name: AWSSyncSchedule
Properties:
Enabled: !If [OnSchedule, false, true]
Schedule: !If [OnSchedule, !Ref ScheduleExpression, "rate(15 minutes)"]
KeyAlias:
Type: AWS::KMS::Alias
Condition: CreateKey
Properties:
AliasName: alias/SSOSync
TargetKeyId: !Ref KeyForSecrets
KeyForSecrets:
Type: AWS::KMS::Key
Condition: CreateKey
Properties:
Description: Key for protecting SSOSync Secrets in cross-account deployment
Enabled: true
KeySpec: SYMMETRIC_DEFAULT
KeyUsage: ENCRYPT_DECRYPT
MultiRegion: false
PendingWindowInDays: 7
KeyPolicy:
Version: 2012-10-17
Id: key-default-1
Statement:
- Sid: Enable IAM User Permissions
Effect: Allow
Principal:
AWS: !Sub arn:aws:iam::${AWS::AccountId}:root
Action: 'kms:*'
Resource: '*'
- Sid: AppRole in Other account
Effect: Allow
Principal:
AWS: !Sub arn:aws:iam::${CrossStackConfig}:root
Action:
- kms:Decrypt
- kms:DescribeKey
Resource: '*'
SecretGoogleCredentials:
Type: "AWS::SecretsManager::Secret"
Condition: CreateSecrets
Properties:
Name: SSOSyncGoogleCredentials
SecretString: !Ref GoogleCredentials
KmsKeyId: !If [CreateKey, !Ref KeyAlias, alias/aws/secretsmanager]
SecretGoogleCredentialsPolicy:
Type: AWS::SecretsManager::ResourcePolicy
Condition: CreateKey
Properties:
SecretId: !Ref SecretGoogleCredentials
ResourcePolicy:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
AWS: !Sub arn:aws:iam::${CrossStackConfig}:root
Action:
- secretsmanager:GetSecretValue
Resource: '*'
SecretGoogleAdminEmail:
Type: "AWS::SecretsManager::Secret"
Condition: CreateSecrets
Properties:
Name: SSOSyncGoogleAdminEmail
SecretString: !Ref GoogleAdminEmail
KmsKeyId: !If [CreateKey, !Ref KeyAlias, alias/aws/secretsmanager]
SecretGoogleAdminEmailPolicy:
Type: AWS::SecretsManager::ResourcePolicy
Condition: CreateKey
Properties:
SecretId: !Ref SecretGoogleAdminEmail
ResourcePolicy:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
AWS: !Sub arn:aws:iam::${CrossStackConfig}:root
Action:
- secretsmanager:GetSecretValue
Resource: '*'
SecretSCIMEndpoint: # This can be moved to custom provider
Type: "AWS::SecretsManager::Secret"
Condition: CreateSecrets
Properties:
Name: SSOSyncSCIMEndpointUrl
SecretString: !Ref SCIMEndpointUrl
KmsKeyId: !If [CreateKey, !Ref KeyAlias, alias/aws/secretsmanager]
SecretSCIMEndpointPolicy:
Type: AWS::SecretsManager::ResourcePolicy
Condition: CreateKey
Properties:
SecretId: !Ref SecretSCIMEndpoint
ResourcePolicy:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
AWS: !Sub arn:aws:iam::${CrossStackConfig}:root
Action:
- secretsmanager:GetSecretValue
Resource: '*'
SecretSCIMAccessToken: # This can be moved to custom provider
Type: "AWS::SecretsManager::Secret"
Condition: CreateSecrets
Properties:
Name: SSOSyncSCIMAccessToken
SecretString: !Ref SCIMEndpointAccessToken
KmsKeyId: !If [CreateKey, !Ref KeyAlias, alias/aws/secretsmanager]
SecretSCIMAccessTokenPolicy:
Type: AWS::SecretsManager::ResourcePolicy
Condition: CreateKey
Properties:
SecretId: !Ref SecretSCIMAccessToken
ResourcePolicy:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
AWS: !Sub arn:aws:iam::${CrossStackConfig}:root
Action:
- secretsmanager:GetSecretValue
Resource: '*'
SecretRegion:
Type: "AWS::SecretsManager::Secret"
Condition: CreateSecrets
Properties:
Name: SSOSyncRegion
SecretString: !Ref Region
KmsKeyId: !If [CreateKey, !Ref KeyAlias, alias/aws/secretsmanager]
SecretRegionPolicy:
Type: AWS::SecretsManager::ResourcePolicy
Condition: CreateKey
Properties:
SecretId: !Ref SecretRegion
ResourcePolicy:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
AWS: !Sub arn:aws:iam::${CrossStackConfig}:root
Action:
- secretsmanager:GetSecretValue
Resource: '*'
SecretIdentityStoreID:
Type: "AWS::SecretsManager::Secret"
Condition: CreateSecrets
Properties:
Name: SSOSyncIdentityStoreID
SecretString: !Ref IdentityStoreID
KmsKeyId: !If [CreateKey, !Ref KeyAlias, alias/aws/secretsmanager]
SecretIdentityStoreIDPolicy:
Type: AWS::SecretsManager::ResourcePolicy
Condition: CreateKey
Properties:
SecretId: !Ref SecretIdentityStoreID
ResourcePolicy:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
AWS: !Sub arn:aws:iam::${CrossStackConfig}:root
Action:
- secretsmanager:GetSecretValue
Resource: '*'
Outputs:
FunctionArn:
Condition: OutputFunction
Description: "The Arn of the deployed lambda function"
Value: !GetAtt SSOSyncFunction.Arn
Export:
Name: FunctionARN
AppConfigLocal:
Condition: OutputSecrets
Description: "The Comma Separated list of secrets ARNs to copy and paste into the CrossStackConfig field of the App only stack."
Value: !Sub ${SecretGoogleCredentials},${SecretGoogleAdminEmail},${SecretSCIMEndpoint},${SecretSCIMAccessToken},${SecretRegion},${SecretIdentityStoreID}
Export:
Name: AppConfig
AppConfigRemote:
Condition: CreateKey
Description: "The Comma Separated list of Secrets and KMS Key ARNs to copy and paste into the CrossStackConfig field of the app for cross-account stack."
Value: !Sub ${SecretGoogleCredentials},${SecretGoogleAdminEmail},${SecretSCIMEndpoint},${SecretSCIMAccessToken},${SecretRegion},${SecretIdentityStoreID},arn:aws:kms:${AWS::Region}:${AWS::AccountId}:key/${KeyForSecrets}
Export:
Name: AppConfig