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

feat(cli): support bypassing Admin API Auth by configuration #9147

Merged
merged 21 commits into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions apisix/cli/ngx_tpl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ worker_shutdown_timeout {* worker_shutdown_timeout *};
env APISIX_PROFILE;
env PATH; # for searching external plugin runner's binary

env APISIX_ALLOW_NONE_AUTHENTICATION; # allow any IP with empty admin_key
An-DJ marked this conversation as resolved.
Show resolved Hide resolved
moonming marked this conversation as resolved.
Show resolved Hide resolved

# reserved environment variables for configuration
env APISIX_DEPLOYMENT_ETCD_HOST;

Expand Down
7 changes: 7 additions & 0 deletions apisix/cli/ops.lua
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@ local function init(env)
end
end

-- check if APISIX_ALLOW_NONE_AUTHENTICATION=true
-- if so, allow any IP to access admin api with empty admin_key
local allow_none_auth = getenv("APISIX_ALLOW_NONE_AUTHENTICATION")
if allow_none_auth == "true" then
checked_admin_key = true
end

if yaml_conf.apisix.enable_admin and not checked_admin_key then
local help = [[

Expand Down
21 changes: 21 additions & 0 deletions t/cli/test_admin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,27 @@ fi

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

# allow any IP to access admin api with empty admin_key, when APISIX_ALLOW_NONE_AUTHENTICATION=true

git checkout conf/config.yaml

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

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

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

echo "pass: allow empty admin_key, when APISIX_ALLOW_NONE_AUTHENTICATION=true"

# admin api, allow any IP but use default key

echo '
Expand Down