DecentraLabs Gateway
🎯 Overview
DecentraLabs Gateway provides a complete blockchain-based authentication system for laboratory access. It includes all components needed for a decentralized lab access solution with advanced features, wallet management, and institutional treasury operations.
🏗️ Architecture
┌─────────────────┐ ┌─────────────────┐ ┌───────────────────┐
│ User Wallet │ │ OpenResty │ │Blockchain Services│
│ or JWT ├────┤ (Nginx + Lua) ├────┤ (Spring Boot) │
└─────────────────┘ └─────────────────┘ └───────────────────┘
│ │
│ │
┌─────────────────┐ ┌─────────────────┐
│ Guacamole │ │ Blockchain │
│ (Lab Access) │ │ (Smart │
└─────────────────┘ │ Contracts) │
│ └─────────────────┘
│
┌─────────────────┐
│ MySQL │
│ (Database) │
└─────────────────┘🌟 Features
✅ Blockchain Authentication
Flexible Signature Verification: Users authenticate using their crypto wallet or SSO credentials in an external trusted system that emits a signed JWT
Smart Contract Integration: Validates users' lab reservations on-chain
JWT Token Generation: Issues secure access tokens for lab sessions (to be consumed by Guacamole)
✅ Authentication Service (Spring Boot)
RESTful API: Comprehensive authentication endpoints
Blockchain Integration: Web3j for smart contract interaction
JWT Management: Token validation and generation
Wallet Operations: Create, import, and manage Ethereum wallets
Institutional Treasury: Full treasury management with spending limits and period controls
Health Monitoring: Built-in health checks and metrics
✅ Lab Access & Management
Apache Guacamole Integration: Clientless RDP/VNC/SSH access through the browser
Session Cookie Management: JTI-based session validation with automatic expiration
Header Propagation: Authenticated username forwarded to Guacamole for auto-login
Ops Worker: Remote power management for lab stations (Wake-on-LAN, shutdown)
🚀 Quick Deployment
Using Setup Scripts (Recommended)
The setup scripts will automatically:
✅ Check Docker, Docker Compose, and Git prerequisites
✅ Initialize/refresh the
blockchain-servicessubmodule and env files✅ Configure environment variables (database, domain, blockchain, CORS)
✅ Generate database passwords
✅ Create the
blockchain-data/directory for wallet persistence✅ Optionally start every container with
docker compose up -d✅ Ask if you want to enable a Cloudflare Tunnel so the gateway is reachable without a public IP/DNS
✅ Configure Guacamole admin credentials
✅ Generate OPS worker secret for lab power operations
☑️ Remind you to create/import the institutional wallet later from the blockchain-services web console
Windows:
Linux/macOS:
That's it! The script will guide you through the setup and start all services automatically.
Manual Deployment
If you prefer manual configuration:
Copy environment template:
Edit
.envandblockchain-services/.envwith your configuration (see Configuration section below)Add SSL certificates to
certs/folder:Start the services:
⚙️ Configuration
🔧 Environment Variables
The gateway uses modular configuration with separate .env files:
.env- Gateway-specific configuration (server, database, Guacamole)blockchain-services/.env- Blockchain service configuration (contracts, wallets, RPC)
This separation keeps concerns isolated and makes the blockchain service independently configurable.
Gateway Configuration (.env)
.env)OpenResty and blockchain-services derive public URLs (issuer, OpenID metadata, etc.) from SERVER_NAME and HTTPS_PORT. If you ever need to override that computed value, set BASE_DOMAIN inside blockchain-services/.env or export it in the container's environment. All authentication endpoints live under the fixed /auth base path to match both services.
Deployment modes: Direct vs Router forwarding
Direct (default): Gateway has a public IP or you're testing locally.
Behind a router/NAT: External traffic arrives via port forwarding (e.g., router:8043 → host:443). Set
HTTPS_PORTto the public port (e.g., 8043) and use the router override:
This binds to 0.0.0.0:443 and 0.0.0.0:80 so the router can reach the gateway.
Optional Cloudflare Tunnel settings (filled automatically if you opt in during setup):
Blockchain Service Configuration (blockchain-services/.env)
blockchain-services/.env)Institutional Wallet Setup
The institutional wallet is managed automatically by blockchain-services:
First-time setup: Create or import the wallet via:
Web console:
https://localhost:8443/wallet-dashboard(orhttps://your-domain/wallet-dashboard)Or API: Call
/wallet/createor/wallet/importendpoints
Automatic configuration: After creation/import, blockchain-services automatically:
Stores the encrypted wallet in
blockchain-data/wallets.jsonWrites credentials to
blockchain-data/wallet-config.propertiesLoads the wallet on every restart using the stored configuration
Manual override (optional): Only needed if using external secret management:
The encrypted wallet and configuration files are stored in blockchain-data/ which is mounted as a Docker volume and excluded from git.
💻 System Requirements
Operating System:
Linux (recommended) - Ubuntu 20.04+, Debian 11+, CentOS 8+
Unix-like systems (BSD, macOS) - supported
Windows - via WSL2 or Docker Desktop
Hardware (Minimum):
2 CPU cores
4GB RAM
20GB disk space (including Docker images and logs)
Network interface with internet connectivity
Software:
Docker Engine 20.10+ (Linux) or Docker Desktop (Windows/macOS)
Docker Compose 2.0+ (included with Docker Desktop)
Network Requirements
The Lab Gateway requires network connectivity to:
External Users - To accept incoming HTTP(s) connections
Internal Laboratory Servers - To proxy RDP/VNC/SSH connections
This can be achieved through various network topologies:
Option A: Dual Network Interface (Most Secure)
✅ Two physical or virtual Network Interface Cards (NICs)
✅ Physical network isolation between public and lab networks
✅ Highest security level
❌ Requires specific hardware/VM configuration
Option B: Single Network Interface (Most Common)
✅ Single NIC with routing configuration
✅ Works with cloud providers (AWS, Azure, GCP, DigitalOcean, etc.)
✅ Works with CDN/proxies (CloudFlare, CloudFront, etc.)
✅ Works with VPS/dedicated servers
✅ Labs accessed via private IPs or VPN tunnels
✅ Most flexible and commonly deployed
Option C: VLAN Segmentation (Enterprise)
✅ Single NIC with 802.1Q VLAN tagging
✅ Logical separation of public and lab traffic
✅ Common in enterprise/datacenter environments
🌐 Remote Access without Public IP (Cloudflare Tunnel)
Enable the Cloudflare Tunnel option during
setup.sh/setup.batto spin up thecloudflaredsidecar (Compose profilecloudflare) and expose the gateway without opening inbound ports.Works behind campus/corporate NAT as long as outbound HTTPS (443) is allowed; WebSockets for Guacamole are supported through the tunnel.
Token mode: paste a Cloudflare Tunnel token from your Zero Trust dashboard and Cloudflare will publish the hostname in your zone.
Quick Tunnel mode: leave the token empty and a random
*.cfargotunnel.comhostname will appear indocker compose --profile cloudflare logs cloudflared.Start/stop with the profile when needed:
docker compose --profile cloudflare up -d/docker compose --profile cloudflare down.
🔐 SSL/TLS Certificates
Development:
Self-signed certificates (auto-generated)
Valid for localhost testing
Production:
Valid SSL certificate from trusted CA
Let's Encrypt (free, automated renewal)
Commercial certificate providers
Wildcard certificates for multiple subdomains
🛠️ Technology Stack
Core Components
OpenResty - Reverse proxy and load balancer with Lua scripting
Apache Guacamole - Clientless remote desktop gateway (RDP/VNC/SSH)
MySQL 8.0 - Primary database for configuration and user data
Docker - Containerization platform with Compose orchestration
Blockchain Integration
Blockchain Services (Spring Boot 3.x) - Authentication and wallet operations microservice
Web3j - Ethereum blockchain integration library
JWT - Generates authentication tokens with blockchain claims
Smart Contract Events - Real-time blockchain monitoring
📁 Project Structure
🧪 Testing
Gateway Tests
Unit tests cover the OpenResty gateway logic (Lua handlers and session guard). They run via the OpenResty container so you do not need a local Lua installation:
The command executes every spec under openresty/tests/unit/ through a lightweight Lua test runner.
Smoke Tests
For an end-to-end smoke check (OpenResty ↔ Guacamole proxy logic):
The script spins up a miniature docker-compose environment with mock services, validates that JWT cookies are issued, and ensures Guacamole receives the propagated Authorization header.
Coverage Reports
To collect LuaCov coverage metrics:
Coverage data will be written to luacov.report.out and luacov.stats.out.
🛠️ Development
Local Development Setup
Start services in development mode:
Access services:
Blockchain Services: http://localhost:8080/wallet (or configured port)
Guacamole: https://localhost:8443/guacamole
MySQL: localhost:3306
Debugging
Enable debug logging in .env or blockchain-services/.env:
View logs:
🤝 Contributing
Fork the project
Create a feature branch (
git checkout -b feature/amazing-feature)Commit your changes (
git commit -m 'Add amazing feature')Push to the branch (
git push origin feature/amazing-feature)Open a Pull Request
📝 Documentation
Main Documentation: This README (for main branch - full version)
Logging: LOGGING.md - Log configuration and management
Guacamole Setup: configuring-lab-connections/guacamole-connections.md
Blockchain Services: Check blockchain-services/README.md for detailed API documentation
📞 Support
Issues: GitHub Issues
Logs: Use
docker compose logs [service]for troubleshootingConfiguration: Review
.env.exampleandblockchain-services/.env.examplefor all options
DecentraLabs Gateway provides a complete, production-ready blockchain authentication system for decentralized laboratory access.
Last updated