A lightweight, WebSocket-based TCP tunneling solution that enables secure access to on-premise services from the internet without requiring inbound firewall rules.
YASG is a pure JavaScript (Node.js) implementation inspired by IBM Cloud Secure Gateway. It allows you to expose on-premise TCP services (databases, SSH, custom protocols) to the internet through a secure WebSocket tunnel, eliminating the need to open inbound firewall ports.
Internet Client → Gateway Server (Cloud) ←WebSocket→ Gateway Client (On-Premise) → Target Service
- Gateway Client (on-premise) establishes an outbound WebSocket connection to Gateway Server (cloud)
- Internet clients connect to the Gateway Server via TCP
- Data is tunneled through the WebSocket connection to the on-premise service
- No inbound firewall rules required!
- YASG can't handle Redirect features.
- You can browse on-premise web server(HTTP/HTTPS) with YASG. But if server need authentication and ask for redict to other on-premise authentication server, you will just see "can not resolve host" error.
- ✅ WebSocket-based TCP tunneling
- ✅ Bidirectional data forwarding
- ✅ Connection lifecycle management
- ✅ Automatic reconnection (client-side)
- ✅ Support for any TCP protocol
- ✅ Pure JavaScript implementation (no build step!)
- ✅ Comprehensive logging
- 🔜 Authentication and authorization
- 🔜 TLS/SSL support (wss://)
- 🔜 Multiple client support
- 🔜 Access control lists
- 🔜 Web-based management UI
- 🔜 Metrics and monitoring dashboard
- Node.js v18 or higher
- npm or yarn
# Clone the repository
git clone <repository-url>
cd yasg
# Install dependencies
npm installNo build step required! YASG is written in pure JavaScript.
# Start the server with default configuration
npm run start:server
# With custom configuration file
npm run start:server -- --config ./config/server-config.json
# With environment variables
export YASG_TCP_PORT=9090
export YASG_WS_PORT=9091
npm run start:server
# Combining config file and environment variables (env takes precedence)
export YASG_LOG_LEVEL=debug
npm run start:server -- --config ./config/server-config.jsonThe server will start:
- TCP listener on port 8080 (for internet clients)
- WebSocket server on port 8081 (for gateway clients)
# Start the client with default configuration
npm run start:client
# With custom configuration file
npm run start:client -- --config ./config/client-config.json
# With environment variables (useful for Docker/Kubernetes)
export YASG_SERVER_URL=ws://gateway.example.com:8081/gateway
export YASG_TARGET_HOST=localhost
export YASG_TARGET_PORT=22
npm run start:client
# Combining config file and environment variables (env takes precedence)
export YASG_TARGET_PORT=3306
export YASG_LOG_LEVEL=info
npm run start:client -- --config ./config/client-config.jsonThe client will:
- Connect to the gateway server via WebSocket
- Forward connections to the configured target service
Configuration Priority: Environment Variables > Config File > Default Values
For a complete list of environment variables, see ENVIRONMENT_VARIABLES.md.
# Example: Accessing an on-premise MySQL database
mysql -h <gateway-server-ip> -P 8080 -u username -p
# Example: Accessing an on-premise HTTP server
curl http://<gateway-server-ip>:8080
# Example: SSH to an on-premise server
ssh -p 8080 user@<gateway-server-ip>yasg/
├── src/
│ ├── server/ # Gateway server components
│ │ ├── index.js # Server entry point
│ │ ├── TcpListener.js # TCP server
│ │ ├── WebSocketServer.js
│ │ ├── ConnectionManager.js
│ │ └── DataForwarder.js
│ ├── client/ # Gateway client components
│ │ ├── index.js # Client entry point
│ │ ├── WebSocketClient.js
│ │ ├── TcpConnector.js
│ │ ├── ConnectionPool.js
│ │ └── DataForwarder.js
│ └── shared/ # Shared code
│ ├── protocol.js # Protocol implementation
│ └── utils.js # Utilities
├── config/ # Configuration files
├── examples/ # Usage examples
├── package.json
├── README.md
├── QUICKSTART.md # Quick start guide
├── INSTALLATION.md # Installation guide
├── ENVIRONMENT_VARIABLES.md # Environment variables guide
├── TECHNICAL_SPEC.md # Technical specification
├── ARCHITECTURE.md # Architecture details
└── IMPLEMENTATION_ROADMAP.md # Implementation guide
YASG supports configuration through both configuration files and environment variables. Environment variables take precedence over configuration files.
For detailed information about environment variables, see ENVIRONMENT_VARIABLES.md.
Create config/server-config.json:
{
"tcp": {
"host": "0.0.0.0",
"port": 8080
},
"websocket": {
"port": 8081,
"path": "/gateway"
},
"connection": {
"timeout": 30000,
"maxConnections": 100
},
"logging": {
"level": "info"
}
}Create config/client-config.json:
{
"server": {
"url": "ws://your-gateway-server.com:8081/gateway",
"reconnect": true,
"reconnectInterval": 5000,
"maxReconnectAttempts": 10
},
"target": {
"host": "localhost",
"port": 3306
},
"connection": {
"timeout": 30000,
"poolSize": 10
},
"logging": {
"level": "info"
}
}-
YASG Server
-
$ docker pull dotnsf/yasg-server -
$ docker run -d -e YASG_TCP_PORT=90 -e YASG_WS_PORT=9000 -e YASG_SECURITY_KEYWORD=keyword -e YASG_LOG_LEVEL=debug -p 90:90 -p 9000:9000 dotnsf/yasg-server
-
-
YASG Client
-
$ docker pull dotnsf/yasg-client -
$ docker run -d -e YASG_SERVER_URL=ws://yasg-server:9000/gateway -e YASG_TARGET_HOST=192.168.1.100 -e YASG_TARGET_PORT=22 -e YASG_SECURITY_KEYWORD=keyword -e YASG_LOG_LEVEL=debug -p 9000:9000 dotnsf/yasg-client> ssh user@yasg-server -p 90
-
$ docker run -d -e YASG_SERVER_URL=ws://yasg-server:9000/gateway -e YASG_TARGET_HOST=private.test.local -e YASG_TARGET_PORT=443 -e YASG_SECURITY_KEYWORD=keyword -e YASG_LOG_LEVEL=debug -p 9000:9000 dotnsf/yasg-client> curl -k https://yasg-server:90/
-
- Technical Specification - Detailed technical design
- Architecture - System architecture and diagrams
- Implementation Roadmap - Development guide
- Quick Start Guide - Getting started quickly
- Installation Guide - Detailed installation instructions
# Run tests (when available)
npm test
# Run in development mode with auto-reload
npm run dev:server # For server
npm run dev:client # For client# Install dependencies
npm install
# Run in development mode with auto-reload
npm run dev:server # For server
npm run dev:client # For client
# Lint code
npm run lintAccess on-premise databases from cloud applications:
- MySQL
- PostgreSQL
- MongoDB
- Redis
Securely SSH into on-premise servers without VPN:
ssh -p 8080 user@gateway-server.comTunnel any TCP-based protocol:
- Custom APIs
- Legacy applications
- IoT devices
- Internal tools
Test cloud applications against local services:
- Local development databases
- Mock services
- Testing environments
The current implementation does NOT include:
- Authentication
- Encryption (uses ws:// not wss://)
- Access control
- Rate limiting
For production use, you MUST add:
- TLS/SSL encryption (wss://)
- Token-based or certificate authentication
- Access control lists
- Rate limiting and DDoS protection
- Audit logging
- Network segmentation
See TECHNICAL_SPEC.md for details.
Problem: Client shows connection errors
Solutions:
- Verify server is running:
netstat -an | grep 8081 - Check firewall rules allow outbound WebSocket connections
- Verify WebSocket URL in client configuration
- Check server logs for errors
Problem: Client connects but cannot reach target service
Solutions:
- Verify target service is running
- Check host and port in client configuration
- Test local connectivity:
telnet localhost 3306 - Review client logs for connection errors
Problem: Slow or corrupted data transfer
Solutions:
- Check network bandwidth and latency
- Monitor CPU and memory usage
- Review buffer sizes in configuration
- Check for errors in logs
Problem: WebSocket connection drops frequently
Solutions:
- Check network stability
- Increase timeout values
- Review reconnection settings
- Monitor server resources
- Latency: < 50ms (local network)
- Throughput: > 10 MB/s
- Concurrent Connections: 100+
- Memory Usage: < 100 MB
- CPU Usage: < 20%
Actual performance depends on network conditions and hardware
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
[Specify your license here]
- Inspired by IBM Cloud Secure Gateway
- Built with Node.js and pure JavaScript
- Uses the excellent ws library
- Issues: GitHub Issues
- Documentation: See
docs/directory - Email: [your-email@example.com]
- ✅ Basic WebSocket tunneling
- ✅ TCP connection forwarding
- ✅ Automatic reconnection
- ✅ Pure JavaScript implementation
- 🔜 Authentication system
- 🔜 TLS/SSL support
- 🔜 Access control lists
- 🔜 Enhanced logging
- 🔜 Multiple client support
- 🔜 Web management UI
- 🔜 Metrics dashboard
- 🔜 Load balancing
Made with ❤️ using Node.js and JavaScript