Azure-sdk-for-java: Date parsing issue in MSIToken [BUG]

Created on 18 Dec 2019  路  12Comments  路  Source: Azure/azure-sdk-for-java

Describe the bug

Azure App Service Environment MSI endpoint is returning a JWT token with an expires_on with "AM" in it. "12/19/2019 5:03:41 AM +00:00"

parseDateToEpochSeconds() in MSIToken is parsing with a fixed pattern of "MM/dd/yyyy HH:mm:ss XXX" which will not parse with the expires_on coming from the MSI endpoint.

Exception or Stack Trace
Suppressed: com.fasterxml.jackson.databind.exc.ValueInstantiationException: Cannot construct instance of com.azure.identity.implementation.MSIToken, problem: Unable to parse date time 12/19/2019 5:03:41 AM +00:00
at [Source: (String)"{"access_token":"..."[truncated 1060 chars]; line: 1, column: 1427]
at com.fasterxml.jackson.databind.exc.ValueInstantiationException.from(ValueInstantiationException.java:47)
at com.fasterxml.jackson.databind.DeserializationContext.instantiationException(DeserializationContext.java:1732)
at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator.wrapAsJsonMappingException(StdValueInstantiator.java:491)
at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator.rewrapCtorProblem(StdValueInstantiator.java:514)
at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator.createFromObjectWith(StdValueInstantiator.java:285)
at com.fasterxml.jackson.databind.deser.ValueInstantiator.createFromObjectWith(ValueInstantiator.java:229)
at com.fasterxml.jackson.databind.deser.impl.PropertyBasedCreator.build(PropertyBasedCreator.java:198)
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeUsingPropertyBased(BeanDeserializer.java:422)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1287)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:326)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:159)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4202)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3205)
at com.azure.core.util.serializer.JacksonAdapter.deserialize(JacksonAdapter.java:174)
at com.azure.identity.implementation.IdentityClient.authenticateToManagedIdentityEndpoint(IdentityClient.java:350)
at com.azure.identity.AppServiceMsiCredential.authenticate(AppServiceMsiCredential.java:53)
at com.azure.identity.ManagedIdentityCredential.getToken(ManagedIdentityCredential.java:57)
at com.azure.identity.ChainedTokenCredential.lambda$getToken$1(ChainedTokenCredential.java:40)
at reactor.core.publisher.FluxFlatMap$FlatMapMain.onNext(FluxFlatMap.java:378)
... 60 common frames omitted
Caused by: java.lang.IllegalArgumentException: Unable to parse date time 12/19/2019 5:03:41 AM +00:00
at com.azure.identity.implementation.MSIToken.parseDateToEpochSeconds(MSIToken.java:83)
at com.azure.identity.implementation.MSIToken.(MSIToken.java:46)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.fasterxml.jackson.databind.introspect.AnnotatedConstructor.call(AnnotatedConstructor.java:124)
at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator.createFromObjectWith(StdValueInstantiator.java:283)
... 74 common frames omitted

To Reproduce
Use DefaultAzureCredentialBuilder to build credentials in an App Service Environment. The impacted one is in US East, so the ASE's locale may have something to do with this issue.

Setup (please complete the following information):

  • Version:
    <dependency> <groupId>com.azure</groupId> <artifactId>azure-identity</artifactId> <version>1.0.1</version> </dependency>
Azure.Identity

Most helpful comment

The problem seems to have started again. Using 1.1.0-beta.3

All 12 comments

This is caused by Specific Date format in App Service, we will fix it.

@jongio

So it looks like this fix missed the January SDK update? Any idea when its going to get in there?

This not working means there's no mechanism to securely use the SDK in Azure hosted apps, still.

@lpghartz The package azureidentitiy1.0.3 fix the issue

Hi @lpghartz,
How is this issue going? Feel free to let us know if further help is needed.

The update fixed the problem. Thanks!

Im getting this error with following versions:
1.0.3, 1.0.4, 1.0.5

Exception: IllegalArgumentException: Unable to parse date time 5/4/2020 12:00:05 PM +00:00

We seem to have the same problem with the latest versions.

3 more Caused by: java.lang.IllegalArgumentException: Unable to parse date time 5/7/2020 12:25:07 PM +00:00 at com.azure.identity.implementation.MSIToken.parseDateToEpochSeconds(MSIToken.java:77) at com.azure.identity.implementation.MSIToken.<init>(MSIToken.java:42) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at com.fasterxml.jackson.databind.introspect.AnnotatedConstructor.call(AnnotatedConstructor.java:124) at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator.createFromObjectWith(StdValueInstantiator.java:283) ... 30 more

I have no idea if this regressed or not, but we're still building on 1.0.3 and the fix is still working for us (as of a clean build of our system on a VSO-hosted build server a couple hour ago).

It works with 1.1.0-beta.3

The problem seems to have started again. Using 1.1.0-beta.3

@Luyunmt

using the version 1.1.0-beta.6, the problem still seems to be there:

Cannot construct instance of com.azure.identity.implementation.MSIToken, problem: Unable to parse date time 7/21/2020 12:54:17 PM +00:00

I am using a Windows AppService

Was this page helpful?
0 / 5 - 0 ratings