A Rust implementation of a gRPC-based stunnel configuration manager, providing programmatic control over stunnel instances.
stunnel-space/
├── Cargo.toml # Rust project configuration
├── Cargo.lock # Dependency lock file
├── build.rs # Build script for proto generation
├── Makefile # Build automation
├── Dockerfile # Container build configuration
├── README.md # This file
├── .gitignore # Git ignore patterns
├── stunnel.conf # Sample stunnel configuration
├── proto/
│ └── stunnel.proto # gRPC service definitions
└── src/
└── main.rs # Main application code
During build, the proto files are compiled to:
target/debug/build/stunnel-space-*/out/stunnel.rs(debug builds)target/release/build/stunnel-space-*/out/stunnel.rs(release builds)
These are automatically included via the tonic::include_proto! macro.
# Debug build
make build
# or
cargo build
# Release build
make release
# or
cargo build --release
# Generate proto files (happens automatically during build)
make protogendocker build -t stunnel-manager .# Default configuration
cargo run
# Custom configuration
STUNNEL_CONFIG=/path/to/stunnel.conf STUNNEL_PID_FILE=/path/to/stunnel.pid cargo run# Run with default port mappings
docker run -p 50055:50055 -p 50000-50010:50000-50010 stunnel-manager
# Or use the helper function from export.sh
source export.sh
run_dockerThe application exposes the following ports:
- 50055: gRPC server (configurable via GRPC_PORT)
- 50000-50010: Stunnel service ports for SSL/TLS tunneling
These ports allow you to configure multiple stunnel services, each listening on a different port in the 50000-50010 range.
The service listens on port 50055 and provides:
- ReloadConfig: Validate and reload stunnel configuration
- GetStatus: Check stunnel status and active connections
- UpdateConfig: Update configuration with validation
- GenerateConfig: Generate new stunnel configuration
- AddProvider: Add new service providers to existing config
- Rust 1.73+
- Protocol Buffers compiler (protoc)
- Stunnel (for testing)
make testmake fmtmake clippyThe application can be configured using environment variables. You have three options:
# Copy the example file
cp .env.example .env
# Edit the .env file with your configuration
nano .env
# Run the application (will auto-load .env)
cargo run# Source the export script
source export.sh
# View current configuration
print_config
# Run the server
run_serverexport STUNNEL_CONFIG=/path/to/stunnel.conf
export STUNNEL_PID_FILE=/path/to/stunnel.pid
export GRPC_PORT=8080
cargo runSTUNNEL_CONFIG: Path to stunnel configuration file (default:./stunnel.conf)STUNNEL_PID_FILE: Path to stunnel PID file (default:/tmp/stunnel.pid)GRPC_PORT: gRPC server port (default:50055)LOG_LEVEL: Log level - debug, info, warn, error (default:info)SSL_CERT_DIR: Path to SSL certificates directorySTUNNEL_ACCEPT_PORT: Default stunnel accept portSTUNNEL_CONNECT_HOST: Default stunnel connect hostSTUNNEL_CONNECT_PORT: Default stunnel connect portRUST_LOG: Rust log configuration (default:stunnel_space=info)
See .env.example for a complete list of available variables