【发布时间】:2021-06-10 19:20:56
【问题描述】:
我有一个 Spring Boot 应用程序,它的属性文件中有一些加密值
例如spring.security.user.password=ENC(ZUkuSkFAiu/k7v7G1538ouQmuSWeAuOucAVuvxLCDwwJ0mgnIdfl3N/RgiZMGeBm)
我正在使用 jasypt 即时解密这些。这在本地运行良好。
但是,当我在 Cloud Foundry 上部署应用程序时,我的属性文件现在会从 vcap 环境变量中提取值。
例如
spring.security.user.password=${vcap.services.myconfig.credentials.user.password}
在 PCF 中,值被添加为
user.password = ENC(ZUkuSkFAiu/k7v7G1538ouQmuSWeAuOucAVuvxLCDwwJ0mgnIdfl3N/RgiZMGeBm)
但是现在我的应用程序无法启动并且我收到一条错误消息
错误 22 --- [主] o.s.b.web.embedded.tomcat.TomcatStarter:错误 启动 Tomcat 上下文。例外: org.springframework.beans.factory.UnsatisfiedDependencyException。 消息:使用名称创建 bean 时出错 类路径资源中定义的“securityFilterChainRegistration” [org/springframework/boot/autoconfigure/security/servlet/SecurityFilterAutoConfiguration.class]: 通过方法表达的不满足的依赖关系 'securityFilterChainRegistration' 参数 0;嵌套异常是 org.springframework.boot.context.properties.ConfigurationPropertiesBindException: 创建具有名称的 bean 时出错 'spring.security-org.springframework.boot.autoconfigure.security.SecurityProperties': 无法将属性绑定到“SecurityProperties”: 前缀=spring.security,ignoreInvalidFields=false, 忽略未知字段=真;嵌套异常是 org.springframework.boot.context.properties.bind.BindException:失败 将“spring.security.user.password”下的属性绑定到 java.lang.String
我有什么理由错过为什么这在本地有效但在 Cloud Foundry 上无效?
更新
cf env returns ...
System-Provided:
{
"VCAP_SERVICES": {
"user-provided": [
{
"binding_name": null,
"credentials": {
"JAVA_OPTS": "-Dspring.security.user.password=ENC\\\\(ZUkuSkFAiu/k7v7G1538ouQmuSWeAuOucAVuvxLCDwwJ0mgnIdfl3N/RgiZMGeBm\\\\)",
"user.password": "ENC(ZUkuSkFAiu/k7v7G1538ouQmuSWeAuOucAVuvxLCDwwJ0mgnIdfl3N/RgiZMGeBm)"
},
"instance_name": "myconfig",
"label": "user-provided",
"name": "myconfig",
"syslog_drain_url": "",
"tags": [],
"volume_mounts": []
}
]
}
}
这会播种有效的 JAVA_OPTS 版本以及无法解析的 user.password 属性
【问题讨论】:
-
如何将
user.password添加到CF?您是否使用用户提供的服务?如果是这样,您是如何创建它的?您能否为您的应用添加一个经过清理的cf env版本? -
见上面的更新
-
这在 application-pcf.yaml spring.security.user.password=ENC(${vcap.services.myconfig.credentials.user.password}) 中不起作用吗??
-
Tatha,这也解决不了
-
部分我想知道您在键名中的
.是否存在问题以及它是如何变平的。我建议你尝试几件事。 1.) 删除点,所以使用类似userPassword的东西,看看它是否有效,所以${vcap.services.myconfig.credentials.userPassword}并尝试将${vcap.services.myconfig.credentials.userPassword}插入应用程序中的某个东西,它只会记录它收到的值。如果您可以看到该值,则可能会提供一些线索来说明它无法绑定的原因。
标签: spring-boot encryption cloud-foundry jasypt