question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Managed Identity - DefaultAzureCredential - RestError: [TokenExpired] Error validating token: 'S2S12086'

See original GitHub issue
  • Package Name:
  • @azure/identity
  • Package Version:
  • ^2.0.0
  • Operating system:
  • Linux
  • nodejs
    • version: 16.x
  • browser
    • name/version:
  • typescript
    • version:
  • Is the bug related to documentation in

Describe the bug

Hello

I have a Node.js application running in App Service that needs to fetch secrets from a KeyVault. This App Service has a Managed Identity. Here’s the relevant pseudo code :

const secretClient = new SecretClient(this.keyVaultUrl, new DefaultAzureCredential());
const secret = (await secretClient.getSecret(secretName))?.value;

This has been working great for months, but suddently about 10 days ago, our app wasn’t able to fetch secrets anymore. A first basic look at the logs, showed this error message, coming from the underlying library:

RestError: [TokenExpired] Error validating token: 'S2S12086'

We’re using DefaultAzureCredential, which in our case instantiate a ManagedIdentityCredential in the end. So it looks like that there’s an issue with the token expiration date received by the App Service by the internal Azure issuer.

To better understand what’s happening under the hood, I enabled the maximum verbosity with AZURE_LOG_LEVEL=verbose environment variable.

Then, one particular line looks quite suspicious at the end of the token acquisition dance :

azure:identity:info IdentityClient: [http://172.16.2.7:8081/msi/token?resource=https%3A%2F%2Fvault.azure.net&api-version=2019-08-01] token acquired, expires on NaN

It corresponds to the following line : https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/src/client/identityClient.ts#L140

The NaN at the end of the log line (which is token.accessToken.expiresOnTimestamp) looks quite surprising and I think it may be related to the problem we experiencing.

Do you confirm this intuition? Thanks.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:4
  • Comments:20 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
xirzeccommented, Sep 20, 2022

Hi again patient friends, I would like to update this thread with the news that my fix was released as part of @azure/identity 3.0.0 yesterday. 🎉

I believe this should hopefully resolve the issue, so in my optimism I am going to resolve but please let me know if you are still having issues with token expiration!

1reaction
goenningcommented, Aug 30, 2022

Just lost 2 days troubleshooting this 😔

As reported by multiple people above, on version 2.1.0 sometimes the expiresOnTimestamp is NaN, which caused our internal refresh logic to fail and never refresh it, so after 24h the token became invalid and we were still trying to use it.

For context, we’re using App Service with user-assigned managed identity.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Azure Key Vault REST API Error Codes - Microsoft Learn
No authentication token attached to the request. Here is an example PUT request, setting the value of a secret: Copy.
Read more >
Issues · Azure/azure-sdk-for-js · GitHub
Managed Identity - DefaultAzureCredential - RestError: [TokenExpired] Error validating token: 'S2S12086' Azure.Identity bug This issue requires a change to ...
Read more >
node.js - "refresh token has expired" with VSCode Azure ...
I've signed in with my management account which has admin access to my subscription, but now I'm getting a 403 RestError. Still, progress...
Read more >
azure-sdk-for-python - bytemeta
ClientAuthenticationError with System Assigned Managed identity for Azure ML Studio ... DefaultAzureCredential - RestError: [TokenExpired] Error validating ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found