azure-sdk-for-java icon indicating copy to clipboard operation
azure-sdk-for-java copied to clipboard

Date parsing issue in MSIToken [BUG]

Open ghost opened this issue 6 years ago • 12 comments

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>
    

ghost avatar Dec 18 '19 21:12 ghost

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

Luyunmt avatar Dec 26 '19 02:12 Luyunmt

@jongio

Luyunmt avatar Dec 26 '19 02:12 Luyunmt

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.

ghost avatar Jan 12 '20 18:01 ghost

@lpghartz The package azureidentitiy1.0.3 fix the issue

Luyunmt avatar Feb 12 '20 05:02 Luyunmt

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

Luyunmt avatar Feb 18 '20 01:02 Luyunmt

The update fixed the problem. Thanks!

ghost avatar Feb 18 '20 12:02 ghost

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

mletynski avatar May 04 '20 11:05 mletynski

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

jelmew avatar May 06 '20 12:05 jelmew

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).

ghost avatar May 06 '20 13:05 ghost

It works with 1.1.0-beta.3

mletynski avatar May 06 '20 13:05 mletynski

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

athempel avatar Jun 29 '20 13:06 athempel

@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

jonno85 avatar Jul 21 '20 14:07 jonno85