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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ matrix:
- docker
env: OSNAME=linux_openresty
- os: linux
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run this test case in Github Action, the Travis-CI is slow.

what do you think? @nic-chen

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's good. I will try to move to github actions.

env: OSNAME=linux_openresty_two_side_ssl_auth
env: OSNAME=linux_openresty_mtls
- os: osx
env: OSNAME=osx_openresty
cache:
Expand Down
13 changes: 5 additions & 8 deletions bin/apisix
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,11 @@ http {
{%if https_admin then%}
listen {* port_admin *} ssl;

{%if ssl.verify_client then%}
ssl_certificate cert/two_side_server.crt;
ssl_certificate_key cert/two_side_server.key;
{%if mtls and mtls.enable then%}
ssl_verify_client on;
ssl_certificate {* mtls.server_cert *};
ssl_certificate_key {* mtls.server_key *};
ssl_client_certificate {* mtls.ca_cert *};
nic-chen marked this conversation as resolved.
Show resolved Hide resolved
{% else %}
ssl_certificate cert/apisix_admin_ssl.crt;
ssl_certificate_key cert/apisix_admin_ssl.key;
Expand All @@ -305,11 +307,6 @@ http {
ssl_ciphers {* ssl.ssl_ciphers *};
ssl_prefer_server_ciphers on;

{%if ssl.verify_client then%}
ssl_client_certificate cert/two_side_ca.crt;
ssl_verify_client on;
{%end%}

{% else %}
listen {* port_admin *};
{%end%}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ apisix:
# - "::/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 will use conf/apisix_admin_api.crt and conf/apisix_admin_api.key as certificate.
mtls:
enable: true # Enable or disable mtls. Enable depends on `port_admin` and `https_admin`.
ca_cert: "../t/certs/mtls_ca.crt" # Path of your self-signed ca cert.
server_key: "../t/certs/mtls_server.key" # Path of your self-signed server side cert.
server_cert: "../t/certs/mtls_server.crt" # Path of your self-signed server side key.

# 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 Expand Up @@ -93,7 +98,6 @@ apisix:
listen_port: 9443
ssl_protocols: "TLSv1 TLSv1.1 TLSv1.2 TLSv1.3"
ssl_ciphers: "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA256:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA"
verify_client: true
key_encrypt_salt: "edd1c9f0985e76a2" # If not set, will save origin ssl key into etcd.
# If set this, must be a string of length 16. And it will encrypt ssl key with AES-128-CBC
# !!! So do not change it after saving your ssl, it can't decrypt the ssl keys have be saved if you change !!
Expand Down
8 changes: 5 additions & 3 deletions conf/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ apisix:
# 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.
mtls:
nic-chen marked this conversation as resolved.
Show resolved Hide resolved
enable: false # Enable or disable mtls. Enable depends on `port_admin` and `https_admin`.
ca_cert: "" # Path of your self-signed ca cert.
nic-chen marked this conversation as resolved.
Show resolved Hide resolved
server_key: "" # Path of your self-signed server side cert.
server_cert: "" # Path of your self-signed server side key.

# 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 Expand Up @@ -93,9 +98,6 @@ apisix:
listen_port: 9443
ssl_protocols: "TLSv1 TLSv1.1 TLSv1.2 TLSv1.3"
ssl_ciphers: "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA256:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA"
verify_client: false # Enable or disable client-to-server authentication with HTTPS client certificates
# It depends on `port_admin` and `https_admin`, they need to be enable if you want to enable `verify_client`.
# And you need to replace your real certs to `cert/two_side_ca.crt`, `cert/two_side_server.crt` and `cert/two_side_server.key`.
key_encrypt_salt: "edd1c9f0985e76a2" # If not set, will save origin ssl key into etcd.
# If set this, must be a string of length 16. And it will encrypt ssl key with AES-128-CBC
# !!! So do not change it after saving your ssl, it can't decrypt the ssl keys have be saved if you change !!
Expand Down
17 changes: 9 additions & 8 deletions doc/two-side-auth-with-ssl.md → doc/mtls.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,25 @@
#
-->

[Chinese](zh-cn/two-side-auth-with-ssl.md)
[Chinese](zh-cn/mtls.md)

## Enable client-to-server authentication with ssl certificates
## Enable mutual TLS authentication

nic-chen marked this conversation as resolved.
Show resolved Hide resolved
1. Generate self-signed key pairs, including ca, server, client key pairs.

2. Replace `cert/two-side-ca.crt` with the ca cert just generated. And replace `cert/two-side-client.crt` and `cert/two-side-client.key` in the same way.

3. Modify configuration items in `conf/config.yaml`:
2. Modify configuration items in `conf/config.yaml`:
```yaml
port_admin: 9180
https_admin: true

ssl:
verify_client: true
mtls:
enable: true # Enable or disable mtls. Enable depends on `port_admin` and `https_admin`.
ca_cert: "/data/certs/mtls_ca.crt" # Path of your self-signed ca cert.
server_key: "/data/certs/mtls_server.key" # Path of your self-signed server side cert.
server_cert: "/data/certs/mtls_server.crt" # Path of your self-signed server side key.
```

4. Run command:
3. Run command:
```shell
membphis marked this conversation as resolved.
Show resolved Hide resolved
apisix init
apisix reload
Expand Down
15 changes: 8 additions & 7 deletions doc/zh-cn/two-side-auth-with-ssl.md → doc/zh-cn/mtls.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,25 @@
#
-->

[English](../two-side-auth-with-ssl.md)
[English](../mtls.md)

## 开启双向认证

1. 生成自签证书对,包括 ca、server、client 证书对。

2. 用刚刚生成的证书相应的替换 `cert/two-side-ca.crt`、`cert/two-side-client.crt` 和 `cert/two-side-client.key`。

3. 修改 `conf/config.yaml` 中的配置项:
2. 修改 `conf/config.yaml` 中的配置项:
```yaml
port_admin: 9180
https_admin: true

ssl:
verify_client: true
mtls:
enable: true # Enable or disable mtls. Enable depends on `port_admin` and `https_admin`.
ca_cert: "/data/certs/mtls_ca.crt" # Path of your self-signed ca cert.
server_key: "/data/certs/mtls_server.key" # Path of your self-signed server side cert.
server_cert: "/data/certs/mtls_server.crt" # Path of your self-signed server side key.
```

4. 执行命令:
3. 执行命令:
```shell
apisix init
apisix reload
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.