Skip to content

Commit

Permalink
keyring: set MinQueryIndex on stale queries
Browse files Browse the repository at this point in the history
When keyring replication makes a stale query to non-leader peers to find a key
the leader doesn't have, we need to make sure the peer we're querying has had a
chance to catch up to the most current index for that key. Otherwise it's
possible for newly-added servers to query another newly-added server and get a
non-error nil response for that key ID.

Note that the "not found" does not return an error, just an empty key. So as a
belt-and-suspenders, update the handling of empty responses so that we don't
break the loop early if we hit a server that doesn't have the key.
  • Loading branch information
tgross committed Oct 20, 2022
1 parent 958fab4 commit 12902d4
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions nomad/encrypter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}
getResp := &structs.KeyringGetRootKeyResponse{}
Expand All @@ -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
}
}
Expand Down

0 comments on commit 12902d4

Please sign in to comment.