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

autoencrypt: helpful error for clients with wrong dc #14832

Merged
merged 2 commits into from
Oct 25, 2022

Conversation

lkysow
Copy link
Member

@lkysow lkysow commented Oct 2, 2022

If clients have set a different datacenter than the servers they're connecting with for autoencrypt, give a helpful error message. Fixes #10205

The change is to check when we're about to call ForwardRPC if the datacenter matches our current DC. There's no use-case for forwarding to a remote DC so we can short-circuit right there.

Testing & Reproduction steps

# server.hcl
server = true
bootstrap_expect = 1
data_dir = "/tmp/consul-server"
auto_encrypt {
  allow_tls = true
}
tls {
  defaults {
    ca_file = "certs/consul-agent-ca.pem"
    cert_file = "certs/dc1-server-consul-0.pem"
    key_file = "certs/dc1-server-consul-0-key.pem"
  }
}
# client.hcl
datacenter = "different"
retry_join = ["127.0.0.1:8301"]
ports {
  http = 9501
  dns = 9600
  serf_lan = 9301
}
data_dir = "/tmp/consul-client"
auto_encrypt {
  tls = true
}

Old logs:

[ERROR] agent.auto_config: AutoEncrypt.Sign RPC failed: addr=172.25.20.152:8300 error="rpcinsecure error making call: No path to datacenter"
[ERROR] agent.auto_config: No servers successfully responded to the auto-encrypt request

New logs:

2022-10-01T21:58:08.525-0700 [ERROR] agent.auto_config: No servers successfully responded to the auto-encrypt request
2022-10-01T21:59:55.456-0700 [ERROR] agent.auto_config: AutoEncrypt.Sign RPC failed: addr=127.0.0.1:8300 error="rpcinsecure: error making call: mismatched datacenter (client_dc='different' server_dc='dc1'); check client has same datacenter set as servers"

PR Checklist

  • updated test coverage
  • external facing docs updated
  • not a security concern

@@ -607,14 +607,14 @@ func (p *ConnPool) rpcInsecure(dc string, addr net.Addr, method string, args int
var codec rpc.ClientCodec
conn, _, err := p.dial(dc, addr, 0, RPCTLSInsecure)
if err != nil {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought adding :'s here would be nice because rpcinsecure is meant to indicate the area the code is in. It's not an "rpcinsecure error" which makes me think rpcinsecure is having an issue, it's an error while making an rpcinsecure call.

lkysow added 2 commits October 3, 2022 15:22
If clients have set a different datacenter than the servers they're
connecting with for autoencrypt, give a helpful error message.
@lkysow lkysow force-pushed the lkysow/autoencrypt-logs branch from 890a400 to 7f3a76e Compare October 3, 2022 22:22
@lkysow lkysow marked this pull request as ready for review October 3, 2022 22:24
@lkysow lkysow requested a review from a team October 3, 2022 23:58
Copy link
Contributor

@ishustava ishustava left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!! I definitely hit those errors in the past and it took me a while to figure out what was wrong.

@lkysow lkysow merged commit 9999672 into main Oct 25, 2022
@lkysow lkysow deleted the lkysow/autoencrypt-logs branch October 25, 2022 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Give better error if client datacenter does not match server datacenter
2 participants