Skip to content

Create gcloud-node client that uses metadata service auth #511

Description

@drewbryant

How can I force the gcloud-node client to attempt to use the compute engine environment, which relies upon the "metadata service" for getting auth tokens?

I see this chunk of code in lib/storage/index.js, and I don't see where/how it is checking for the compute engine environment:

function Storage(config) {
  if (!(this instanceof Storage)) {
    return new Storage(config);
  }

  this.makeAuthorizedRequest_ = util.makeAuthorizedRequest({
    credentials: config.credentials,
    keyFile: config.keyFilename,
    scopes: SCOPES
  });

  this.projectId = config.projectId;
}

Basically I'm attempting to create my client like this:

var gcloud = require('gcloud');
var storage = gcloud.storage();

And I'm hitting an error because I haven't passed a config object with credentials. The docs here made it seem like this was the expected syntax on compute engine however (i.e., gcloud.storage()).

Is this auth approach supported currently?

Activity

  1. stephenplusplus commented on Apr 27, 2015

    @stephenplusplus
    Contributor

    Can you try with master? We recently went through an overhaul of how we authenticate, but it hasn't had a release yet.

  2. drewbryant commented on Apr 27, 2015

    @drewbryant
    Author

    Thanks Stephen, it looks like the version in master is working on GCE with the metadata auth approach.

    Follow-up question:
    How have you been testing the GCE support locally (i.e., outside of GCE)? Do you simulate the GCE metadata service?

  3. stephenplusplus commented on Apr 27, 2015

    @stephenplusplus
    Contributor

    For my testing, I actually pushed to a GCE endpoint. But fortunately, with our upcoming release, we have removed most of our auth code and instead use the google-auth-library. They have many unit tests that make sure the right requests are made for auth tokens and such.

    I'm glad to hear master solves the problem, and sorry for the confusion with the current release. We should be getting a new release out soon.

  4. added a commit that references this issue on Sep 15, 2022
  5. 33 remaining items

  6. added a commit that references this issue on Feb 26, 2026
  7. added a commit that references this issue on Mar 27, 2026
  8. added a commit that references this issue on May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

coretype: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions