Skip to content

Commit 31f325c

Browse files
authored
Merge pull request #153 from awslabs/improved-param-validation
Improved param validation
2 parents b1f4499 + 25520c9 commit 31f325c

File tree

6 files changed

+183
-202
lines changed

6 files changed

+183
-202
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,8 @@ ssosync
3535
.DS_Store
3636
*.swp
3737
*/.DS_Store
38+
cicd/.DS_Store
39+
release.yaml
40+
staging.yaml
41+
*.orig
42+
*.rej

cicd/build/package/release.patch

Lines changed: 4 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,11 @@
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 16:34:16
2+
+++ release.yaml 2023-10-27 16:34:37
3+
@@ -36,7 +36,7 @@
4+
- ScheduleExpression
55

66
AWS::ServerlessRepo::Application:
77
- Name: ssosync
88
+ Name: SSOSync
99
Description: Helping you populate AWS SSO directly with your Google Apps users.
1010
Author: Sebastian Doell
1111
SpdxLicenseId: Apache-2.0
12-
@@ -111,7 +111,7 @@
13-
Default: 'none'
14-
IncludeGroups:
15-
Type: String
16-
- Description: |
17-
+ Description: |
18-
Include only these Google Workspace groups. (Only applicable for SyncMethod user_groups)
19-
Default: '*'
20-
SyncMethod:
21-
@@ -121,16 +121,16 @@
22-
AllowedValues:
23-
- groups
24-
- users_groups
25-
+
26-
+
27-
+
28-
29-
-
30-
-
31-
-
32-
Resources:
33-
SSOSyncFunction:
34-
Type: AWS::Serverless::Function
35-
Properties:
36-
Runtime: provided.al2
37-
- Handler: dist/ssosync_linux_arm64/ssosync
38-
+ Handler: bootstrap
39-
Architectures:
40-
- arm64
41-
Timeout: 300
42-
@@ -163,8 +163,6 @@
43-
- !Ref AWSSCIMAccessTokenSecret
44-
- !Ref AWSRegionSecret
45-
- !Ref AWSIdentityStoreIDSecret
46-
- - Version: '2012-10-17'
47-
- Statement:
48-
- Sid: IdentityStoreAccesPolicy
49-
Effect: Allow
50-
Action:
51-
@@ -187,8 +185,6 @@
52-
Properties:
53-
Enabled: true
54-
Schedule: !Ref ScheduleExpression
55-
- Metadata:
56-
- BuildMethod: makefile
57-
58-
AWSGoogleCredentialsSecret:
59-
Type: "AWS::SecretsManager::Secret"

cicd/build/package/staging.patch

Lines changed: 4 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,11 @@
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-30 14:21:20
2+
+++ staging.yaml 2023-10-30 14:21:59
3+
@@ -38,7 +38,7 @@
4+
- ScheduleExpression
55

66
AWS::ServerlessRepo::Application:
77
- Name: ssosync
88
+ Name: SSOSync-Staging
99
Description: Helping you populate AWS SSO directly with your Google Apps users.
1010
Author: Sebastian Doell
1111
SpdxLicenseId: Apache-2.0
12-
@@ -111,7 +111,7 @@
13-
Default: 'none'
14-
IncludeGroups:
15-
Type: String
16-
- Description: |
17-
+ Description: |
18-
Include only these Google Workspace groups. (Only applicable for SyncMethod user_groups)
19-
Default: '*'
20-
SyncMethod:
21-
@@ -121,16 +121,17 @@
22-
AllowedValues:
23-
- groups
24-
- users_groups
25-
+
26-
+
27-
+
28-
29-
-
30-
-
31-
-
32-
Resources:
33-
SSOSyncFunction:
34-
Type: AWS::Serverless::Function
35-
Properties:
36-
+ FunctionName: SSOSyncFunction
37-
Runtime: provided.al2
38-
- Handler: dist/ssosync_linux_arm64/ssosync
39-
+ Handler: bootstrap
40-
Architectures:
41-
- arm64
42-
Timeout: 300
43-
@@ -163,8 +164,6 @@
44-
- !Ref AWSSCIMAccessTokenSecret
45-
- !Ref AWSRegionSecret
46-
- !Ref AWSIdentityStoreIDSecret
47-
- - Version: '2012-10-17'
48-
- Statement:
49-
- Sid: IdentityStoreAccesPolicy
50-
Effect: Allow
51-
Action:
52-
@@ -180,16 +179,14 @@
53-
- "identitystore:DeleteGroup"
54-
Resource:
55-
- "*"
56-
- Events:
57-
- SyncScheduledEvent:
58-
- Type: Schedule
59-
- Name: AWSSyncSchedule
60-
- Properties:
61-
- Enabled: true
62-
- Schedule: !Ref ScheduleExpression
63-
- Metadata:
64-
- BuildMethod: makefile
65-
66-
+ - Sid: CodePipelinePolicy
67-
+ Effect: Allow
68-
+ Action:
69-
+ - codepipeline:PutJobSuccessResult
70-
+ - codepipeline:PutJobFailureResult
71-
+ Resource: "*"
72-
+
73-
AWSGoogleCredentialsSecret:
74-
Type: "AWS::SecretsManager::Secret"
75-
Properties:
76-
@@ -225,3 +222,10 @@
77-
Properties:
78-
Name: SSOSyncIdentityStoreID
79-
SecretString: !Ref IdentityStoreID
80-
+
81-
+Outputs:
82-
+ FunctionArn:
83-
+ Description: "The Arn of the deployed lambda function"
84-
+ Value: !GetAtt SSOSyncFunction.Arn
85-
+ Export:
86-
+ Name: SSOSyncFunctionARN

cicd/cloudformation/secrets.yaml

Lines changed: 86 additions & 10 deletions
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"

cicd/staging/build/stack.yml

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,14 @@ Resources:
2828
ApplicationId: !Ref AppArn
2929
SemanticVersion: !Ref AppVersion
3030
Parameters:
31+
FunctionName: SSOSyncFunction
3132
GoogleAdminEmail: '{{resolve:secretsmanager:TestGoogleAdminEmail}}'
3233
GoogleCredentials: '{{resolve:secretsmanager:TestGoogleCredentials}}'
3334
SCIMEndpointUrl: '{{resolve:secretsmanager:TestSCIMEndpointUrl}}'
3435
SCIMEndpointAccessToken: '{{resolve:secretsmanager:TestSCIMAccessToken}}'
3536
Region: '{{resolve:secretsmanager:TestRegion}}'
3637
IdentityStoreID: '{{resolve:secretsmanager:TestIdentityStoreId}}'
3738
SyncMethod: groups
38-
GoogleUserMatch: 'name:*'
3939
GoogleGroupMatch: !Ref GroupMatch
4040
LogLevel: warn
4141
LogFormat: json
42-
IgnoreUsers: None
43-
IgnoreGroups: None
44-
IncludeGroups: None
45-
ScheduleExpression: 'rate(1 day)'
46-
47-
FunctionArnParam:
48-
Type: AWS::SSM::Parameter
49-
Properties:
50-
Name: "/SSOSync/Staging/FunctionArn"
51-
Type: String
52-
Value: !GetAtt SARApp.Outputs.FunctionArn
53-
Description: The Arn of the lambda function ssosync
54-
55-
Outputs:
56-
FunctionArn:
57-
Description: "The Arn of the deployed lambda function"
58-
Value: !GetAtt SARApp.Outputs.FunctionArn
59-
Export:
60-
Name: FunctionArn

0 commit comments

Comments
 (0)