HTTPS mutual authentication lets the server and client verify each other. Use it on ALB Ingress in banking, financial services, IoT, internal services, or government scenarios where data is sensitive or access must be limited to trusted clients.
How it works
| HTTPS one-way authentication | HTTPS mutual authentication | |
|---|---|---|
| Client verifies server | Yes | Yes |
| Server verifies client | No | Yes |
| Client holds | — | SSL or TLS certificate signed by root CA |
| Server holds | Server certificate | Root CA certificate |
The server uses its root CA certificate to verify the client certificate before establishing the connection.
Prerequisites
Ensure that you have:
-
An SSL or TLS certificate is configured on the ALB listener.
-
A root CA certificate obtained by either:
-
Purchasing a private CA in Certificate Management Service
-
(Optional) Step 1: Generate a self-signed CA certificate
Skip this step if you already have a root CA certificate.
-
Generate a private key:
openssl genrsa -out ca.key 4096 -
Create a certificate signing request (CSR):
Field Required Description Country Name Yes Two-letter country code, for example, cnState or Province Name Yes Province or region name Locality Name Yes City name Organization Name Yes Organization name Organizational Unit Name Yes Department name Common Name No A commonly used name Email Address No Certificate administrator email A challenge password No Optional CSR security password. Leave blank if not needed openssl req -new -out ca.csr -key ca.keyOpenSSL prompts for the following fields:
Country Name (2 letter code) [XX]:cn State or Province Name (full name) []:bj Locality Name (eg, city) [Default City]:bj Organization Name (eg, company) [Default Company Ltd]:alibaba Organizational Unit Name (eg, section) []:test Common Name (eg, your name or your servers hostname) []:root Email Address []:example@ali A challenge password []: -
Create the root CA certificate with a validity of 3,650 days:
File Description ca.crtRoot CA certificate ca.csrCSR file ca.keyPrivate key openssl x509 -req -in ca.csr -out ca.crt -signkey ca.key -CAcreateserial -days 3650Run
lsto confirm the output files:ca.crt ca.csr ca.key
Step 2: Upload the CA certificate
Upload the root CA certificate to Certificate Management Service to obtain a certificate identifier for the AlbConfig.
-
Log on to the Certificate Management Service console. Select the Outside Chinese Mainland region. In the left navigation pane, click Certificate Application Repository.
-
On the Certificate Application Repository page, click Create Repository. In the Create Repository panel, set the following parameters and click OK.
Parameter Description Repository Name Custom repository name Data Source Select Upload CA Certificates to upload certificates signed by third-party CAs -
Click your repository, then click Uploaded Certificates.
-
In the CA Information panel, fill in the following fields and click Confirm and Enable.
Parameter Description Package Name Custom certificate name CA Certificates Paste the certificate content, or click Upload and Parse File -
Click Details for the uploaded certificate and record the certificate identifier for Step 4.
Step 3: Generate a client certificate
Use the root CA certificate to sign a client certificate.
-
Generate a private key for the client:
openssl genrsa -out client.key 4096 -
Create a CSR for the client certificate:
openssl req -new -out client.csr -key client.keyComplete the same fields as Step 1. Values can differ from the CA certificate.
-
Sign the client certificate using the root CA:
File Description client.crtClient certificate signed by the root CA client.csrCSR file client.keyClient private key openssl x509 -req -in client.csr -out client.crt -CA ca.crt -CAkey ca.key -CAcreateserial -days 3650ca.crtandca.keyare from Step 1. Runlsto confirm the output:client.crt client.csr client.key
Step 4: Enable and test mutual authentication
Enable mutual authentication
-
Open the AlbConfig for editing:
kubectl edit albconfig <ALBCONFIG_NAME>Replace
<ALBCONFIG_NAME>with your AlbConfig name. -
In the HTTPS listener configuration (port 443), add
caEnabled: trueand setcaCertificates.CertificateIdto the certificate identifier from Step 2:apiVersion: alibabacloud.com/v1 kind: AlbConfig metadata: name: #... spec: config: #... listeners: - port: 443 protocol: HTTPS caEnabled: true # Enable mutual authentication caCertificates: - CertificateId: 0e40dda998174723af39d37fcaf***** # Certificate identifier from Step 2 certificates: #...
Test mutual authentication
-
Get the Ingress hostname and address:
kubectl get ingressExpected output:
NAME CLASS HOSTS ADDRESS PORTS AGE https-ingress https-ingressclass demo.alb.ingress.top alb-********.alb.aliyuncs.com 80, 443 83mRecord the
HOSTSandADDRESSvalues. -
Send a request with the client certificate. Replace
demo.alb.ingress.topandalb-********.alb.aliyuncs.comwith values from the previous step:curl -H HOST:demo.alb.ingress.top -k https://alb-********.alb.aliyuncs.com --cert client.crt --key client.keyExpected output:
old
(Optional) Step 5: Disable mutual authentication
-
Open the AlbConfig for editing:
kubectl edit albconfig <ALBCONFIG_NAME> -
Set
caEnabledtofalse:apiVersion: alibabacloud.com/v1 kind: AlbConfig metadata: name: #... spec: config: #... listeners: - port: 443 protocol: HTTPS caEnabled: false # Disable mutual authentication caCertificates: - CertificateId: 0e40dda998174723af39d37fcaf***** certificates: #...