Skip to content

hawk2012/GubinNET

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

59 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

GubinNET – Secure Go-Based Web Server with Dynamic Module Support

GubinNET is a high-performance, secure, and modular HTTP server written in Go. It’s designed for production-grade hosting with built-in support for:

βœ… Static file serving (SPA-ready)
βœ… Reverse proxy with SNI
βœ… Dynamic modules (C/C++, Go, Python, WASM)
βœ… Built-in DDoS protection
βœ… Prometheus + pprof monitoring
βœ… Structured logging & hot reload

Unlike traditional proxies, GubinNET allows secure execution of native modules β€” but with strict signing and isolation to prevent RCE and privilege escalation.

πŸ” Security-first: No dynamic g++ compilation. All modules must be pre-compiled and signed.


πŸ“¦ Key Features

Feature Description
Static Hosting Serve SPAs (React, Vue) with try_files fallback
Reverse Proxy Forward traffic to backend services
SNI / HTTPS TLS with per-host certificates
Dynamic Modules Load .so or WASM modules (C/C++, Go, Rust)
Module Signing Ed25519 signature verification for .so binaries
DDoS Protection Rate limiting + IP banning
Observability Prometheus /metrics, pprof, and /healthz
Structured Logging JSON logs with request ID, duration, status
Hot Reload SIGHUP to reload config without downtime

πŸ” Security Model

GubinNET prioritizes security over convenience:

  • ❌ No dynamic C++ compilation – g++ execution removed to prevent RCE.
  • βœ… Modules must be pre-compiled – developers compile module.cpp β†’ module.so offline.
  • βœ… All modules must be signed with Ed25519 key.
  • βœ… Path traversal protection via safeJoin() and strict validation.
  • βœ… Security headers: X-Frame-Options, X-XSS-Protection, HSTS.
  • βœ… Isolation: Modules run in main process but are monitored and logged.

🧩 Module System (Secure)

GubinNET supports dynamic modules via CGO or WASM β€” but only if they are trusted and signed.

1. cgo – C/C++ Modules (.so)

server_name=modules.example.com
listen_port=80
app_mode=cgo
module_path=/etc/gubinnet/modules/my_module/module.so
module_sig=/etc/gubinnet/modules/my_module/module.so.sig
use_ssl=true
cert_path=/etc/ssl/certs/modules.crt
key_path=/etc/ssl/private/modules.key
  • Module must be compiled manually:
    g++ -shared -fPIC module.cpp -o module.so
  • Signed with private key:
    openssl dgst -sha256 -sign private.pem -out module.so.sig module.so
  • Server verifies signature using /etc/gubinnet/gubinnet.pub.

⚠️ No .cpp β†’ .so compilation at runtime.


2. wasm – WebAssembly Modules (Future)

Coming soon: WASM support via wazero for full sandboxing.


3. proxy – Reverse Proxy Mode

server_name=api.example.com
listen_port=80
app_mode=proxy
proxy_url=http://internal-service:8080
use_ssl=true
cert_path=/etc/ssl/certs/api.crt
key_path=/etc/ssl/private/api.key
redirect_to_https=true
  • All traffic forwarded to backend.
  • Supports SNI and HTTPS termination.

4. static – Static Site / SPA

server_name=spa.example.com
listen_port=80
app_mode=static
root_path=/var/www/spa
try_files=index.html
use_ssl=true
cert_path=/etc/ssl/certs/spa.crt
key_path=/etc/ssl/private/spa.key
  • Ideal for React, Vue, Angular apps.
  • Fallback to index.html for client-side routing.

βš™οΈ Installation

1. Clone & Build

git clone https://github.com/yourusername/gubinnet.git
cd gubinnet
go build -o gubinnet main.go

2. Create Directories

sudo mkdir -p /etc/gubinnet/{config,logs,modules}
sudo mkdir -p /var/www

3. Generate Signing Keys

# Generate Ed25519 key pair
openssl genpkey -algorithm ED25519 -out /etc/gubinnet/private.pem
openssl pkey -in /etc/gubinnet/private.pem -pubout -out /etc/gubinnet/gubinnet.pub

Server requires /etc/gubinnet/gubinnet.pub to verify module signatures.


πŸ› οΈ Configuration Example

