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

fix(cli): fix allow_admin allows non-127.0.0.0/24 to access admin api with empty admin_key #9146

Merged
merged 4 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions apisix/cli/ops.lua
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,9 @@ local function init(env)
local checked_admin_key = false
local allow_admin = yaml_conf.deployment.admin and
yaml_conf.deployment.admin.allow_admin
if yaml_conf.apisix.enable_admin and allow_admin then
for _, allow_ip in ipairs(allow_admin) do
if allow_ip == "127.0.0.0/24" then
checked_admin_key = true
end
end
if yaml_conf.apisix.enable_admin and allow_admin
and #allow_admin == 1 and allow_admin[1] == "127.0.0.0/24" then
checked_admin_key = true
end

if yaml_conf.apisix.enable_admin and not checked_admin_key then
Expand Down
35 changes: 35 additions & 0 deletions t/cli/test_admin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,41 @@ fi

echo "pass: missing admin key and show ERROR message"

# missing admin key, only allow 127.0.0.0/24 to access admin api

echo '
deployment:
admin:
admin_key: ~
allow_admin:
- 127.0.0.0/24
' > conf/config.yaml

make init > output.log 2>&1 | true

if grep -E "ERROR: missing valid Admin API token." output.log > /dev/null; then
echo "failed: should not show 'ERROR: missing valid Admin API token.'"
exit 1
fi

echo '
deployment:
admin:
admin_key: ~
allow_admin:
- 0.0.0.0/0
- 127.0.0.0/24
' > conf/config.yaml

make init > output.log 2>&1 | true

if ! grep -E "ERROR: missing valid Admin API token." output.log > /dev/null; then
echo "failed: should show 'ERROR: missing valid Admin API token.'"
exit 1
fi

echo "pass: missing admin key and only allow 127.0.0.0/24 to access admin api"

# admin api, allow any IP but use default key

echo '
Expand Down