Tailscale is a VPN service that creates secure, private networks between your devices and applications. By integrating Tailscale with your Upsun applications, you can make your containers part of a “tailnet” - Tailscale’s term for their private networks. This guide demonstrates how you can leverage Tailscale to connect to external endpoints over a secure network. An example Go application will be added as a placeholder and example for your own application. This setup enables secure communication between your application and other resources in your tailnet.Documentation Index
Fetch the complete documentation index at: https://developer.upsun.com/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
Before starting, you’ll need:- A Tailscale account with an auth key
- Basic familiarity with Upsun configuration
- Understanding of Go applications
Tailscale implementation limitations
Tailscale usually relies on a specific tunnel networking device (tun0) to route traffic from their machine to their network. Because Upsun run containers directly, a userspace application can’t add a new network interface. To work around this limitation, Tailscale can be started as a HTTP proxy to the tailnet. Our example application will connect to the external endpoints via this exposed HTTP proxy.
Create a basic Go application
Start by creating a simple Go application. Create ago.mod file:
main.go file:
.upsun/config.yaml:
Configure multiple processes with Supervisor
Since Upsun’sweb.commands.start is designed to run only one process, you will use Supervisor to start and manage both your application and the Tailscale daemon processes. Update your .upsun/config.yaml:
supervisor.conf file to manage your processes:
Download and configure Tailscale
The easiest way to run Tailscale is to download and run theamd64 binary directly. Create a script to download Tailscale and cache it between builds. Create scripts/download-tailscale.sh:
.upsun/config.yaml to use this script:
Add Tailscale daemon to Supervisor
Update yoursupervisor.conf file to include the Tailscale daemon:
--state=mem:creates a new Tailscale client on each restart. For persistent clients, use a file on a mount instead--outbound-http-proxy-listen=0.0.0.0:8080exposes the VPN through an HTTP proxy on port 8080--socks5-server=0.0.0.0:1080provides SOCKS5 proxy access on port 1080
Connect to your tailnet
After the Tailscale daemon starts, you need to runtailscale up to join your tailnet. You could add this to your post_start command:
tailscaled daemon needs time to start, causing tailscale up to fail. Instead, create a scripts/tailscale-up.sh script that waits for the daemon:
Set up authentication
Create an environment variable with your Tailscale authentication key:Using your tailnet connection
Outbound connections
To connect to resources in your tailnet from your application, use the HTTP proxy on port 8080:Inbound connections
Your application becomes immediately accessible from other devices in your tailnet. To expose additional services like databases, use tools likesocat to forward traffic:
Next steps
With Tailscale running on Upsun, you can:- Connect securely to your application from any device in your tailnet
- Access private databases and services through your application
- Create secure communication channels between multiple Upsun applications
- Implement zero-trust networking for your infrastructure