Spring Cloud Config Server verifies that any property sources it loads are from configured locations for security. To do that has used the property source name to get this information.
In boot 2.3.x we got classpath:/configs/application.yaml from applicationConfig: [classpath:/configs/application.yaml]
.
In boot 2.4.0 we updated the parsing logic in https://github.com/spring-cloud/spring-cloud-config/commit/854060b019f6c3821fbaf0094f8c904c2b990778
https://github.com/spring-projects/spring-boot/issues/24428 changed the property source names and hence broke config server. It has been updated again as seen in the issue below, but this is a brittle approach. We likely didn't say anything in the 2.3.x or prior timeline because it didn't change.
I've added support for checking the location by parsing classpath:/configs/
from Config resource 'class path resource [configs/application.yml]' via location 'classpath:/configs/' (document #0)
which works for both 2.4.0 and 2.4.1.
https://github.com/spring-cloud/spring-cloud-config/issues/1771
/cc @philwebb
Comment From: philwebb
This one is a bit tricky. If I've read the code correctly, you ideally want a way to get the ConfigDataLocation
from a PropertySource
? We unfortunately have an additional PropertySourceLoader
abstraction to deal with.
The only ideas I've had so far are to either try to create some kind of registry that links a PropertySource
to the ConfigDataLocation
that created it, or, to somehow use OrginLookup
. Another idea is to perhaps change ConfigDataEnvironmentPostProcessor.applyTo
so that it accepts some kind of callback that could be used to track things on your side.
I definitely needs more thought.
Comment From: philwebb
@spencergibb I've pushed something to 2.4.x, can you take a look and see if you think it will work.
I hope you can update NativeEnvironmentRepository.findOne
to setup tracking. Something like:
TrackingConfigDataEnvironmentUpdateListener listener = new TrackingConfigDataEnvironmentUpdateListener()
ConfigurableEnvironment environment = getEnvironment(config, profile, label, listener);
...
ConfigDataEnvironmentPostProcessor.applyTo(environment, resourceLoader, null,
StringUtils.commaDelimitedListToStringArray(profile), listener);
The TrackingConfigDataEnvironmentUpdateListener
can implement onPropertySourceAdded
a stash the propertySource
and location
in a Map
.
You can then hopefully update the clean(...)
method to use that Map
to get back the location for any given propertySource
.
Let me know if that doesn't work and we can have another go.
Comment From: spencergibb
I'll take a look in an hour or so.
Comment From: philwebb
Reopening to make StandardConfigDataResource.getResource()
public