Decrypt the password of the nacos connected account
Opened this issue · 0 comments
Company regulations require that passwords in plain text not appear in the configuration file.
- Recently, the project introduced Nacos as the configuration center of the service, using the package spring-cloud-starter-alibaba-nacos-config
- Implement Jasypt encryption of Nacos Client login password for Nacos client and Nacos Server connection
Have you dealt with cases like this, asking for advice?
local:
namespace: dev
spring:
application:
name: mars-springboot-nacos
cloud:
nacos:
config:
server-addr: 192.168.0.1:8848
namespace: ${local.namespace}
username: nacos
password: ENC(GABwNsWUVBFqHr7iURHTZNbXNiI3FrAphcRkYCue0+ZBQXndNfnnOEmsxd)
discovery:
server-addr: 192.168.0.1:8848:8848
metadata:
user.name: "admin"
user.password: "admin"
username: nacos
password: ENC(GABwNsWUVBFqHr7iURHTZNbXNiI3FrAphcRkYCue0+ZBQXndNfnnOEmsxd)
namespace: ${local.namespace}
1.Company-defined StringEncryptor
public class CoustormStringEncryptor implements StringEncryptor
2. config class
@bean(name="coustormStringEncryptor ")
public StringEncryptor stringEncryptor() {
return new CoustormStringEncryptor();
}
3. Unable to decrypt
However, it is possible to encrypt and decrypt nacos connection passwords using StringEncryptor without overwriting
Update your application's configuration
2024-11-05 15:47:22.005 ERROR 1668 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
APPLICATION FAILED TO START
Description:
Failed to bind properties under 'spring.cloud.nacos.config.password' to java.lang.String:
Reason: org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'spring.cloud.nacos.config.password' to java.lang.String
Action:
Update your application's configuration
Disconnected from the target VM, address: 'javadebug', transport: 'shared memory'
Process finished with exit code 1