Skip to content

Commit 29b4794

Browse files
committed
Improving param validation in template
1 parent 315e85d commit 29b4794

File tree

5 files changed

+190
-51
lines changed

5 files changed

+190
-51
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@ ssosync
3535
.DS_Store
3636
*.swp
3737
*/.DS_Store
38+
cicd/.DS_Store
39+
release.yaml
40+
staging.yaml

cicd/build/package/release.patch

+32-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,38 @@
1-
--- template.yaml 2023-10-25 09:44:33
2-
+++ release.yaml 2023-10-25 16:02:21
3-
@@ -27,7 +27,7 @@
4-
- IncludeGroups
1+
--- template.yaml 2023-10-27 14:15:25
2+
+++ release.yaml 2023-10-27 14:41:17
3+
@@ -11,7 +11,7 @@
4+
- SCIMEndpointAccessToken
5+
- IdentityStoreId
6+
- Label:
7+
- default: Google Workspace Credentials
8+
+ default: Google Workspace Credentials
9+
Parameters:
10+
- GoogleAdminEmail
11+
- GoogleCredentials
12+
@@ -36,7 +36,7 @@
13+
- ScheduleExpression
514

615
AWS::ServerlessRepo::Application:
716
- Name: ssosync
817
+ Name: SSOSync
918
Description: Helping you populate AWS SSO directly with your Google Apps users.
1019
Author: Sebastian Doell
1120
SpdxLicenseId: Apache-2.0
12-
@@ -111,7 +111,7 @@
21+
@@ -113,13 +113,11 @@
22+
Description: |
23+
Google Workspace user filter query parameter, example: 'name:John* email:admin*', see: https://developers.google.com/admin-sdk/directory/v1/guides/search-users
24+
Default: '*'
25+
- AllowedPattern: "(*)|(name|Name|NAME)(:([a-zA-Z0-9]{1,64})(\*))|(name|Name|NAME)(=([a-zA-Z0-9 ]{1,64}))|(email|Email|EMAIL)(:([a-zA-Z0-9.-_]{1,64})(\*))|(email|Email|EMAIL)(=([a-zA-Z0-9.-_]{1,64})@([a-zA-Z0-9.-]{5,260}))"
26+
GoogleGroupMatch:
27+
Type: String
28+
Description: |
29+
Google Workspace group filter query parameter, example: 'name:Admin* email:aws-*', see: https://developers.google.com/admin-sdk/directory/v1/guides/search-groups
30+
Default: 'name:AWS*'
31+
- AllowedPattern: "((name|Name|NAME)(:([a-zA-Z0-9]{1,64})\*)|(name|Name|NAME)(=([a-zA-Z0-9 ]{1,64})))|((email|Email|EMAIL)(:([a-zA-Z0-9.-_]{1,64})\*)|(email|Email|EMAIL)(=([a-zA-Z0-9.-_]{1,64})@([a-zA-Z0-9.-]{5,260})))"
32+
IgnoreGroups:
33+
Type: String
34+
Description: |
35+
@@ -132,7 +130,7 @@
1336
Default: 'none'
1437
IncludeGroups:
1538
Type: String
@@ -18,7 +41,7 @@
1841
Include only these Google Workspace groups. (Only applicable for SyncMethod user_groups)
1942
Default: '*'
2043
SyncMethod:
21-
@@ -121,16 +121,16 @@
44+
@@ -142,16 +140,16 @@
2245
AllowedValues:
2346
- groups
2447
- users_groups
@@ -38,8 +61,8 @@
3861
+ Handler: bootstrap
3962
Architectures:
4063
- arm64
41-
Timeout: 300
42-
@@ -163,8 +163,6 @@
64+
Timeout: !Ref TimeOut
65+
@@ -184,8 +182,6 @@
4366
- !Ref AWSSCIMAccessTokenSecret
4467
- !Ref AWSRegionSecret
4568
- !Ref AWSIdentityStoreIDSecret
@@ -48,7 +71,7 @@
4871
- Sid: IdentityStoreAccesPolicy
4972
Effect: Allow
5073
Action:
51-
@@ -187,8 +185,6 @@
74+
@@ -214,8 +210,6 @@
5275
Properties:
5376
Enabled: true
5477
Schedule: !Ref ScheduleExpression

