Overriding configuration in profile specific files does not seem to work
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 30/100
- Issue type
- Bug
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- java, spring, spring-boot
Research direction
Start with the pom.xml and compare application.properties with application-local.properties. Reproduce the packaged launch using mvn clean install and the shown java -jar command, checking how the active profile and Vault configuration are supplied. Done means the local profile's Vault properties are selected during startup without the ${VAULT_ADDR} error.
Written by the indexing model from the issue text.
Description
I'm trying to integrate my Spring Boot app with Vault for loading secrets. The app runs on PCF environment so the main configuration file (application.properties) is configured appropriately. For local development, the vault authentication is done via a regular token. So I have created application-local.properties file with appropriate configuration for local development. Then I set the "Active Profiles" value to "local" under the run/debug configuration.
Problem is that when I try to start the app in IDEA, I get the following error. So it's clear that the vault related properties mentioned in application-local.properties are not being picked up during startup.
23:32:40.289 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
java.lang.IllegalArgumentException: Illegal character in path at index 1: ${VAULT_ADDR}
at java.base/java.net.URI.create(URI.java:906)
at org.springframework.cloud.vault.config.VaultConfiguration.createVaultEndpoint(VaultConfiguration.java:121)
at org.springframework.cloud.vault.config.VaultConfigDataLoader$ImperativeInfrastructure.<init>(VaultConfigDataLoader.java:445)
at org.springframework.cloud.vault.config.VaultConfigDataLoader.registerImperativeInfrastructure(VaultConfigDataLoader.java:177)
Here is the complete pom and main application.properties and application-local.properties files.
I have generated the deployment artifact using command mvn clean install and then tried to run the app using java -jar demo-0.0.0.1-snapshot.jar -Dspring.profiles.active=local.
Since I'm passing the profile, I was expecting that configuration from the application-local.properties file will be picked up but from the stacktrace it seems like the main configuration file is being read.
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.14</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
<spring-cloud.version>2021.0.8</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-vault-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
application-local.properties
spring.application.name=sbvaultapp
spring.main.allow-bean-definition-overriding=true
spring.main.web-application-type= reactive
spring.main.lazy-initialization= false
spring.profiles.group.dev=cloud
spring.profiles.group.qa=cloud
spring.profiles.group.uat=cloud
spring.profiles.group.prod=cloud
spring.config.import=optional:vault://
spring.cloud.vault.enabled=true
spring.cloud.vault.reactive.enabled=true
spring.cloud.vault.authentication= PCF
spring.cloud.vault.uri= ${VAULT_ADDR}
spring.cloud.vault.namespace= ${VAULT_NAMESPACE}
spring.cloud.vault.pcf.role= ${VAULT_CF_ROLE}
spring.cloud.vault.pcf.pcf-path= ${VAULT_CF_PATH}
spring.cloud.vault.kv.enabled= true
spring.cloud.vault.kv.backend= kv
spring.cloud.vault.kv.default-context=${spring.application.name}
application-local.properties
spring.application.name=sbvaultapp
spring.main.allow-bean-definition-overriding=true
spring.main.web-application-type= reactive
spring.main.lazy-initialization= false
spring.profiles.group.dev=cloud
spring.profiles.group.qa=cloud
spring.profiles.group.uat=cloud
spring.profiles.group.prod=cloud
spring.config.import=optional:vault://
spring.cloud.vault.enabled=true
spring.cloud.vault.reactive.enabled=true
spring.cloud.vault.authentication= token
spring.cloud.vault.token='Xxxxxxxxx'
spring.cloud.vault.uri= 'https://vault.myvault.org:8200'
spring.cloud.vault.namespace= 'apps'
spring.cloud.vault.scheme=https
spring.cloud.vault.kv.enabled= true
spring.cloud.vault.kv.backend= kv
spring.cloud.vault.kv.default-context=${spring.application.name}
spring.cloud.vault.kv.profiles=dev
- Dominant language
- Java
- Stars
- 291
- Forks
- 152
- Avg merge
- 11h 24m
- Merged PRs (30d)
- 3
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from spring-cloud/spring-cloud-vault
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
spring-cloud/spring-cloud-vault#958 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
spring-cloud/spring-cloud-vault#940 · 1 reaction ·
All issues in spring-cloud/spring-cloud-vault
Similar issues
-
area-deployment area-integrations triage:bot-seen
Difficulty 2/5 Half a day Newbie friendliness 86/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
apache/flink-agents#1156 ·
-
[source-shopify] FAILED bulk operation without partialDataUrl is silently treated as successful Openarea/connectors autoteam community connectors/source/shopify needs-triage team/use type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100