azure-sdk-for-java: [BUG] Token Credential to AppConfiguration not working with Spring Boot 3

Describe the bug Upgrading application from Spring Boot 2.7.8 using spring-cloud-azure-dependencies BOM v4.3.0 to Spring Boot 3.0.2 using spring-cloud-azure-dependencies BOM v5.0.0. App Configuration/Key Vault is bootstrapped expecting to authenticate via AzureCliCredential locally using DefaultCredentialBuilder as a Bean but get messages “Azure Identity => Attempted credential AzureCliCredential is unavailable.” for all credential types.

Exception or Stack Trace

2023-03-06T16:41:37.345-05:00  INFO 13752 --- [     parallel-4] c.azure.identity.ChainedTokenCredential  : Azure Identity => Attempted credential EnvironmentCredential is unavailable.
2023-03-06T16:41:37.361-05:00  INFO 13752 --- [onPool-worker-2] c.azure.identity.ChainedTokenCredential  : Azure Identity => Attempted credential ManagedIdentityCredential is unavailable.
2023-03-06T16:41:37.440-05:00  INFO 13752 --- [onPool-worker-2] c.azure.identity.ChainedTokenCredential  : Azure Identity => Attempted credential AzureDeveloperCliCredential is unavailable.
2023-03-06T16:41:37.440-05:00  INFO 13752 --- [onPool-worker-2] c.azure.identity.ChainedTokenCredential  : Azure Identity => Attempted credential SharedTokenCacheCredential is unavailable.
2023-03-06T16:41:37.441-05:00 ERROR 13752 --- [onPool-worker-2] c.a.i.i.WindowsCredentialAccessor        : Element not found.
2023-03-06T16:41:37.442-05:00  INFO 13752 --- [onPool-worker-2] c.azure.identity.ChainedTokenCredential  : Azure Identity => Attempted credential IntelliJCredential is unavailable.
2023-03-06T16:41:39.660-05:00  INFO 13752 --- [onPool-worker-2] c.azure.identity.ChainedTokenCredential  : Azure Identity => Attempted credential AzureCliCredential is unavailable.
2023-03-06T16:41:50.230-05:00 ERROR 13752 --- [onPool-worker-2] c.a.c.implementation.AccessTokenCache    : Failed to acquire a new access token.
2023-03-06T16:41:50.232-05:00 ERROR 13752 --- [onPool-worker-2] com.azure.core.http.policy.RetryPolicy   : {"az.sdk.message":"Retry attempts have been exhausted.","exception":"DefaultAzureCredential authentication failed. ---> AzurePowerShellCredential authentication failed. Error Details: Azure Powershell authentication failed. Error Details: Text '/Date(1678144130000)/' could not be parsed at index 0. To mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azsdk/java/identity/powershellcredential/troubleshoot","tryCount":2}
2023-03-06T16:41:50.233-05:00 ERROR 13752 --- [           main] .i.AppConfigurationPropertySourceLocator : Fail fast is set and there was an error reading configuration from Azure App Configuration store https://[my]appconfig.azconfig.io.
2023-03-06T16:41:50.264-05:00 ERROR 13752 --- [           main] o.s.boot.SpringApplication               : Application run failed

java.lang.RuntimeException: Failed to generate property sources for https://[my]appconfig.azconfig.io
	at com.azure.spring.cloud.config.implementation.AppConfigurationPropertySourceLocator.failedToGeneratePropertySource(AppConfigurationPropertySourceLocator.java:252) ~[azure-spring-cloud-appconfiguration-config-2.11.0.jar:2.11.0]
	at com.azure.spring.cloud.config.implementation.AppConfigurationPropertySourceLocator.locate(AppConfigurationPropertySourceLocator.java:170) ~[azure-spring-cloud-appconfiguration-config-2.11.0.jar:2.11.0]
	at org.springframework.cloud.bootstrap.config.PropertySourceLocator.locateCollection(PropertySourceLocator.java:50) ~[spring-cloud-context-4.0.1.jar:4.0.1]
	at org.springframework.cloud.bootstrap.config.PropertySourceLocator.locateCollection(PropertySourceLocator.java:46) ~[spring-cloud-context-4.0.1.jar:4.0.1]
	at org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration.initialize(PropertySourceBootstrapConfiguration.java:95) ~[spring-cloud-context-4.0.1.jar:4.0.1]
	at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:605) ~[spring-boot-3.0.3.jar:3.0.3]
	at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:385) ~[spring-boot-3.0.3.jar:3.0.3]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:309) ~[spring-boot-3.0.3.jar:3.0.3]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1304) ~[spring-boot-3.0.3.jar:3.0.3]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1293) ~[spring-boot-3.0.3.jar:3.0.3]
	at com._3cloudsolutions.demo.appconfigkeyvault.AppConfigKeyvaultApp.main(AppConfigKeyvaultApp.java:15) ~[classes/:na]
