Skip to content

akhilkumar-dot/ZeroTrust

Repository files navigation

πŸ” Zero-Trust API Gateway

A production-grade API Gateway built with Spring Boot 3.x that implements Zero-Trust security architecture. Every incoming request is verified at multiple levels before reaching backend services.


πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        INCOMING REQUEST                             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚
                               β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    ZERO-TRUST FILTER CHAIN                           β”‚
β”‚                                                                      β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚ IP Filter│──▢│JWT Auth Filter│──▢│RateLimit Flt.│──▢│Role Auth β”‚ β”‚
β”‚  β”‚ (Order 1)β”‚   β”‚  (Order 2)   β”‚   β”‚  (Order 3)   β”‚   β”‚(Order 4) β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚   Redis:Block    JWT Validate       Redis:Counter     Role Check    β”‚
β”‚   PostgreSQL:    + Blacklist        + INCR/EXPIRE     ADMIN/PRO/    β”‚
β”‚   Whitelist      Check              Per-User          FREE          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚
                               β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                       PROXY / ROUTING LAYER                          β”‚
β”‚                                                                      β”‚
β”‚  /api/users/*    ──▢  User Service    (port 8081)                   β”‚
β”‚  /api/orders/*   ──▢  Order Service   (port 8082)                   β”‚
β”‚  /api/payments/* ──▢  Payment Service (port 8083)                   β”‚
β”‚                                                                      β”‚
β”‚  Headers Added: X-User-ID, X-User-Role, X-Request-ID, X-Forwarded  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ› οΈ Tech Stack

Layer Technology
Backend Spring Boot 3.4, Spring Security, WebFlux
Cache Redis 7 (rate limiting, token blacklist)
Database PostgreSQL 16 (audit logs, IP rules)
Frontend React 18, Tailwind CSS, Recharts
Auth JWT (jjwt) β€” Access 15m + Refresh 7d
DevOps Docker, Docker Compose

πŸ“ Project Structure

zero-trust-gateway/
β”œβ”€β”€ gateway-service/          # Spring Boot API Gateway
β”‚   └── src/main/java/com/gateway/
β”‚       β”œβ”€β”€ config/           # SecurityConfig, RedisConfig, RoutingConfig
β”‚       β”œβ”€β”€ filter/           # IpFilter, JwtAuthFilter, RateLimitFilter, RoleAuthFilter
β”‚       β”œβ”€β”€ service/          # TokenService, RateLimitService, IpService, AuditLogService
β”‚       β”œβ”€β”€ controller/       # AuthController, AdminController, ProxyController
β”‚       β”œβ”€β”€ model/            # User, AuditLog, IpRule
β”‚       └── repository/       # JPA Repositories
β”œβ”€β”€ dummy-backend/            # Simulated microservices
β”œβ”€β”€ admin-dashboard/          # React Admin Dashboard
β”‚   └── src/
β”‚       β”œβ”€β”€ pages/            # Dashboard, IpManager, TokenMonitor, RateLimitConfig
β”‚       └── components/       # Sidebar, RequestChart, LiveRequestFeed
β”œβ”€β”€ docker-compose.yml
└── init-db.sql

πŸš€ Quick Start

Prerequisites

  • Docker & Docker Compose
  • Java 17+ (for local development)
  • Node.js 18+ (for frontend development)

Run with Docker (recommended)

# Clone & start all services
docker-compose up --build

# Services will be available at:
# Gateway:    http://localhost:8080
# Dashboard:  http://localhost:3000
# PostgreSQL: localhost:5432
# Redis:      localhost:6379

Run Locally (development)

# 1. Start Redis & PostgreSQL
docker-compose up redis postgres -d

# 2. Start the dummy backend
cd dummy-backend
./mvnw spring-boot:run

# 3. Start the gateway
cd gateway-service
./mvnw spring-boot:run

# 4. Start the React dashboard
cd admin-dashboard
npm install && npm run dev

πŸ”‘ Authentication

Default Credentials

Username Password Role
Akhil Akhil9664 ADMIN
testuser user12345 FREE

Login

curl -X POST http://localhost:8080/auth/login \
  -H "Content-Type: application/json" \
  -d '{"username":"Akhil","password":"Akhil9664"}'

Token Refresh

curl -X POST http://localhost:8080/auth/refresh \
  -H "Content-Type: application/json" \
  -d '{"refreshToken":"<your-refresh-token>"}'

Logout

curl -X POST http://localhost:8080/auth/logout \
  -H "Authorization: Bearer <your-access-token>"

πŸ“‘ API Endpoints

Auth (Public)

Method Endpoint Description
POST /auth/register Register new user
POST /auth/login Login β†’ tokens
POST /auth/refresh Rotate tokens
POST /auth/logout Blacklist current token

Admin (ADMIN role only)

Method Endpoint Description
GET /admin/stats Dashboard metrics
GET /admin/live-feed Last 50 requests
GET /admin/logs Paginated audit logs
GET /admin/ip-rules List IP rules
POST /admin/ip-rules/block Block an IP
POST /admin/ip-rules/unblock Unblock an IP
POST /admin/ip-rules/whitelist Whitelist an IP
POST /admin/tokens/revoke Revoke a token
GET /admin/rate-limits View rate limits
PUT /admin/rate-limits Update rate limits

Proxy (Authenticated)

Pattern Target
/api/users/** User Service :8081
/api/orders/** Order Service :8082
/api/payments/** Payment Service :8083

πŸ—„οΈ Redis Key Patterns

Key Pattern Type TTL Purpose
rate_limit:{userId}:{yyyyMMddHHmm} Integer 60s Request counter per minute
blacklist:token:{tokenHash} String Token's remaining TTL Revoked token flag
ip:blocked:{ipAddress} String 60min Blocked IP with reason
ip:failed_attempts:{ipAddress} Integer 60min Failed auth attempt counter
refresh_token:{userId} String 7 days Latest refresh token hash

πŸ›‘οΈ Security Features

  • IP Filtering β€” Redis blocklist + PostgreSQL whitelist, auto-block after 10 failed auth attempts
  • JWT Validation β€” Signature + expiry + blacklist check on every request
  • Rate Limiting β€” Tiered limits (FREE=100, PRO=1000, ADMIN=unlimited), 429 with Retry-After
  • Role Authorization β€” Admin endpoints locked to ADMIN role
  • Token Rotation β€” One-time-use refresh tokens with reuse detection (theft protection)
  • Audit Logging β€” Async logging of every request to PostgreSQL
  • CORS β€” Configured for dashboard origin only

πŸ“Š Admin Dashboard Pages

  1. Live Dashboard β€” Requests/min chart, error rate, top endpoints, active users, live feed
  2. IP Manager β€” Block/unblock/whitelist IPs, auto-blocked IPs section, search
  3. Token Monitor β€” Active sessions, revoke tokens, audit log viewer
  4. Rate Limit Config β€” View and edit tier limits in real-time

πŸ“„ License

This project is for educational and demonstration purposes.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors