-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
feat(cli): support bypassing Admin API Auth by configuration #9147
Conversation
If this option is turned on, can we provide some hints, otherwise there may be security risks |
Yes for sure, need to log it in error log as well. |
CC @monkeyDluffy6017 Key hints are added. Besides, I have changed the implementation details according to @moonming 's advice. If |
Please make the CI pass |
apisix/cli/ops.lua
Outdated
-- check if APISIX_BYPASS_ADMIN_API_AUTH=true | ||
local allow_none_auth = getenv("APISIX_BYPASS_ADMIN_API_AUTH") | ||
if allow_none_auth == "true" then | ||
checked_admin_key = true | ||
print("Warning! AdminKey is bypassed because of APISIX_BYPASS_ADMIN_API_AUTH=true.", | ||
"If you are deploying APISIX in a production environment,", | ||
"please disable it and set a secure password for the adminKey!") | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are there duplicate codes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean that hint appears in both stdout and log?
opt.lua
checks if allow_admin in config.yaml is correct before APISIX starts. We need to bypass the adminKey check here.init.lua
checks the adminKey when accessing the Admin API (after APISIX starts). We need to bypass check_token, too.
That's why I have implemented bypass-logic in two different stage.(before and after the start).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In other words, opt.lua
does a static check on the configuration file (if it is not 127.0.0.0/24 and the adminKey is empty, APISIX will not start).
We also have to bypass the checks here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is repeated code, then it needs to be abstracted into a function
apisix/cli/ops.lua
Outdated
if yaml_conf.deployment.admin.admin_key_required == false then | ||
checked_admin_key = true | ||
print("Warning! Admin key is bypassed! " | ||
.. "If you are deploying APISIX in a production environment, " | ||
.. "please disable it and set a secure password for the admin Key!") | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicate code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add an issue for the duplicate code and fix it later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that the only code common to both sides is:
if conf.deployment.admin.admin_key_required == false then
print / log
end
Actually the output approach is different (before APISIX starting is print
, after starting is log
).
So IMHO, merge this two part to one function is unnecessary, because the common part is too simple (only with common part conf.deployment.admin.admin_key_required == false
)
bffbf56
t/admin/api.t
Outdated
=== TEST 11: Access without api key, but admin_key_required=true | ||
--- yaml_config | ||
deployment: | ||
admin: | ||
admin_key_required: true | ||
--- request | ||
GET /apisix/admin/routes | ||
--- error_code: 401 | ||
|
||
|
||
|
||
=== TEST 12: Access without api key, but admin_key_required=true | ||
--- yaml_config | ||
deployment: | ||
admin: | ||
admin_key_required: true | ||
--- request | ||
GET /apisix/admin/routes | ||
--- error_code: 401 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are these two test cases the same?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be Access with api key, but admin_key_required=false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
Test cases are designed as below: CC @moonming |
* upstream/master: (25 commits) fix: upgrade lua-resty-ldap to 0.2.2 (apache#9254) feat(cli): support bypassing Admin API Auth by configuration (apache#9147) fix(ci): write version into xds first (apache#9274) fix: skip warning log when apisix.data_encryption.enable is false (apache#9057) docs: add-api7-information (apache#9260) docs: Fixed typo (apache#9244) docs: clarify what is client.ca in client-to-apisix-mtls.md (apache#9221) docs: Corrected typos and grammatical errors (apache#9216) docs: updated ssl sni parameter requirement in admin-api.md (apache#9176) fix: check upstream reference in traffic-split plugin when delete upstream (apache#9044) docs: Update proxy-rewrite headers.add docs (apache#9220) feat: suppot header injection for fault-injection plugin (apache#9039) fix: upgrade lua-resty-etcd to 1.10.4 (apache#9235) docs: fix incorrect semantic.yml link (apache#9231) feat: Upstream status report (apache#9151) fix: host_hdr should not be false (apache#9150) docs: remove APISIX base instruction (apache#9117) fix(cli): prevent non-`127.0.0.0/24` to access admin api with empty admin_key (apache#9146) docs: fix 404 link (apache#9160) fix(cors): consider using `allow_origins_by_regex` only when it is not `nil` (apache#9028) ...
Description
APISIX now does not allow the requests with empty adminKey to access Admin API except 127.0.0.0/24.
The user can allow this by the configuration below.
Fixes #9071
Checklist