Skip to content

Commit

Permalink
fix: correct the validation for ssl_trusted_certificate (#3832)
Browse files Browse the repository at this point in the history
Signed-off-by: spacewander <[email protected]>
  • Loading branch information
spacewander authored Mar 16, 2021
1 parent 7047932 commit 0c1b208
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
11 changes: 10 additions & 1 deletion apisix/cli/ops.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ local ngx_tpl = require("apisix.cli.ngx_tpl")
local profile = require("apisix.core.profile")
local template = require("resty.template")
local argparse = require("argparse")
local pl_path = require("pl.path")

local stderr = io.stderr
local ipairs = ipairs
Expand Down Expand Up @@ -260,10 +261,18 @@ Please modify "admin_key" in conf/config.yaml .
end

if yaml_conf.apisix.ssl.ssl_trusted_certificate ~= nil then
local ok, err = util.is_file_exist(yaml_conf.apisix.ssl.ssl_trusted_certificate)
local cert_path = yaml_conf.apisix.ssl.ssl_trusted_certificate
-- During validation, the path is relative to PWD
-- When Nginx starts, the path is relative to conf
-- Therefore we need to check the absolute version instead
cert_path = pl_path.abspath(cert_path)

local ok, err = util.is_file_exist(cert_path)
if not ok then
util.die(err, "\n")
end

yaml_conf.apisix.ssl.ssl_trusted_certificate = cert_path
end

local admin_api_mtls = yaml_conf.apisix.admin_api_mtls
Expand Down
4 changes: 2 additions & 2 deletions bin/apisix
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ if [[ -e $OR_EXEC && "$OR_VER" =~ "1.19" ]]; then

# use the luajit of openresty
echo "$LUAJIT_BIN $APISIX_LUA $*"
$LUAJIT_BIN $APISIX_LUA $*
exec $LUAJIT_BIN $APISIX_LUA $*
elif [[ "$LUA_VERSION" =~ "Lua 5.1" ]]; then
# OpenResty version is not 1.19, use Lua 5.1 by default
echo "lua $APISIX_LUA $*"
lua $APISIX_LUA $*
exec lua $APISIX_LUA $*
else
echo "ERROR: Please check the version of OpenResty and Lua, OpenResty 1.19 and Lua 5.1 are recommended before install Apache APISIX."
fi
1 change: 1 addition & 0 deletions rockspec/apisix-master-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ dependencies = {
"luasocket = 3.0rc1-2",
"luasec = 0.9-1",
"lua-resty-consul = 0.3-2",
"penlight = 1.9.2-1",
}

build = {
Expand Down
14 changes: 14 additions & 0 deletions t/cli/test_validate_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,17 @@ if ! echo "$out" | grep 'dns_resolver_valid should be a number'; then
fi

echo "passed: dns_resolver_valid should be a number"

echo '
apisix:
ssl:
ssl_trusted_certificate: t/certs/mtls_ca.crt
' > conf/config.yaml

out=$(make run 2>&1)
if echo "$out" | grep 'no such file'; then
echo "failed: find the certificate correctly"
exit 1
fi

echo "passed: find the certificate correctly"

0 comments on commit 0c1b208

Please sign in to comment.