cicd/build/package/staging.patch

+31-21
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
1-
--- template.yaml 2023-10-25 09:44:33
2-
+++ staging.yaml 2023-10-25 16:02:07
3-
@@ -27,7 +27,7 @@
4-
- IncludeGroups
1+
--- template.yaml 2023-10-27 14:15:25
2+
+++ staging.yaml 2023-10-27 14:15:30
3+
@@ -11,7 +11,7 @@
4+
- SCIMEndpointAccessToken
5+
- IdentityStoreId
6+
- Label:
7+
- default: Google Workspace Credentials
8+
+ default: Google Workspace Credentials
9+
Parameters:
10+
- GoogleAdminEmail
11+
- GoogleCredentials
12+
@@ -36,7 +36,7 @@
13+
- ScheduleExpression
514

615
AWS::ServerlessRepo::Application:
716
- Name: ssosync
817
+ Name: SSOSync-Staging
918
Description: Helping you populate AWS SSO directly with your Google Apps users.
1019
Author: Sebastian Doell
1120
SpdxLicenseId: Apache-2.0
12-
@@ -111,7 +111,7 @@
21+
@@ -132,7 +132,7 @@
1322
Default: 'none'
1423
IncludeGroups:
1524
Type: String
@@ -18,7 +27,7 @@
1827
Include only these Google Workspace groups. (Only applicable for SyncMethod user_groups)
1928
Default: '*'
2029
SyncMethod:
21-
@@ -121,16 +121,17 @@
30+
@@ -142,16 +142,17 @@
2231
AllowedValues:
2332
- groups
2433
- users_groups
@@ -39,8 +48,8 @@
3948
+ Handler: bootstrap
4049
Architectures:
4150
- arm64
42-
Timeout: 300
43-
@@ -163,8 +164,6 @@
51+
Timeout: !Ref TimeOut
52+
@@ -184,8 +185,6 @@
4453
- !Ref AWSSCIMAccessTokenSecret
4554
- !Ref AWSRegionSecret
4655
- !Ref AWSIdentityStoreIDSecret
@@ -49,10 +58,10 @@
4958
- Sid: IdentityStoreAccesPolicy
5059
Effect: Allow
5160
Action:
52-
@@ -180,16 +179,14 @@
53-
- "identitystore:DeleteGroup"
54-
Resource:
55-
- "*"
61+
@@ -207,15 +206,6 @@
62+
- codepipeline:PutJobSuccessResult
63+
- codepipeline:PutJobFailureResult
64+
Resource: "*"
5665
- Events:
5766
- SyncScheduledEvent:
5867
- Type: Schedule
@@ -63,20 +72,21 @@
6372
- Metadata:
6473
- BuildMethod: makefile
6574

66-
+ - Sid: CodePipelinePolicy
67-
+ Effect: Allow
68-
+ Action:
69-
+ - codepipeline:PutJobSuccessResult
70-
+ - codepipeline:PutJobFailureResult
71-
+ Resource: "*"
72-
+
7375
AWSGoogleCredentialsSecret:
7476
Type: "AWS::SecretsManager::Secret"
77+
@@ -245,10 +235,17 @@
78+
Type: "AWS::SecretsManager::Secret"
7579
Properties:
76-
@@ -225,3 +222,10 @@
80+
Name: SSOSyncRegion
81+
- SecretString: !Select [1, !Split [".", !Ref SCIMEndpointUrl]]
82+
+ SecretString: !Ref Region
83+
84+
AWSIdentityStoreIDSecret:
85+
Type: "AWS::SecretsManager::Secret"
7786
Properties:
7887
Name: SSOSyncIdentityStoreID
79-
SecretString: !Ref IdentityStoreID
88+
- SecretString: !Ref IdentityStoreID
89+
+ SecretString: !Select [1, !Split [".", !Ref SCIMEndpointUrl]]
8090
+
8191
+Outputs:
8292
+ FunctionArn:

