当前位置:网站首页>Micro combat | centralized configuration service center Config asymmetric encryption and security management
Micro combat | centralized configuration service center Config asymmetric encryption and security management
2022-07-29 15:05:00 【Rain _ time to cook】
前言
上一篇:微服务实战|集中配置组件Config规避敏感信息泄露
上一篇文章中,我们介绍了使用集中配置中心组件ConfigImplemented symmetric encryption algorithm Implemented encryption and decryption of configuration information,This article will introduce the use of asymmetric encryption algorithms to achieve the same function and the security management of the configuration center.
一、ConfigAsymmetric encryption in action
1、生成秘钥文件
使用 JDK In their own digital certificate management toolskeytool .进入jdk安装目录下的bin目录,Execute the following command to generate the key file:
D:\soft\Java\jdk1.8.0_181\bin>keytool -genkeypair -alias config-server -keyalg RSA -dname "CN=cn,OU=cn,O=cn,L=cn,S=cn,C=cn" -keypass 123456 -keystroe d:/config-server.jks -storepass 123456
将生成的config-server.jks文件copy到config-server项目的resource目录下面.
2、配置秘钥
继续修改我们的config-server项目,将bootstrap.yml文件内容修改如下:
#Symmetric encryption configuration
#encrypt:
# key: 123456
#Asymmetric encryption configuration
encrypt:
key-store:
location: config-server.jks
alias: config-server
password: 123456
secret: 123456
3、启动验证
启动config-server项目,验证一下加密解密是否正常:
同样访问http://localhost:8005/encrypt/status,返回ok

再来访问http://localhost:8081/encrypt 加密接口:
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-7yY7TB6s-1659000221062)(D:\document\cxy\art\09-1.png)]](/img/eb/35d589c8ca2d5c017bc8e9b7dfd4a2.png)
Also everything works,能够正常加密和解密.
4、项目实战
加密和解密功能正常之后,就要修改我们的配置文件内容了.
修改我们的config-server项目,在repo文件夹下,修改客户端的配置文件configclient-dev.yml,修改内容如下:
#Symmetrically encrypted ciphertext
#app:
# key: '{cipher}5ab3ce1502c40c276074f400aee0be0f6279d6a85bb9d8d315a78c7a91603dde58d4512a6bc9f6492a8eddd34dbeeac0'
#Asymmetric encryption ciphertext
app:
key: '{cipher}AQBFywM+SuemUIS18U8wXrw96hxmhq26u4UUKCxQ1jLTLEcT7MEldJ9C7H4USE+bxVIlHernOewcfWQBg8SwSqK9MuLr07Z1bTEwPEu8KfbEMKTXJBaK6OOVLPFKjaUS/ezHKlke1DYjPpxuo9QO5GOTXIGZOBIlcclJbBCAc2/JIEK34Na/vJdbmSVtNdo6qLw1ufDNPES5q7pweWrnaP4vmtzV8JSs7+UAOV4caf8Zxrv7Sp6KuxuRlEn2yNPoi9bzf4pBWoqxZ5cUsEkzMb5ZEEkmqXCXT4o6+AWdantXbzUXCVculh0FGHvJnnvzsDjoKnVJm0JULjNa5yWNik42tdqsj4KlW76XWcBNv4ditrNsYz13IhZpwsZGHtqTZ97AwobvaTY/UrV1We5ssx3O'
注意密文前面增加{cipher},这样才能正常解密.
5、验证
最后,再次重启registry项目以及config-server,config-client两个服务,访问client端的hello接口:http://localhost:8007/hello,Also returned to normal plaintext encrypted:

二、Configuration Center Security Management
just now we noticed,visit between us as:http://localhost:8005/encrypt/status、http://localhost:8081/encrypt 等状态,加密、The decryption interface is accessible between.Even we can access the configuration center to get the interface address of the configuration file:http://localhost:8005/configclient/dev:

