Skip to content

Commit fae24e3

Browse files
jgwesterlundclaude
andauthored
fix(auth): restrict Keep service account to Keep API calls only (#414)
When a Keep-specific service account file (keep-sa-*.json) exists, tokenSourceForServiceAccountScopes falls back to it for all API calls, not just Keep. This causes 401 errors on Calendar, Gmail, Drive, and other services that should use OAuth. Only use keep-sa and legacy Keep SA files when serviceLabel is "keep", allowing other services to fall through to OAuth authentication. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8036c59 commit fae24e3

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

internal/googleapi/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func optionsForAccountScopes(ctx context.Context, serviceLabel string, email str
111111

112112
var ts oauth2.TokenSource
113113

114-
if serviceAccountTS, saPath, ok, err := tokenSourceForServiceAccountScopes(ctx, email, scopes); err != nil {
114+
if serviceAccountTS, saPath, ok, err := tokenSourceForServiceAccountScopes(ctx, serviceLabel, email, scopes); err != nil {
115115
return nil, fmt.Errorf("service account token source: %w", err)
116116
} else if ok {
117117
slog.Debug("using service account credentials", "email", email, "path", saPath)

internal/googleapi/service_account.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var newServiceAccountTokenSource = func(ctx context.Context, keyJSON []byte, sub
2525
return cfg.TokenSource(ctx), nil
2626
}
2727

28-
func tokenSourceForServiceAccountScopes(ctx context.Context, email string, scopes []string) (oauth2.TokenSource, string, bool, error) {
28+
func tokenSourceForServiceAccountScopes(ctx context.Context, serviceLabel string, email string, scopes []string) (oauth2.TokenSource, string, bool, error) {
2929
saPath, err := config.ServiceAccountPath(email)
3030
if err != nil {
3131
return nil, "", false, fmt.Errorf("service account path: %w", err)
@@ -45,6 +45,11 @@ func tokenSourceForServiceAccountScopes(ctx context.Context, email string, scope
4545
return nil, "", false, fmt.Errorf("read service account key: %w", readErr)
4646
}
4747

48+
// Keep-specific service account files should only be used for Keep.
49+
if serviceLabel != "keep" {
50+
return nil, "", false, nil
51+
}
52+
4853
// Backwards compatibility: Keep used a dedicated stored service account file.
4954
keepSAPath, keepErr := config.KeepServiceAccountPath(email)
5055
if keepErr == nil {

0 commit comments

Comments
 (0)