-
Notifications
You must be signed in to change notification settings - Fork 111
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
Support fetching tokens from compute instance metadata #85
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
|
||
def start(_type, _args) do | ||
children = [ | ||
{Goth, name: MyApp.Goth, url: "http://metadata.google.internal", credentials: {:instance, "default"}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
double-checking "http://metadata.google.internal"
or "https://..."
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can confirm it's HTTP -- probably because it's internal
Here's a reference in the docs: https://cloud.google.com/appengine/docs/standard/java/accessing-instance-metadata#identifying_which_metadata_endpoint_to_use
To query the metadata server for an access token, you must configure | ||
the following: | ||
|
||
* `url` must be set to the base url for the metadata server. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder: if {:instance, account}
is given, should we automatically default the url or that'd be trying to be too clever?
The advantage is there's less copy-pasting for the users as they'd most likely always use the same exact metadata url (I never used it so I wouldn't know, though.) We could do the same thing for the lower level Goth.Token.fetch/1
, then it's really super simple to use:
iex> Goth.Token.fetch(credentials: {:instance, "default"})
(This reminds me that currently that function needs to explicitly be passed the url & scope, but I think it's fine to use the same defaults as in Goth.start_link
, I'll make this change later.)
(Edit: done: #86)
Here's how we could document this then, I think it doesn't sound too bad:
## Google Compute Metadata
Every compute instance stores its metadata on a metadata server.
Goth can query this metadata server to fetch authentication credentials
for a service account within the instance.
To query the metadata server for an access token, you must set `:credentials`
to tuple `{:instance, account}`. If such credentials are set, the `:url`
will automatically default to `https://metadata.google.internal`.
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I did not add the "magic" because I was not sure we wanted it and also I was not sure how we would want to test it. So I am open to suggestions there :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, testing it would be a little bit tricky, we'd still assert on the /computeMetadata...
bit but we wouldn't test the the hostname was set to metadata.google.internal
because then we couldn't use Bypass which then I guess we could introduce a mock but I'd rather avoid that. I wouldn't be super concerned if we didn't test that particular bit, that we use the correct hostname, though.
Coming back to wether we want to introduce this magic in the first place, it's your call :D If not today, we'd always be able to add it later if someone wanted it because it would be backwards compatible, if someone explicitly sets the :url
we would never touch it.
I've added the http client contract on master which caused conflicts, please rebase and sorry about that! |
Co-authored-by: Wojtek Mach <wojtekmach@users.noreply.github.com>
c15bb49
to
59ca258
Compare
Thank you! |
Hi @peburrows and @wojtekmach - I'm loving the redesign for v1.3!
This PR attempts to get the ball rolling for instance metadata support. WDYT?
Ref: #82