Alibaba Cloud Service Mesh (ASM) lets you add a certificate for a domain name on the console. This helps you secure access to your domain name by using protocols such as HTTPS and enhances the security of your service gateway. This topic describes how to add a certificate for a domain name.
Prerequisites
-
You have deployed an application in the cluster associated with your ASM instance, and the instance is an Enterprise Edition or Ultimate Edition.
An ingress gateway is deployed. For more information, see Create an ingress gateway.
-
You have enabled automatic sidecar proxy injection for the namespace. For more information, see Enable automatic sidecar injection.
-
You have obtained the IP address of the ASM gateway. For more information, see Obtain the IP address of an ASM gateway.
Background information
This topic uses the myexampleapp service for the domain name aliyun.com as an example to describe how to add a certificate for the aliyun.com domain name. After the certificate is added successfully, you can use an ASM gateway to access the myexampleapp service for the domain name aliyun.com by using the HTTPS protocol.
Procedure
-
Create the sample service myexampleapp.
-
Create a file named myexample-nginx.conf that contains the following content.
This sample service is based on NGINX. You must create a configuration file for the NGINX server. For the service with the domain name aliyun.com, the following configuration specifies that requests to the root path return the message
Welcome to aliyun.com!and the status code200.events { } http { log_format main '$remote_addr - $remote_user [$time_local] $status ' '"$request" $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; error_log /var/log/nginx/error.log; server { listen 80; location / { return 200 'Welcome to aliyun.com!'; add_header Content-Type text/plain; } } } -
Run the following command to create a ConfigMap for the NGINX server:
kubectl create configmap myexample-nginx-configmap --from-file=nginx.conf=./myexample-nginx.conf -
Create a file named myexampleapp.yaml that contains the following content.
-
Run the following command to create the internal service for the aliyun.com domain name:
kubectl apply -f myexampleapp.yaml
-
-
Import the myexampleapp service into the ASM gateway.
-
Log on to the ASM console. In the left-side navigation pane, choose .
-
On the Mesh Management page, click the name of the ASM instance. In the left-side navigation pane, choose .
-
On the Ingress Gateway page, click the name of the target gateway.
-
On the Gateway Details page, click Upstream Service in the navigation pane on the left.
-
On the Upstream Service page, click Import service.
-
On the Import service page, select a Namespaces, select the myexampleapp service, click the
icon, and then click Submit.
-
-
Create a certificate and a private key.
-
Run the following command in OpenSSL to create a root certificate and a private key:
openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 -subj '/O=myexample Inc./CN=aliyun.com' -keyout aliyun.root.key -out aliyun.root.crt -
Run the following commands to generate a certificate and a private key for the aliyun.com domain.
-
Run the following command to create the aliyun.com.crt certificate:
openssl x509 -req -days 365 -CA aliyun.root.crt -CAkey aliyun.root.key -set_serial 0 -in aliyun.com.csr -out aliyun.com.crt -
Run the following command to create the private key aliyun.com.key.
openssl req -out aliyun.com.csr -newkey rsa:2048 -nodes -keyout aliyun.com.key -subj "/CN=aliyun.com/O=myexample organization"
-
-
-
Add the certificate and private key to the ASM gateway.
Note-
Starting from V1.17, ASM instances support certificates from the Certificate Management page. We recommend that you migrate your certificates to Certificate Management. You can create a certificate with the same name on the Certificate Management page to automatically overwrite the existing certificate. You do not need to delete the old certificate. For more information about how to upgrade an instance, see Upgrade an ASM instance.
-
A certificate on the Certificate Management page automatically creates a Secret with the same name on the data plane. This action overwrites the content of any existing Secret with the same name.
ASM instances before v1.17
-
Log on to the ASM console. In the left-side navigation pane, choose .
-
On the Mesh Management page, click the name of the ASM instance. In the left-side navigation pane, choose .
-
On the Ingress Gateway page, click the name of the target gateway. On the Gateway Details page, click Domain/Certificate in the navigation pane on the left.
-
On the Domain/Certificate page, click the Certificate tab, and then click Create.
-
On the New Certificate page, enter a Name, paste the content of
aliyun.com.crtinto the Certificate text box and the content ofaliyun.com.keyinto the key text box, and then click Create.
ASM v1.17 and later
-
Log on to the ASM console. In the left-side navigation pane, choose .
-
On the Mesh Management page, click the name of the target instance. In the navigation pane on the left, choose .
-
On the Certificate Management page, click Create. In the Certificate Information panel, configure the parameters and click OK.
Parameter
Description
Name
Enter a name for the certificate. In this example, use myexample-credential.
Public Key Certificate
The content of the
aliyun.com.crtfile from Step 3.Private Key
The content of the
aliyun.com.keyfile from Step 3.
-
-
Bind the domain name to the certificate.
-
Log on to the ASM console. In the left-side navigation pane, choose .
-
On the Mesh Management page, click the name of the ASM instance. In the left-side navigation pane, choose .
-
On the Ingress Gateway page, click the name of the target gateway. On the Gateway Details page, click Domain/Certificate in the navigation pane on the left.
-
On the Domain/Certificate page, click the Domain tab, and then click Create.
-
On the Add domain page, set Domain Name to *.aliyun.com and Protocol to HTTPS. Enter a Port Name and a Port. Select a credential and select Secure connections with standard TLS semantics.. Then, click Create.
NoteIf you select Secure connections with standard TLS semantics., only TLS-encrypted requests can access the domain name.
-
-
Run the following command to access aliyun.com over HTTPS and verify that the certificate is bound to the domain name:
curl -k -H Host:www.aliyun.com --resolve www.aliyun.com:443:<IP address of the ASM gateway> https://www.aliyun.comExpected output:
Welcome to aliyun.com!If you successfully access aliyun.com by using the HTTPS protocol, it indicates that the domain name and the certificate are successfully bound.