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) (#16186)

* 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 959a8c2 commit 90b1453
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 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
29 changes: 19 additions & 10 deletions vault/identity_store_util.go
Expand Up @@ -22,8 +22,10 @@ import (
"github.com/hashicorp/vault/sdk/logical"
)

var errDuplicateIdentityName = errors.New("duplicate identity name")
var tmpSuffix = ".tmp"
var (
errDuplicateIdentityName = errors.New("duplicate identity name")
tmpSuffix = ".tmp"
)

func (c *Core) SetLoadCaseSensitiveIdentityStore(caseSensitive bool) {
c.loadCaseSensitiveIdentityStore = caseSensitive
Expand Down Expand Up @@ -1500,17 +1502,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 90b1453

Please sign in to comment.