A small, dependency-free toolkit for putting machines you don't fully trust (GPU pods, CI runners, containers) on your Tailscale tailnet, then cleaning them up. It works from Python, Bash and the command line, and it is the sibling of runpodkit.
- Mint safe auth keys: single-use, pre-approved, short-lived (15 min by default), ephemeral or tagged.
- Join a container:
pod/bootstrap.shruns tailscaled in userspace mode (no TUN device). The key goes to tailscale through a 0600 file, never argv, and is never printed. - Find, wait for, and remove devices by hostname. Tailscale's
-1duplicate suffixes are handled. - Verify revocation properly. The API keeps revoked keys readable (HTTP 200 with
"invalid": true), so tailscalekit checks the flag, not the status code. - Check your policy for the default allow-everything ACL before you expose a service.
pipx install tailscalekit # CLI
python3 -m pip install tailscalekit # library, inside a venvFor development, clone it and run ./install.sh python3, which links the clone into an interpreter so git pull updates every user on the host. That link carries no package metadata, so a package that declares tailscalekit as a dependency should use the pip install above.
tailscalekit reads credentials from the environment only. There are no key flags, so a credential never lands in argv or shell history.
| Variables | Use |
|---|---|
TS_OAUTH_CLIENT_ID + TS_OAUTH_CLIENT_SECRET |
Recommended. An OAuth client scoped to auth_keys (write) and devices:core (read/write), plus policy_file (read) for policy-check. It doesn't expire and can only do what you scoped. Keys minted with it must carry a tag. |
TS_API_KEY |
A personal API key (tskey-api-…). Simpler, but it is full-admin and expires within 90 days. |
TS_TAILNET |
Tailnet name; defaults to - (the credential's own tailnet). |
Letting an AI coding agent drive this? Store the credential in cred-broker and run cred exec tailscale -- tailscalekit …. The agent uses the credential without ever seeing it.
Put a container on the tailnet
# on your machine: mint a single-use key for one container (expires in 15 minutes)
KEY=$(tailscalekit authkey --tag tag:llm-starter)
# in the container (image with curl; static tailscale is downloaded and sha256-checked if missing)
TS_AUTHKEY="$KEY" TS_HOSTNAME=llm-pod1 bash "$(tailscalekit pod-bootstrap)"
# TAILSCALEKIT TAILNET_UP ip=100.x.y.z hostname=llm-pod1
# back on your machine
tailscalekit wait-online llm-pod1 # prints the tailnet IP once it is connected
tailscalekit delete llm-pod1 # when you're donePython
from tailscalekit import Tailscale, device_ip
ts = Tailscale() # env credentials
key = ts.create_auth_key(tags=["tag:llm-starter"], expiry_seconds=600)
# … hand key["key"] to the machine (e.g. as a pod environment variable) …
device = ts.wait_online("llm-pod1", timeout=300)
print(device_ip(device))
ts.revoke_key(key["id"]); assert ts.key_revoked(key["id"])Bash
. "$(tailscalekit bash-lib)"
ip=$(ts_wait_online llm-pod1 300) && curl "http://$ip:11434/api/tags"
ts_delete llm-pod1The default Tailscale policy lets every device reach every other device. If the machine you add runs a service with no authentication of its own (an Ollama server, a Jupyter kernel), anyone on the tailnet can use it. And if that machine is compromised, it can reach your laptop and NAS. tailscalekit policy-check prints default-allow when that is the case. A minimal policy for one tagged service:
Merge this into your existing policy rather than replacing it. Minting a tagged key fails with HTTP 400 ("not permitted") until the minting identity owns the tag.
| Method | Result |
|---|---|
list_devices() |
All devices (dicts) |
find_device(hostname, created_after=None, tag=None) |
Newest exact match (then hostname-N duplicates), or None |
get_device(id) / delete_device(id) |
Device or None on 404 / HTTP status (404 = already gone) |
create_auth_key(reusable=False, ephemeral=True, preauthorized=True, tags=None, expiry_seconds=900, description="tailscalekit") |
{"id", "key", "expires", …}; the only copy of the key |
list_keys() / get_key(id) |
Key metadata, never values |
revoke_key(id) / key_revoked(id) |
HTTP status / True once the key is unusable |
get_policy() |
The tailnet policy as JSON |
wait_online(hostname, timeout=240, poll=5, created_after=None, tag=None) |
The device once connectedToControl with an IP; retries transport errors, 429 and 5xx; raises TailscaleTimeoutError |
Helpers: device_ip(device, version=4), public_device(device) (drops node, machine and lock keys), policy_allows_all(policy), redact(text, *secrets) (removes every tskey-…).
| Command | Output | Exit |
|---|---|---|
devices [--all-fields] |
JSON; node, machine and lock keys hidden by default | 0 |
device HOST|ID [--all-fields] |
Device JSON | 0, or 3 if not found |
ip HOST|ID [--ipv6] |
Tailnet IP | 0, or 3 if not found |
authkey [--tag T]… [--reusable] [--no-ephemeral] [--no-preauthorized] [--expiry S] [--description D] [--json] |
The key, or {"id","key","expires"} |
0 |
keys |
Key metadata JSON | 0 |
revoke KEYID |
HTTP status; then verifies the key is invalid | 0, or 1 if still valid |
delete HOST|ID |
HTTP status | 0, or 3 if not found |
wait-online HOST [--timeout N] [--after ISO] [--tag T] [--json] |
IP or device JSON | 0, or 3 on timeout |
policy-check |
default-allow or restricted |
0 |
bash-lib / pod-bootstrap / version / --version |
Path / path / version | 0 |
All commands also use 1 for errors (one tailscalekit: line on stderr, secrets redacted), 2 for usage errors, and 130 on Ctrl-C.
ts_authkey [flags], ts_ip HOST, ts_wait_online HOST [TIMEOUT], ts_delete HOST (an already-missing device counts as success), ts_revoke KEYID. Credentials are exported only inside the CLI's subshell. The library is safe under set -uo pipefail and works on Bash 3.2.
| Variable | Default | Meaning |
|---|---|---|
TS_AUTHKEY |
– | Used only if the node isn't already authenticated; unset immediately and passed via a 0600 file |
TS_HOSTNAME |
$RUNPOD_POD_ID, else hostname |
Tailnet hostname |
TS_STATE_DIR |
/workspace/tailscale |
Keep it on a persistent volume so a restarted container rejoins without a new key |
TS_VERSION |
1.104.7 |
Static build to install if tailscale is missing (sha256-pinned for amd64) |
Ephemeral vs. tagged: an ephemeral node vanishes shortly after it goes offline, which suits throwaway runs. A tagged, non-ephemeral node (--no-ephemeral --tag …) keeps its identity across stop/start through the saved state, and tagged devices don't hit key expiry. Delete it explicitly when you're done.
- Keys come from the environment only. Error output redacts the configured secret and any
tskey-…token. - A key given to a machine should be assumed readable by whoever controls that machine's platform. Single-use, short expiry and revoke-after-join keep the blast radius small.
authkeyprints the minted key, on purpose: piping it to a machine is its job.- Tests are offline; every unmocked network call fails the test.
python3 -m unittest discover -s tests -v
TAILSCALEKIT_TEST_BASHES=/path/to/bash3.2:/bin/bash python3 -m unittest tests.test_bash -vMIT. See LICENSE. Not affiliated with or endorsed by Tailscale Inc.
{ "tagOwners": { "tag:llm-starter": ["autogroup:admin"] }, "grants": [ // your own devices may reach the service port on tagged machines… { "src": ["autogroup:member"], "dst": ["tag:llm-starter"], "ip": ["tcp:11434"] } // …and nothing is granted FROM tag:llm-starter, so the pod can't reach your devices. ] }