Skip to content

Conversation

@jisung-02
Copy link
Contributor

Summary

  • Implements TCP tunneling functionality between Alpacon console and local services.
  • Multiple TCP connections are multiplexed into a single WebSocket connection through WebSocket-based smux multiplexing, and tunnel workers run as the nobody user for enhanced security.

Key Change

  1. New Features
    • Added opentunnel / closetunnel commands - Support remote tunnel creation/termination from Alpacon console
    • Implemented WebSocket-based TCP stream multiplexing through smux library
    • Tunnel session management (activeTunnels map) and prevention of duplicate sessions
  2. Security Enhancements
    • Run tunnel worker process as nobody user (privilege degradation)
    • Restrict connections to localhost only (allow 127.0.0.1 and localhost only)
      • Tunneling is only possible for services on machines where the agent is installed.
    • Prevent DoS attacks with stream metadata size limit (1KB)
    • Port range validation (1-65535)
  3. Performance Optimization
    • Reduced memory allocation/GC overhead with sync.Pool-based buffer pooling
    • Optimized smux configuration (KeepAlive 10s, MaxFrameSize 32KB, MaxReceiveBuffer 4MB)
    • Improved connection stability with TCP KeepAlive and NoDelay settings

  - Add username/groupname fields to opentunnel command
  - Implement tunnel-worker subprocess with demoted credentials
  - Add platform-specific credential handling (Linux/macOS)
  - Spawn separate process for TCP connections to enforce user permissions
  - Validate targetAddr is localhost-only (127.0.0.1 or localhost) in tunnel_worker.go
    to prevent connections to arbitrary external hosts
  - Add TargetPort range validation (1-65535) in command.go opentunnel handler
  - Implement metadata size limit (1KB) with LimitedReader in tunnel_client.go
    to prevent DoS attacks from malicious servers
  - Add error logging for tunnel worker process Kill failures
@jisung-02 jisung-02 changed the title feat: Websh based TCP-tunneling feat: Support for Websh based TCP-tunneling Dec 19, 2025
@jisung-02 jisung-02 self-assigned this Dec 19, 2025
@jisung-02 jisung-02 marked this pull request as draft December 22, 2025 08:23
@jisung-02 jisung-02 marked this pull request as ready for review December 22, 2025 13:38
@jisung-02 jisung-02 marked this pull request as draft December 23, 2025 01:55
@jisung-02 jisung-02 marked this pull request as ready for review December 23, 2025 01:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants