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: Support admin API authentication with SSL certificates #1747

Merged
merged 38 commits into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
bc33857
Client-to-server authentication with HTTPS client certificates
johzchen Jun 20, 2020
1074440
test
johzchen Jun 20, 2020
844118c
fix: admin port
johzchen Jun 20, 2020
0a972c8
fix: https
johzchen Jun 20, 2020
408df70
test
johzchen Jun 20, 2020
ba41a01
test
johzchen Jun 20, 2020
32067b5
test
johzchen Jun 20, 2020
717f226
test
johzchen Jun 20, 2020
b9d2af9
fix lint error
johzchen Jun 20, 2020
73b311d
test
johzchen Jun 20, 2020
22cbe7d
test
johzchen Jun 20, 2020
ac1c52e
test
johzchen Jun 20, 2020
c67ec40
new cert
johzchen Jun 20, 2020
9ce5960
fix: domain
johzchen Jun 20, 2020
d349020
fix: domain
johzchen Jun 20, 2020
5addff3
config option
johzchen Jun 21, 2020
acf0d6c
Merge branch 'apisix/master' into cli-srv-auth
johzchen Jun 21, 2020
3421255
doc
johzchen Jun 21, 2020
03487a6
optimize
johzchen Jun 22, 2020
a71cd51
optimize
johzchen Jun 22, 2020
e57b026
optimize
johzchen Jun 22, 2020
f0c21b1
fix error
johzchen Jun 22, 2020
9104603
fix path error
johzchen Jun 22, 2020
beb4d3e
check http status after call mtls admin api
johzchen Jun 22, 2020
1ba44f1
remove useless config file
johzchen Jun 22, 2020
62b916f
set default path for mTLS certs
johzchen Jun 22, 2020
3219d85
fix text style
johzchen Jun 24, 2020
ac82691
fix: naming
johzchen Jun 24, 2020
586c1bc
more test cases
johzchen Jun 24, 2020
b9591f0
fix lint check
johzchen Jun 24, 2020
d479370
fix error
johzchen Jun 24, 2020
450e926
test
johzchen Jun 24, 2020
988253c
update doc for admin api mTLS
johzchen Jun 24, 2020
83a45b8
Merge branch 'master' into cli-srv-auth
johzchen Jul 16, 2020
473a59b
fix lint
johzchen Jul 16, 2020
a689132
fix etcd version
johzchen Jul 16, 2020
e256756
Merge branch 'master' into cli-srv-auth
johzchen Jul 17, 2020
b0838e8
run mTLS test cases with github ations
johzchen Jul 17, 2020
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
23 changes: 22 additions & 1 deletion .travis/linux_openresty_mtls_runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,34 @@ script() {
sleep 1
cat logs/error.log


# correct certs
code=$(curl -i -o /dev/null -s -w %{http_code} --cacert ./t/certs/mtls_ca.crt --key ./t/certs/mtls_client.key --cert ./t/certs/mtls_client.crt -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' https://admin.apisix.dev:9180/apisix/admin/routes)
nic-chen marked this conversation as resolved.
Show resolved Hide resolved
nic-chen marked this conversation as resolved.
Show resolved Hide resolved
if [ ! $code -eq 200 ]; then
echo "failed: failed to enabled mTLS for admin"
exit 1
fi

# no certs
code=$(curl -i -o /dev/null -s -w %{http_code} -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' https://admin.apisix.dev:9180/apisix/admin/routes)
if [ ! $code -eq 000 ]; then
nic-chen marked this conversation as resolved.
Show resolved Hide resolved
echo "failed: failed to enabled mTLS for admin"
exit 1
fi

# no ca cert
code=$(curl -i -o /dev/null -s -w %{http_code} --key ./t/certs/mtls_client.key --cert ./t/certs/mtls_client.crt -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' https://admin.apisix.dev:9180/apisix/admin/routes)
if [ ! $code -eq 000 ]; then
echo "failed: failed to enabled mTLS for admin"
exit 1
fi

# error key
code=$(curl -i -o /dev/null -s -w %{http_code} --cacert ./t/certs/mtls_ca.crt --key ./t/certs/mtls_server.key --cert ./t/certs/mtls_client.crt -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' https://admin.apisix.dev:9180/apisix/admin/routes)
if [ ! $code -eq 000 ]; then
echo "failed: failed to enabled mTLS for admin"
exit 1
fi

./bin/apisix stop
sleep 1

Expand Down
5 changes: 4 additions & 1 deletion bin/apisix
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,10 @@ http {
{%if https_admin then%}
listen {* port_admin *} ssl;

{%if admin_api_mtls and admin_api_mtls.mtls_enable then%}
{%if admin_api_mtls and admin_api_mtls.admin_ssl_cert and admin_api_mtls.admin_ssl_cert ~= "" and
admin_api_mtls.admin_ssl_cert_key and admin_api_mtls.admin_ssl_cert_key ~= "" and
admin_api_mtls.admin_ssl_ca_cert and admin_api_mtls.admin_ssl_ca_cert ~= ""
then%}
ssl_verify_client on;
ssl_certificate {* admin_api_mtls.admin_ssl_cert *};
ssl_certificate_key {* admin_api_mtls.admin_ssl_cert_key *};
Expand Down
15 changes: 7 additions & 8 deletions conf/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,13 @@ apisix:
allow_admin: # http://nginx.org/en/docs/http/ngx_http_access_module.html#allow
- 127.0.0.0/24 # If we don't set any IP list, then any IP access is allowed by default.
# - "::/64"
port_admin: 9180 # use a separate port
https_admin: true # enable HTTPS when use a separate port for Admin API.
# Admin API will use conf/apisix_admin_api.crt and conf/apisix_admin_api.key as certificate.
admin_api_mtls:
mtls_enable: true # Enable or disable mTLS. Enable depends on `port_admin` and `https_admin`.
admin_ssl_cert: "../t/certs/mtls_server.crt" # Path of your self-signed server side cert.
admin_ssl_cert_key: "../t/certs/mtls_server.key" # Path of your self-signed server side key.
admin_ssl_ca_cert: "../t/certs/mtls_ca.crt" # Path of your self-signed ca cert.
# port_admin: 9180 # use a separate port
# https_admin: true # enable HTTPS when use a separate port for Admin API.
# Admin API will use conf/apisix_admin_api.crt and conf/apisix_admin_api.key as certificate.
admin_api_mtls: # Depends on `port_admin` and `https_admin`.
admin_ssl_cert: "" # Path of your self-signed server side cert.
admin_ssl_cert_key: "" # Path of your self-signed server side key.
admin_ssl_ca_cert: "" # Path of your self-signed ca cert.

# Default token when use API to call for Admin API.
# *NOTE*: Highly recommended to modify this value to protect APISIX's Admin API.
Expand Down