Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Avoid impersonation #202

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions cicd/account_execution/staging/stack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ Parameters:
Description: The version of this build in SAR
Default: 'v1.0.0-rc.10'
Type: String
GoogleAdminEmailArn:
# GoogleAdminEmailArn:
# Type: String
GoogleCustomerIdArn:
Type: String
GoogleCredentialsArn:
Type: String
Expand All @@ -41,10 +43,10 @@ Resources:
SemanticVersion: !Ref AppVersion
Parameters:
FunctionName: SSOSyncFunction
GoogleAdminEmail: !Join
GoogleCustomerId: !Join
- ''
- - '{{resolve:secretsmanager:'
- !Ref GoogleAdminEmailArn
- !Ref GoogleCustomerIdArn
- '}}'
GoogleCredentials: !Join
- ''
Expand Down
4 changes: 3 additions & 1 deletion cicd/cloudformation/developer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,9 @@ Resources:
Value: !Select [3, !Split [',', !Ref SecretsConfig]]
- Name: SecretGoogleCredentials
Value: !Select [4, !Split [',', !Ref SecretsConfig]]
- Name: SecretGoogleAdminEmail
#- Name: SecretGoogleAdminEmail
# Value: !Select [5, !Split [',', !Ref SecretsConfig]]
- Name: SecretGoogleCustomerId
Value: !Select [5, !Split [',', !Ref SecretsConfig]]
- Name: SecretWIFClientLibraryConfig
Value: !Select [6, !Split [',', !Ref SecretsConfig]]
Expand Down
75 changes: 60 additions & 15 deletions cicd/cloudformation/secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,15 @@ Parameters:
AllowedPattern: '(?!.*\s)|(\{(\s)*(".*")(\s)*:(\s)*(".*")(\s)*\})'
NoEcho: true

GoogleAdminEmail:
Description: Google Workspaces Admin email
# GoogleAdminEmail:
# Description: Google Workspaces Admin email
# Type: String
# 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
GoogleCustomerId:
Description: Google Workspaces Customer id
Type: String
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])?)*)'
AllowedPattern: '(?!.*\s)|C[A-Za-z0-9]{8}'
NoEcho: true

WIFServiceAccountEmail:
Expand Down Expand Up @@ -87,7 +92,8 @@ Metadata:
- Label:
default: Parameters for Google Credentials based authentication, required if either Google Credentials or Both have been selected for Google Authentication Method
Parameters:
- GoogleAdminEmail
#- GoogleAdminEmail
- GoogleCustomerId
- GoogleCredentials
- Label:
default: Parameters for Workload Identity Federation based authentication, required if either Workload Identity Federation or Both have been selected for Google Authentication Method
Expand All @@ -112,8 +118,10 @@ Metadata:
default: "Which Google Auth Methods do you want to test with?"
GoogleCredentials:
default: "contents of credentials.json"
GoogleAdminEmail:
default: "admin@WorkspaceDomain"
GoogleCustomerId:
default: "C12345678"
# GoogleAdminEmail:
# default: "admin@WorkspaceDomain"
WIFServiceAccountEmail:
default: "service-account@@WorkspaceDomain"
WIFClientLibraryConfig:
Expand Down Expand Up @@ -163,10 +171,10 @@ Rules:
- !Ref GoogleAuthMethod
- "Both"
Assertions:
- AssertDescription: You have selected Google Credentials, You need to provide a Google Admin email address.
- AssertDescription: You have selected Google Credentials, You need to provide a Google Workspace customer id.
Assert: !Not
- !Equals
- !Ref GoogleAdminEmail
- !Ref GoogleCustomerId
- ""
- AssertDescription: You have selected Google Credentials, You need to provide the content of a Credentials file (json).
Assert: !Not
Expand Down Expand Up @@ -284,21 +292,58 @@ Resources:
- secretsmanager:GetSecretValue
Resource: '*'

SecretGoogleAdminEmail:
# SecretGoogleAdminEmail:
# Type: "AWS::SecretsManager::Secret"
# Condition: CreateGoogle
# DeletionPolicy: Retain
# UpdateReplacePolicy: Delete
# Properties:
# Name: PipelineGoogleAdminEmail
# SecretString: !Ref GoogleAdminEmail
# KmsKeyId: !Ref KeyAlias

SecretGoogleCustomerId:
Type: "AWS::SecretsManager::Secret"
Condition: CreateGoogle
DeletionPolicy: Retain
UpdateReplacePolicy: Delete
Properties:
Name: PipelineGoogleAdminEmail
SecretString: !Ref GoogleAdminEmail
Name: PipelineGoogleCustomerId
SecretString: !Ref GoogleCustomerId
KmsKeyId: !Ref KeyAlias

