Skip to content

Commit

Permalink
Add locking when adding aliases to existing entities (#4965)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrishoffman authored and jefferai committed Jul 25, 2018
1 parent 558c64a commit 8152811
Show file tree
Hide file tree
Showing 8 changed files with 271 additions and 542 deletions.
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

0 comments on commit 8152811

Please sign in to comment.