[FEATURE][AUTH]: Just-in-Time (JIT) access and temporary privilege elevation#3292
[FEATURE][AUTH]: Just-in-Time (JIT) access and temporary privilege elevation#3292yiannis2804 wants to merge 6 commits intoIBM:mainfrom
Conversation
|
Thanks @yiannis2804. Comprehensive implementation of JIT access for #2227 — good that it includes the full lifecycle (request, approve, reject, revoke, auto-expire). A few things to check:
|
…vation (IBM#2227) - Add JITGrant SQLAlchemy model to db.py with full lifecycle tracking - Add JIT schemas (request, approve, reject, revoke, response) to schemas.py - Add JITService with create, approve, reject, revoke, expire_grants methods - Add JIT REST API router with endpoints: POST /jit, GET /jit, GET /jit/mine, GET /jit/{id}, POST /jit/{id}/approve, POST /jit/{id}/reject, POST /jit/{id}/revoke - Register JIT router in main.py alongside RBAC router - Add Alembic migration a1b2c3d4e5f6 for jit_grants table - Add 17 unit tests with 97% coverage Closes IBM#2227 Signed-off-by: yiannis2804 <yiannis2804@gmail.com>
Signed-off-by: yiannis2804 <yiannis2804@gmail.com>
- Add jit_enabled, jit_max_duration_hours, jit_default_duration_hours - Add jit_require_justification, jit_require_approval, jit_approval_timeout_hours Signed-off-by: yiannis2804 <yiannis2804@gmail.com>
Signed-off-by: yiannis2804 <yiannis2804@gmail.com>
- Fix Alembic down_revision to point to latest head (b2d9c6e4f1a7) - Add ORM relationships to JITGrant model for consistency with existing patterns - Add router-level deny-path tests (unauthenticated, 403, 404, invalid status) - Fix token scoping middleware mock in test_main.py to prevent 403 interference - Fix metrics settings conftest to override DB_METRICS_RECORDING_ENABLED=false - Fix test_tool_service_coverage mock fields and plugin_manager for pydantic validation - Rebase onto upstream/main Signed-off-by: yiannis2804 <yiannis2804@gmail.com>
1cfa77b to
cc195e9
Compare
|
Hi @crivetimihai, thanks for the review! I've addressed all three points:
|
…M#2227) - Convert jit_service tests from asyncio.get_event_loop() to pytest.mark.asyncio - Fix log_aggregator tests: set _use_sql_percentiles and enabled directly on instance - Fix metrics_buffer/rollup tests: use usefixtures reset_metrics_settings - Fix dcr_service test: update client_name assertion to MCP Gateway - Fix prompt_service test: patch get_plugin_manager directly to return None - Fix tool_service_coverage test: add missing mock fields and patch _plugin_manager - Update services conftest: add patch_is_postgresql autouse fixture Signed-off-by: yiannis2804 <yiannis2804@gmail.com>
🔗 Related Issue
Closes #2227
Sweng Group 5
📝 Summary
Implements Just-in-Time (JIT) access and temporary privilege elevation to enforce least-privilege principles (FedRAMP AC-6, HIPAA). Instead of granting standing elevated access, users request temporary roles with a justification, an admin approves or rejects the request, and access automatically expires after the specified duration.
New files:
mcpgateway/db.py—JITGrantSQLAlchemy model with full lifecycle trackingmcpgateway/schemas.py— Pydantic schemas for request, approve, reject, revoke, and responsemcpgateway/services/jit_service.py—JITServicewith create, approve, reject, revoke, andexpire_grantsmethodsmcpgateway/routers/jit.py— REST API router with 7 endpointsmcpgateway/alembic/versions/a1b2c3d4e5f6_add_jit_grants_table.py— Alembic migration forjit_grantstabledocs/docs/manage/jit.md— Full feature documentation with API examples, config reference, and compliance tabletests/unit/mcpgateway/services/test_jit_service.py— 17 unit tests at 97% coverageModified files:
mcpgateway/main.py— JIT router registered alongside RBAC routermcpgateway/config.py— 6 new JIT config settings (JIT_ENABLED,JIT_MAX_DURATION_HOURS,JIT_DEFAULT_DURATION_HOURS,JIT_REQUIRE_JUSTIFICATION,JIT_REQUIRE_APPROVAL,JIT_APPROVAL_TIMEOUT_HOURS)API endpoints added:
POST /jit— Request temporary elevated accessGET /jit— List all grants (admin only)GET /jit/mine— List current user's own grantsGET /jit/{id}— Get grant by IDPOST /jit/{id}/approve— Approve a pending grant (admin only)POST /jit/{id}/reject— Reject a pending grant (admin only)POST /jit/{id}/revoke— Revoke an active grant (self or admin)Grant lifecycle:
pending → active → expired(auto) orpending → rejectedoractive → revoked🏷️ Type of Change
🧪 Verification
make lintmake testmake coveragejit_service.pymake verify✅ Checklist
make black isort pre-commit)docs/docs/manage/jit.md)📓 Notes
a1b2c3d4e5f6creates thejit_grantstable with indexes onrequester_email,status,expires_at, andcreated_atexpire_grants()method inJITServiceis designed to be called by a scheduler (e.g. APScheduler) to auto-expire active grants — scheduler integration can be added as a follow-up