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

WIP: Added refresh to the metadata credentials. #251

Closed
wants to merge 7 commits into from

Conversation

toastdriven
Copy link
Contributor

This also heavily restructures the module itself, which enables adding/removing credentials without altering module-level scope. The behavior should be backward-compatible, though if anyone was importing the functions (or altering the global list of credentials), that will break.

At this time, there's one failing test & I'm planning on adding tests for the CredentialResolver, but I'd like to get some early-ish feedback on the approach. Feedback is most welcome. I'd like to think this is a good change, but would be happy to fix/change any part of it.

Review please? @jamesls @danielgtaylor @garnaat

This also heavily restructures the module itself, which enables
adding/removing credentials without altering module-level scope.

"""
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commented block will get removed, just was keeping it around for reference that we were processing things in the correct order.

# to calculate this ourselves. This is straight from the
# datetime docs.
day_in_seconds = delta.days * 24 * 3600
micro_in_seconds = delta.microseconds * 10**6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be division?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. Poorly ported from Boto. Will fix & add a test.



class UnknownCredentialError(BotoCoreError):
"""Tried to insert before/after an unregister credential type."""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grammar. Maybe unregistered?

@toastdriven
Copy link
Contributor Author

Post-talking with James, I'm going to further restructure this a bit, making the Credentials object very simple again & changing the Credentials subclasses inheritance/behavior. Expect another commit in a bit.

@garnaat
Copy link
Member

garnaat commented Mar 6, 2014

Is this intended to accommodate other temporary credentials besides IAM Roles deployed to an EC2 instance? What about the ability to use credentials from an AssumeRole call or a GetSessionToken call with an MFA? Or would those be considered extensions that would make use of this?

I am finding the ability to do cross-account roles extremely important for teams with multiple AWS environments (e.g. dev, prod). Being able to create a single account in dev and then assume roles for specific activities in prod is a killer feature.

Should I try to rewrite #226 to use this? Or will this do what #226 was trying to do?

@toastdriven
Copy link
Contributor Author

@garnaat Yes, the intent is to be able to support basically any type of credentials, even ones we haven't thought of yet. Those examples (AssumeRole, MFA, keyring, etc) all seem like ways we could extend this (or allow opt-in) in the future.

As for #226, I'm guilty of not having reviewed it before doing this work. The primary reason was just to get IAM refresh in-place, but it grew beyond those bounds. 😬 There's a lot of overlap between them.

The upshot of the approach here is that we can make the credential changes specific to each Session eventually (put a CredentialResolver on the Session). This would allow plugins or specific code to use a different chain without modifying the global variables everything else is depending on.

IMO, I think the best would be updating #226 to build off of this (should actually just be deleting some of the code & shuffling other parts), because I think the temporary credentials would be useful to have. I would hold off on that until this is finalized though, as I'm rearchitecting bits (which should make the rewrite easier). Sorry for the pain & more than willing to change this further so we're all happy with it.

@garnaat
Copy link
Member

garnaat commented Mar 6, 2014

I'm not particularly concerned with #226. It's kind of kludgy and I wasn't really that happy with it. I am, however, really determined to get the AssumeRole functionality (at least) enabled because I think it is a really important feature. Probably more so for the CLI but we need the the core functionality here.

I will try to rethink #226 in the context of this. Thanks.

@toastdriven
Copy link
Contributor Author

Alright, I pushed an updated version of this. Changes:

  • Credentials becomes a simple object again
  • Added RefreshableCredentials, which has the logic to be able to update a given set of credentials if they expire (the refresh_using kwarg takes a callable)
  • The *Credentials subclasses now have become *Providers, got simpler (just the loading) & just return Credentials/RefreshableCredentials objects
  • Fully passing tests (there was a single unit failure before)

I think this is done (relatively happy with it), but would be happy to incorporate feedback/changes & write docs for it. Review again please? @jamesls @danielgtaylor @garnaat

@danielgtaylor
Copy link
Member

LGTM, but I'd wait and see if others have any feedback.


def __init__(self, access_key=None, secret_key=None, token=None):
def __init__(self, access_key=None, secret_key=None, token=None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there ever a case where we should allow access_key/secret_key to be None? Seems like these should be required params.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, hit "Comment" too soon. I'm open to changing it, I just did that to be consistent.

It's possible you might instantiate temporary credentials on their own, then wait to populate them until they're needed (to lazy-load). That's about the only valid use I can see.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we cover the "anonymous S3 connection" use case from boto in this?

@jamesls
Copy link
Member

jamesls commented Mar 7, 2014

I think this looks good, I've made just a few small suggestions.

@toastdriven
Copy link
Contributor Author

@jamesls Feedback applied. Mind reviewing SHA: 3692880 please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants