request help: apisix connected use tls with etcd
Issue description
Environment
- apisix version (cmd:
apisix version): 2.1 - OS: (cmd:
uname -a) Centos7.6 - OpenResty / Nginx version: (cmd:
nginx -Voropenresty -V)
apisix config.yaml about config etcd
apisix:
config_center: etcd
etcd:
host: # it's possible to define multiple etcd hosts addresses of the same etcd cluster.
- "https://192.168.1.1:2379" # multiple etcd address, if your etcd cluster enables TLS, please use https scheme,
# e.g. "https://127.0.0.1:2379".
prefix: "/apisix" # apisix configurations prefix
timeout: 30 # 30 seconds
resync_delay: 5 # when sync failed and a rest is needed, resync after the configured seconds plus 50% random jitter
user: root # root username for etcd password: 123456 # root password for etcd tls: verify: true
Hi, @Yangzcy423911 According to the configuration information you provided, the problem cannot be seen. Can you describe the problem you encountered or provide more information? This helps us troubleshoot the problem.
It is recommended to format your configuration information. This helps to confirm whether there is a problem with the configuration information. ^ _ ^
@Yangzcy423911 You didn't describe your problem.
etcd start
etcd --cert-file=server.pem --key-file=server-key.pem --advertise-client-urls=https://127.0.0.1:2379 --listen-client-urls=https://127.0.0.1:2379
log
raft2021/01/09 11:15:15 INFO: 8e9e05c52164694d is starting a new election at term 7 raft2021/01/09 11:15:15 INFO: 8e9e05c52164694d became candidate at term 8 raft2021/01/09 11:15:15 INFO: 8e9e05c52164694d received MsgVoteResp from 8e9e05c52164694d at term 8 raft2021/01/09 11:15:15 INFO: 8e9e05c52164694d became leader at term 8 raft2021/01/09 11:15:15 INFO: raft.node: 8e9e05c52164694d elected leader 8e9e05c52164694d at term 8 2021-01-09 11:15:15.560528 I | etcdserver: published {Name:default ClientURLs:[https://127.0.0.1:2379]} to cluster cdf818194e3a8c32 2021-01-09 11:15:15.560639 I | embed: ready to serve client requests 2021-01-09 11:15:15.562946 I | embed: serving client requests on 127.0.0.1:2379
local test
curl -k https://127.0.0.1:2379/version {"etcdserver":"3.4.13","etcdcluster":"3.4.0"}
apisix test error
about config
etcd: host: # it's possible to define multiple etcd hosts addresses of the same etcd cluster. - "https://127.0.0.1:2379" # multiple etcd address, if your etcd cluster enables TLS, please use https scheme, # e.g. "https://127.0.0.1:2379". prefix: "/apisix" # apisix configurations prefix timeout: 30 # 30 seconds user: "root" # root username for etcd password: "123456" # root password for etcd
apisix restart nginx: [error] open() "/usr/local/apisix/logs/nginx.pid" failed (2: No such file or directory) got malformed version message: "" from etcd
etcd log
2021-01-09 11:17:01.293987 I | embed: rejected connection from "127.0.0.1:52492" (error "remote error: tls: unknown certificate authority", ServerName "")
@Yangzcy423911 By default APISIX will verify etcd server's certificate. You may try to set the etcd.tls.verify to false in config.yaml.
I test in config set etcd.tls.verify to false , can't connect etcd this restart apisix appear log
apisix restart nginx: [error] open() "/usr/local/apisix/logs/nginx.pid" failed (2: No such file or directory) got malformed version message: "" from etcd
etcd log
2021-01-09 12:40:17.264706 I | embed: rejected connection from "127.0.0.1:44352" (error "remote error: tls: unknown certificate authority", ServerName "")
apisix config about etcd
etcd: host: # it's possible to define multiple etcd hosts addresses of the same etcd cluster. - "https://127.0.0.1:2379" # multiple etcd address, if your etcd cluster enables TLS, please use https scheme, # e.g. "https://127.0.0.1:2379". prefix: "/apisix" # apisix configurations prefix timeout: 30 # 30 seconds user: "uat_entry" # root username for etcd password: "123456" # root password for etcd tls: verify: false
@Yangzcy423911 Could you connect to etcd through curl call?
local call connected etcd is success, I try branch 2.2 code apisix with tls connected etcd error This is a Bug ,you can test use tls apisix connected etcd
can you provide a mini case which we can use to reproduce this issue? @Yangzcy423911
etcd start etcd --cert-file=server.pem --key-file=server-key.pem --advertise-client-urls=https://127.0.0.1:2379 --listen-client-urls=https://127.0.0.1:2379
log
raft2021/01/09 11:15:15 INFO: 8e9e05c52164694d is starting a new election at term 7 raft2021/01/09 11:15:15 INFO: 8e9e05c52164694d became candidate at term 8 raft2021/01/09 11:15:15 INFO: 8e9e05c52164694d received MsgVoteResp from 8e9e05c52164694d at term 8 raft2021/01/09 11:15:15 INFO: 8e9e05c52164694d became leader at term 8 raft2021/01/09 11:15:15 INFO: raft.node: 8e9e05c52164694d elected leader 8e9e05c52164694d at term 8 2021-01-09 11:15:15.560528 I | etcdserver: published {Name:default ClientURLs:[https://127.0.0.1:2379]} to cluster cdf818194e3a8c32 2021-01-09 11:15:15.560639 I | embed: ready to serve client requests 2021-01-09 11:15:15.562946 I | embed: serving client requests on 127.0.0.1:2379
local test
curl -k https://127.0.0.1:2379/version {"etcdserver":"3.4.13","etcdcluster":"3.4.0"}
apisix test error
about config
etcd: host: # it's possible to define multiple etcd hosts addresses of the same etcd cluster.
- "https://127.0.0.1:2379" # multiple etcd address, if your etcd cluster enables TLS, please use https scheme,
e.g. "https://127.0.0.1:2379".
prefix: "/apisix" # apisix configurations prefix timeout: 30 # 30 seconds user: "root" # root username for etcd password: "123456" # root password for etcd
apisix restart nginx: [error] open() "/usr/local/apisix/logs/nginx.pid" failed (2: No such file or directory) got malformed version message: "" from etcd
etcd log
2021-01-09 11:17:01.293987 I | embed: rejected connection from "127.0.0.1:52492" (error "remote error: tls: unknown certificate authority", ServerName "") This is a mini case , you have try it Thanks
This is due to etcd bootstrap step doesn't ignore the certificate verification. Thanks for your feedback!
Hi @Yangzcy423911. This is because the apisix bootstrap doesn't ignore the certificate verification.
I think you can modify this file apisix/cli/etcd.lua and and -k option for every curl.
Please have a try. Any feedback is welcome.
apisix/cli/etcd.lua
source 136 local cmd = str_format("curl -s -m %d %s", timeout * 2, uri) modify local cmd = str_format("curl -s -k -m %d %s", timeout * 2, uri) is right?
apisix/cli/etcd.lua
source 136 local cmd = str_format("curl -s -m %d %s", timeout * 2, uri) modify local cmd = str_format("curl -s -k -m %d %s", timeout * 2, uri) is right?
Yes, the same as:
https://github.com/apache/apisix/blob/9c7e96e608099bcc7a0fa10b1ee4395e7a03d3fa/apisix/cli/etcd.lua#L136 https://github.com/apache/apisix/blob/9c7e96e608099bcc7a0fa10b1ee4395e7a03d3fa/apisix/cli/etcd.lua#L173 https://github.com/apache/apisix/blob/9c7e96e608099bcc7a0fa10b1ee4395e7a03d3fa/apisix/cli/etcd.lua#L197
We also need to support it with lua-resty-etcd, not just fix it when running the command. I have created an issue for it: https://github.com/apache/apisix/issues/3283
The lua-resty-etcd already supports disabling tls verify: https://github.com/apache/apisix/blob/5482a4bf72b33eabb83fd4bf396a222366c589f3/conf/config-default.yaml#L192-L193
For old version, add -k to curl is enough.
So we close the issue now.