Nacos supports TLS to encrypt data transmitted between clients and servers, preventing sensitive information from being intercepted or tampered with.
Prerequisites
-
or Activate MSE.
-
A Nacos engine of version 2.1.2.1 or later is created. Create a Nacos engine. To upgrade an earlier version, see Upgrade a Nacos engine version.
-
The Java Development Kit (JDK) version is 8u252 or later.
NoteJDK versions earlier than 8u252 have TLS compatibility issues. Upgrade to 8u252 or later, or use a pure nacos-client instead. How do I import a pure nacos-client?.
-
A pure nacos-client can use OpenSSL as the SSL provider, but you must remove the
nacos.remote.client.rpc.tls.providerparameter. -
Pure Nacos versions do not shade dependent second-party packages. You may need to resolve package conflicts.
-
Step 1: Modify Nacos parameter settings
-
Log on to the MSE console, and select a region in the top navigation bar.
-
In the left-side navigation pane, choose Microservices Registry > Instances. Click the name of the instance.
-
In the navigation pane on the left, click Parameter Settings. Click Edit, set the TLSEnabled parameter to Yes, and then click Save and Restart Instance.
After the restart, the server accepts TLS connections from Nacos clients.
Step 2: Upgrade the nacos-client
Nacos client 2.2.1 or later is required for TLS.
-
Upgrade the nacos-client to version 2.2.1 or later.
<dependency> <groupId>com.alibaba.nacos</groupId> <artifactId>nacos-client</artifactId> <version>2.2.1</version> </dependency> -
Set the
tlsparameters to enable the TLS feature.Set
tlsparameters using one of the following methods. Priority: properties file > JVM parameters > environment variables.-
Set parameters in a properties file. Pass them when building NacosConfigService or NacosNamingService instances.
-
properties.put("nacos.remote.client.rpc.tls.enable","true"); -
properties.put("nacos.remote.client.rpc.tls.trustAll","true"); -
properties.put("nacos.remote.client.rpc.tls.provider","JDK");
This method takes precedence over JVM parameters and environment variables. It applies at the NacosConfigService and NacosNamingService instance level.
-
-
Set JVM parameters.
-
-Dnacos.remote.client.rpc.tls.enable=true -
-Dnacos.remote.client.rpc.tls.trustAll=true -
-Dnacos.remote.client.rpc.tls.provider=JDK
This method applies at the JVM process level to all NacosConfigService and NacosNamingService instances without properties-file overrides.
-
-
Set environment variables.
-
nacos_remote_client_rpc_tls_enable=true -
nacos_remote_client_rpc_tls_trustAll=true -
nacos_remote_client_rpc_tls_provider=JDK
This method applies at the server level to all instances without JVM or properties-file overrides.
-
-
-
Confirm that TLS encryption is enabled.
-
View the startup logs.
The nacos-client logs TLS configuration to
{user.home}/logs/nacos/remote.logat startup.2023-04-06 09:56:56.539 INFO [com.alibaba.nacos.client.Worker:c.a.n.c.r.c.g.GrpcClient] grpc client connection server:mse-xxx.nacos-ans.mse.aliyuncs.com ip,serverPort:9848,grpcTslConfig:{"sslProvider":"","enableTls":true,"mutualAuthEnable":false,"trustAll":true}The
"enableTls":truefield confirms that TLS is active. If the client starts and reads/writes configurations normally, encryption is working. -
Capture data packets with the
tcpdumpcommand.Run
tcpdumpto capture packets. The following example saves output to/tmp/tcptrace.cap. Adjust the path as needed.sudo tcpdump -i any -w /tmp/tcptrace.cap -p 9848Open the file in Wireshark or a similar tool. If the protocol shows TCP&TLS, encryption is active.
-
FAQ
How do I import a pure nacos-client?
Add the following dependencies:
<dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
<version>2.2.1</version>
<classifier>pure</classifier>
</dependency>
<dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-common</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-api</artifactId>
<version>2.2.1</version>
</dependency>
If TLS is enabled on the server-side engine, are older nacos-client versions supported for encryption?
No. You must upgrade the nacos-client to 2.2.1 or later to enable TLS encryption.
If TLS is enabled on the server-side engine, are there compatibility issues with older nacos-client versions?
The DPI engine starts in compatibility mode by default to support normal access for older, non-TLS clients.
Does MSE Nacos support one-way authentication or mutual authentication?
MSE Nacos supports one-way authentication only: the client verifies the server, but the server does not verify the client.
Why do clients use the trustAll mode?
The trustAll mode simplifies TLS setup. For stricter security, contact MSE technical support (DingTalk group ID: 43525005207) to obtain the official MSE CA certificate, then specify it as the trusted CA file:
-
Properties file:
nacos.remote.client.rpc.tls.trustCollectionChainPath=file:{filePath} -
JVM parameter:
-Dnacos.remote.client.rpc.tls.trustCollectionChainPath=file:{filePath} -
Environment variable:
nacos_remote_client_rpc_tls_trustCollectionChainPath=file:{filePath}
Parameter priority: properties file > JVM parameters > environment variables.
Why do TLS parameters injected through the properties file not take effect?
TLS property values must be strings. Do not pass boolean values.
-
Correct format:
properties.put("nacos.remote.client.rpc.tls.enable","true"); -
Incorrect format:
properties.put("nacos.remote.client.rpc.tls.enable",true);
What should I do if the log NotSslRecordException: not an SSL/TLS record appears in the nacos-client logs?
The server returned a non-TLS response because TLS is not enabled on the server. Enable TLS on the server to resolve this issue. Step 1: Modify Nacos parameter settings.