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

Don't copy HA lock file during migration #5503

Merged
merged 1 commit into from
Oct 12, 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
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