Skip to content

feat: support GOG_SA_KEY_PATH env var for explicit SA key file path#4

Merged
delight-ai-agent merged 4 commits intomainfrom
feat/sa-key-path-env
Mar 5, 2026
Merged

feat: support GOG_SA_KEY_PATH env var for explicit SA key file path#4
delight-ai-agent merged 4 commits intomainfrom
feat/sa-key-path-env

Conversation

@delight-ai-agent
Copy link
Member

Summary

When using a Service Account with Domain-Wide Delegation (DWD), the account email (used as the impersonation subject) differs from the SA's own identity. Currently, tokenSourceForServiceAccountScopes derives the SA key file path from the account email, so the SA key must be placed at a path matching the impersonated user's email — requiring duplicate copies for each user.

This adds support for a GOG_SA_KEY_PATH environment variable that lets callers specify the SA key file path directly, decoupling the account email from the key file location.

Changes

  • internal/googleapi/service_account.go: Check GOG_SA_KEY_PATH at the top of tokenSourceForServiceAccountScopes; if set, read the key from that path and skip email-based path derivation
  • internal/googleapi/service_account_test.go: Add tests for the new env var (success + file-not-found)

Use case

A proxy wrapper manages SA credentials centrally and passes the target user email as the account. With GOG_SA_KEY_PATH, the proxy can point to a single SA key file while the account email flows through as the DWD subject:

GOG_ACCOUNT=user@example.com  → used as impersonation subject
GOG_SA_KEY_PATH=/etc/sa.json  → SA key file (single copy)

Without this, the proxy would need to place copies of the same SA key at sa-{base64(user1)}.json, sa-{base64(user2)}.json, etc.

✍️ Author: Claude Code with @carrotRakko (AI-written, human-approved)

When GOG_SA_KEY_PATH is set, tokenSourceForServiceAccountScopes reads
the SA key from the specified path instead of deriving it from the
account email. This decouples the account email (used as the DWD
impersonation subject) from the key file location, enabling proxy
wrappers to pass a user email as the account while pointing to a
single SA key file.

✍️ Author: Claude Code with @carrotRakko (AI-written, human-approved)
✍️ Author: Claude Code with @carrotRakko (AI-written, human-approved)
✍️ Author: Claude Code with @carrotRakko (AI-written, human-approved)
✍️ Author: Claude Code with @carrotRakko (AI-written, human-approved)
@delight-ai-agent delight-ai-agent merged commit c220f0b into main Mar 5, 2026
2 of 8 checks passed
@delight-ai-agent delight-ai-agent deleted the feat/sa-key-path-env branch March 5, 2026 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants