Requests to Spring Cloud config-server fail with error Invalid profile ' prod': must contain only letters, digits, '-', or '_'
search cancel

Requests to Spring Cloud config-server fail with error Invalid profile ' prod': must contain only letters, digits, '-', or '_'

book

Article ID: 406919

calendar_today

Updated On:

Products

VMware Tanzu Application Service

Issue/Introduction

Spring Cloud Services config-server backing application logs contains error:

[APP/PROC/WEB/0]
OUT Caused by: java.lang.IllegalStateException: Invalid profile ' prod': must contain only letters, digits, '-', or '_'

Application show requests to config-server failing witth 500 error: 

org.springframework.boot.loader.launch.JarLauncher.main(JarLauncher.java:40)\nCaused by: org.springframework.web.client.HttpServerErrorException$InternalServerError: 500 Internal Server Error: \"
{\"timestamp\":1754594093127,\"status\":500,\"error\":\"Internal Server Error\",\"path\":\"/<property>/<profile name with invalid character>/<value>\"}

Spring Cloud Services tile was upgraded recently to v3.3.7 or higher.

Cause

SCS Config-server is dependent on Spring boot which was bumped to version 3.5.0 in SCS v3.3.7. Spring Boot 3.5.0 adds stricter profile validation per this pull request: https://github.com/spring-projects/spring-boot/pull/43176

If applications are configured to use special character (spaces, commas) in SPRING.PROFILES.ACTIVE then requests to config server will fail due to these stricter checks in Spring Boot v.3.5.0.

Resolution

The preferred mitigation to resolve this issue is to ensure profile (SPRING.PROFILES.ACTIVE) configured for application contains only permitted characters. See documentation: https://docs.spring.io/spring-boot/reference/features/profiles.html

By default, profile names in Spring Boot may contain letters, numbers, or permitted characters (-, _, ., +, @). In addition, they can only start and end with a letter or number.

An option to opt out of these checks was added in later Spring boot version - https://github.com/spring-projects/spring-boot/issues/45947. This opt out feature requires SCS v3.3.8 and then setting a variable-group on config-server backing applications such that stricter validation is disabled.

Example:

cf set-running-environment-variable-group '{"SPRING_PROFILES_VALIDATE":"false"}'