TailSwan allows you to connect existing IPsec VPN networks to your Tailscale network (tailnet). It's perfect for:
- Devices that don't support Tailscale but have IPsec VPN capability
- Bridging legacy IPsec infrastructure with modern Tailscale networks
- Exposing IPsec-connected subnets to your tailnet
- Centralized IPsec gateway management with Tailscale's security and access controls
- Unified CLI Tool:
tailswancommand for managing all services and connections - Dual VPN Bridge: Runs both strongSwan (IPsec) and Tailscale in a single container
- Web UI Control Panel: Modern web interface for managing IPsec connections via Tailscale
- REST API: Programmatic control of IPsec connections via HTTP API
- Real-time Monitoring: Server-Sent Events (SSE) for live status updates in the web UI
- Automatic Subnet Advertisement: IPsec subnets are automatically advertised to your Tailscale network
- Tailscale SSH Access: SSH into the container via Tailscale to manage IPsec connections
- Process Supervision: Automatic service restart and health monitoring
- Multiple Authentication Methods: Supports PSK, certificates, and other IPsec auth methods
- Site-to-Site & Remote Access: Configure both site-to-site and road warrior VPN scenarios
- Health Monitoring: Built-in health checks for both services
- Easy Configuration: Environment variables and standard swanctl.conf syntax
[IPsec Client/Site] <--IPsec--> [TailSwan Container] <--Tailscale--> [Your Tailnet]
├── tailswan (supervisor)
├── strongSwan (charon)
├── Tailscale client
├── Control Server (Web UI + API)
└── SSH daemon (via Tailscale)
TailSwan is built with a modern Go-based architecture:
tailswanCLI: Main supervisor that manages all services, with built-in commands for connection management- Control Server: RESTful API and web UI for remote management
- Process Supervisor: Manages Tailscale and strongSwan daemons with automatic restarts
- Real-time Updates: Server-Sent Events (SSE) for live status monitoring in the web UI
Access the control server from any device on your Tailnet at http://tailswan:8080/
- Docker installed
- Tailscale account
- IPsec peer configuration details
TailSwan images are automatically built and published to GitHub Container Registry:
# Pull the latest image from GHCR
docker pull ghcr.io/klowdo/tailswan:latest
# Or use a specific version
docker pull ghcr.io/klowdo/tailswan:v1.0.0Supported platforms: linux/amd64, linux/arm64
- Create a swanctl configuration file (
swanctl.conf):
connections {
mysite {
version = 2
local_addrs = 0.0.0.0
remote_addrs = 203.0.113.10
local {
auth = psk
id = my-gateway
}
remote {
auth = psk
id = remote-gateway
}
children {
net-net {
local_ts = 10.1.0.0/24
remote_ts = 10.2.0.0/24
start_action = trap
esp_proposals = aes256-sha256-modp2048
}
}
proposals = aes256-sha256-modp2048
}
}
secrets {
ike-mysite {
id = my-gateway
secret = "your-strong-preshared-key"
}
}- Run the container:
docker run -d \
--name tailswan \
--cap-add=NET_ADMIN \
--cap-add=NET_RAW \
--device=/dev/net/tun \
-v $(pwd)/swanctl.conf:/etc/swanctl/swanctl.conf:ro \
-e TS_AUTHKEY=tskey-auth-xxxxxxxxxxxx \
-e TS_ROUTES=10.1.0.0/24,10.2.0.0/24 \
-e TS_HOSTNAME=tailswan-gateway \
-e TS_SSH=true \
ghcr.io/klowdo/tailswan:latest-
Approve routes in Tailscale admin console:
- Go to https://login.tailscale.com/admin/machines
- Find your TailSwan device
- Click "Edit route settings"
- Approve the advertised routes
-
SSH into the container via Tailscale:
ssh root@tailswan-gateway- Initiate the IPsec connection (if not using auto-start):
swanctl --initiate --child net-net| Variable | Default | Description |
|---|---|---|
| General Configuration | ||
CONTROL_PORT |
8080 |
Port for the web UI and REST API control server |
LOG_LEVEL |
info |
Logging level (debug, info, warn, error) |
USE_TSNET |
false |
Use embedded tsnet instead of standalone tailscaled. When true, runs Tailscale client embedded in the control server process |
| Tailscale Configuration | ||
TS_AUTHKEY |
(required) | Tailscale authentication key. Get from https://login.tailscale.com/admin/settings/keys |
TS_HOSTNAME |
tailswan |
Hostname for the Tailscale node in your tailnet |
TS_ROUTES |
(empty) | Comma-separated list of subnets to advertise to your tailnet (e.g., 10.1.0.0/24,10.2.0.0/24) |
TS_SSH |
true |
Enable Tailscale SSH server for remote access via tailnet |
TS_EXTRA_ARGS |
(empty) | Additional arguments to pass to tailscale up command |
TS_STATE_DIR |
/var/lib/tailscale |
Directory for storing Tailscale state and configuration |
TS_SOCKET |
/var/run/tailscale/tailscaled.sock |
Path to tailscaled control socket (only used when USE_TSNET=false) |
| strongSwan Configuration | ||
SWAN_CONFIG |
/etc/swanctl/swanctl.conf |
Path to swanctl configuration file |
SWAN_AUTO_START |
false |
Automatically initiate IPsec connections on container start |
SWAN_CONNECTIONS |
(empty) | Comma-separated list of connection names to auto-start (requires SWAN_AUTO_START=true) |
docker run -d \
--name tailswan \
--cap-add=NET_ADMIN \
--cap-add=NET_RAW \
--device=/dev/net/tun \
-v $(pwd)/swanctl.conf:/etc/swanctl/swanctl.conf:ro \
-e TS_AUTHKEY=tskey-auth-xxxxxxxxxxxx \
-e TS_ROUTES=10.1.0.0/24,10.2.0.0/24 \
-e TS_HOSTNAME=office-gateway \
-e SWAN_AUTO_START=true \
-e SWAN_CONNECTIONS=net-net \
ghcr.io/klowdo/tailswan:latestSee docker-compose.yml for a complete example.
Mount certificate directories:
docker run -d \
--name tailswan \
--cap-add=NET_ADMIN \
--cap-add=NET_RAW \
--device=/dev/net/tun \
-v $(pwd)/swanctl.conf:/etc/swanctl/swanctl.conf:ro \
-v $(pwd)/certs/x509:/etc/swanctl/x509:ro \
-v $(pwd)/certs/x509ca:/etc/swanctl/x509ca:ro \
-v $(pwd)/certs/private:/etc/swanctl/private:ro \
-e TS_AUTHKEY=tskey-auth-xxxxxxxxxxxx \
-e TS_ROUTES=10.0.0.0/8 \
ghcr.io/klowdo/tailswan:latestThe tailswan CLI provides a unified interface for managing the container and IPsec connections:
# Run supervisor (start all services) - default behavior
tailswan
# Check if all services are healthy
tailswan healthcheck
# Show status of Tailscale and strongSwan
tailswan status
# List all configured connections
tailswan connections
# List active security associations
tailswan sas
# Initiate a connection
tailswan start mysite
# Terminate a connection
tailswan stop mysite
# Reload strongSwan configuration
tailswan reload
# Show help
tailswan helpOnce the container is running and connected to your tailnet:
# SSH using the hostname
ssh root@tailswan-gateway
# Or using the Tailscale IP
ssh [email protected]
# Then use the tailswan CLI
tailswan status
tailswan connectionsAccess the web-based control panel from any device on your Tailnet:
http://tailswan:8080/
The web UI provides:
- Real-time server status monitoring
- List of configured connections with quick action buttons
- Active security associations viewer
- Manual connection control (bring up/down)
- Auto-refreshing status (every 10 seconds)
Control connections programmatically:
# Bring a connection up
curl -X POST http://tailswan:8080/connections/up \
-H "Content-Type: application/json" \
-d '{"name":"net-net"}'
# Bring a connection down
curl -X POST http://tailswan:8080/connections/down \
-H "Content-Type: application/json" \
-d '{"name":"net-net"}'
# List all configured connections
curl http://tailswan:8080/connections/list
# List active security associations
curl http://tailswan:8080/sas/list
# Health check
curl http://tailswan:8080/healthSee cmd/controlserver/README.md for full API documentation.
# Load configuration
swanctl --load-all
# List configured connections
swanctl --list-conns
# Initiate a connection
swanctl --initiate --child net-net
# List active Security Associations
swanctl --list-sas
# Terminate a connection
swanctl --terminate --ike mysitegit clone https://github.com/klowdo/tailswan.git
cd tailswan
docker build -t tailswan:latest .TailSwan follows a standard Go project layout:
tailswan/
├── cmd/
│ ├── tailswan/ # Main supervisor CLI
│ │ ├── main.go # Entry point and command routing
│ │ ├── commands.go # CLI command implementations
│ │ └── supervisor.go # Supervisor startup logic
│ └── controlserver/ # Web UI and REST API server
│ ├── main.go # HTTP server entry point
│ └── web/ # Static assets (HTML, JS, CSS)
├── internal/
│ ├── supervisor/ # Process supervision and management
│ │ ├── supervisor.go # Main supervisor logic
│ │ ├── tailscale.go # Tailscale daemon management
│ │ ├── swan.go # strongSwan daemon management
│ │ ├── process.go # Generic process manager
│ │ ├── health.go # Health check implementations
│ │ └── sysconfig.go # System configuration (routing, forwarding)
│ ├── handlers/ # HTTP request handlers
│ │ ├── vici.go # strongSwan VICI protocol handlers
│ │ ├── tailscale.go # Tailscale status handlers
│ │ ├── sse.go # Server-Sent Events handlers
│ │ └── health.go # Health check endpoints
│ ├── server/ # HTTP server setup
│ ├── routes/ # API route definitions
│ ├── models/ # Data models and structures
│ ├── sse/ # SSE broadcaster for real-time updates
│ └── config/ # Configuration management
├── scripts/ # Helper shell scripts
├── config/ # Example configurations
└── Dockerfile # Multi-stage build container
Key Components:
- Supervisor: Manages Tailscale and strongSwan as child processes with automatic restarts
- VICI Integration: Uses strongSwan's VICI protocol for programmatic control
- SSE Broadcasting: Real-time status updates pushed to web UI clients
- Health Checks: Docker-compatible health monitoring for all services
- Ensure you have the required capabilities:
NET_ADMIN,NET_RAW - Check that
/dev/net/tundevice is available - Verify your swanctl.conf syntax
# Check logs
docker logs tailswan
# SSH into container and check status
ssh root@tailswan-gateway
tailswan status
tailswan connections
tailswan sas- Verify routes are approved in Tailscale admin console
- Check that
TS_ROUTESmatches your IPsec subnet configuration - Ensure IP forwarding is enabled (automatically set by entrypoint)
- Verify
TS_SSH=trueis set - Check Tailscale ACLs allow SSH access
- Ensure the container is showing as "Connected" in Tailscale admin
- Authentication Keys: Use environment variables or Docker secrets for sensitive data
- Tailscale ACLs: Configure proper access controls in your Tailscale admin console
- IPsec Credentials: Prefer certificate-based authentication over PSK for production
- SSH Access: Leverage Tailscale's built-in SSH with ACL-based access control
- Subnet Routing: Only advertise routes you intend to expose to your tailnet
For more complex routing scenarios, you can use Virtual Tunnel Interfaces (VTI). See the swanctl.conf.example file for configuration details.
Configure multiple connections in your swanctl.conf and use SWAN_CONNECTIONS to auto-start them:
-e SWAN_CONNECTIONS=site1,site2,site3-e TG_NAMESERVERS=8.8.8.8,1.1.1.1- TailGuard - Bridges WireGuard and Tailscale (inspiration for this project)
Contributions are welcome! Please feel free to submit issues or pull requests.
See LICENSE file for details.
