SpringBoot配置文件安全

10/8/2023 SpringBoot配置安全
(adsbygoogle = window.adsbygoogle || []).push({});

# 前言

# 配置优先级

Default properties (specified by setting SpringApplication.setDefaultProperties).

@PropertySource annotations on your @Configuration classes. Please note that such property sources are not added to the Environment until the application context is being refreshed. This is too late to configure certain properties such as logging.* and spring.main.* which are read before refresh begins.

Config data (such as application.properties files).

A RandomValuePropertySource that has properties only in random.*.

OS environment variables.

Java System properties (System.getProperties()).

JNDI attributes from java:comp/env.

ServletContext init parameters.

ServletConfig init parameters.

Properties from SPRING_APPLICATION_JSON (inline JSON embedded in an environment variable or system property).

Command line arguments.

properties attribute on your tests. Available on @SpringBootTest and the test annotations for testing a particular slice of your application.

@DynamicPropertySource annotations in your tests.

@TestPropertySource annotations on your tests.

Devtools global settings properties in the $HOME/.config/spring-boot directory when devtools is active.

Config data files are considered in the following order:

Application properties packaged inside your jar (application.properties and YAML variants).

Profile-specific application properties packaged inside your jar (application-{profile}.properties and YAML variants).

Application properties outside of your packaged jar (application.properties and YAML variants).

Profile-specific application properties outside of your packaged jar (application-{profile}.properties and YAML variants). https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config

# 多环境配置

# 安全整改方法

项目配置文件容易泄露密码,存在安全风险

# 改到配置中心

看项目使用,可以移动到nacos里面

# 对配置项进行加密

使用 jasypt 对配置项进行加密 https://juejin.cn/post/6850418120726446093

# 修改配置到k8s字典里面

# 改到环境变量里面

这个优先级比较高

# 参考

https://juejin.cn/post/6850418120726446093