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

"Could not load the default credentials" when using custom apiEndpoint with getSignedUrl. #2197

Open
psigen opened this issue May 13, 2023 · 4 comments
Labels
api: storage Issues related to the googleapis/nodejs-storage API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@psigen
Copy link

psigen commented May 13, 2023

Environment details

  • OS: Ubuntu 22.04
  • Node.js version: v18.15.0
  • npm version: 9.5.0
  • @google-cloud/storage version: 6.10.0

Steps to reproduce

Run the following code when using a storage emulator such as fake-gcs-server or firebase storage emulator:

import { Storage } from "@google-cloud/storage";

const storage = new Storage({
  apiEndpoint: 'http://localhost:9199',
  projectId: 'random-fake-proj-id',
  useAuthWithCustomEndpoint: false,
});

const expiration = new Date();
const expirationSecs = 60 * 10; // 10 minutes
expiration.setSeconds(expirationSecs);

const options = {
  version: "v4" as const,
  action: "read" as const,
  expires: expiration,
};

const [url] = await storage.bucket(BUCKET_NAME)
  .file(path)
  .getSignedUrl(options);

This will return the following error about credentials, even though the emulator doesn't use credentials, so they aren't needed to sign the URL:

Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information.
    at GoogleAuth.getApplicationDefaultAsync (/app/api/index.js:65733:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async GoogleAuth.getClient (/app/api/index.js:66050:20)
    at async GoogleAuth.getCredentialsAsync (/app/api/index.js:66009:24)
    at async sign (/app/api/index.js:93784:33)

This was previously mentioned in a comment on this previous ticket: #1373 (comment)

@psigen psigen added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels May 13, 2023
@product-auto-label product-auto-label bot added the api: storage Issues related to the googleapis/nodejs-storage API. label May 13, 2023
@psigen psigen changed the title "Could not load the default credentials" when using custom apiEndpoint with getSignedUrl. "Could not load the default credentials" when using custom apiEndpoint with getSignedUrl. May 13, 2023
@ddelgrosso1
Copy link
Contributor

ddelgrosso1 commented May 18, 2023

@danielbankhead I poked into this a bit and it appears that the problem comes in that there doesn't appear to be a way to tell the auth library to "faux" sign a request. Is there a clean way we can bypass this in storage when the user does not want to use authentication?

@danielbankhead
Copy link
Member

[discussed offline, sharing here] We may need to take a similar approach as googleapis/gcs-resumable-upload#416 for this issue.

@BrennaEpp
Copy link

Hijacking this issue to track the implementation of this feature:

When a custom endpoint is set on the client, Sign URLs and Post Policies should automatically use that domain.

Optional: allow users to set a custom hostname for Sign URL and Post policy methods

See: go/signurl-custom-endpoint-gcs

@danielbankhead danielbankhead added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. and removed type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Nov 14, 2023
@danielbankhead
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the googleapis/nodejs-storage API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

4 participants