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

RefreshableCredentials serializing without timezone info #869

Closed
jordmantheman opened this issue Apr 7, 2016 · 2 comments
Closed

RefreshableCredentials serializing without timezone info #869

jordmantheman opened this issue Apr 7, 2016 · 2 comments
Labels
bug This issue is a confirmed bug.

Comments

@jordmantheman
Copy link

Hey boto folks -

I'm currently implementing my own CredentialsProvider that provides RefreshableCredentials. I'm having issues with code that has been working, but recently broke. I have to wonder if either one of my dependencies got bumped (although I can't prove it) or because we just entered daylight savings.

Basically, I'm always hitting this condition:

Credentials were refreshed, but the refreshed credentials are still expired.

To create my meta-data, I'm using the same(?) code used in botocore:

from datetime import datetime, timedelta
from dateutil.tz import tzlocal
expiration = datetime.now(tzlocal()) + timedelta(minutes=5)
expiration.strftime('%Y-%m-%dT%H:%M:%SZ')

'2016-04-07T10:26:04Z'

This doesn't encode my local time zone information, as %Z is needed.

I can demonstrate this inconsistency using some of the internal boto funcs

from botocore.credentials import _local_now, _serialize_if_needed, _parse_if_needed
now = _local_now()
print now
serialized = _serialize_if_needed(now)
print serialized
deserialized = _parse_if_needed(serialized)
print deserialized
print now - deserialized

2016-04-07 10:24:12.336556-04:00
2016-04-07T10:24:12Z
2016-04-07 10:24:12+00:00
4:00:00.336556

I can fix this issue on my end by encoding the timezone information in my format string '%Y-%m-%dT%H:%M:%S%Z', but I'm convinced botocore should do the same in its default time serialization code

TL;DR
It seems like your time_fetcher is using a timezone aware (tzlocal) datetime, but you're losing the timezone information upon serialization, defaulting to UTC. So in my case, it's comparing EST to UTC when determining expiration time.

@jordmantheman
Copy link
Author

Let me add some versions...
Python 2.7.11
botocore (1.3.29)
python-dateutil (2.4.1)

@JordonPhillips JordonPhillips added the bug This issue is a confirmed bug. label Apr 7, 2016
@JordonPhillips
Copy link
Contributor

Nice catch! Maybe this could also solve aws/aws-cli#1611? I'll get on it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a confirmed bug.
Projects
None yet
Development

No branches or pull requests

2 participants