Skip to content

Commit

Permalink
Don't copy HA lock file during migration (#5503)
Browse files Browse the repository at this point in the history
  • Loading branch information
kalafut authored Oct 12, 2018
1 parent ab29c42 commit 46ccb88
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
3 changes: 2 additions & 1 deletion command/operator_migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/hashicorp/vault/command/server"
"github.com/hashicorp/vault/helper/logging"
"github.com/hashicorp/vault/physical"
"github.com/hashicorp/vault/vault"
"github.com/mitchellh/cli"
"github.com/pkg/errors"
"github.com/posener/complete"
Expand Down Expand Up @@ -196,7 +197,7 @@ func (c *OperatorMigrateCommand) migrate(config *migratorConfig) error {
// migrateAll copies all keys in lexicographic order.
func (c *OperatorMigrateCommand) migrateAll(ctx context.Context, from physical.Backend, to physical.Backend) error {
return dfsScan(ctx, from, func(ctx context.Context, path string) error {
if path < c.flagStart || path == migrationLock {
if path < c.flagStart || path == migrationLock || path == vault.CoreLockPath {
return nil
}

Expand Down
13 changes: 13 additions & 0 deletions command/operator_migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/hashicorp/vault/helper/base62"
"github.com/hashicorp/vault/helper/testhelpers"
"github.com/hashicorp/vault/physical"
"github.com/hashicorp/vault/vault"
)

func init() {
Expand Down Expand Up @@ -262,6 +263,10 @@ func generateData() map[string][]byte {
result[strings.Join(segments, "/")] = data
}

// Add special keys that should be excluded from migration
result[migrationLock] = []byte{}
result[vault.CoreLockPath] = []byte{}

return result
}

Expand All @@ -286,6 +291,14 @@ func compareStoredData(s physical.Backend, ref map[string][]byte, start string)
if err != nil {
return err
}

if k == migrationLock || k == vault.CoreLockPath {
if entry == nil {
continue
}
return fmt.Errorf("key found that should have been excluded: %s", k)
}

if k >= start {
if entry == nil {
return fmt.Errorf("key not found: %s", k)
Expand Down
4 changes: 2 additions & 2 deletions vault/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ import (
)

const (
// coreLockPath is the path used to acquire a coordinating lock
// CoreLockPath is the path used to acquire a coordinating lock
// for a highly-available deploy.
coreLockPath = "core/lock"
CoreLockPath = "core/lock"

// The poison pill is used as a check during certain scenarios to indicate
// to standby nodes that they should seal
Expand Down
4 changes: 2 additions & 2 deletions vault/ha.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (c *Core) Leader() (isLeader bool, leaderAddr, clusterAddr string, err erro
}

// Initialize a lock
lock, err := c.ha.LockWith(coreLockPath, "read")
lock, err := c.ha.LockWith(CoreLockPath, "read")
if err != nil {
c.stateLock.RUnlock()
return false, "", "", err
Expand Down Expand Up @@ -392,7 +392,7 @@ func (c *Core) waitForLeadership(newLeaderCh chan func(), manualStepDownCh, stop
c.logger.Error("failed to generate uuid", "error", err)
return
}
lock, err := c.ha.LockWith(coreLockPath, uuid)
lock, err := c.ha.LockWith(CoreLockPath, uuid)
if err != nil {
c.logger.Error("failed to create lock", "error", err)
return
Expand Down

0 comments on commit 46ccb88

Please sign in to comment.