From a7531526abdb2cbad7a348bf618487eca6b05eb7 Mon Sep 17 00:00:00 2001 From: Jim Kalafut Date: Thu, 7 Mar 2019 11:48:48 -0800 Subject: [PATCH] Fix hanging on empty keys during operator migrate (#6371) --- command/operator_migrate.go | 4 +++- command/operator_migrate_test.go | 12 +++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/command/operator_migrate.go b/command/operator_migrate.go index 0a330d993f..0e6000dd80 100644 --- a/command/operator_migrate.go +++ b/command/operator_migrate.go @@ -311,7 +311,9 @@ func dfsScan(ctx context.Context, source physical.Backend, cb func(ctx context.C // remove List-triggering key and add children in reverse order dfs = dfs[:len(dfs)-1] for i := len(children) - 1; i >= 0; i-- { - dfs = append(dfs, key+children[i]) + if children[i] != "" { + dfs = append(dfs, key+children[i]) + } } } else { err := cb(ctx, key) diff --git a/command/operator_migrate_test.go b/command/operator_migrate_test.go index 6f0bdda363..812200d654 100644 --- a/command/operator_migrate_test.go +++ b/command/operator_migrate_test.go @@ -23,6 +23,8 @@ import ( "github.com/hashicorp/vault/vault" ) +const trailing_slash_key = "trailing_slash/" + func init() { rand.Seed(time.Now().UnixNano()) } @@ -209,6 +211,9 @@ storage_destination "dest_type2" { return nil }) + delete(data, trailing_slash_key) + delete(data, "") + var keys []string for key := range data { keys = append(keys, key) @@ -267,6 +272,11 @@ func generateData() map[string][]byte { result[storageMigrationLock] = []byte{} result[vault.CoreLockPath] = []byte{} + // Empty keys are now prevented in Vault, but older data sets + // might contain them. + result[""] = []byte{} + result[trailing_slash_key] = []byte{} + return result } @@ -292,7 +302,7 @@ func compareStoredData(s physical.Backend, ref map[string][]byte, start string) return err } - if k == storageMigrationLock || k == vault.CoreLockPath { + if k == storageMigrationLock || k == vault.CoreLockPath || k == "" || strings.HasSuffix(k, "/") { if entry == nil { continue }