Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] KeyVaultClient.getAccessToken() may generate NullPointerException #44508

Open
3 tasks done
ecnabogs opened this issue Mar 5, 2025 · 1 comment
Open
3 tasks done
Assignees
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. customer-reported Issues that are reported by GitHub users external to the Azure organization. KeyVault needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team

Comments

@ecnabogs
Copy link

ecnabogs commented Mar 5, 2025

Describe the bug
The private getAccessToken() method of the KeyVaultClient class generates a NullPointerException if it cannot get an access token. There is no protection against the use case where the HTTP request fails to fetch an access token, the code considers to get such an object whatever the HTTP response, as illustrated below:

    private String getAccessToken() {

        ... 

        accessToken = getAccessTokenByHttpRequest();

        return accessToken.getAccessToken();
    }

Exception or Stack Trace

Caused by: java.lang.NullPointerException: Cannot invoke "com.azure.security.keyvault.jca.implementation.model.AccessToken.getAccessToken()" because "this.accessToken" is null
        at com.azure.security.keyvault.jca.implementation.KeyVaultClient.getAccessToken(KeyVaultClient.java:178) ~[azure-security-keyvault-jca-2.10.0.jar:2.10.0]
        at com.azure.security.keyvault.jca.implementation.KeyVaultClient.getAliases(KeyVaultClient.java:226) ~[azure-security-keyvault-jca-2.10.0.jar:2.10.0]
        at com.azure.security.keyvault.jca.implementation.certificates.KeyVaultCertificates.refreshCertificates(KeyVaultCertificates.java:157) ~[azure-security-keyvault-jca-2.10.0.jar:2.10.0]
        at com.azure.security.keyvault.jca.implementation.certificates.KeyVaultCertificates.refreshCertificatesIfNeeded(KeyVaultCertificates.java:146) ~[azure-security-keyvault-jca-2.10.0.jar:2.10.0]
        at com.azure.security.keyvault.jca.implementation.certificates.KeyVaultCertificates.getAliases(KeyVaultCertificates.java:105) ~[azure-security-keyvault-jca-2.10.0.jar:2.10.0]
        at com.azure.security.keyvault.jca.KeyVaultKeyStore.<init>(KeyVaultKeyStore.java:151) ~[azure-security-keyvault-jca-2.10.0.jar:2.10.0]
        at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(Unknown Source) ~[na:na]
        at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Unknown Source) ~[na:na]
        at java.base/java.lang.reflect.Constructor.newInstance(Unknown Source) ~[na:na]
        at java.base/java.security.Provider$Service.newInstanceOf(Unknown Source) ~[na:na]
        at java.base/java.security.Provider$Service.newInstanceUtil(Unknown Source) ~[na:na]
        ... 65 common frames omitted

To Reproduce
Any failure to contact the token endpoint or to get an access token due to insufficient rights leads to that unexpected and unintelligible error.

Code Snippet

            KeyVaultJcaProvider provider = new KeyVaultJcaProvider();
            Security.addProvider(provider);
            System.setProperty("azure.keyvault.uri", "...");
            System.setProperty("azure.keyvault.managed-identity", "my_managed_identity_with_insufficient_rights");
            KeyStore keyStore = KeyVaultKeyStore.getKeyVaultKeyStoreBySystemProperty();

Expected behavior
I would expect to get a specialized type of exception, giving the reason of the failure, rather than a very obscur NullPointerException from which we cannot recover.

Screenshots
N/A

Setup (please complete the following information):

  • OS: Linux / MacOS
  • IDE: IntelliJ
  • Library/Libraries: com.azure:azure-security-keyvault-jca:2.10.0
  • Java version: 21
  • App Server/Environment: Embedded Tomcat
  • Frameworks: Spring Boo 3.4.3

Additional context
N/A

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

  • Bug Description Added
  • Repro Steps Added
  • Setup information Added
@github-actions github-actions bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Mar 5, 2025
@joshfree
Copy link
Member

joshfree commented Mar 5, 2025

@vcolin7 can you please follow up on this with @ecnabogs

@github-actions github-actions bot removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Mar 5, 2025
@joshfree joshfree added bug This issue requires a change to an existing behavior in the product in order to be resolved. and removed question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Mar 5, 2025
@github-actions github-actions bot added the needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team label Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. customer-reported Issues that are reported by GitHub users external to the Azure organization. KeyVault needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team
Projects
Status: Untriaged
Development

No branches or pull requests

3 participants