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

Replicate member_entity_ids and policies in identity/group across nodes identically #16088

Merged
merged 3 commits into from Jun 28, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/16088.txt
@@ -0,0 +1,3 @@
```release-note:bug
core/identity: Replicate member_entity_ids and policies in identity/group across nodes identically
```
14 changes: 13 additions & 1 deletion vault/external_tests/identity/identity_test.go
Expand Up @@ -628,8 +628,20 @@ func assertMember(t *testing.T, client *api.Client, entityID, groupName, groupID
t.Fatal(err)
}
groupMap := secret.Data

groupEntityMembers, ok := groupMap["member_entity_ids"].([]interface{})
if !ok && expectFound {
t.Fatalf("expected member_entity_ids not to be nil")
}

// if type assertion fails and expectFound is false, groupEntityMembers
// is nil, then let's just return, nothing to be done!
if !ok && !expectFound {
return
}

found := false
for _, entityIDRaw := range groupMap["member_entity_ids"].([]interface{}) {
for _, entityIDRaw := range groupEntityMembers {
if entityIDRaw.(string) == entityID {
found = true
}
Expand Down
22 changes: 13 additions & 9 deletions vault/identity_store_util.go
Expand Up @@ -1473,19 +1473,23 @@ func (i *IdentityStore) sanitizeAndUpsertGroup(ctx context.Context, group *ident
}

// Remove duplicate entity IDs and check if all IDs are valid
group.MemberEntityIDs = strutil.RemoveDuplicates(group.MemberEntityIDs, false)
for _, entityID := range group.MemberEntityIDs {
entity, err := i.MemDBEntityByID(entityID, false)
if err != nil {
return fmt.Errorf("failed to validate entity ID %q: %w", entityID, err)
}
if entity == nil {
return fmt.Errorf("invalid entity ID %q", entityID)
if group.MemberEntityIDs != nil {
group.MemberEntityIDs = strutil.RemoveDuplicates(group.MemberEntityIDs, false)
for _, entityID := range group.MemberEntityIDs {
entity, err := i.MemDBEntityByID(entityID, false)
if err != nil {
return fmt.Errorf("failed to validate entity ID %q: %w", entityID, err)
}
if entity == nil {
return fmt.Errorf("invalid entity ID %q", entityID)
}
}
}

// Remove duplicate policies
group.Policies = strutil.RemoveDuplicates(group.Policies, false)
if group.Policies != nil {
group.Policies = strutil.RemoveDuplicates(group.Policies, false)
}

txn := i.db.Txn(true)
defer txn.Abort()
Expand Down