Caused by: java.lang.NullPointerException: Cannot invoke "com.azure.core.http.HttpResponse.getStatusCode()" because the return value of "com.azure.core.exception.HttpResponseException.getResponse()" is null
	at com.azure.spring.cloud.config.implementation.AppConfigurationReplicaClient.listConfigurationSettings(AppConfigurationReplicaClient.java:121) ~[azure-spring-cloud-appconfiguration-config-2.11.0.jar:2.11.0]
	at com.azure.spring.cloud.config.implementation.AppConfigurationPropertySource.initProperties(AppConfigurationPropertySource.java:183) ~[azure-spring-cloud-appconfiguration-config-2.11.0.jar:2.11.0]
	at com.azure.spring.cloud.config.implementation.AppConfigurationPropertySourceLocator.create(AppConfigurationPropertySourceLocator.java:283) ~[azure-spring-cloud-appconfiguration-config-2.11.0.jar:2.11.0]
	at com.azure.spring.cloud.config.implementation.AppConfigurationPropertySourceLocator.locate(AppConfigurationPropertySourceLocator.java:144) ~[azure-spring-cloud-appconfiguration-config-2.11.0.jar:2.11.0]
	... 9 common frames omitted

To Reproduce To troubleshoot, I have created a simple project expecting POJOs to be populated with AppConfiguration values using the following 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>3.0.3</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <groupId>com.my.demos</groupId>
    <artifactId>appconfig-keyvault</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>appconfig-keyvault</name>
    <description>appconfig keyvault demo</description>

    <properties>
        <java.version>17</java.version>
        <spring-cloud-azure.version>5.0.0</spring-cloud-azure.version>
        <spring-cloud.version>2022.0.1</spring-cloud.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>com.azure.spring</groupId>
            <artifactId>spring-cloud-azure-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>com.azure.spring</groupId>
            <artifactId>azure-spring-cloud-starter-appconfiguration-config</artifactId>
            <version>2.11.0</version>
        </dependency>
       <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-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>
            <dependency>
                <groupId>com.azure.spring</groupId>
                <artifactId>spring-cloud-azure-dependencies</artifactId>
                <version>${spring-cloud-azure.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>

Code Snippet bootstrap file:

spring:
  cloud:
    azure:
      appconfiguration:
        enabled: true
        stores:
          -
            endpoint: ${APP_CONFIGURATION_ENDPOINT}
            monitoring:
              enabled: true
              refresh-interval: 20s
              triggers:
                -
                  key: sentinel-keys

Credential builder class:

public class AppCfgCredentials implements AppConfigurationCredentialProvider, KeyVaultCredentialProvider {

    @Override
    public TokenCredential getKeyVaultCredential(String uri) {
			return getCredential();
    }

    @Override
    public TokenCredential getAppConfigCredential(String uri) {
			return getCredential();
    }

    public TokenCredential getCredential()  {
    	return new DefaultAzureCredentialBuilder().build();
    }
}

Config class:

@Configuration
public class AzureBootConfig {

    @Bean
    public AppCfgCredentials  appCfgCredentials() {
        return new AppCfgCredentials();
    }
}

Pojo class to populate with AppCfg values:

@ConfigurationProperties(prefix = "test")
public class ValuesConfig {
    private String value;
    ...
}

Application class

@SpringBootApplication
@EnableConfigurationProperties({ValuesConfig.class})
public class AppConfigKeyvaultApp {

    public static void main(String[] args) {
        SpringApplication.run(AppConfigKeyvaultApp.class);
    }
}

META-INF/spring-factories:

org.springframework.cloud.bootstrap.BootstrapConfiguration=\
com.my.demo.appconfigkeyvault.config.AzureBootConfig

Create App Cfg values to match POJO members: /application/test.value etc

Expected behavior Upon startup, the app should connect to app config to fetch k/v pairs and populate POJOs annotated with @ConfigurationProperties

Screenshots If applicable, add screenshots to help explain your problem.

Setup (please complete the following information):

  • OS: Windows 11
  • IDE: IntelliJ
  • Library/Libraries: com.azure.spring:spring-cloud-azure-dependencies:5.0.0, com.azure.spring:azure-spring-cloud-starter-appconfiguration-config:2.11.0
  • Java version: 17
  • App Server/Environment: Tomcat
  • Frameworks: Spring Boot

Additional context This is still working in Spring Boot 2.7.8, I tried overriding the version of azure-identity with 1.8.0 with the same results

Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

  • [x ] Bug Description Added
  • [ x] Repro Steps Added
  • [ x] Setup information Added

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 4
  • Comments: 16 (9 by maintainers)

Most upvoted comments

@vaculajm, @FCoder86 5.1.0 has been released. It does have a few breaking changes if you are moving from a 2.x version, not from the 4.x version. If you are updating from 2.x you can reference https://learn.microsoft.com/en-us/azure/azure-app-configuration/howto-convert-to-the-new-spring-boot

@vaculajm I would assume it would be because a version of the App Configuration library hasn’t been released for Spring Boot 3.0 yet. ETA for the release is end of April.

I will look at it a bit and see if there is a workaround.