SecretGoogleAdminEmailPolicy:
# SecretGoogleAdminEmailPolicy:
# Type: AWS::SecretsManager::ResourcePolicy
# Condition: CreateGoogle
# Properties:
# SecretId: !Ref SecretGoogleAdminEmail
# ResourcePolicy:
# Version: 2012-10-17
# Statement:
# - Effect: Allow
# Principal:
# AWS: !Sub arn:aws:iam::${ManagementAccount}:root
# Action:
# - secretsmanager:GetSecretValue
# Resource: '*'
# - Effect: Allow
# Principal:
# AWS: !Sub arn:aws:iam::${DelegatedAccount}:root
# Action:
# - secretsmanager:GetSecretValue
# Resource: '*'
# - Effect: Allow
# Principal:
# AWS: !Sub arn:aws:iam::${NonDelegatedAccount}:root
# Action:
# - secretsmanager:GetSecretValue
# Resource: '*'

SecretGoogleCustomerIdPolicy:
Type: AWS::SecretsManager::ResourcePolicy
Condition: CreateGoogle
Properties:
SecretId: !Ref SecretGoogleAdminEmail
SecretId: !Ref SecretGoogleCustomerId
ResourcePolicy:
Version: 2012-10-17
Statement:
Expand Down Expand Up @@ -538,7 +583,7 @@ Outputs:
TestConfigGoogleCreds:
Condition: GoogleCreds
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 ${SecretSCIMEndpoint},${SecretSCIMAccessToken},${SecretRegion},${SecretIdentityStoreID},${SecretGoogleCredentials},${SecretGoogleAdminEmail},"","",arn:aws:kms:${AWS::Region}:${AWS::AccountId}:key/${KeyForSecrets}
Value: !Sub ${SecretSCIMEndpoint},${SecretSCIMAccessToken},${SecretRegion},${SecretIdentityStoreID},${SecretGoogleCredentials},${SecretGoogleCustomerId},"","",arn:aws:kms:${AWS::Region}:${AWS::AccountId}:key/${KeyForSecrets}
Export:
Name: TestConfig

Expand All @@ -552,6 +597,6 @@ Outputs:
TestConfigBoth:
Condition: BothCreds
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 ${SecretSCIMEndpoint},${SecretSCIMAccessToken},${SecretRegion},${SecretIdentityStoreID},${SecretGoogleCredentials},${SecretGoogleAdminEmail},${SecretWIFClientLibraryConfig},${SecretWIFServiceAccountEmail},arn:aws:kms:${AWS::Region}:${AWS::AccountId}:key/${KeyForSecrets}
Value: !Sub ${SecretSCIMEndpoint},${SecretSCIMAccessToken},${SecretRegion},${SecretIdentityStoreID},${SecretGoogleCredentials},${SecretGoogleCustomerId},${SecretWIFClientLibraryConfig},${SecretWIFServiceAccountEmail},arn:aws:kms:${AWS::Region}:${AWS::AccountId}:key/${KeyForSecrets}
Export:
Name: TestConfig
2 changes: 1 addition & 1 deletion cicd/deploy_patterns/singlestack/buildspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ phases:
# Update params with the values for this run for a developer account
- |
jq -n \
--argjson Parameters "{\"AppArn\": \"$AppArn\", \"AppVersion\": \"$AppVersion\", \"GoogleAdminEmailArn\": \"$SecretGoogleAdminEmail\", \"GoogleCredentialsArn\": \"$SecretGoogleCredentials\", \"SCIMEndpointUrlArn\": \"$SecretSCIMEndpoint\", \"SCIMAccessTokenArn\": \"$SecretSCIMAccessToken\", \"RegionArn\": \"$SecretRegion\", \"IdentityStoreIdArn\": \"$SecretIdentityStoreID\", \"GroupMatch\": \"name:AWS*\"}" \
--argjson Parameters "{\"AppArn\": \"$AppArn\", \"AppVersion\": \"$AppVersion\", \"GoogleCustomerIdArn\": \"$SecretGoogleCustomerId\", \"GoogleCredentialsArn\": \"$SecretGoogleCredentials\", \"SCIMEndpointUrlArn\": \"$SecretSCIMEndpoint\", \"SCIMAccessTokenArn\": \"$SecretSCIMAccessToken\", \"RegionArn\": \"$SecretRegion\", \"IdentityStoreIdArn\": \"$SecretIdentityStoreID\", \"GroupMatch\": \"name:AWS*\"}" \
--argjson StackPolicy "{\"Statement\":[{\"Effect\": \"Allow\", \"NotAction\": \"Update:Delete\", \"Principal\": \"*\", \"Resource\": \"*\"}]}" \
'$ARGS.named' > ./deploy/singlestack.json
- cat ./deploy/singlestack.json
Expand Down
5 changes: 3 additions & 2 deletions cicd/deploy_patterns/singlestack/namedfunction.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ Parameters:
Description: The version of this build in SAR
Default: 'v1.0.0-rc.10'
Type: String
GoogleAdminEmailArn:
Type: String
# GoogleAdminEmailArn:
# Type: String

