Configuration property overrides via environment variables does not work

116 views
Skip to first unread message

Paul Roemer

unread,
Jun 25, 2020, 11:04:50 AM6/25/20
to CAS Community
Hey guys,

today we noticed that we are not able to override properties set in some application properties file by environment variables.
For example, we have some property 'secrect' that we configure with value 'unknown' in application-production.properties. Now, for the deployment we want to override the property by setting the env variable SECRET=dontaskme. But it fails and it's still 'unknown'. On the other hand after removing the property 'secret' from the application-production.properties, the environment variable is taken into account and the value is 'dontaskme'.

So, does CAS not behave as normal Spring Boot applications when it comes to property overrides?

Cheers,
  Paul

Ray Bon

unread,
Jun 25, 2020, 11:24:09 AM6/25/20
to cas-...@apereo.org
Paul,

Is the value in properties 'secrect' a typo?
What about case, SECRET != secret?

Ray

On Thu, 2020-06-25 at 08:04 -0700, Paul Roemer wrote:
Notice: This message was sent from outside the University of Victoria email system. Please be cautious with links and sensitive information.
-- 
Ray Bon
Programmer Analyst
Development Services, University Systems

I respectfully acknowledge that my place of work is located within the ancestral, traditional and unceded territory of the Songhees, Esquimalt and WSÁNEĆ Nations.

Paul Roemer

unread,
Jun 25, 2020, 12:11:45 PM6/25/20
to CAS Community, rbon
Hey Ray,

this was just an example. We actually used the property to set the JSON registry location for testing:

cas.service-registry.json.location=file:etc/cas/services

Also, Docker is in use and then you end up with something like that

1) docker run --rm -it -v $PWD/etc/cas/config:/etc/cas/config cas:latest

[...]
2020-06-25 12:45:14,401 WARN [org.apereo.cas.web.CasWebApplicationContext] - <Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jsonServiceRegistry' defined in class path resource [org/apereo/cas/config/JsonServiceRegistryConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apereo.cas.services.ServiceRegistry]: Factory method 'jsonServiceRegistry' threw exception; nested exception is java.lang.IllegalArgumentException: /cas-overlay/etc/cas/services does not exist>

Configuration from the application-production.properties is used with value '/cas-overlay/etc/cas/services'

2a) docker run --rm -it -v $PWD/etc/cas/config:/etc/cas/config -e cas.service-registry.json.location=file:/foobar cas:latest
2b) docker run --rm -it -v $PWD/etc/cas/config:/etc/cas/config -e CAS.SERVICE_REGISTRY_JSON_LOCATION=file:/foobar cas:latest

We got the same result as above. The environment variable is not respected.

3) Same commands as above but we commented out 'cas.service-registry.json.location' in the properties file

[...]
2020-06-25 12:47:48,725 WARN [org.apereo.cas.web.CasWebApplicationContext] - <Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jsonServiceRegistry' defined in class path resource [org/apereo/cas/config/JsonServiceRegistryConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apereo.cas.services.ServiceRegistry]: Factory method 'jsonServiceRegistry' threw exception; nested exception is java.lang.IllegalArgumentException: /foobar does not exist>

Only now, the environment variable's value is respected...

Very strange.

Ray Bon

unread,
Jun 25, 2020, 3:10:21 PM6/25/20
to cas-...@apereo.org, pa...@vaadin.com
Paul,


I am not sure how you make comparisons with lower case and upper case for what looks to be the same property.

You might also consider mounting the the test/prod services with docker and leave the default variable value.

Ray

Jérôme Steve

unread,
Jun 25, 2020, 3:43:00 PM6/25/20
to cas-...@apereo.org
Hi Paul,

I had the same probleme. What I notice :

If you coment or you remove property in app.properties, the corresponding env var is used. 

But if you have it in the app.properties, property will not be erasse by env var.

But for me is same as other spring-boot app. Maybe what you are tallking about it's a new feature in a newest version of sprint boot ?!

For your purpose use spring boot profil and multi app.properties.











--
- Website: https://apereo.github.io/cas
- Gitter Chatroom: https://gitter.im/apereo/cas
- List Guidelines: https://goo.gl/1VRrw7
- Contributions: https://goo.gl/mh7qDG
---
You received this message because you are subscribed to the Google Groups "CAS Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cas-user+u...@apereo.org.
To view this discussion on the web visit https://groups.google.com/a/apereo.org/d/msgid/cas-user/0e49b715-d2d6-49f4-b33e-01670375343cn%40apereo.org.

Paul Roemer

unread,
Jun 30, 2020, 1:52:00 PM6/30/20
to CAS Community, ste
Hey guys,

I was out sick for a couple of days so I could not answer.

@Ray, I am using the latest and greatest CAS 6.2 release. And I do not recall in which RC but at some point it was decided to switch from camelCase to kebab-case. That is why it is cas.service-registry.json.location in my case.

@ste, so you are facing the same issue. Are you sure about the Spring Boot behavior? I just tried it (Spring Boot 2.2.8 as CAS 6.2 is using it, too) and it works at least for the server.port property:

java -jar ./build/libs/demo-0.0.1-SNAPSHOT.jar --server.port=8080

I set it to 8081 in the application.properties and override it via command line parameter. And that's also what I understand from the Spring Boot documentation.

Reply all
Reply to author
Forward
0 new messages