It is not possible to provide they encryption key properties in later stage of application startup (e.g via EnvironmentPostProcessor).
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- java, spring, spring-boot
- 领域
- backend
调研方向
从 spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/TextEncryptorConfigBootstrapper.java 开始,尤其关注第 67-85 行,并使用 spring-cloud-config-server 和一个 EnvironmentPostProcessor 重现该示例。跟踪在 bootstrap 属性不存在时,KeyProperties、RsaProperties 和 TextEncryptor 是如何被提升的。当后续提供的属性能够生成可用的 encryptor,而不是 FailsafeTextEncryptor,且不需要 legacy bootstrap 时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
Describe the bug
TextEncryptorConfigBootstrapper.java#L67-L85 promotes KeyProperties, RsaProperties and TextEncryptor beans to ApplicationContext. When key properties are not available during bootstrap, default instances of KeyProperties, RsaProperties, and TextEncryptor (FailsafeTextEncryptor) are promoted.
In later stage of startup, if key properties are supplied (in my case via EnvironmentPostProcessor), they will be ignored by AutoConfiguration classes, because the relevant bean (TextEncryptor) is present in the ApplicationContext.
Sample
A simple spring-boot app like the following, with org.springframework.cloud:spring-cloud-config-server as dependency, shows the issue:
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
class Processor implements EnvironmentPostProcessor {
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
final MutablePropertySources propertySources = environment.getPropertySources();
propertySources.addFirst(new MapPropertySource("test", Map.of("encrypt.key", "my-secret-key")));
}
}
@Component
class Test {
@Autowired
private TextEncryptor encryptor;
@PostConstruct
void test() {
System.out.println("### Encryptor:: " + encryptor.getClass().getSimpleName());
}
}
sample output:
### Encryptor:: FailsafeTextEncryptor
The output shows that FailsafeTextEncryptor is registered which cannot encrypt/decrypt any secret.
Workaround
Currently I workaround the issue by enabling the legacy bootstrap (e.g adding org.springframework.cloud:spring-cloud-starter-bootstrap as dependency). See the if condition in TextEncryptorConfigBootstrapper.java#L69-L71 which cancels the promotion, in case legacy bootstrap is enabled.
- 主要语言
- Java
- 星标
- 751
- 派生
- 771
- 平均合并
- 3 天 15 小时
- 30 天内合并 PR
- 19
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
spring-cloud/spring-cloud-commons 的其他 Issue
-
waiting-for-triage
难度 2/5 1-3 小时 新手友好度 68/100
spring-cloud/spring-cloud-commons#1813 ·
维护者通常 1 天内回复
-
enhancement for team discussion
难度 5/5 一周以上 新手友好度 42/100
spring-cloud/spring-cloud-commons#1676 ·
维护者通常 1 天内回复
-
waiting-for-triage
难度 5/5 一周以上 新手友好度 38/100
spring-cloud/spring-cloud-commons#1675 · 1 条评论 ·
维护者通常 1 天内回复
-
waiting-for-triage
难度 4/5 3-5 天 新手友好度 42/100
spring-cloud/spring-cloud-commons#1640 · 1 条评论 ·
维护者通常 1 天内回复
-
waiting-for-triage
难度 4/5 3-5 天 新手友好度 35/100
spring-cloud/spring-cloud-commons#1629 · 2 条评论 ·
维护者通常 1 天内回复
查看 spring-cloud/spring-cloud-commons 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
enhancement good first issue
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 80/100
java-native-access/jna#1757 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
eclipse-ee4j/eclipselink#3105 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 65/100
humblemuzzu/dumbtv#250 ·
维护者通常 3 天内回复