Skip to content

Commit

Permalink
Replicate member_entity_ids and policies in identity/group across nod…
Browse files Browse the repository at this point in the history
…es identically (#16088) (#16185)

* Replicate values of group member_entity_ids and policies across nodes identically

* Adding CL

* fixing tests
  • Loading branch information
hghaf099 committed Jun 29, 2022
1 parent 0382d7b commit 713ef5e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
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
23 changes: 15 additions & 8 deletions vault/identity_store_util.go
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

0 comments on commit 713ef5e

Please sign in to comment.