From db4661f3f8cdb1120b14b395371b8815fbd51345 Mon Sep 17 00:00:00 2001 From: Clint Date: Fri, 14 Feb 2020 14:25:53 -0600 Subject: [PATCH] Guard against using Raft as a seperate HA Storage (#8239) * Guard against using Raft as a seperate HA Storage * Document that Raft cannot be used as a seperate ha_storage backend at this time * remove duplicate imports from updating with master --- command/server.go | 6 ++++++ physical/raft/raft.go | 7 +++++++ website/source/docs/configuration/storage/raft.html.md | 8 +++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/command/server.go b/command/server.go index 10f93b50758b..b3ad41f18712 100644 --- a/command/server.go +++ b/command/server.go @@ -1073,6 +1073,12 @@ func (c *ServerCommand) Run(args []string) int { // Initialize the separate HA storage backend, if it exists var ok bool if config.HAStorage != nil { + // TODO: Remove when Raft can server as the ha_storage backend. + // See https://github.com/hashicorp/vault/issues/8206 + if config.HAStorage.Type == "raft" { + c.UI.Error("Raft cannot be used as seperate HA storage at this time") + return 1 + } factory, exists := c.PhysicalBackends[config.HAStorage.Type] if !exists { c.UI.Error(fmt.Sprintf("Unknown HA storage type %s", config.HAStorage.Type)) diff --git a/physical/raft/raft.go b/physical/raft/raft.go index d1fdfcb0deaa..5e8ada7d0667 100644 --- a/physical/raft/raft.go +++ b/physical/raft/raft.go @@ -963,6 +963,13 @@ func (l *RaftLock) Lock(stopCh <-chan struct{}) (<-chan struct{}, error) { // Cache the notifyCh locally leaderNotifyCh := l.b.raftNotifyCh + // TODO: Remove when Raft can server as the ha_storage backend. The internal + // raft pointer should not be nil here, but the nil check is a guard against + // https://github.com/hashicorp/vault/issues/8206 + if l.b.raft == nil { + return nil, errors.New("attempted to grab a lock on a nil raft backend") + } + // Check to see if we are already leader. if l.b.raft.State() == raft.Leader { err := l.b.applyLog(context.Background(), &LogData{ diff --git a/website/source/docs/configuration/storage/raft.html.md b/website/source/docs/configuration/storage/raft.html.md index 3312fb5351ee..d80367b319d0 100644 --- a/website/source/docs/configuration/storage/raft.html.md +++ b/website/source/docs/configuration/storage/raft.html.md @@ -38,7 +38,13 @@ storage "raft" { cluster_addr = "http://127.0.0.1:8201" ``` -**Note:** When using the Raft storage backend, it is required to provide `cluster_addr` to indicate the address and port to be used for communication between the nodes in the Raft cluster. +~> **Note:** When using the Raft storage backend, it is required to provide +`cluster_addr` to indicate the address and port to be used for communication +between the nodes in the Raft cluster. + +~> **Note:** Raft cannot be used as the configured `ha_storage` backend at this +time. To use Raft for HA coordination users must also use Raft for storage and +set `ha_enabled = true`. ## `raft` Parameters