-
Notifications
You must be signed in to change notification settings - Fork 61
Configuration Encryption
For encrypting and decrypting the sensitive parameters, you need to do several things:
First you need to install Oracle JCE (Java Cryptography Extension) to your JRE.
# go to your tmp directory
cd /tmp/
# download and unzip JCE zip file
curl -k -LO "http://download.oracle.com/otn-pub/java/jce/8/jce_policy-8.zip" -H 'Cookie: oraclelicense=accept-securebackup-cookie' && unzip jce_policy-8.zip
# delete the original zip file
rm jce_policy-8.zip
# go to Java JRE lib directory
cd "$(/usr/libexec/java_home)/jre/lib/"
# back up the original security directory
sudo tar czf security_backup.tar.gz security
# copy 2 jar files from the JCE directory to the security directory
sudo cp -v /tmp/UnlimitedJCEPolicyJDK8/*.jar "$(/usr/libexec/java_home)/jre/lib/security"
This step, you need to set up a symmetric encryption key as an environment variable.
- If you run the config server in command-line, use need to use this command:
export ENCRYPT_KEY=IMSYMMETRIC
- If you run the config server in Eclipse, you need to add this environment variable into the run configuration of the application start class of the config server.
This step, we will make a HTTP request (method must be POST) to the config server to get the encrypted value of the sensitive information. In this example, we will use spring.datasource.password as the sensitive parameter.
Request
METHOD: POST
URL: http://localhost:8888/encrypt
BODY: 6ytow2-;S3lA
Response
8e2e38b0e293fb4c0a8def88b828a8b2a6d1f5984ebbdedc0a6dd54ff355dd86
This long hex string is the encrypted value of the password.
This step, you need to replace the original value of the spring.datasource.password parameter by the encrypted value in the licenssingservice.yml file.
spring.datasource.password: "{cipher}8e2e38b0e293fb4c0a8def88b828a8b2a6d1f5984ebbdedc0a6dd54ff355dd86"
The {cipher}
value tells Spring Cloud configuration server to deal this value as an encrypted value.
Before this step, if you ping the endpoint of the config server, it will still return the original value of the password. You need to change the bootstrap.yml file to disable the server-side decryption of the sensitive parameter.
spring:
cloud:
config:
server:
encrypt.enabled: false
Notice that encrypt.enabled
should be together and in the same line.
In the client-side, you need to add the same encryption key for decrypting the encrypted value.
- If you run the licensing service in command-line, use need to use this command:
export ENCRYPT_KEY=IMSYMMETRIC
- If you run the licensing service in Eclipse, you need to add this environment variable into the run configuration of the application start class of the licensing service.
- Overview
- Getting Started
-
Technical Essentials
- Autowired
- SpringData JPA
- Configuration File Auto-loading
- Configuration Encryption
- Service Discovery with Eureka
- Resiliency Patterns with Hystrix
- Configure Hystrix
- Service Gateway with Zuul
- Zuul Filters
- Protect Service with Spring Security and OAuth2
- Use JWT as Access Token
- Store Clients and Users' Credentials to DB
- Integrate with Message Queue (Kafka)
- Integrate with Redis
- Tune Logging
- Log Aggregation
- Send Trace to Zipkin
- Build Runnable Jar
- Core Application Logic
- Components