当前位置:网站首页>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 】 566. Reshape the matrix
- 【IIC通信】Chap.2 (I2C)IIC协议的特点;为什么IIC需要开漏输出、上拉电阻?
- 这 6 款在线 PDF 转换工具,得试
- 【LeetCode】217. 存在重复元素
- dedecms编辑器支持pdf导入
- I quit my job after cutting the brothers, and turned to do a small clerk
- 令人难以置信的DeepMind数据库现在包括了科学界已知的几乎所有蛋白质
- hyperbench:plugin.Open(“./fabric“): plugin was built with a different version of package golang.
- MySQL Index Common Interview Questions (2022 Edition)
- WOLFLAB一方老师带你解读虚拟云网络《VMware NSX-T卷2》-1
猜你喜欢
随机推荐
如何编辑CAD图库里的图纸
软件测试架构师的工作日常
uni 的下拉式筛选菜单的功能/图片懒加载
CNCF Keith Chan:分布式云时代,云原生社区的发展与趋势
【C语言】AI三子棋的成长之路
Interfaces and Abstractions
AVH部署实践 (一) | 在Arm虚拟硬件上部署飞桨模型
升级openssl1.1.1(mix2s哪个版本不断流)
AOP implementation enterprise API access interface monitoring (via Google Guava cache data)
从一道面试题说起:GET 请求能传图片吗?
【微服务】(十六)—— 分布式事务Seata
【ArcGIS微课1000例】0030:ArcGIS利用MXD doctor工具分析并修复mxd地图文档
【LeetCode】1. 两数之和
Violence recursion to dynamic programming 02 (very clever game of CARDS)
论人生自动化
第4章_2——视图的使用
Guangzhou fire: high temperature weather frequent fire fire safety should not be ignored
这 6 款在线 PDF 转换工具,得试试
About inner classes
ArcGIS Molder Builder模型构建器基本知识








