This is an automated email from the ASF dual-hosted git repository. membphis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push: new 18909a2 feat: allow disabling search option in resolv.conf (#3609) 18909a2 is described below commit 18909a2a0bf62fd5dc5e1dbcc59ef563545ff359 Author: 罗泽轩 <spacewander...@gmail.com> AuthorDate: Sat Feb 20 15:38:45 2021 +0800 feat: allow disabling search option in resolv.conf (#3609) Also disable it in the test to avoid occassional DNS query timeout. --- apisix/core/utils.lua | 7 +++++++ conf/config-default.yaml | 1 + t/APISIX.pm | 1 + t/core/utils.t | 28 ++++++++++++++++++++++++++++ 4 files changed, 37 insertions(+) diff --git a/apisix/core/utils.lua b/apisix/core/utils.lua index 788f3e2..f302790 100644 --- a/apisix/core/utils.lua +++ b/apisix/core/utils.lua @@ -88,6 +88,8 @@ local function dns_parse(domain) if dns_resolvers ~= current_inited_resolvers then local local_conf = config_local.local_conf() local valid = table.try_read_attr(local_conf, "apisix", "dns_resolver_valid") + local enable_resolv_search_opt = table.try_read_attr(local_conf, "apisix", + "enable_resolv_search_opt") local opts = { ipv6 = true, @@ -97,6 +99,11 @@ local function dns_parse(domain) order = {"last", "A", "AAAA", "CNAME"}, -- avoid querying SRV (we don't support it yet) validTtl = valid, } + + if not enable_resolv_search_opt then + opts.search = {} + end + local ok, err = dns_client.init(opts) if not ok then return nil, "failed to init the dns client: " .. err diff --git a/conf/config-default.yaml b/conf/config-default.yaml index 885007d..14b5168 100644 --- a/conf/config-default.yaml +++ b/conf/config-default.yaml @@ -110,6 +110,7 @@ apisix: # - 8.8.8.8 # dns_resolver_valid: 30 # if given, override the TTL of the valid records. The unit is second. resolver_timeout: 5 # resolver timeout + enable_resolv_search_opt: true # enable search option in resolv.conf ssl: enable: true enable_http2: true diff --git a/t/APISIX.pm b/t/APISIX.pm index 618443b..d5880cb 100644 --- a/t/APISIX.pm +++ b/t/APISIX.pm @@ -93,6 +93,7 @@ apisix: tcp: - 9100 admin_key: null + enable_resolv_search_opt: false _EOC_ my $etcd_enable_auth = $ENV{"ETCD_ENABLE_AUTH"} || "false"; diff --git a/t/core/utils.t b/t/core/utils.t index 42cba26..0e0b8ee 100644 --- a/t/core/utils.t +++ b/t/core/utils.t @@ -271,6 +271,10 @@ ip_info: {"address":"127.0.0.1","class":1,"name":"test.com","ttl":315360000,"typ === TEST 8: search host with '.org' suffix +--- yaml_config +apisix: + node_listen: 1984 + enable_resolv_search_opt: true --- config location /t { content_by_lua_block { @@ -289,3 +293,27 @@ GET /t .+"name":"apisix\.apache\.org".+ --- no_error_log [error] + + + +=== TEST 9: disable search option +--- yaml_config +apisix: + node_listen: 1984 + enable_resolv_search_opt: false +--- config + location /t { + content_by_lua_block { + local core = require("apisix.core") + local ip_info, err = core.utils.dns_parse("apisix") + if not ip_info then + core.log.error("failed to parse domain: ", host, ", error: ",err) + return + end + ngx.say("ip_info: ", require("toolkit.json").encode(ip_info)) + } + } +--- request +GET /t +--- error_log +error: failed to query the DNS server