Skip to content

Conversation

fujiwara
Copy link
Owner

@fujiwara fujiwara commented Jun 6, 2025

Summary

  • Add --public flag to enable port forwarding on all interfaces (0.0.0.0) instead of localhost only
  • Implement pure Go TCP proxy to forward traffic from 0.0.0.0 to Session Manager Plugin on 127.0.0.1
  • Resolve port binding conflicts by using ephemeral ports for Session Manager Plugin when --public is specified

Changes

  • New --public flag: Simple boolean flag to enable public access
  • TCP Proxy Implementation: Pure Go implementation with bidirectional data forwarding
  • Port Conflict Resolution: Smart port allocation to avoid 127.0.0.1 vs 0.0.0.0 binding conflicts
  • Enhanced Logging: Structured logging with security warnings and connection details
  • Comprehensive Tests: Unit and integration tests for new functionality

Technical Details

  • No External Dependencies: No socat or other external tools required
  • Context-Aware: Proper context handling for graceful shutdown
  • Security Warning: Alerts users when binding to all interfaces
  • Ephemeral Port Strategy: Pre-allocates specific ephemeral ports to avoid race conditions

Testing

Tested with external connections showing successful proxy operation:

2025-06-07T01:41:13.048+09:00 [WARN] TCP proxy will bind to all interfaces (0.0.0.0)
2025-06-07T01:41:13.048+09:00 [INFO] Session Manager Plugin will use port [port:39133]
2025-06-07T01:41:13.048+09:00 [INFO] TCP proxy listening [address:0.0.0.0:9999]
2025-06-07T01:41:47.993+09:00 [DEBUG] proxying connection [client:100.118.212.19:43368]

Benefits

  • Docker Access: Enables access from Docker containers without socat workaround
  • Network Flexibility: Supports access from any network interface
  • Backward Compatibility: Default behavior unchanged (localhost only)
  • Clean Implementation: Simple, maintainable code structure

Fixes #83

🤖 Generated with Claude Code

fujiwara and others added 2 commits June 7, 2025 01:44
- Add --public flag to PortforwardOption to enable binding on 0.0.0.0
- Implement TCP proxy functionality to forward from 0.0.0.0 to localhost
- Use ephemeral ports for Session Manager Plugin when --public is specified
- Add bidirectional TCP proxy with proper connection handling and context cancellation
- Resolve port binding conflicts between Session Manager Plugin and public access
- Enable Docker container access without requiring socat workaround

Fixes #83

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add proper context-based listener shutdown in startTCPProxyToLocalhost
- Fix integration tests to terminate correctly without goroutine leaks
- Implement timeout handling and proper resource cleanup in tests
- Ensure all tests pass with race detection enabled
- Maintain test coverage while fixing CI reliability issues
- Update .gitignore to exclude build artifacts and test data

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@fujiwara fujiwara force-pushed the add-public-port-binding branch from 26ee670 to bbf83e8 Compare June 6, 2025 17:05
- Convert Japanese comments in portforward_test.go to English
- Maintain consistent English-only codebase for international collaboration

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@fujiwara fujiwara merged commit b072fc7 into main Jun 6, 2025
4 checks passed
@fujiwara fujiwara deleted the add-public-port-binding branch June 6, 2025 17:11
@github-actions github-actions bot mentioned this pull request Jun 6, 2025
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.

Allow binding to public 0.0.0.0 address
1 participant