returned by the browserjsonWhy is the message formatted directly??Just install this plugin:Chrome浏览器插件:FeHelper
This is also a security risk!We also need to do further security management:
1、引入依赖
继续修改我们的config-server项目的pom文件,增加如下依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
添加完成之后,重启 config_server 项目,Note that the following log will be printed in the background when restarting:
Using generated security password: 8dc1da66-b6ea-4aa7-a67d-3d02f97e179c
Then the browser accesses the address again: http://localhost:8005/configclient/dev,就会跳转到登录页面,without directly returning configuration information,The default username for the login information isuser,And the password is the random password generated in the log printed above,We can also specify username and password:
2、Increase safety management configuration
修改config-server项目中的application.yml配置文件:
server:
port: 8005
spring:
application:
name: config-server
profiles:
active: native #本地文件
cloud:
config:
server:
native:
search-locations: classpath:/repo
security: #Increase safety management configuration
user:
name: cxy965
roles: admin
password: 123456
eureka:
client:
service-url:
defaultZone: http://localhost:8001/eureka/
这样,You can log in with the username and password we specified.
3、Adjust client calls
Increase safety management configuration,我们重新启动config-client项目,就会发现,Unable to pull configuration from configuration center:
2022-07-28 17:09:03.416 WARN 29296 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: Could not extract response: no suitable HttpMessageConverter found for response type [class org.springframework.cloud.config.environment.Environment] and content type [text/html;charset=UTF-8]
2022-07-28 17:09:03.418 INFO 29296 --- [ main] com.cxy965.demo.ConfigClientApplication : No active profile set, falling back to default profiles: default
Means through our configuration information,Unable to get available configuration resources,It is because the configuration center adds security management,The client has no right to access,这时,Just add the user name and password for access on the client side..
修改config-client项目的bootstrap.yml,如下:
spring:
application:
name: configclient
cloud:
config:
username: cxy965 #Increased access to configuration center user name information
password: 123456 #Add password information for accessing configuration center
name: configclient
profile: dev
discovery:
enabled: true
service‐id: config-server
eureka:
client:
service‐url:
defaultZone: http://localhost:8001/eureka/
再重新启动就可以了!
边栏推荐
- 【 LeetCode 】 217. Duplicate elements
- 兆骑科创海外高层次人才引进平台,企业项目对接,赛事活动路演
- 【C语言】AI三子棋的成长之路
- 部门例会上做测试分享,不知道分享什么内容?
- 自动化配置SSH免密登录和取消SSH免密配置脚本
- RAMAN 中 OPTIMIZATION 优化选项的作用
- Couldn‘t create temporary file /tmp/apt.conf.uko4Kd for passing config to apt-key
- 光鲜亮丽的业绩,也掩盖不了科大讯飞的“一身病痛”
- 【LeetCode】350. 两个数组的交集 II
- Guangzhou Emergency Management Bureau released the top ten safety risks of hazardous chemicals in summer
猜你喜欢
随机推荐
广州消防:高温天气火灾频发 消防安全不容忽视
疫情之下的裁员浪潮,7点建议帮你斩获心仪offer
交叉编译工具链的安装和配置过程
MySQL 是如何实现 ACID 的?
Guangzhou Emergency Management Bureau released the top ten safety risks of hazardous chemicals in summer
rosbag数据画图MATLAB
AOP实现企业级API访问接口监控(通过Google Guava缓存数据)
企业级存储详解与存储资源盘活
Zhaoqi Technology creates a platform for overseas high-level talent introduction, corporate project docking, and event roadshows
C语言 5:bool类型,关系表达式,逻辑表达式,分支语句,函数调用机制,break,continue,goto,return/exit跳转语句
dedecms编辑器支持pdf导入
Instant Messaging - New Software that Changes Social and Work Status
【 LeetCode 】 350. The intersection of two arrays. II
Couldn‘t create temporary file /tmp/apt.conf.uko4Kd for passing config to apt-key
hyperbench:plugin.Open(“./fabric“): plugin was built with a different version of package golang.
回放线上流量利器-GoReplay
【Try to Hack】IDS入侵检测系统
第4章_1——SQL语句实现MySQL增删改查
Topic 1125: - delegate * C language training
RAMAN CONFIGURE 命令都能实现哪些功能









