Refactor auth dependencies to use graph-scoped user context#47
Conversation
…aph` for improved user context handling - Updated various routers and middleware to replace `get_current_user` with `get_current_user_with_graph`, ensuring consistent user access management across graph-related endpoints. - Enhanced JWT token extraction from request headers in multiple authentication-related functions, improving clarity and maintainability. - Adjusted tests to reflect changes in authentication dependency overrides, ensuring comprehensive coverage for new user context handling.
|
@claude please review this PR |
|
Claude finished @jfrench9's task —— View job PR Review: Authentication RefactoringI've completed a thorough review of this authentication refactoring PR. Overall, this is a well-executed refactoring that improves code maintainability and provides better context handling. However, there are some important considerations and recommendations below. ✅ Strengths1. Improved Code Organization
2. Excellent Test Coverage
3. Security Enhancements
4. Consistent Pattern Application
|
There was a problem hiding this comment.
💡 Codex Review
robosystems/robosystems/middleware/auth/dependencies.py
Lines 323 to 332 in 7ac2453
The new get_current_user_with_graph only verifies graph permissions via UserGraph.user_has_access, which handles per-user graphs but ignores shared repositories (e.g., "sec") that previously relied on UserRepository checks in get_universal_repository_with_auth/get_graph_repository_with_auth. With this change a user who legitimately has shared-repository access and authenticates with a JWT will always receive 403 because no UserRepository lookup occurs; only API-key auth still checks shared repo access. This breaks all JWT-based access to shared graphs. The function needs to branch on graph type (shared vs user graph) and validate accordingly before caching the result.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…ontext and validation - Updated `get_current_user_with_graph` to utilize a new user creation method from cached data, enhancing validation and fallback mechanisms. - Introduced shared repository access validation for improved security in graph access. - Enhanced API documentation for graph-related endpoints, providing clearer descriptions and examples for user roles and graph selection. - Improved response handling in graph access endpoints to ensure accurate user permissions and selection status. - Updated tests to cover new authentication flows and shared repository access scenarios, ensuring comprehensive integration coverage.
|
@claude can you review our recent changes |
|
Claude finished @jfrench9's task —— View job PR Review: Recent ChangesReviewing the recent changes to this authentication refactoring PR following the initial review and subsequent fixes. ✅ Issues ResolvedGreat work addressing the critical issues from the previous review! Here's what was fixed: 1. Security Issue Fixed ✅ (High Priority)Location: The unsafe User object construction has been fixed. The code now uses user = _create_user_from_cache(user_data)
if not user:
# Validation failed - fallback to database query
user = User.get_by_id(user_id, session())This ensures consistent validation across all code paths and prevents cached corruption from propagating. Excellent fix! 2. Shared Repository Access Fixed ✅ (P1 Issue)Location: Both JWT and API key authentication paths now properly handle shared repositories (like "sec"): if MultiTenantUtils.is_shared_repository(graph_id):
# Use generic repository access validation for shared repositories
has_access = MultiTenantUtils.validate_repository_access(
graph_id,
user_id,
"read",
)
else:
# Use UserGraph access validation for personal user graphs
has_access = UserGraph.user_has_access(user_id, graph_id, session())This resolves the critical Codex P1 issue where JWT users couldn't access shared repositories. Well done! 3. Integration Tests Enabled ✅ (Medium Priority)Location: The integration tests are now enabled and comprehensive:
This provides end-to-end validation that the authentication flow works correctly. 4. Enhanced API Documentation ✅Location: API documentation has been significantly improved with:
|
…TableManager - Updated `query_table` method in `GraphClient` to accept optional parameters for safe SQL execution. - Modified `DuckDBTableManager` to utilize query parameters in SQL execution, improving security against injection attacks. - Enhanced API documentation for SQL and Cypher queries to emphasize the use of parameterized queries for safe value substitution. - Updated models to include parameters in request schemas, ensuring consistent handling across the application. - Improved test coverage for query execution with parameterized inputs, ensuring robust validation of new features.
|
@claude can I get a final review? |
|
Claude finished @jfrench9's task —— View job Final PR Review ✅Completed comprehensive final review of the authentication refactoring PR. Tasks:
🎉 Excellent Work!This authentication refactoring PR is ready to merge. All critical and high-priority issues from previous reviews have been successfully addressed, and the latest commits demonstrate strong attention to code quality and maintainability. ✅ Issues Successfully Resolved1. Security Issue: Safe User Object Construction ✅Status: FIXED in commit The unsafe User object construction has been properly addressed: Location: # ✅ Now uses safe helper with validation
user = _create_user_from_cache(user_data)
if not user:
# Validation failed - fallback to database query
user = User.get_by_id(user_id, session())
2. P1 Issue: Shared Repository Access for JWT Users ✅Status: FIXED in commit JWT authentication now properly handles shared repositories: Location: if MultiTenantUtils.is_shared_repository(graph_id):
# Use generic repository access validation for shared repositories
has_access = MultiTenantUtils.validate_repository_access(
graph_id, user_id, "read"
)
else:
# Use UserGraph access validation for personal user graphs
has_access = UserGraph.user_has_access(user_id, graph_id, session())
3. Integration Test Coverage ✅Status: FIXED with comprehensive test suite Integration tests are now enabled and thorough: New Fixtures Added:
Test Coverage:
4. Redundant Authorization Checks ✅Status: FIXED in commit The latest commit removed redundant authorization checks from 8 router files: Files cleaned up:
Total cleanup: 202 lines removed, eliminating duplicate validation logic since 🌟 Code Quality Highlights1. Excellent Security Architecture
2. Clean Refactoring Pattern
3. Comprehensive Test Coverage
4. Improved Documentation
📊 Impact AnalysisChanged Files: 60
Code Metrics:
Performance Considerations:
🎯 Final RecommendationsApproved for Merge ✅All critical issues resolved. The PR is production-ready. Post-Merge Monitoring:
No Blockers Remaining
🚀 SummaryThis is a well-executed refactoring that significantly improves the codebase: Achievements:
Code Quality: ⭐⭐⭐⭐⭐ Verdict: APPROVED - Excellent work addressing all feedback and maintaining high code quality throughout the refactoring process! |
- Updated `SchemaValidationRequest` and `SchemaValidationResponse` models to include more comprehensive examples and improved validation messages. - Introduced `SchemaInfoResponse` for runtime schema introspection, providing detailed insights into the current state of the graph database. - Enhanced `SchemaExportResponse` to support additional export formats and include detailed schema metadata. - Improved API documentation for schema-related endpoints, clarifying usage and expected responses. - Added examples for various schema scenarios, including valid, invalid, and schema with warnings, to aid in user understanding and testing.
- Added a new `demo-sec` command in the `justfile` to facilitate loading SEC data and granting access to users. - Introduced `sec_demo/main.py` for setting up the SEC repository, including user credential management and data loading. - Created `sec_demo/query_examples.py` to provide preset queries and interactive exploration for the SEC shared repository. - Updated `graph_query.py` and `kuzu_query.py` to normalize single quotes in Cypher queries for better usability. - Enhanced query execution methods to support parameterized queries, improving security and flexibility. - Refactored various functions to improve clarity and maintainability in handling user credentials and query execution.
Summary
This PR refactors the authentication system to use
get_current_user_with_graphinstead of separate user and graph dependencies, providing improved user context handling and better integration between authentication and graph-scoped operations.Key Changes
dependencies.pyto provide unified user-graph context handlingKey Accomplishments
Areas Impacted
Breaking Changes
Testing Notes
Infrastructure Considerations
🤖 Generated with Claude Code
Branch Info:
refactor/graph-scoped-authmainCo-Authored-By: Claude noreply@anthropic.com