TLS interception and decryption

Updated at:
Copy as MD

After you enable TLS interception and configure a private CA certificate for an instance, Egress Proxy Gateway (EPG) can decrypt outbound HTTPS traffic and inspect its content. This allows you to audit encrypted traffic and implement fine-grained control over it, which helps meet security requirements such as data leak prevention and classified protection compliance.

How it works

After TLS interception is enabled, EPG acts as a proxy and establishes a separate TLS connection with the client and with the destination server. The process is as follows:

  1. The client sends an HTTPS request to EPG. EPG uses the configured private CA certificate to dynamically issue a server certificate for the destination domain name, and completes the TLS handshake with the client by using the certificate.

  2. EPG decrypts the request into HTTP plaintext and performs rule matching in the PreRequest phase based on content such as the URI path, request method, and request headers.

  3. After the request passes rule matching, EPG establishes a TLS connection with the destination server, encrypts the request, and forwards it.

  4. After EPG receives the encrypted response from the destination server, EPG decrypts the response, re-encrypts it over the TLS connection with the client, and returns it to the client.

Because EPG must maintain two TLS connections at the same time, one with the client and one with the destination server, and must decrypt and re-encrypt the traffic, enabling TLS interception introduces some forwarding latency.

Important

TLS interception and TLS client access are two independent concepts. Do not confuse them.

  • TLS interception: controls whether EPG decrypts the HTTPS traffic between the client and the destination server. After TLS interception is enabled, EPG acts as a proxy, uses the configured private CA certificate to dynamically issue a server certificate, and completes the TLS handshake with the client. This way, traffic is decrypted into plaintext, which allows Layer 7 content to be controlled and audited.

  • TLS client access: controls whether the communication between the client and EPG is encrypted. It uses the HTTPS listener port of the EPG instance (such as port 443) to protect the proxy channel itself, which is typically used in zero trust scenarios.

If TLS interception is disabled for an instance, the client uses the CONNECT method to establish an end-to-end encrypted tunnel with the destination server through EPG for HTTPS requests. EPG only forwards the traffic and cannot parse the request content inside the tunnel. In this case, HTTPS requests do not enter the PreRequest phase, and neither the rules nor the default action of the phase take effect. The requests are forwarded directly through the default address pool. To control HTTPS traffic, enable TLS interception. If you need to control traffic only by source IP address or destination domain name, configure rules in the PreDns phase.

Prerequisites

  • You have created an EPG instance.

  • You have created an ECS instance that runs Alibaba Cloud Linux and supports Secure Shell (SSH) logons in the VPC where the EPG instance resides.

Procedure

1. Enable TLS interception

TLS interception can be enabled when you create an instance or after the instance is created. This topic uses an example where TLS interception is enabled after the instance is created.

  1. On the Instances page of the EPG console, click the ID of the target instance to go to the details page.

  2. On the Listener configuration tab, click Edit to the right of TLS interception configuration.

  3. In the Edit the TLS interception configuration. dialog box, select TLS interception configuration, and select the private CA that is used for decryption from the Certificate ID drop-down list. If no certificate is available, click Create Certificate to go to the PCA certificate management console to create one (a private CA is a paid resource). After the configuration is complete, click Save.

TLS interception supports private CAs that use the RSA (RSA_2048 or RSA_4096) or ECC (ECC_256 or ECC_384) algorithm. Both root CAs and subordinate CAs are supported. We recommend that you use a subordinate CA to reduce the frequency of use and the exposure risk of the root CA private key.
Make sure that the private CA certificate that is used for TLS interception is within its validity period. Renew the certificate or replace it with another valid certificate before it expires. Otherwise, TLS interception may not work as expected.
To disable TLS interception, clear TLS interception configuration at the same entry and click Save. After TLS interception is disabled, TLS interception mode is displayed as Not enabled.

2. Configure the client to trust the private CA certificate

After TLS interception is enabled, EPG uses the private CA certificate to dynamically issue certificates for destination domain names. The client must trust the private CA certificate. Otherwise, the SSL certificate problem certificate warning is reported.

  1. In the PCA certificate management console, find the private CA that is used for TLS interception. In the Actions column, choose More > Details. Copy the Certificate Information (in PEM format, from -----BEGIN CERTIFICATE----- to -----END CERTIFICATE-----).

  2. Write the certificate content to the ECS instance. Example: /tmp/epg-ca.pem.

    sudo tee /tmp/epg-ca.pem > /dev/null <<'EOF'
    (Paste the certificate content, from -----BEGIN CERTIFICATE----- to -----END CERTIFICATE-----)
    EOF
  3. Install the certificate into the system trust store.

    # Alibaba Cloud Linux / CentOS
    sudo cp /tmp/epg-ca.pem /etc/pki/ca-trust/source/anchors/epg-ca.crt
    sudo update-ca-trust extract
    
    # Ubuntu / Debian
    sudo cp /tmp/epg-ca.pem /usr/local/share/ca-certificates/epg-ca.crt
    sudo update-ca-certificates
Some applications or programming languages, such as Java, Node.js, and some Python libraries, use their own certificate trust stores instead of the system trust store. If the warning persists after you import the certificate into the system trust store, import the private CA certificate into the trust store of the corresponding runtime as required.

3. Verify that TLS interception takes effect

Before you verify, configure the proxy environment variables. If they are not configured, see Configure HTTP/HTTPS proxy access to complete the proxy access configuration. On the ECS instance, access an HTTPS site through the proxy, and check whether the issuer of the server certificate is the private CA that EPG uses:

curl -v --max-time 15 https://www.example.com 2>&1 | grep "issuer"

If the issuer is displayed as the name of the private CA that EPG uses, TLS interception takes effect. This indicates that EPG has reissued the certificate by using your private CA and successfully decrypted the traffic.

To further verify whether the rules of the PreRequest phase take effect on HTTPS requests after decryption, first configure rules and associate the rule group with the egress proxy configuration. Then, send a request and observe the result.