fix: don't use oauth client project_id as quota project#880
Conversation
🦋 Changeset detectedLatest commit: 7fbd29a The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses an issue where the CLI incorrectly used the OAuth client's project ID as the quota project for API requests. By removing this behavior, the CLI avoids unnecessary 403 errors for users who are not IAM members of the client project, as quota for end-user OAuth credentials is already handled via the OAuth client ID. Explicit overrides via environment variables remain supported. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request stops using the project_id from the OAuth client configuration (client_secret.json) as the quota project, which previously caused 403 errors for users without specific IAM permissions. Instead, quota attribution for end-user OAuth credentials will rely on the OAuth client ID. Feedback on the changes suggests setting GOOGLE_APPLICATION_CREDENTIALS to a non-existent path in tests rather than removing it, preventing flaky test failures on Windows where the host's actual ADC file might otherwise be read.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request removes the use of the OAuth client's project_id as the quota project when making API requests, preventing 403 errors for users who are not IAM members of that project. The get_quota_project function in auth.rs has been updated to bypass the client configuration and prioritize the GOOGLE_WORKSPACE_PROJECT_ID environment variable and Application Default Credentials (ADC) instead. Corresponding unit tests have been updated to reflect this change. There are no review comments, and I have no additional feedback to provide.
Fixes #729.
Problem
get_quota_project()returns theproject_idfromclient_secret.json, which is then sent asx-goog-user-projecton every API request. Google only honors that header if the authenticated end user holdsserviceusage.services.useon that project, so any user who is not an IAM member of the project gets:This affects every command. It is invisible to the project owner (who has the permission implicitly) and breaks every other user, including anyone distributing an OAuth client to end users.
Repro
gws auth setup/gws auth loginwith an OAuth client from project P.gws drive files list --params '{"pageSize":1}'→ 403 as above.Verified against a live account before/after with the same credentials and command — only the binary differs.
Fix
Drop
client_secret.json'sproject_idas a quota-project source. Workspace APIs already attribute quota via the OAuth client ID, so the header is unnecessary for end-user OAuth credentials.Both legitimate sources are kept:
GOOGLE_WORKSPACE_PROJECT_ID— explicit opt-in, any credential typequota_project_id— service accounts / ADC, where the header is genuinely requiredCompatibility
This is a behavior change for anyone whose end users do hold
serviceUsageConsumerand who relies on quota being billed to the client-secret project. They can restore the old behavior by settingGOOGLE_WORKSPACE_PROJECT_ID. I filed it as apatchchangeset as a bug fix, but happy to relabel if you'd preferminor.Tests
test_get_quota_project_priority_config→test_get_quota_project_ignores_client_config, now assertsNonetest_get_quota_project_env_var_overrides_client_configBoth pass. Note:
test_get_quota_project_reads_adcandtest_get_quota_project_priority_adc_fallbackfail on Windows both before and after this change — the tests setHOME, butdirs::home_dir()readsUSERPROFILEon Windows, so the temp ADC file is never found. Unrelated to this patch; happy to open a separate issue.