diff --git a/nomad/encrypter.go b/nomad/encrypter.go index 388482b4e8f8..9b6a13864b87 100644 --- a/nomad/encrypter.go +++ b/nomad/encrypter.go @@ -464,7 +464,8 @@ START: getReq := &structs.KeyringGetRootKeyRequest{ KeyID: keyID, QueryOptions: structs.QueryOptions{ - Region: krr.srv.config.Region, + Region: krr.srv.config.Region, + MinQueryIndex: keyMeta.ModifyIndex - 1, }, } getResp := &structs.KeyringGetRootKeyResponse{} @@ -482,7 +483,7 @@ START: getReq.AllowStale = true for _, peer := range krr.getAllPeers() { err = krr.srv.forwardServer(peer, "Keyring.Get", getReq, getResp) - if err == nil { + if err == nil && getResp.Key != nil { break } } diff --git a/nomad/keyring_endpoint.go b/nomad/keyring_endpoint.go index 78d4808ce298..9b7e27ad90f7 100644 --- a/nomad/keyring_endpoint.go +++ b/nomad/keyring_endpoint.go @@ -264,7 +264,20 @@ func (k *Keyring) Get(args *structs.KeyringGetRootKeyRequest, reply *structs.Key Key: key, } reply.Key = rootKey - reply.Index = keyMeta.ModifyIndex + + // Use the last index that affected the policy table + index, err := s.Index(state.TableRootKeyMeta) + if err != nil { + return err + } + + // Ensure we never set the index to zero, otherwise a blocking query + // cannot be used. We floor the index at one, since realistically + // the first write must have a higher index. + if index == 0 { + index = 1 + } + reply.Index = index return nil }, }