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 nod… #16185

Merged
merged 1 commit into from
Jun 29, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/16088.txt
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
23 changes: 15 additions & 8 deletions vault/identity_store_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -1137,17 +1137,24 @@ 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
if group.Policies != nil {
group.Policies = strutil.RemoveDuplicates(group.Policies, false)
}

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

Expand Down