fix: derive git identity from GitHub/GitLab credentials at runtime#617
Conversation
Previously, git commits in sessions were attributed to "Ambient Code Bot" because git user.name and user.email were not configured from the user's GitHub/GitLab credentials. This fix: - Enhances GitHub/GitLab credential endpoints to fetch user identity from their respective APIs and return userName, email, and provider fields - Updates the runner to configure git identity (both git config and environment variables) when populating runtime credentials - GitHub identity takes precedence over GitLab when both are configured - Falls back to bot identity when no credentials have user info Fixes: GitHub credentials aren't mounted to session Also: Adds provider field to distinguish GitHub vs GitLab credentials Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This comment has been minimized.
This comment has been minimized.
- Redact email from logs to avoid PII exposure (use hasEmail boolean) - Add structured logging context with session/project info - Improve Python exception handling with specific exception types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The runtime_credentials_test.go file had its own RunSpecs entry point, which conflicted with the main suite in backend_unit_test.go. Ginkgo does not support calling RunSpecs more than once per package. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Claude Code ReviewSummaryThis PR enhances GitHub and GitLab credential endpoints to fetch user identity (name, email) from provider APIs and configures git identity dynamically in the runner. This ensures commits are properly attributed to users rather than the default bot identity. The implementation follows established patterns with strong test coverage. Issues by Severity🚫 Blocker IssuesNone identified - code is ready to merge. 🔴 Critical IssuesNone identified. 🟡 Major Issues1. GitHub API Token Header Uses Deprecated Format ( Current: req.Header.Set("Authorization", "token "+token)Recommended: req.Header.Set("Authorization", "Bearer "+token)2. Error Response Bodies Not Read ( Suggested improvement: if resp.StatusCode != http.StatusOK {
body, _ := io.ReadAll(resp.Body)
if resp.StatusCode == http.StatusForbidden {
log.Printf("GitHub API /user returned 403 (token may lack 'read:user' scope). Response: %s", string(body))
} else {
log.Printf("GitHub API /user returned status %d: %s", resp.StatusCode, string(body))
}
return "", ""
}3. HTTP Client Timeout Consistency const apiCallTimeout = 10 * time.Second🔵 Minor Issues1. Test Coverage Gap - Integration Tests ( Recommendation: Consider adding integration tests that use mock K8s clients (similar to existing backend integration tests). 2. Missing Context Cancellation Check ( if ctx.Err() != nil {
log.Printf("Context cancelled before fetching user identity")
return "", ""
}3. Potential Data Race in Environment Variables ( 4. Magic String "user@example.com" ( EXAMPLE_EMAIL_SENTINEL = "user@example.com"
if user_email and user_email != EXAMPLE_EMAIL_SENTINEL:Positive Highlights✅ Excellent Security Practices
✅ Comprehensive Test Coverage
✅ Follows Established Patterns
✅ Provider Distinction
✅ User Experience Improvement
RecommendationsPriority 1 (Address Before Merge)
Priority 2 (Follow-up PRs)
Priority 3 (Nice-to-Have)
Architecture Alignment✅ CLAUDE.md Compliance:
✅ ADR Compliance:
ConclusionThis is a well-designed and thoroughly tested enhancement that solves a real UX problem (proper commit attribution). The code follows project standards and includes comprehensive test coverage. The identified issues are minor and most can be addressed in follow-up PRs. Recommendation: Approve with Priority 1 fix applied (GitHub token header format). 🔍 View AI decision process (logs available for 90 days) 📋 View memory system files loaded (click to expand)What Amber Loaded for Code ReviewAmber automatically loaded these repository standards from the memory system:
Impact: This review used your repository's specific code quality standards, security patterns, and best practices from the memory system (PRs #359, #360) - not just generic code review guidelines. |
Extract HTTP timeout constant, use Bearer token format for GitHub API, read error response bodies for debugging, add context cancellation checks, and extract placeholder email constant in runner. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Claude Code ReviewSummaryThis PR successfully addresses the git identity attribution issue by fetching user identity from GitHub/GitLab APIs at runtime and configuring git credentials in the runner. The implementation follows established patterns with comprehensive test coverage and good error handling. Issues by Severity🚫 Blocker IssuesNone - PR is ready to merge after addressing critical issues below. 🔴 Critical Issues1. Potential Token Leakage in Logs (backend) - runtime_credentials.go:465, 532
2. Missing io.ReadAll Response Size Limits - runtime_credentials.go:442, 509
🟡 Major Issues3. Race Condition in Git Config - auth.py:360-369
4. Context Cancellation Not Propagated to HTTP Client - runtime_credentials.go:414, 486
🔵 Minor Issues5. Test Coverage Gap - runtime_credentials_test.go
6. Python Import Inside Function - auth.py:348
7. Inconsistent Error Logging - auth.py:371-374
Positive Highlights✅ Excellent Test Coverage: 403 lines of comprehensive Python tests covering all edge cases ✅ Security Conscious: Token validation, RBAC checks, context cancellation handling ✅ Graceful Degradation: Falls back to Ambient Code Bot identity when credentials unavailable ✅ Clear Precedence Logic: GitHub takes precedence over GitLab, well-documented ✅ Type-Safe Backend Code: Proper use of unstructured.NestedString ✅ Follows Error Handling Patterns: Logs errors with context, returns empty strings on failure ✅ No Token Leakage: Tokens are never logged, only metadata like hasEmail ✅ Proper Context Usage: http.NewRequestWithContext used throughout RecommendationsPriority 1 (Before Merge):
Priority 2 (Follow-up PR):
Priority 3 (Nice to Have):
Architectural Review✅ Separation of Concerns: Backend fetches identity, runner configures git ✅ Backward Compatible: Falls back to bot identity when no credentials available ✅ Multi-Provider Support: Provider field distinguishes GitHub from GitLab ✅ Stateless Design: Identity fetched at runtime, not stored in session CR Compliance Checklist
Summary VerdictAPPROVE with minor fixes recommended before merge This is a well-implemented fix that follows the platforms security and error handling patterns. The critical issues should be addressed before merge to prevent potential DoS and ensure consistent git configuration state. The code is production-ready after these fixes. Great work on comprehensive test coverage and graceful degradation! Review by Claude Code with loaded context from CLAUDE.md, backend-development.md, security-standards.md, k8s-client-usage.md, and error-handling.md 🔍 View AI decision process (logs available for 90 days) 📋 View memory system files loaded (click to expand)What Amber Loaded for Code ReviewAmber automatically loaded these repository standards from the memory system:
Impact: This review used your repository's specific code quality standards, security patterns, and best practices from the memory system (PRs #359, #360) - not just generic code review guidelines. |
Previously, git commits in sessions were attributed to "Ambient Code Bot" because git user.name and user.email were not configured from the user's GitHub/GitLab credentials.
This fix:
Fixes: GitHub credentials aren't mounted to session
Also: Adds provider field to distinguish GitHub vs GitLab credentials