我有一个连接到数据库的 springboot 应用程序,目前数据库密码在应用程序属性中以纯文本形式显示。
在 PROD 环境中安全保护密码的标准是什么?
如果应用程序密码位于作为 JAR 一部分内置的应用程序属性内,尤其是当应用程序处于事件状态时,如何更改数据库密码?
最佳答案
您可以使用jasypt处理加密,然后使用 Jasypt's Spring integration或者这个Jasypt Spring Boot Starter将其连接到 Spring 中。
这将允许您定义加密的数据库密码属性,例如在 application.properties
中
db.password=ENC(.....)
您问题的另一部分是:
How to change the database password if the application password is inside the application properties
您可以通过使用系统属性覆盖属性文件中定义的属性来实现此目的。例如:-Ddb.password='....'
。您还可以定义 JAR 外部的附加属性源,并且可以在运行时进行编辑。例如:
@PropertySources({
@PropertySource(value = "classpath:/**.properties"),
@PropertySource(value = "file:/some/external/directory/override.properties", ignoreResourceNotFound = true)
})
public class Application {
// ...
}
创建文件 /some/external/directory/override.properties
并用 db.password=...
填充它会导致您的应用程序 - 在下次重新启动时 -使用那个属性值。
关于spring-boot - Springboot fat jar应用连接数据库中PROD数据库密码的标准是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46054027/