GoogleCredentialsArn:
Type: String
SCIMEndpointUrlArn:
Expand Down
20 changes: 14 additions & 6 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/aws/aws-lambda-go/lambda"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/codepipeline"
"github.com/aws/aws-sdk-go/service/codepipeline"
"github.com/aws/aws-sdk-go/service/secretsmanager"
"github.com/awslabs/ssosync/internal"
"github.com/awslabs/ssosync/internal/config"
Expand Down Expand Up @@ -157,7 +157,8 @@ func initConfig() {
viper.AutomaticEnv()

appEnvVars := []string{
"google_admin",
//"google_admin",
"customer_id",
"google_credentials",
"scim_access_token",
"scim_endpoint",
Expand Down Expand Up @@ -197,11 +198,17 @@ func configLambda() {
svc := secretsmanager.New(s)
secrets := config.NewSecrets(svc)

unwrap, err := secrets.GoogleAdminEmail(os.Getenv("GOOGLE_ADMIN"))
// unwrap, err := secrets.GoogleAdminEmail(os.Getenv("GOOGLE_ADMIN"))
// if err != nil {
// log.Fatalf(errors.Wrap(err, "cannot read config: GOOGLE_ADMIN").Error())
// }
// cfg.GoogleAdmin = unwrap

unwrap, err := secrets.GoogleCustomerId(os.Getenv("CUSTOMER_ID"))
if err != nil {
log.Fatalf(errors.Wrap(err, "cannot read config: GOOGLE_ADMIN").Error())
log.Fatalf(errors.Wrap(err, "cannot read config: CUSTOMER_ID").Error())
}
cfg.GoogleAdmin = unwrap
cfg.CustomerId = unwrap

unwrap, err = secrets.GoogleCredentials(os.Getenv("GOOGLE_CREDENTIALS"))
if err != nil {
Expand Down Expand Up @@ -291,7 +298,8 @@ func addFlags(cmd *cobra.Command, cfg *config.Config) {
rootCmd.Flags().StringVarP(&cfg.SCIMAccessToken, "access-token", "t", "", "AWS SSO SCIM API Access Token")
rootCmd.Flags().StringVarP(&cfg.SCIMEndpoint, "endpoint", "e", "", "AWS SSO SCIM API Endpoint")
rootCmd.Flags().StringVarP(&cfg.GoogleCredentials, "google-credentials", "c", config.DefaultGoogleCredentials, "path to Google Workspace credentials file")
rootCmd.Flags().StringVarP(&cfg.GoogleAdmin, "google-admin", "u", "", "Google Workspace admin user email")
//rootCmd.Flags().StringVarP(&cfg.GoogleAdmin, "google-admin", "u", "", "Google Workspace admin user email")
rootCmd.Flags().StringVarP(&cfg.CustomerId, "customer-id", "u", "", "Google Workspace customer id")
rootCmd.Flags().StringSliceVar(&cfg.IgnoreUsers, "ignore-users", []string{}, "ignores these Google Workspace users")
rootCmd.Flags().StringSliceVar(&cfg.IgnoreGroups, "ignore-groups", []string{}, "ignores these Google Workspace groups")
rootCmd.Flags().StringSliceVar(&cfg.IncludeGroups, "include-groups", []string{}, "include only these Google Workspace groups, NOTE: only works when --sync-method 'users_groups'")
Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ module github.com/awslabs/ssosync
go 1.16

require (
cloud.google.com/go/compute v1.12.1 // indirect
github.com/BurntSushi/toml v1.0.0
github.com/aws/aws-lambda-go v1.23.0
github.com/aws/aws-sdk-go v1.44.102
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/golang/mock v1.5.0
github.com/golang/mock v1.6.0
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-retryablehttp v0.7.0
github.com/magiconair/properties v1.8.5 // indirect
Expand All @@ -21,7 +22,7 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/viper v1.7.1
github.com/stretchr/testify v1.7.0
golang.org/x/oauth2 v0.0.0-20210427180440-81ed05c6b58c
google.golang.org/api v0.46.0
golang.org/x/oauth2 v0.21.0
google.golang.org/api v0.100.0
gopkg.in/ini.v1 v1.62.0 // indirect
)
Loading