Feature request: --subject flag (or env var) for service-account impersonation on user-context APIs (Keep, Admin Directory, etc.)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 52/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- rust
- Domain
- api, authentication, cli
Research direction
No source file or test is named. Start by locating the Rust service-account credential construction and CLI global-argument or environment-variable parsing, then reproduce the Keep notes request with domain-wide delegation. Done means a supported subject setting reaches the credentials and enables the documented user-context API flow without breaking existing service-account authentication.
Written by the indexing model from the issue text.
Description
Problem
Some Google Workspace APIs only work with a service account that impersonates a user via domain-wide delegation. Notable examples:
- Keep API (
keep.googleapis.com) — explicitly states user OAuth is unsupported; only service accounts work, and they need to act on behalf of a real user (since notes belong to users). - Admin Directory write operations on certain entities.
- Cloud Identity device APIs.
gws today supports two auth modes:
- User OAuth via
gws auth login - Service account via
GOOGLE_APPLICATION_CREDENTIALS=/path/to/sa.json
In the SA path, there's no way to set the JWT subject (the user to impersonate). Without it, gws keep notes list returns:
{
"error": {
"code": 403,
"message": "Request had insufficient authentication scopes.",
"reason": "unknown"
}
}
even when the SA has DWD authorized for https://www.googleapis.com/auth/keep on the target domain.
Reproduction
- Create an SA in GCP, enable DWD via Workspace Admin (
admin.google.com → Security → API controls → Domain-wide Delegation) with scopehttps://www.googleapis.com/auth/keep. - Export
GOOGLE_APPLICATION_CREDENTIALS=/path/to/sa.json. - Run
gws keep notes list. - 403 — there is no user context attached to the request.
Proposed solution
Add one of:
- CLI flag
--subject <[email protected]>on commands (or globally ongws auth login). - Env var
GOOGLE_WORKSPACE_CLI_SUBJECTorGOOGLE_WORKSPACE_CLI_IMPERSONATE.
Internally this maps to subject=... when constructing google.oauth2.service_account.Credentials (or the equivalent Go/Rust binding depending on the implementation language).
Workaround used today
Standalone Python script using google-auth directly:
creds = service_account.Credentials.from_service_account_file(
"sa.json",
scopes=["https://www.googleapis.com/auth/keep"],
subject="[email protected]",
)
Works, but means losing all the schema-discovery / formatting / pagination ergonomics that gws ships with.
Why it matters
Without subject impersonation, gws-keep, parts of gws-admin-directory, and other DWD-only flows are effectively dead code in the skill set — the auth path can't be completed.
Happy to PR this if there's interest in the direction.
- Dominant language
- Rust
- Stars
- 32.3k
- Forks
- 2k
- Avg merge
- 16h 3m
- Merged PRs (30d)
- 1
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from googleworkspace/cli
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
googleworkspace/cli#984 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
googleworkspace/cli#983 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 82/100
googleworkspace/cli#958 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
googleworkspace/cli#921 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
googleworkspace/cli#920 ·
Maintainers usually reply within 1 day
All issues in googleworkspace/cli
Similar issues
-
area:cli area:security bug priority:medium
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
status: new topic: ga4gh-sdk type: bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
comp-rbac
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
ClickHouse/ClickHouse#131875 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Maintainers usually reply within 1 day
-
bug(python): read_transaction raises TypeError on a Rewrite with rewritten indicesPossibly taken @Borg93 claimed this today. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
lance-format/lance#11117 ·
Maintainers usually reply within 2 days