cicd/cloudformation/secrets.yaml

+86-10
Original file line numberDiff line numberDiff line change
@@ -6,72 +6,148 @@ Description:
66
(via privately shared app in the AWS Serverless Application Repository (SAR).
77

88
Parameters:
9+
GoogleAuthMethod:
10+
Type: String
11+
AllowedValues: ["Google Credentials", "Workload Identity Federation", "Both"]
12+
Default: "Google Credentials"
913
GoogleCredentials:
10-
Description: Credentials to log into Google (content of credentials.json)
14+
Description: Google Workspaces Credentials File, to log into Google (content of credentials.json)
1115
Type: String
1216
NoEcho: true
1317
GoogleAdminEmail:
1418
Description: Google Workspaces Admin email
1519
Type: String
1620
NoEcho: true
21+
WIFServiceAccountEmail:
22+
Description: Workload Identity Federation, the email address of service account used to impersonate a user using
23+
Type: String
24+
NoEcho: true
25+
WIFClientLibraryConfig:
26+
Description: Workload Identity Federation, the client library config file for the provider (AWS Account) (contents of clientLibraryConfig-provider.json)
27+
Type: String
28+
NoEcho: true
1729
SCIMEndpointUrl:
1830
Description: AWS IAM Identity Center SCIM Endpoint Url
1931
Type: String
2032
NoEcho: true
33+
AllowedPattern: "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/"
2134
SCIMEndpointAccessToken:
2235
Description: AWS IAM Identity Center SCIM AccessToken
2336
Type: String
2437
NoEcho: true
25-
Region:
26-
Description: Region in which IAM Identity Center is deployed
27-
Type: String
2838
IdentityStoreId:
2939
Description: The Id of the Identity Store for the AWS IAM Identity Center instance see (settings page)
3040
Type: String
41+
AllowedPattern: "d-[1-z0-9]{10}"
3142

3243

3344
Metadata:
3445
AWS::CloudFormation::Interface:
3546
ParameterGroups:
3647
- Label:
37-
default: Google Workspace
48+
default: Google Authentication Method
49+
Parameters:
50+
- GoogleAuthMethod
51+
- Label:
52+
default: Parameters for Google Credentials based authentication, required if either Google Credentials or Both have been selected for Google Authentication Method
3853
Parameters:
3954
- GoogleAdminEmail
4055
- GoogleCredentials
56+
- Label:
57+
default: Parameters for Workload Identity Federation based authentication, required if either Workload Identity Federation or Both have been selected for Google Authentication Method
58+
Parameters:
59+
- WIFServiceAccountEmail
60+
- WIFClientLibraryConfig
4161
- Label:
42-
default: AWS SSO
62+
default: AWS IAM Identity Center
4363
Parameters:
4464
- SCIMEndpointUrl
4565
- SCIMEndpointAccessToken
66+
- IdentityStoreId
4667

4768
ParameterLabels:
69+
GoogleAuthMethod:
70+
default: "Which Google Auth Methods do you want to test with?"
4871
GoogleCredentials:
4972
default: "contents of credentials.json"
5073
GoogleAdminEmail:
5174
default: "admin@WorkspaceDomain"
75+
WIFServiceAccountEmail:
76+
default: "service-account@@WorkspaceDomain"
77+
WIFClientLibraryConfig:
78+
default: "contents of clientLibraryConfig-provider.json"
5279
SCIMEndpointUrl:
5380
default: "https://scim.<region>.amazonaws.com/<instance id>/scim/v2/"
5481
SCIMEndpointAccessToken:
5582
default: "AWS SSO SCIM Access Token"
56-
Region:
57-
default: "us-east-1"
5883
IdentityStoreId:
5984
default: "d-1234567abc"
6085

86+
Conditions:
87+
GoogleCreds: !Or [!Equals [!Ref "GoogleAuthMethod", Google Credentials], !Equals [!Ref "GoogleAuthMethod", Both]]
88+
WIFCreds: !Or [!Equals [!Ref "GoogleAuthMethod", Workload Identity Federation], !Equals [!Ref "GoogleAuthMethod", Both]]
89+
90+
91+
Rules:
92+
# Fail when any assertion returns false
93+
# If they have selected Google Credentials then check they have provided valid data for GoogleCredentials
94+
GoogleCredentialsOnly:
95+
RuleCondition: !Or [!Equals [!Ref "GoogleAuthMethod", Google Credentials], !Equals [!Ref "GoogleAuthMethod", Both]]
96+
Assertions:
97+
- AssertDescription: You have selected Google Credentials, You need to provide a Google Admin email address.
98+
Assert: !Not
99+
- !Equals
100+
- !Ref GoogleAdminEmail
101+
- ""
102+
- AssertDescription: You have selected Google Credentials, You need to provide the content of a Credentials file (json).
103+
Assert: !Not
104+
- !Equals
105+
- !Ref GoogleCredentials
106+
- ""
107+
# If they have selected Workload Identity Federation, then check they have provide valid data for WIF
108+
WorkloadIdentityFederationOnly:
109+
RuleCondition: !Or [!Equals [!Ref "GoogleAuthMethod", Workload Identity Federation], !Equals [!Ref "GoogleAuthMethod", Both]]
110+
Assertions:
111+
- AssertDescription: You have selected Workload Identity Federation, You need to provide a Google Service Account email address.
112+
Assert: !Not
113+
- !Equals
114+
- !Ref WIFServiceAccountEmail
115+
- ""
116+
- AssertDescription: You have selected Workload Identity Federation, You need to provide the content of a Client Library Config file (json).
117+
Assert: !Not
118+
- !Equals
119+
- !Ref WIFClientLibraryConfig
120+
- ""
121+
61122
Resources:
62-
63123
GoogleCredentialSecret:
64124
Type: "AWS::SecretsManager::Secret"
125+
Condition: GoogleCreds
65126
Properties:
66127
Name: TestGoogleCredentials
67128
SecretString: !Ref GoogleCredentials
68129

69130
GoogleAdminEmailSecret:
70131
Type: "AWS::SecretsManager::Secret"
132+
Condition: GoogleCreds
71133
Properties:
72134
Name: TestGoogleAdminEmail
73135
SecretString: !Ref GoogleAdminEmail
74136

137+
WIFServiceAccountEmailSecret:
138+
Type: "AWS::SecretsManager::Secret"
139+
Condition: WIFCreds
140+
Properties:
141+
Name: TestWIFServiceAccountEmail
142+
SecretString: !Ref WIFServiceAccountEmail
143+
144+
WIFClientLibraryConfigSecret:
145+
Type: "AWS::SecretsManager::Secret"
146+
Condition: WIFCreds
147+
Properties:
148+
Name: TestWIFClientLibraryConfigSecret
149+
SecretString: !Ref WIFClientLibraryConfig
150+
75151
SSoSCIMUrlSecret: # This can be moved to custom provider
76152
Type: "AWS::SecretsManager::Secret"
77153
Properties:
@@ -88,7 +164,7 @@ Resources:
88164
Type: "AWS::SecretsManager::Secret"
89165
Properties:
90166
Name: TestRegion
91-
SecretString: !Ref Region
167+
SecretString: !Select [1, !Split [".", !Ref SCIMEndpointUrl]]
92168

93169
IdentityStoreIdSecret:
94170
Type: "AWS::SecretsManager::Secret"

0 commit comments

Comments
 (0)