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

Add locking when adding aliases to existing entities #4965

Merged
merged 4 commits into from
Jul 25, 2018
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ DEPRECATIONS/CHANGES:
* CLI Retries: The CLI will no longer retry commands on 5xx errors. This was a
source of confusion to users as to why Vault would "hang" before returning a
5xx error. The Go API client still defaults to two retries.
* Identity Entity Alias metadata: You can no longer manually set metadata on
entity aliases. All alias data (except the canonical entity ID it refers to)
is intended to be managed by the plugin providing the alias information, so
allowing it to be set manually didn't make sense.

FEATURES:

Expand Down
17 changes: 9 additions & 8 deletions vault/identity_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
log "github.com/hashicorp/go-hclog"
memdb "github.com/hashicorp/go-memdb"
"github.com/hashicorp/vault/helper/identity"
"github.com/hashicorp/vault/helper/locksutil"
"github.com/hashicorp/vault/helper/storagepacker"
"github.com/hashicorp/vault/logical"
"github.com/hashicorp/vault/logical/framework"
Expand All @@ -35,11 +34,10 @@ func NewIdentityStore(ctx context.Context, core *Core, config *logical.BackendCo
}

iStore := &IdentityStore{
view: config.StorageView,
db: db,
entityLocks: locksutil.CreateLocks(),
logger: logger,
core: core,
view: config.StorageView,
db: db,
logger: logger,
core: core,
}

iStore.entityPacker, err = storagepacker.NewStoragePacker(iStore.view, iStore.logger, "")
Expand Down Expand Up @@ -144,7 +142,7 @@ func (i *IdentityStore) Invalidate(ctx context.Context, key string) {
}

// Only update MemDB and don't touch the storage
err = i.upsertEntityInTxn(txn, entity, nil, false, false)
err = i.upsertEntityInTxn(txn, entity, nil, false)
if err != nil {
i.logger.Error("failed to update entity in MemDB", "error", err)
return
Expand Down Expand Up @@ -346,6 +344,9 @@ func (i *IdentityStore) CreateOrFetchEntity(alias *logical.Alias) (*identity.Ent
return entity, nil
}

i.lock.Lock()
defer i.lock.Unlock()

// Create a MemDB transaction to update both alias and entity
txn := i.db.Txn(true)
defer txn.Abort()
Expand Down Expand Up @@ -388,7 +389,7 @@ func (i *IdentityStore) CreateOrFetchEntity(alias *logical.Alias) (*identity.Ent
}

// Update MemDB and persist entity object
err = i.upsertEntityInTxn(txn, entity, nil, true, false)
err = i.upsertEntityInTxn(txn, entity, nil, true)
if err != nil {
return nil, err
}
Expand Down
Loading