-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e9bdbf
commit 1b71fa3
Showing
11 changed files
with
876 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
apiVersion: v1 | ||
kind: Secret | ||
type: kubernetes.io/tls | ||
metadata: | ||
name: ca-key-pair | ||
data: | ||
tls.crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUY5ekNDQTkrZ0F3SUJBZ0lVRkt1ekFKWmdtL2ZzRlM2SkRyZCtsY3BWWnI4d0RRWUpLb1pJaHZjTkFRRUwKQlFBd2dad3hDekFKQmdOVkJBWVRBa05PTVJFd0R3WURWUVFJREFoYWFHVnFhV0Z1WnpFUk1BOEdBMVVFQnd3SQpTR0Z1WjNwb2IzVXhHREFXQmdOVkJBb01EMEZRU1ZOSldDMVVaWE4wTFVOQlh6RVlNQllHQTFVRUN3d1BRVkJKClUwbFlYME5CWDFKUFQxUmZNUlV3RXdZRFZRUUREQXhCVUVsVFNWZ3VVazlQVkY4eEhEQWFCZ2txaGtpRzl3MEIKQ1FFV0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9JQkFBVDUyOFdGVE9BOTdyQUFIeFJqOGprQUI2NEV4ZlRkY2w1eHpsQW5uQ09pQ3lGNWtlOTFwYjRECklZMkcvVk1mN2ZNakNCNy93RTNxa3RkTE5pQW9GdTlkZW1ydmdrTVI4VU5RTitwSzAyWWU2VUxsMTJwUTcxczcKQktTYjRpOVVUY0phVmFWT2hZbkNnTTcwQnBkQ2FKWFVQMGhqUC9BRVRESVJQZnFZRWhtend4dWt5c0VCTkpscApjWXlCOWRRSjhCV3M4R282T1d2Q2dic0Fwa0FTOTdOY1czZzRwL3c3dDlDSXVCblFuS2hUMUpVUmswS0pNeDAxCkU0cysxTndQN0I5R2Ivdlpja01FejBDM282WDJwbnk2eVkwcUtHK3lZOUh2NVV1M3M4UE1ZeFJKckU2ZUJuMGoKNDQ1ME9EOEg2d1MxSldPaGFZSEY1OGJoVW5zY0Zkbz0KLS0tLS1FTkQgUFJJVkFURSBLRVktLS0tLQo= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
apiVersion: cert-manager.io/v1alpha2 | ||
kind: Issuer | ||
metadata: | ||
name: ca-issuer | ||
spec: | ||
ca: | ||
secretName: ca-key-pair |
241 changes: 241 additions & 0 deletions
241
docs/en/latest/practices/manage-certificates-with-cert-manager.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,241 @@ | ||
--- | ||
title: Manage Certificates With Cert Manager | ||
--- | ||
|
||
<!-- | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
--> | ||
|
||
This tutorial will detail how to manage secrets of ApisixTls using cert-manager. | ||
|
||
## Prerequisites | ||
|
||
* Prepare an available Kubernetes cluster in your workstation, we recommend you to use [KIND](https://kind.sigs.k8s.io/docs/user/quick-start/) to create a local Kubernetes cluster. | ||
* Install Apache APISIX in Kubernetes by [Helm Chart](https://github.com/apache/apisix-helm-chart). | ||
* Install [apisix-ingress-controller](https://github.com/apache/apisix-ingress-controller/blob/master/install.md). | ||
* Install [cert-manager](https://cert-manager.io/docs/installation/#default-static-install). | ||
|
||
In this guide, we assume that your APISIX is installed with `ssl` enabled, which is not enabled by default in the Helm Chart. To enable it, you need to set `gateway.tls.enabled=true` during installation. | ||
|
||
For example, you could install APISIX and APISIX ingress controller by running: | ||
|
||
```bash | ||
helm install apisix apisix/apisix --set gateway.type=NodePort --set ingress-controller.enabled=true --set gateway.tls.enabled=true | ||
``` | ||
|
||
Assume that the SSL port is `9443`. | ||
|
||
## Create Issuer | ||
|
||
For testing purposes, we will use a simple CA issuer. All required files can be found [here](./cert-manager). | ||
|
||
To create a CA issuer, use the following commands: | ||
|
||
```bash | ||
kubectl apply -f ./cert-manager/ca.yaml | ||
kubectl apply -f ./cert-manager/issuer.yaml | ||
``` | ||
|
||
If the cert-manager is working correctly, we should be able to see the Ready status by running: | ||
|
||
```bash | ||
kubectl get issuer | ||
``` | ||
|
||
It should output: | ||
|
||
```text | ||
NAME READY AGE | ||
ca-issuer True 50s | ||
``` | ||
|
||
## Create Certificate | ||
|
||
Before creating ApisixTls, we should create a `Certificate` resource. | ||
|
||
```yaml | ||
apiVersion: cert-manager.io/v1 | ||
kind: Certificate | ||
metadata: | ||
name: demo-cert | ||
spec: | ||
dnsNames: | ||
- local.httpbin.org | ||
issuerRef: | ||
kind: Issuer | ||
name: ca-issuer | ||
secretName: example-cert | ||
usages: | ||
- digital signature | ||
- key encipherment | ||
renewBefore: 0h55m0s | ||
duration: 1h0m0s | ||
``` | ||
Note that we set the parameters `duration` and `renewBefore`. We want to test if the certificate rotation functionality is working well, so a shorter renewal time will help. | ||
|
||
Like `Issuer`, we could see its readiness status by running: | ||
|
||
```bash | ||
kubectl get certificate | ||
``` | ||
|
||
It should output: | ||
|
||
```text | ||
NAME READY SECRET AGE | ||
demo-cert True example-cert 50s | ||
``` | ||
|
||
Check the secrets by running: | ||
|
||
```bash | ||
kubectl get secret | ||
``` | ||
|
||
It should output: | ||
|
||
```text | ||
NAME TYPE DATA AGE | ||
example-cert kubernetes.io/tls 3 2m20s | ||
``` | ||
|
||
This means that our cert-manager is working properly. | ||
|
||
## Create Test Service | ||
|
||
We use [kennethreitz/httpbin](https://hub.docker.com/r/kennethreitz/httpbin/) as the service image. | ||
|
||
Deploy it by running: | ||
|
||
```bash | ||
kubectl run httpbin --image kennethreitz/httpbin --expose --port 80 | ||
``` | ||
|
||
## Route the Service | ||
|
||
Create an ApisixRoute to route the service: | ||
|
||
```yaml | ||
apiVersion: apisix.apache.org/v2beta1 | ||
kind: ApisixRoute | ||
metadata: | ||
name: httpserver-route | ||
spec: | ||
http: | ||
- name: httpbin | ||
match: | ||
hosts: | ||
- local.httpbin.org | ||
paths: | ||
- "/*" | ||
backend: | ||
serviceName: httpbin | ||
servicePort: 80 | ||
``` | ||
|
||
Run curl command in a APISIX pod to see if the routing configuration works. | ||
|
||
```bash | ||
kubectl -n <APISIX_NAMESPACE> exec -it <APISIX_POD_NAME> -- curl http://127.0.0.1:9080/ip -H 'Host: local.httpbin.org' | ||
``` | ||
|
||
It should output: | ||
|
||
```json | ||
{ | ||
"origin": "127.0.0.1" | ||
} | ||
``` | ||
|
||
## Secure the Route | ||
|
||
Create an ApisixTls to secure the route, referring to the secret created by cert-manager: | ||
|
||
```yaml | ||
apiVersion: apisix.apache.org/v1 | ||
kind: ApisixTls | ||
metadata: | ||
name: example-tls | ||
spec: | ||
hosts: | ||
- local.httpbin.org | ||
secret: | ||
name: example-cert # the secret created by cert-manager | ||
namespace: default # secret namespace | ||
``` | ||
|
||
Run curl command in a APISIX pod to see if the Ingress and TLS configuration are working. | ||
|
||
```bash | ||
kubectl -n <APISIX_NAMESPACE> exec -it <APISIX_POD_NAME> -- curl --resolve 'local.httpbin.org:9443:127.0.0.1' "https://local.httpbin.org:9443/ip" -k | ||
``` | ||
|
||
It should output: | ||
|
||
```json | ||
{ | ||
"origin": "127.0.0.1" | ||
} | ||
``` | ||
|
||
## Test Certificate Rotation | ||
|
||
To verify certificate rotation, we can add a verbose parameter `-v` to curl command: | ||
|
||
```bash | ||
kubectl -n <APISIX_NAMESPACE> exec -it <APISIX_POD_NAME> -- curl --resolve 'local.httpbin.org:9443:127.0.0.1' "https://local.httpbin.org:9443/ip" -k -v | ||
``` | ||
|
||
The verbose option will show us the handshake log, which also contains the certificate information. | ||
|
||
Example output: | ||
|
||
```text | ||
* Added local.httpbin.org:9443:127.0.0.1 to DNS cache | ||
* Hostname local.httpbin.org was found in DNS cache | ||
* Trying 127.0.0.1:9443... | ||
* Connected to local.httpbin.org (127.0.0.1) port 9443 (#0) | ||
... | ||
... | ||
* Server certificate: | ||
* subject: [NONE] | ||
* start date: Sep 16 00:14:55 2021 GMT | ||
* expire date: Sep 16 01:14:55 2021 GMT | ||
* issuer: C=CN; ST=Zhejiang; L=Hangzhou; O=APISIX-Test-CA_; OU=APISIX_CA_ROOT_; CN=APISIX.ROOT_; emailAddress=test@test.com | ||
``` | ||
|
||
We could see the start date and expiration date of the server certificate. | ||
|
||
Since the `Certificate` we defined requires the cert-manager to renew the cert every 5 minutes, we should be able to see the changes to the server certificate after 5 minutes. | ||
|
||
```text | ||
* Added local.httpbin.org:9443:127.0.0.1 to DNS cache | ||
* Hostname local.httpbin.org was found in DNS cache | ||
* Trying 127.0.0.1:9443... | ||
* Connected to local.httpbin.org (127.0.0.1) port 9443 (#0) | ||
... | ||
... | ||
* Server certificate: | ||
* subject: [NONE] | ||
* start date: Sep 16 00:19:55 2021 GMT | ||
* expire date: Sep 16 01:19:55 2021 GMT | ||
* issuer: C=CN; ST=Zhejiang; L=Hangzhou; O=APISIX-Test-CA_; OU=APISIX_CA_ROOT_; CN=APISIX.ROOT_; emailAddress=test@test.com | ||
``` | ||
|
||
The certificate was rotated as expected. |
Oops, something went wrong.