Skip to content

haolipeng/ebpf-based-microsegment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

eBPF Microsegmentation

License: MIT Go Version Linux Kernel eBPF

English | δΈ­ζ–‡

A high-performance, kernel-native microsegmentation solution using eBPF for fine-grained network traffic control in cloud-native environments.

Overview

eBPF Microsegmentation provides network isolation and access control at the kernel level, delivering sub-microsecond latency for packet processing. The system consists of:

  • Data Plane: eBPF programs attached to TC (Traffic Control) hooks for line-rate packet filtering
  • Control Plane: Go-based agent and server components for policy management and monitoring
  • Web UI: React-based dashboard for visualization and management

Features

  • High Performance: Hot path latency < 1ΞΌs, cold path < 20ΞΌs
  • Session Tracking: LRU-based connection tracking with 100K concurrent sessions
  • Multi-tier Policy Matching: Exact match + Wildcard (CIDR/port ranges) + Default policy
  • Per-CPU Statistics: Lock-free counters with zero CPU contention
  • Real-time Events: Ring buffer for flow events (new connections, denials)
  • RESTful API: Full CRUD operations for policy management
  • gRPC Communication: Agent-Server communication with Protocol Buffers
  • TCP State Machine: Connection state tracking for stateful filtering

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     User / External Systems                     β”‚
β”‚                  (Web UI / API / Orchestrators)                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚ HTTP/gRPC
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Control Plane (User Space)                   β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚    Server    β”‚  β”‚    Agent     β”‚  β”‚   Policy Manager      β”‚ β”‚
β”‚  β”‚  (gRPC API)  │◄──  (eBPF Mgr)  │───   + DataPlane Mgr     β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚ Cilium eBPF Library
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     Data Plane (Kernel Space)                   β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚  TC eBPF Program                                         β”‚  β”‚
β”‚  β”‚  β€’ Packet parsing (5-tuple)  β€’ Session tracking (LRU)    β”‚  β”‚
β”‚  β”‚  β€’ Policy matching (Hash)    β€’ Statistics (Per-CPU)      β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚  eBPF Maps: session_map | policy_map | stats_map | ...   β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Quick Start

Prerequisites

  • Linux kernel 6.x+ (with eBPF support)
  • Go 1.21+
  • Clang/LLVM (for eBPF compilation)
  • PostgreSQL 14+ (for server)
  • Node.js 18+ (for web UI)

Installation

# Clone the repository
git clone https://github.com/your-org/ebpf-based-microsegment.git
cd ebpf-based-microsegment

# Install dependencies
make deps

# Build all components
make all

# Or build specific components
make agent    # Build agent only
make server   # Build server only

Running

Start the Server:

# Initialize database
./src/server/scripts/migrate.sh

# Start server
./bin/microsegment-server --config config/server.yaml

Start the Agent:

# Requires root privileges for eBPF
sudo ./bin/microsegment-agent --interface eth0 --server localhost:50051

Start Web UI:

cd web
npm install
npm run dev

Quick Demo

# Start all components (server + agent + web)
./start-all.sh

# Access Web UI at http://localhost:5173
# API available at http://localhost:8080

Configuration

Agent Configuration

Flag Description Default
--interface Network interface to attach eBPF eth0
--server Server gRPC address localhost:50051
--api-addr Local API listen address 127.0.0.1:8080
--log-level Log level (debug/info/warn/error) info

Server Configuration

Configuration via config/server.yaml:

server:
  grpc_port: 50051
  http_port: 8081

database:
  host: localhost
  port: 5432
  user: microsegment_user
  password: secret
  name: microsegment

API Reference

Policy Management

Method Endpoint Description
POST /api/v1/policies Create policy
GET /api/v1/policies List all policies
GET /api/v1/policies/:id Get policy by ID
PUT /api/v1/policies/:id Update policy
DELETE /api/v1/policies/:id Delete policy

Statistics

Method Endpoint Description
GET /api/v1/stats Get all statistics
GET /api/v1/stats/packets Get packet statistics
GET /api/v1/stats/policies Get policy hit statistics

Health Check

Method Endpoint Description
GET /api/v1/health Simple health check
GET /api/v1/status Detailed system status

Example: Create Policy

curl -X POST http://localhost:8080/api/v1/policies \
  -H "Content-Type: application/json" \
  -d '{
    "rule_id": 1001,
    "src_ip": "10.0.0.0/24",
    "dst_ip": "192.168.1.100",
    "dst_port": 443,
    "protocol": "tcp",
    "action": "allow"
  }'

Build Options

# Production build (optimized, all features)
make build-production

# Debug build (with debug logging)
make build-debug

# Minimal build (no NAT/fragment handling)
make build-minimal

# Show current configuration
make show-config

eBPF Feature Flags

Flag Description Default
DEBUG_MODE Enable eBPF debug logging 0
ENABLE_IP_FRAGMENT_HANDLING Handle IP fragments 1
ENABLE_NAT_SUPPORT NAT detection support 1

Performance

Metric Value Notes
Hot path latency < 1ΞΌs 99%+ packets (existing sessions)
Cold path latency 5-20ΞΌs New sessions with policy lookup
Exact policy match ~0.1ΞΌs O(1) hash lookup
Wildcard policy match 2-20ΞΌs Index scan with CIDR matching
Max concurrent sessions 100K LRU auto-eviction
Max policies 10K exact + 1K wildcard Configurable

Project Structure

.
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ agent/          # Agent component (eBPF management)
β”‚   β”‚   β”œβ”€β”€ cmd/        # Entry point
β”‚   β”‚   └── pkg/        # Packages (api, dataplane, policy)
β”‚   β”œβ”€β”€ bpf/            # eBPF C programs
β”‚   └── server/         # Server component (policy server)
β”œβ”€β”€ api/
β”‚   └── proto/          # Protocol Buffer definitions
β”œβ”€β”€ web/                # React Web UI
β”œβ”€β”€ config/             # Configuration files
β”œβ”€β”€ deploy/             # Deployment scripts (systemd, docker)
β”œβ”€β”€ docs/               # Documentation
└── tests/              # Integration tests

Testing

# Run unit tests
make test

# Run integration tests (requires root)
sudo make test-integration

# Run specific test
cd src/agent && go test -v ./pkg/dataplane/...

Deployment

Systemd

# Install systemd services
sudo ./deploy/scripts/install-systemd.sh

# Start services
sudo systemctl start microsegment-server
sudo systemctl start microsegment-agent

Docker

# Build and run with docker-compose
docker-compose up -d

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •