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

Backport of identity/entity-alias: fix bug where wrong metadata was updated into release/1.9.x #16841

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
2 changes: 1 addition & 1 deletion vault/identity_store.go
Expand Up @@ -850,7 +850,7 @@ func (i *IdentityStore) CreateOrFetchEntity(ctx context.Context, alias *logical.
// names match or no metadata is different, -1 is returned.
func changedAliasIndex(entity *identity.Entity, alias *logical.Alias) int {
for i, a := range entity.Aliases {
if a.Name == alias.Name && !strutil.EqualStringMaps(a.Metadata, alias.Metadata) {
if a.Name == alias.Name && a.MountAccessor == alias.MountAccessor && !strutil.EqualStringMaps(a.Metadata, alias.Metadata) {
return i
}
}
Expand Down
49 changes: 49 additions & 0 deletions vault/identity_store_test.go
Expand Up @@ -807,3 +807,52 @@ func TestIdentityStore_NewEntityCounter(t *testing.T) {

expectSingleCount(t, sink, "identity.entity.creation")
}

func TestIdentityStore_UpdateAliasMetadataPerAccessor(t *testing.T) {
entity := &identity.Entity{
ID: "testEntityID",
Name: "testEntityName",
Policies: []string{"foo", "bar"},
Aliases: []*identity.Alias{
{
ID: "testAliasID1",
CanonicalID: "testEntityID",
MountType: "testMountType",
MountAccessor: "testMountAccessor",
Name: "sameAliasName",
},
{
ID: "testAliasID2",
CanonicalID: "testEntityID",
MountType: "testMountType",
MountAccessor: "testMountAccessor2",
Name: "sameAliasName",
},
},
NamespaceID: namespace.RootNamespaceID,
}

login := &logical.Alias{
MountType: "testMountType",
MountAccessor: "testMountAccessor",
Name: "sameAliasName",
ID: "testAliasID",
Metadata: map[string]string{"foo": "bar"},
}

if i := changedAliasIndex(entity, login); i != 0 {
t.Fatalf("wrong alias index changed. Expected 0, got %d", i)
}

login2 := &logical.Alias{
MountType: "testMountType",
MountAccessor: "testMountAccessor2",
Name: "sameAliasName",
ID: "testAliasID2",
Metadata: map[string]string{"bar": "foo"},
}

if i := changedAliasIndex(entity, login2); i != 1 {
t.Fatalf("wrong alias index changed. Expected 1, got %d", i)
}
}