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

199 group flattening can lead to conflicts due to non uniqueness #201

Merged
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
2 changes: 1 addition & 1 deletion cicd/account_execution/staging/buildspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,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\", \"GoogleAdminEmailArn\": \"$SecretGoogleAdminEmail\", \"GoogleCredentialsArn\": \"$SecretGoogleCredentials\", \"SCIMEndpointUrlArn\": \"$SecretSCIMEndpoint\", \"SCIMAccessTokenArn\": \"$SecretSCIMAccessToken\", \"RegionArn\": \"$SecretRegion\", \"IdentityStoreIdArn\": \"$SecretIdentityStoreID\", \"GroupMatch\": \"name:AWS*,name=NestedGroups\"}" \
--argjson StackPolicy "{\"Statement\":[{\"Effect\": \"Allow\", \"NotAction\": \"Update:Delete\", \"Principal\": \"*\", \"Resource\": \"*\"}]}" \
'$ARGS.named' > ./deploy/developer.json
- cat ./deploy/developer.json
Expand Down
14 changes: 13 additions & 1 deletion internal/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@
log.Info("creating user")
_, err := s.aws.CreateUser(awsUser)
if err != nil {
errHttp := new(aws.ErrHttpNotOK)

Check failure on line 394 in internal/sync.go

View workflow job for this annotation

GitHub Actions / test

var errHttp should be errHTTP
if errors.As(err, &errHttp) && errHttp.StatusCode == 409 {
log.WithField("user", awsUser.Username).Warn("user already exists")
continue
Expand Down Expand Up @@ -596,13 +596,25 @@
membersUsers := s.getGoogleUsersInGroup(g, gUserDetailCache, gGroupDetailCache)

// If we've not seen the user email address before add it to the list of unique users
// also, we need to deduplicate the list of members.
gUniqMembers := make(map[string]*admin.User)
for _, m := range membersUsers {
_, ok := gUniqUsers[m.PrimaryEmail]
if !ok {
gUniqUsers[m.PrimaryEmail] = gUserDetailCache[m.PrimaryEmail]
}

_, ok = gUniqMembers[m.PrimaryEmail]
if !ok {
gUniqMembers[m.PrimaryEmail] = gUserDetailCache[m.PrimaryEmail]
}
}
gGroupsUsers[g.Name] = membersUsers

gMembers := make([]*admin.User, 0)
for _, member := range gUniqMembers {
gMembers = append(gMembers, member)
}
gGroupsUsers[g.Name] = gMembers
}

for _, user := range gUniqUsers {
Expand Down Expand Up @@ -778,7 +790,7 @@
if err != nil {
log.WithField("error", err).Warn("Problem performing test query against Identity Store")
return err
} else {

Check failure on line 793 in internal/sync.go

View workflow job for this annotation

GitHub Actions / test

if block ends with a return statement, so drop this else and outdent its block
log.WithField("Groups", response).Info("Test call for groups successful")

}
Expand Down Expand Up @@ -857,7 +869,7 @@
return awsGroups, nil
}

func ListGroupsPagesCallbackFn(page *identitystore.ListGroupsOutput, lastPage bool) bool {

Check failure on line 872 in internal/sync.go

View workflow job for this annotation

GitHub Actions / test

exported function ListGroupsPagesCallbackFn should have comment or be unexported
// Loop through each Group returned
for _, group := range page.Groups {
// Convert to native Group object
Expand Down Expand Up @@ -889,7 +901,7 @@
return awsUsers, nil
}

func ListUsersPagesCallbackFn(page *identitystore.ListUsersOutput, lastPage bool) bool {

Check failure on line 904 in internal/sync.go

View workflow job for this annotation

GitHub Actions / test

exported function ListUsersPagesCallbackFn should have comment or be unexported
// Loop through each User in ListUsersOutput and convert to native User object
for _, user := range page.Users {
awsUsers = append(awsUsers, ConvertSdkUserObjToNative(user))
Expand All @@ -897,7 +909,7 @@
return !lastPage
}

func ConvertSdkUserObjToNative(user *identitystore.User) *aws.User {

Check failure on line 912 in internal/sync.go

View workflow job for this annotation

GitHub Actions / test

exported function ConvertSdkUserObjToNative should have comment or be unexported
// Convert emails into native Email object
userEmails := make([]aws.UserEmail, 0)

Expand Down Expand Up @@ -941,7 +953,7 @@
}
}

func CreateUserIDtoUserObjMap(awsUsers []*aws.User) map[string]*aws.User {

Check failure on line 956 in internal/sync.go

View workflow job for this annotation

GitHub Actions / test

exported function CreateUserIDtoUserObjMap should have comment or be unexported
awsUsersMap := make(map[string]*aws.User)

for _, awsUser := range awsUsers {
Expand All @@ -951,7 +963,7 @@
return awsUsersMap
}

var ListGroupMembershipPagesCallbackFn func(page *identitystore.ListGroupMembershipsOutput, lastPage bool) bool

Check failure on line 966 in internal/sync.go

View workflow job for this annotation

GitHub Actions / test

exported var ListGroupMembershipPagesCallbackFn should have comment or be unexported

func (s *syncGSuite) GetGroupMembershipsLists(awsGroups []*aws.Group, awsUsersMap map[string]*aws.User) (map[string][]*aws.User, error) {
awsGroupsUsers := make(map[string][]*aws.User)
Expand Down
Loading