/etc/gubinnet/config/example.ini:

server_name=modules.example.com
listen_port=80
app_mode=cgo
module_path=/etc/gubinnet/modules/demo/module.so
module_sig=/etc/gubinnet/modules/demo/module.so.sig
use_ssl=true
cert_path=/etc/ssl/certs/example.com.crt
key_path=/etc/ssl/private/example.com.key
redirect_to_https=true

πŸš€ Run the Server

sudo ./gubinnet

Server starts on:

  • :80 – HTTP
  • :443 – HTTPS
  • :9090 – /metrics and /healthz
  • :6060 – pprof (profiling)

πŸ”„ Hot Reload

Reload config without restart:

kill -HUP $(pgrep gubinnet)

πŸ“Š Monitoring & Debugging

1. Health Check

GET http://localhost:9090/healthz
β†’ 200 OK

2. Prometheus Metrics

GET http://localhost:9090/metrics

Metrics include:

  • http_requests_total
  • http_request_duration_seconds
  • http_active_connections
  • module_executions_total
  • module_errors_total

3. Profiling (pprof)

# CPU profile
curl http://localhost:6060/debug/pprof/profile > profile.out

# Heap profile
curl http://localhost:6060/debug/pprof/heap > heap.out

# View with:
go tool pprof profile.out

🐳 Docker Support

Dockerfile

FROM alpine:latest AS builder
RUN apk add --no-cache gcc g++ libc-dev
WORKDIR /app
COPY . .
RUN go build -o gubinnet main.go

FROM alpine:latest
RUN apk add --no-cache ca-certificates
WORKDIR /app
COPY --from=builder /app/gubinnet .
COPY --from=builder /app/config /etc/gubinnet/config
COPY --from=builder /app/modules /etc/gubinnet/modules
COPY --from=builder /app/logs /etc/gubinnet/logs
COPY --from=builder /app/gubinnet.pub /etc/gubinnet/gubinnet.pub

EXPOSE 80 443 9090 6060
CMD ["./gubinnet"]

docker-compose.yml

version: '3'
services:
  gubinnet:
    build: .
    ports:
      - "80:80"
      - "443:443"
      - "9090:9090"
      - "6060:6060"
    volumes:
      - ./ssl:/etc/ssl
      - ./data/config:/etc/gubinnet/config
      - ./data/modules:/etc/gubinnet/modules
      - ./data/logs:/etc/gubinnet/logs
    restart: unless-stopped

πŸ“ Directory Structure

/etc/gubinnet/
β”œβ”€β”€ config/               # .ini configuration files
β”‚   └── site1.ini
β”œβ”€β”€ modules/              # Pre-compiled, signed modules
β”‚   └── demo/
β”‚       β”œβ”€β”€ module.so
β”‚       └── module.so.sig
β”œβ”€β”€ logs/
β”‚   β”œβ”€β”€ access.log        # JSON-formatted access logs
β”‚   └── antiddos.log      # Blocked IPs
└── gubinnet.pub          # Public key for module verification

πŸ“‹ Logging

Logs are written in structured JSON:

{
  "timestamp": "2025-04-05T10:00:00Z",
  "level": "INFO",
  "message": "Request processed",
  "method": "GET",
  "path": "/modules/demo",
  "status": 200,
  "duration": 0.012,
  "remote": "192.168.1.100",
  "user_agent": "curl/7.68.0",
  "request_id": "a1b2c3d4-e5f6-7890-g1h2-i3j4k5l6m7n8"
}

Log rotation: daily.


πŸ›‘ Anti-DDoS Protection

  • Rate limit: 100 requests/sec per IP.
  • Ban duration: 60 seconds.
  • Logs blocked IPs in /etc/gubinnet/logs/antiddos.log.

Configurable via code (in future: config file).


πŸ“„ License

MIT License – see LICENSE


πŸš€ Want to Contribute?

We welcome:

  • WASM module support
  • External module runner (sandboxed processes)
  • JWT auth middleware
  • OpenTelemetry tracing

Open an issue or submit a PR!


βœ… Keep it fast.
βœ… Keep it secure.
βœ… One proxy to rule them all.

About

DotNet, NodeJS and reverse proxy server written in GO.

Topics

Resources

Contributing

Stars

Watchers

Forks