Spring Cloud Vault/Zookeeper do not add property sources if context paths are the same
I maintainer di solito rispondono entro 1 giorno
@mp911de ci sta già lavorando.
Dal 8/10/2024.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
Hello,
It seems that there is a bug or limitation in the Spring Boot + Spring Cloud project.
Problem description:
Precondition:
- There is a Zookeeper instance where configuration parameters are stored in the following paths:
- /config/application
- /config/${spring.application.name}
- There is a HashiCorp Vault instance where configuration parameters ("credentials") are stored in the following paths:
- /config/application
- /config/${spring.application.name}
Yes, you noticed correctly — the issue is that Zookeeper and Vault have the same paths.
How to reproduce:
Create a Spring Boot application (in my case, I used Spring Boot 2.7.18, but looking at the source code, the problem will occur in the latest version as well) and connect spring-cloud-starter-vault-config (in my case, version 3.1.4, but the same issue exists in the master branch) and spring-cloud-starter-zookeeper-config (in my case, version 3.1.5, it looks the same issue exists in the master branch).
When the application starts, only one configuration source will work, specifically the one listed first in spring.config.import.
For example, with the following configuration:
spring.config.import:
- "optional:zookeeper:"
- "optional:vault://"
The application will not have a Vault property source with the required paths.
In this case:
spring.config.import:
- "optional:vault://"
- "optional:zookeeper:"
The application will not have a Zookeeper property source with the required paths.
The issue relates to the *ConfigDataLoader classes.
For example, in spring-cloud-vault-config: the VaultConfigDataLoader (see here)
it creates a LeaseAwareVaultPropertySource with name() == path value. A similar approach is used for Zookeeper.
Then, when starting Spring Boot, in the class org.springframework.boot.context.config.ConfigDataEnvironment, all property sources are added to the property sources list, and here we encounter an issue: the method propertySources.addLast(propertySource); is used (see here).
However, the propertySources.addLast method removes the already added property source from the list based on the equals method, and the equals method in PropertySource is primitive and validates only by name.
So, for both the Vault property source and the Zookeeper property source, we end up with the same names, as they are equal to the path. Adding one removes the other.
Here are links to the source code:
https://github.com/spring-projects/spring-boot/blob/v3.3.4/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataEnvironment.java#L357
https://github.com/spring-projects/spring-framework/blob/v6.1.13/spring-core/src/main/java/org/springframework/core/env/MutablePropertySources.java#L116
https://github.com/spring-projects/spring-framework/blob/v6.1.13/spring-core/src/main/java/org/springframework/core/env/PropertySource.java#L143
It seems that the simplest way to fix this would be to add a prefix when creating the Vault/Zookeeper property source so that not only the path is considered, but also some indicator of which configuration source it belongs to.
For example, for Vault, it could look like this:
String propertySourceName = "vault:" + accessor.getName();
LeaseAwareVaultPropertySource propertySource = new LeaseAwareVaultPropertySource(propertySourceName, secretLeaseContainer, secret, accessor.getPropertyTransformer());
Thanks, have a good day!
- Lingua principale
- Java
- Stelle
- 291
- Fork
- 152
- Merge medio
- 6h 47m
- PR unite (30g)
- 25
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Nessun modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di spring-cloud/spring-cloud-vault
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
spring-cloud/spring-cloud-vault#952 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
spring-cloud/spring-cloud-vault#958 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
spring-cloud/spring-cloud-vault#953 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
spring-cloud/spring-cloud-vault#942 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 48/100
spring-cloud/spring-cloud-vault#940 · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di spring-cloud/spring-cloud-vault
Issue simili
-
enhancement Improvement
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
zowe/zowe-client-java-sdk#647 ·
-
NullPointerException when a `DeserializationProblemHandler` returns `null` for `byte[]` (single value unwrapped) and `char[]` elementsForse già presa @Marti2203 l’ha presa oggi. Aperta
Difficoltà 2/5 Mezza giornata Idoneità per principianti 88/100
FasterXML/jackson-databind#6300 ·
I maintainer di solito rispondono entro 1 giorno
-
content good first issue
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 95/100
cpinitiative/usaco-guide#6699 ·
I maintainer di solito rispondono entro 1 giorno
-
BC remittance upload: a claim MSP refused (S03) is saved with a blank status instead of refused (F)Forse già presa Una pull request collegata a questa issue è aperta o già unita. Apertatype: bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
carlos-emr/carlos#4933 ·
I maintainer di solito rispondono entro 1 giorno
-
[studio] Data source connection tests leak loading and results across modal sessionsForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
apache/rocketmq-dashboard#6925 ·
I maintainer di solito rispondono entro 3 giorni