Giter VIP home page Giter VIP logo

tailscale-lb's Introduction

Tailscale Load Balancer

This project is a basic load-balancer for forwarding Tailscale TCP traffic. This is useful for setting up virtual IPs for services on Tailscale.

Status

This project is largely a proof-of-concept/prototype. Having virtual IPs for services on Tailscale has been discussed upstream and may land eventually, but I had an immediate need for this on my own Tailnet.

I'm sharing the code for this in the interest of sharing the results of my experimentation, but I don't have a ton of time to spare for this particular project. Bugfixes welcome, but don't expect huge feature development or production-readiness. If you find this program useful, consider sponsoring me!

Installation

tailscale-lb is distributed as a Docker image:

docker pull ghcr.io/zombiezen/tailscale-lb

You can check out the available tags on GitHub Container Registry.

Alternatively, if you're using Nix, you can install the binary by checking out the repository and running the following:

nix-env --file . --install

Or if you're using Nix flakes:

nix profile install github:zombiezen/tailscale-lb

If you are deploying to Kubernetes, example manifests are provided in the deploy folder that can also be built with kustomize. Make sure to update the value of TAILSCALE_AUTH_KEY in secret.yaml to be an authentication key that you have generated from your Tailscale Console.

kubectl apply -k deploy

Usage

Create a configuration file:

# This is the hostname that will show up in the Tailscale console
# and be used by MagicDNS.
hostname = example
# (Optional) Use an authentication key from https://login.tailscale.com/admin/settings/keys
# If you don't provide an auth key,
# tailscale-lb will log a URL to visit in your browser to authenticate it.
auth-key = tskey-foo
# (Optional) If given, the load balancer will be non-ephemeral
# and persist state in the given directory.
# If the path is relative, it resolved relative to
# the directory the configuration file is located in.
state-directory = /var/lib/tailscale-lb

# For each port you want to listen on,
# add a section like this:
[tcp 22]
# ... and then add one or more backends.
# tailscale-lb will round-robin TCP connections
# among the various IP addresses it discovers.
# A backend can be one of:

# a) An IPv4 address. If the port is omitted, then the section's port is used.
backend = 127.0.0.1:22

# b) An IPv6 address. If the port is omitted, then the section's port is used.
backend = [2001:db8::1234]:22

# c) A DNS name. If the port is omitted, then the section's port is used.
backend = example.com:22

# d) SRV records. The port is obtained from the SRV record.
# Priority and weight are ignored.
backend = srv _ssh._tcp.example.com

# For each HTTP port you want to listen on,
# add a section like this:
[http 80]

# Backends are specified the same as above.
backend = 127.0.0.1:80

# Add the following request headers (default true):
# Tailscale-User: The connecting user's email address
# Tailscale-Name: The connecting user's display name
# Tailscale-Profile-Picture: A URL to the connecting user's profile picture
whois = true
# Use the MagicDNS HTTPS Certificates described in https://tailscale.com/kb/1153/enabling-https/
# (default false)
tls = false
# Whether to use the request-supplied X-Forwarded-For (default false).
trust-x-forwarded-for = false

Then run tailscale-lb with the configuration file as its argument. If you're using Docker:

docker run --rm \
  --volume "$(pwd)/foo.ini":/etc/tailscale-lb.ini \
  ghcr.io/zombiezen/tailscale-lb /etc/tailscale-lb.ini

Or if you're using a standalone binary:

tailscale-lb foo.ini

You can then see the load balancer's IP address in the logs or in the Tailscale admin console.

License

Apache 2.0

tailscale-lb's People

Contributors

zombiezen avatar gaffneyd4 avatar

Stargazers

Krisztián Szabó  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.