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

fix: do not suppress external project ID determination errors #1153

Merged
merged 2 commits into from
Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/auth/googleauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -671,11 +671,18 @@ export class GoogleAuth {
return null;
}
const creds = await this.getClient();
try {
return await (creds as BaseExternalAccountClient).getProjectId();
} catch (e) {
return null;
}
// Do not suppress the underlying error, as the error could contain helpful
// information for debugging and fixing. This is especially true for
// external account creds as in order to get the project ID, the following
// operations have to succeed:
// 1. Valid credentials file should be supplied.
// 2. Ability to retrieve access tokens from STS token exchange API.
// 3. Ability to exchange for service account impersonated credentials (if
// enabled).
// 4. Ability to get project info using the access token from step 2 or 3.
// Without surfacing the error, it is harder for developers to determine
// which step went wrong.
return await (creds as BaseExternalAccountClient).getProjectId();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions test/test.googleauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1968,7 +1968,7 @@ describe('googleauth', () => {

await assert.rejects(
auth.getProjectId(),
/Unable to detect a Project Id in the current environment/
/The caller does not have permission/
);
scopes.forEach(s => s.done());
});
Expand All @@ -1980,7 +1980,7 @@ describe('googleauth', () => {

await assert.rejects(
auth.getProjectId(),
/Unable to detect a Project Id in the current environment/
/The file at invalid does not exist, or it is not a file/
);
});

Expand Down