Run Tailscale on a Heroku dyno.
This buildpack installs and configures Tailscale in userspace networking mode so that it is able to run on a Heroku dyno. A SOCKS5 proxy is available at localhost:1055
to provide access to a tailnet.
To set up your Heroku application:
-
Add the buildpack to your app with
heroku buildpacks:add https://github.com/ynab/heroku-tailscale-buildpack --app your-app-name
-
Obtain a Tailscale Auth key and set the environment variable
TAILSCALE_AUTH_KEY
using its value:heroku config:set TAILSCALE_AUTH_KEY="your-auth-key-or-oauth-secret" --app your-app-name
⚠ Note: You may also provide an OAuth Client Secret for the
TAILSCALE_AUTH_KEY
value but when doing so, you must also specify at least one tag to assign using the configTAILSCALE_ADVERTISE_TAGS
. -
Configure your application to use the Tailscale network by sending network requests through the SOCKS5 proxy listening at
127.0.0.1:1005
. If any of the following apply to your app, no changes will need to be made:- Your app reads and respects the environment variable
ALL_PROXY
. - You are using a Ruby on Rails app and calling
bundle exec ...
,rake ...
, orrails ...
to start your app. This buildpack will automatically configure the environment to use the SOCKS proxy by configuring a ProxyChains passthrough script for these scripts.
⚠ Note: If you are not able to configure your application to send requests through a SOCKS5 proxy, you will need to use ProxyChains. See additional instructions below.
- Your app reads and respects the environment variable
-
Push a change to your Heroku app to build and deploy a new version
The buildpack pre-installs ProxyChains which is a program that forces any TCP connection made by an application through a proxy like SOCKS5. Usage of ProxyChains is only necessary if your application does not support SOCKS5 proxies natively.
To use ProxyChains, update your Procfile
to prefix your command(s) with bin/tailscale_proxy
. For example, if you are using Django and Celery, your Procfile
might look like this:
web: bin/tailscale_proxy uvicorn --host 0.0.0.0 --port "$PORT" myproject.project.asgi:application
worker: bin/tailscale_proxy celery -A myproject.project worker
If the TAILSCALE_AUTH_KEY
environment variable is set, the bin/tailscale_proxy
script will configure the application to use ProxyChains. Otherwise, the application will be run without ProxyChains.
- Connecting via tailnet hostnames is not supported. You must use the tailnet IP address of the target machine.
To test a connection, you can add the hello.ts.net
machine into your network,
follow the instructions here. Once this machine is added to your network, you can test the connection by running:
heroku run heroku-tailscale-test.sh --app your-app-name
You should see curl respond with <a href="https://hello.ts.net">Found</a>.
The following settings are available for configuration via environment variables:
TAILSCALE_AUTH_KEY
- Provide an Auth key for authentication. You may alternatively provide an OAuth Client Secret but you must also set theTAILSCALE_ADVERTISE_TAGS
environment variable. This must be set.TAILSCALE_ADVERTISE_TAGS
- Tags to assign to this device. Each tag name should be prefixed withtag:
and multiple tags should be delimited with a comma. For example, if you wanted to assign the tagsdevelopment-database
anddevelopment-server
you would specify the valuetag:development-database,tag:development-server
. If theTAILSCALE_AUTH_KEY
is an OAuth Client Secret, this value is required.TAILSCALE_HOSTNAME
- Provide a hostname to use for the device instead of the one provided by the OS. Note that this will change the machine name used in MagicDNS. Defaults to the hostname of the application (a guid). If you have Heroku Labs runtime-dyno-metadata enabled, it defaults to[appname]-[commit]-[dyno]
.TAILSCALE_ADDITIONAL_ARGS
- Additional arguments to pass when runningtailscale up
. See https://tailscale.com/kb/1080/cli for details.
Note: --accept-routes
is always passed to tailscale up
to ensure that any advertized routes are accepted by the Tailscale client.
This approach is based on Tailscale Heroku/Docker docs here: https://tailscale.com/kb/1107/heroku/ but has been adapted for use as a Heroku buildpack.
Thank you to @rdotts, @kongmadai, @mvisonneau for the work on tailscale-docker and tailscale-heroku.
Thank you @tim-schilling for the work on the original heroku-tailscale-buildpack repo from which this repo was forked.