debug(api-server): add V(4) logging to pre-auth stream interceptor#1464
debug(api-server): add V(4) logging to pre-auth stream interceptor#1464markturansky wants to merge 1 commit intomainfrom
Conversation
Temporary diagnostic logging to trace why CallerTypeService is not being set despite GRPC_SERVICE_ACCOUNT being configured. Will be removed once the root cause is identified. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
✅ Deploy Preview for cheerful-kitten-f556a0 canceled.
|
📝 WalkthroughWalkthroughThe stream bearer-token interceptor in the gRPC middleware adds verbose diagnostic logging across multiple pre-authentication control-flow paths, including token validation, JWT username extraction, and failure scenarios, while preserving existing authentication behavior. Changes
Important Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional. ❌ Failed checks (1 error, 1 warning)
✅ Passed checks (6 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
✨ Simplify code
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@components/ambient-api-server/pkg/middleware/bearer_token_grpc.go`:
- Around line 62-66: The current pre-auth logs in the bearer_token_grpc path
emit raw identifiers (username and serviceAccountUsername) via glog.V(4).Infof;
replace those prints with non-identifying information only — e.g., log the match
result and method name and/or a redacted/hashed form of the identifier instead
of the plaintext username. Update the two logging sites that reference
info.FullMethod, username, and serviceAccountUsername (the glog.V(4).Infof calls
surrounding the withCallerType(ctx, CallerTypeService) branch) to remove raw
identifiers and emit either username==serviceAccountUsername (boolean) or a
deterministic hash/redaction token while preserving the existing
CallerTypeService behavior. Ensure any redaction/hashing uses a stable,
non-reversible method and does not change the control flow in withCallerType or
the branch that sets CallerTypeService.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 68c42c0b-f955-4588-9514-fe8cece6b071
📒 Files selected for processing (1)
components/ambient-api-server/pkg/middleware/bearer_token_grpc.go
| glog.V(4).Infof("[pre-auth] stream %s: OIDC username %q matches service account, setting CallerTypeService", info.FullMethod, username) | ||
| ctx = withCallerType(ctx, CallerTypeService) | ||
| } else { | ||
| glog.V(4).Infof("[pre-auth] stream %s: OIDC username %q (service account %q, match=%v)", info.FullMethod, username, serviceAccountUsername, username == serviceAccountUsername) | ||
| } |
There was a problem hiding this comment.
Avoid logging raw usernames/service-account identifiers in pre-auth path
These messages log user identifiers directly. Even at V(4), this creates avoidable privacy/compliance risk in retained logs. Keep only match/state booleans (or hash/redact identifiers).
Suggested change
- glog.V(4).Infof("[pre-auth] stream %s: OIDC username %q matches service account, setting CallerTypeService", info.FullMethod, username)
+ glog.V(4).Infof("[pre-auth] stream %s: OIDC username matches configured service account, setting CallerTypeService", info.FullMethod)
ctx = withCallerType(ctx, CallerTypeService)
} else {
- glog.V(4).Infof("[pre-auth] stream %s: OIDC username %q (service account %q, match=%v)", info.FullMethod, username, serviceAccountUsername, username == serviceAccountUsername)
+ glog.V(4).Infof("[pre-auth] stream %s: OIDC username present (service account configured=%t, match=%v)", info.FullMethod, serviceAccountUsername != "", username == serviceAccountUsername)
}As per coding guidelines, **/*: Flag bugs, security vulnerabilities, logic errors, data loss risks, and meaningful refactoring opportunities.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@components/ambient-api-server/pkg/middleware/bearer_token_grpc.go` around
lines 62 - 66, The current pre-auth logs in the bearer_token_grpc path emit raw
identifiers (username and serviceAccountUsername) via glog.V(4).Infof; replace
those prints with non-identifying information only — e.g., log the match result
and method name and/or a redacted/hashed form of the identifier instead of the
plaintext username. Update the two logging sites that reference info.FullMethod,
username, and serviceAccountUsername (the glog.V(4).Infof calls surrounding the
withCallerType(ctx, CallerTypeService) branch) to remove raw identifiers and
emit either username==serviceAccountUsername (boolean) or a deterministic
hash/redaction token while preserving the existing CallerTypeService behavior.
Ensure any redaction/hashing uses a stable, non-reversible method and does not
change the control flow in withCallerType or the branch that sets
CallerTypeService.
|
Superseded by #1465 which includes the actual fix. Root cause: Keycloak client credentials tokens prefix |
Summary
CallerTypeServiceis not being setContext
PR #1452 added GRPC_SERVICE_ACCOUNT support and PR #1455 fixed the init guard.
Both are merged and deployed to Stage, but runners still get PERMISSION_DENIED.
The init() registration is confirmed (glog file shows the message), but we need
to see which branch the interceptor takes at runtime.
Test plan
[pre-auth]messages🤖 Generated with Claude Code
Summary by CodeRabbit