[FEATURE][SECURITY]: Implement IP-based access control (#536)#3226
[FEATURE][SECURITY]: Implement IP-based access control (#536)#3226kcostell06 wants to merge 4 commits intoIBM:mainfrom
Conversation
Add generic IP-based access control system with allowlist/blocklist modes, CIDR matching, path-scoped rules, temporary blocks, and admin API. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Kelly Costello <kellycostello@Kellys-MacBook-Air.local>
Add tests for service CRUD methods, evaluate_ip session management, error/rollback paths, test_ip diagnostics, get_status, cleanup_expired_blocks, router get_db error handling, list_blocks endpoint, and middleware unknown client IP fallback. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Kelly Costello <kellycostello@Kellys-MacBook-Air.local>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Kelly Costello <kellycostello@Kellys-MacBook-Air.local>
|
Thanks for this @kcostell06. This is a comprehensive implementation with solid test coverage and clean separation across middleware/service/router layers. The feature-flag approach (disabled by default) is the right call. A few items: (1) full CI hasn't run yet — only DCO passed so far, please verify the full suite, (2) the migration filename |
Replace manually-created revision z9j0k1l2m3n4 with alembic-generated 1d27bc0a81f5. Verified down_revision points to current head b2d9c6e4f1a7. Also adds nosec B110 to hit count rollback pass. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Kelly Costello <kellycostello@Kellys-MacBook-Air.local>
|
Thanks for the review! All three items have been addressed: 1. Migration revision ID — Replaced the manually-created 2. 3. Full test suite verified locally — 12,145 passed, 254 skipped, 0 failed (excluding the pre-existing New commits:
|
|
The latest push should also trigger the full CI pipeline — previously only the DCO check had run. All changes are now pushed and ready for CI validation. |
Related Issue
Closes #536
Summary
Implements a generic IP-based access control system with:
Files added
mcpgateway/middleware/ip_control.py- Request middleware with IP extraction and enforcementmcpgateway/services/ip_control_service.py- Core service with evaluation, caching, and CRUDmcpgateway/routers/ip_control_router.py- Admin API endpoints (rules, blocks, test, status, cache)mcpgateway/alembic/versions/z9j0k1l2m3n4_add_ip_access_control_tables.py- MigrationFiles modified
mcpgateway/config.py- Added 8ip_control_*settingsmcpgateway/db.py- AddedIPRuleandIPBlockORM modelsmcpgateway/schemas.py- Added 9 Pydantic schemasmcpgateway/main.py- Conditional middleware and router registration.env.example- AddedIP_CONTROL_*environment variablesType of Change
Verification
make lintmake testmake coverageChecklist
make black isort pre-commit)