tailscalekit 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. tailscalekit-0.1.0/CHANGELOG.md +13 -0
  2. tailscalekit-0.1.0/CONTRIBUTING.md +36 -0
  3. tailscalekit-0.1.0/LICENSE +21 -0
  4. tailscalekit-0.1.0/MANIFEST.in +3 -0
  5. tailscalekit-0.1.0/PKG-INFO +189 -0
  6. tailscalekit-0.1.0/README.md +158 -0
  7. tailscalekit-0.1.0/SECURITY.md +18 -0
  8. tailscalekit-0.1.0/install.sh +137 -0
  9. tailscalekit-0.1.0/pyproject.toml +47 -0
  10. tailscalekit-0.1.0/setup.cfg +4 -0
  11. tailscalekit-0.1.0/tailscalekit/__init__.py +18 -0
  12. tailscalekit-0.1.0/tailscalekit/__main__.py +3 -0
  13. tailscalekit-0.1.0/tailscalekit/cli.py +240 -0
  14. tailscalekit-0.1.0/tailscalekit/client.py +436 -0
  15. tailscalekit-0.1.0/tailscalekit/lib/tailscale.sh +62 -0
  16. tailscalekit-0.1.0/tailscalekit/pod/bootstrap.sh +75 -0
  17. tailscalekit-0.1.0/tailscalekit.egg-info/PKG-INFO +189 -0
  18. tailscalekit-0.1.0/tailscalekit.egg-info/SOURCES.txt +31 -0
  19. tailscalekit-0.1.0/tailscalekit.egg-info/dependency_links.txt +1 -0
  20. tailscalekit-0.1.0/tailscalekit.egg-info/entry_points.txt +2 -0
  21. tailscalekit-0.1.0/tailscalekit.egg-info/top_level.txt +1 -0
  22. tailscalekit-0.1.0/tests/fixtures/devices.json +114 -0
  23. tailscalekit-0.1.0/tests/fixtures/key_active.json +18 -0
  24. tailscalekit-0.1.0/tests/fixtures/key_created.json +19 -0
  25. tailscalekit-0.1.0/tests/fixtures/key_revoked.json +20 -0
  26. tailscalekit-0.1.0/tests/fixtures/keys.json +35 -0
  27. tailscalekit-0.1.0/tests/fixtures/policy_default.json +14 -0
  28. tailscalekit-0.1.0/tests/fixtures/policy_restricted.json +20 -0
  29. tailscalekit-0.1.0/tests/helpers.py +145 -0
  30. tailscalekit-0.1.0/tests/test_bash.py +243 -0
  31. tailscalekit-0.1.0/tests/test_cli.py +187 -0
  32. tailscalekit-0.1.0/tests/test_client.py +430 -0
  33. tailscalekit-0.1.0/tests/test_install.py +212 -0
@@ -0,0 +1,13 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here. Versions follow [Semantic Versioning](https://semver.org/).
4
+
5
+ ## [Unreleased]
6
+
7
+ ## [0.1.0] - 2026-12-02
8
+
9
+ - First release: `Tailscale` client (API key or OAuth client), devices (list/find/get/delete), auth keys (mint with safe defaults, list, get, revoke, verify revocation via `invalid`), policy fetch and default-allow check, `wait_online`.
10
+ - `tailscalekit` CLI, Bash library (Bash 3.2+), and a container `pod-bootstrap` script (userspace tailscaled, key via 0600 file, sha256-pinned static install).
11
+
12
+ [Unreleased]: https://github.com/kcherry497/tailscale-kit/compare/v0.1.0...HEAD
13
+ [0.1.0]: https://github.com/kcherry497/tailscale-kit/releases/tag/v0.1.0
@@ -0,0 +1,36 @@
1
+ # Contributing to tailscalekit
2
+
3
+ Thanks for helping. A few ground rules keep this toolkit small and safe to depend on.
4
+
5
+ ## Ground rules
6
+
7
+ - **Standard library only.** No runtime dependencies. Tests use `unittest`.
8
+ - **Python 3.9+ and Bash 3.2+.** The Bash library has to keep working on the macOS system Bash.
9
+ - **Offline tests for every behavior change.** HTTP is mocked; the suite must never touch the real Tailscale API.
10
+ - **Key safety is a feature.** Minted keys default to single-use, short-lived and pre-approved; keys never go in argv, logs or error text, and revocation is verified with the `invalid` flag.
11
+ - **Never log or print the API key.** Keys come from the environment only, never argv.
12
+
13
+ ## Development
14
+
15
+ ```bash
16
+ git clone https://github.com/kcherry497/tailscale-kit.git
17
+ cd tailscale-kit
18
+ python3 -m unittest discover -s tests -v
19
+ ```
20
+
21
+ To run the shell tests under several Bash builds (for example a Bash 3.2 binary), pass absolute paths:
22
+
23
+ ```bash
24
+ TAILSCALEKIT_TEST_BASHES=/path/to/bash3.2:/bin/bash python3 -m unittest discover -s tests -v
25
+ ```
26
+
27
+ ## Pull requests
28
+
29
+ 1. Open an issue first for anything larger than a small fix.
30
+ 2. Keep each PR focused, with tests.
31
+ 3. Add a line under an "Unreleased" heading in `CHANGELOG.md`.
32
+ 4. CI must pass on every Python version and under Bash 3.2.57. The separate macOS workflow should pass too; it can lag when GitHub's macOS runners are busy.
33
+
34
+ ## Reporting Tailscale API changes
35
+
36
+ If the Tailscale API changes shape, an issue with a redacted response body (strip keys, node keys and anything identifying) is the most useful report you can file.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kevin Cherry
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,3 @@
1
+ include LICENSE README.md CHANGELOG.md CONTRIBUTING.md SECURITY.md install.sh
2
+ graft tests
3
+ global-exclude __pycache__ *.py[cod]
@@ -0,0 +1,189 @@
1
+ Metadata-Version: 2.4
2
+ Name: tailscalekit
3
+ Version: 0.1.0
4
+ Summary: Dependency-free Tailscale API control for Python, Bash and the CLI: devices, single-use auth keys, container join
5
+ Author: Kevin Cherry
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/kcherry497/tailscale-kit
8
+ Project-URL: Issues, https://github.com/kcherry497/tailscale-kit/issues
9
+ Project-URL: Changelog, https://github.com/kcherry497/tailscale-kit/blob/main/CHANGELOG.md
10
+ Keywords: tailscale,vpn,wireguard,auth-keys,containers,cli
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: POSIX
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: Python :: 3.14
23
+ Classifier: Programming Language :: Python :: 3.15
24
+ Classifier: Programming Language :: Unix Shell
25
+ Classifier: Topic :: System :: Networking
26
+ Classifier: Topic :: System :: Systems Administration
27
+ Requires-Python: >=3.9
28
+ Description-Content-Type: text/markdown
29
+ License-File: LICENSE
30
+ Dynamic: license-file
31
+
32
+ # tailscalekit
33
+
34
+ [![CI](https://github.com/kcherry497/tailscale-kit/actions/workflows/ci.yml/badge.svg)](https://github.com/kcherry497/tailscale-kit/actions/workflows/ci.yml)
35
+ ![Python 3.9 – 3.15](https://img.shields.io/badge/python-3.9%20%E2%80%93%203.15-3776AB?logo=python&logoColor=white)
36
+ ![Bash 3.2+](https://img.shields.io/badge/bash-3.2%2B-4EAA25?logo=gnubash&logoColor=white)
37
+ ![Zero dependencies](https://img.shields.io/badge/dependencies-0-brightgreen)
38
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue)](LICENSE)
39
+
40
+ A small, dependency-free toolkit for putting machines you don't fully trust (GPU pods, CI runners, containers) on your [Tailscale](https://tailscale.com/) tailnet, then cleaning them up. It works from Python, Bash and the command line, and it is the sibling of [runpodkit](https://github.com/kcherry497/runpod-kit).
41
+
42
+ - **Mint safe auth keys:** single-use, pre-approved, short-lived (15 min by default), ephemeral or tagged.
43
+ - **Join a container:** `pod/bootstrap.sh` runs tailscaled in userspace mode (no TUN device). The key goes to tailscale through a 0600 file, **never argv**, and is never printed.
44
+ - **Find, wait for, and remove devices** by hostname. Tailscale's `-1` duplicate suffixes are handled.
45
+ - **Verify revocation properly.** The API keeps revoked keys readable (HTTP 200 with `"invalid": true`), so tailscalekit checks the flag, not the status code.
46
+ - **Check your policy** for the default allow-everything ACL before you expose a service.
47
+
48
+ ## Install
49
+
50
+ ```bash
51
+ pipx install tailscalekit # CLI
52
+ python3 -m pip install tailscalekit # library, inside a venv
53
+ ```
54
+
55
+ For 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.
56
+
57
+ ## Credentials
58
+
59
+ tailscalekit reads credentials from the environment only. There are no key flags, so a credential never lands in argv or shell history.
60
+
61
+ | Variables | Use |
62
+ | --- | --- |
63
+ | `TS_OAUTH_CLIENT_ID` + `TS_OAUTH_CLIENT_SECRET` | **Recommended.** An [OAuth client](https://tailscale.com/kb/1215/oauth-clients) 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. |
64
+ | `TS_API_KEY` | A personal API key (`tskey-api-…`). Simpler, but it is full-admin and expires within 90 days. |
65
+ | `TS_TAILNET` | Tailnet name; defaults to `-` (the credential's own tailnet). |
66
+
67
+ Letting an AI coding agent drive this? Store the credential in [cred-broker](https://github.com/kcherry497/cred-broker) and run `cred exec tailscale -- tailscalekit …`. The agent uses the credential without ever seeing it.
68
+
69
+ ## Quick start
70
+
71
+ **Put a container on the tailnet**
72
+
73
+ ```bash
74
+ # on your machine: mint a single-use key for one container (expires in 15 minutes)
75
+ KEY=$(tailscalekit authkey --tag tag:llm-starter)
76
+
77
+ # in the container (image with curl; static tailscale is downloaded and sha256-checked if missing)
78
+ TS_AUTHKEY="$KEY" TS_HOSTNAME=llm-pod1 bash "$(tailscalekit pod-bootstrap)"
79
+ # TAILSCALEKIT TAILNET_UP ip=100.x.y.z hostname=llm-pod1
80
+
81
+ # back on your machine
82
+ tailscalekit wait-online llm-pod1 # prints the tailnet IP once it is connected
83
+ tailscalekit delete llm-pod1 # when you're done
84
+ ```
85
+
86
+ **Python**
87
+
88
+ ```python
89
+ from tailscalekit import Tailscale, device_ip
90
+
91
+ ts = Tailscale() # env credentials
92
+ key = ts.create_auth_key(tags=["tag:llm-starter"], expiry_seconds=600)
93
+ # … hand key["key"] to the machine (e.g. as a pod environment variable) …
94
+ device = ts.wait_online("llm-pod1", timeout=300)
95
+ print(device_ip(device))
96
+ ts.revoke_key(key["id"]); assert ts.key_revoked(key["id"])
97
+ ```
98
+
99
+ **Bash**
100
+
101
+ ```bash
102
+ . "$(tailscalekit bash-lib)"
103
+ ip=$(ts_wait_online llm-pod1 300) && curl "http://$ip:11434/api/tags"
104
+ ts_delete llm-pod1
105
+ ```
106
+
107
+ ## Lock it down: the tailnet policy
108
+
109
+ The 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:
110
+
111
+ ```jsonc
112
+ {
113
+ "tagOwners": { "tag:llm-starter": ["autogroup:admin"] },
114
+ "grants": [
115
+ // your own devices may reach the service port on tagged machines…
116
+ { "src": ["autogroup:member"], "dst": ["tag:llm-starter"], "ip": ["tcp:11434"] }
117
+ // …and nothing is granted FROM tag:llm-starter, so the pod can't reach your devices.
118
+ ]
119
+ }
120
+ ```
121
+
122
+ 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.
123
+
124
+ ## Reference
125
+
126
+ ### Python (`tailscalekit.Tailscale`)
127
+
128
+ | Method | Result |
129
+ | --- | --- |
130
+ | `list_devices()` | All devices (dicts) |
131
+ | `find_device(hostname, created_after=None, tag=None)` | Newest exact match (then `hostname-N` duplicates), or `None` |
132
+ | `get_device(id)` / `delete_device(id)` | Device or `None` on 404 / HTTP status (404 = already gone) |
133
+ | `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 |
134
+ | `list_keys()` / `get_key(id)` | Key metadata, never values |
135
+ | `revoke_key(id)` / `key_revoked(id)` | HTTP status / `True` once the key is unusable |
136
+ | `get_policy()` | The tailnet policy as JSON |
137
+ | `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` |
138
+
139
+ 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-…`).
140
+
141
+ ### CLI
142
+
143
+ | Command | Output | Exit |
144
+ | --- | --- | --- |
145
+ | `devices [--all-fields]` | JSON; node, machine and lock keys hidden by default | 0 |
146
+ | `device HOST\|ID [--all-fields]` | Device JSON | 0, or 3 if not found |
147
+ | `ip HOST\|ID [--ipv6]` | Tailnet IP | 0, or 3 if not found |
148
+ | `authkey [--tag T]… [--reusable] [--no-ephemeral] [--no-preauthorized] [--expiry S] [--description D] [--json]` | The key, or `{"id","key","expires"}` | 0 |
149
+ | `keys` | Key metadata JSON | 0 |
150
+ | `revoke KEYID` | HTTP status; then verifies the key is invalid | 0, or 1 if still valid |
151
+ | `delete HOST\|ID` | HTTP status | 0, or 3 if not found |
152
+ | `wait-online HOST [--timeout N] [--after ISO] [--tag T] [--json]` | IP or device JSON | 0, or 3 on timeout |
153
+ | `policy-check` | `default-allow` or `restricted` | 0 |
154
+ | `bash-lib` / `pod-bootstrap` / `version` / `--version` | Path / path / version | 0 |
155
+
156
+ All commands also use 1 for errors (one `tailscalekit:` line on stderr, secrets redacted), 2 for usage errors, and 130 on Ctrl-C.
157
+
158
+ ### Bash library
159
+
160
+ `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.
161
+
162
+ ### Pod bootstrap (`tailscalekit pod-bootstrap`)
163
+
164
+ | Variable | Default | Meaning |
165
+ | --- | --- | --- |
166
+ | `TS_AUTHKEY` | – | Used only if the node isn't already authenticated; unset immediately and passed via a 0600 file |
167
+ | `TS_HOSTNAME` | `$RUNPOD_POD_ID`, else `hostname` | Tailnet hostname |
168
+ | `TS_STATE_DIR` | `/workspace/tailscale` | Keep it on a persistent volume so a restarted container rejoins without a new key |
169
+ | `TS_VERSION` | `1.104.7` | Static build to install if tailscale is missing (sha256-pinned for amd64) |
170
+
171
+ 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.
172
+
173
+ ## Security notes
174
+
175
+ - Keys come from the environment only. Error output redacts the configured secret and **any** `tskey-…` token.
176
+ - 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.
177
+ - `authkey` prints the minted key, on purpose: piping it to a machine is its job.
178
+ - Tests are offline; every unmocked network call fails the test.
179
+
180
+ ## Development
181
+
182
+ ```bash
183
+ python3 -m unittest discover -s tests -v
184
+ TAILSCALEKIT_TEST_BASHES=/path/to/bash3.2:/bin/bash python3 -m unittest tests.test_bash -v
185
+ ```
186
+
187
+ ## License
188
+
189
+ MIT. See [LICENSE](LICENSE). Not affiliated with or endorsed by Tailscale Inc.
@@ -0,0 +1,158 @@
1
+ # tailscalekit
2
+
3
+ [![CI](https://github.com/kcherry497/tailscale-kit/actions/workflows/ci.yml/badge.svg)](https://github.com/kcherry497/tailscale-kit/actions/workflows/ci.yml)
4
+ ![Python 3.9 – 3.15](https://img.shields.io/badge/python-3.9%20%E2%80%93%203.15-3776AB?logo=python&logoColor=white)
5
+ ![Bash 3.2+](https://img.shields.io/badge/bash-3.2%2B-4EAA25?logo=gnubash&logoColor=white)
6
+ ![Zero dependencies](https://img.shields.io/badge/dependencies-0-brightgreen)
7
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue)](LICENSE)
8
+
9
+ A small, dependency-free toolkit for putting machines you don't fully trust (GPU pods, CI runners, containers) on your [Tailscale](https://tailscale.com/) tailnet, then cleaning them up. It works from Python, Bash and the command line, and it is the sibling of [runpodkit](https://github.com/kcherry497/runpod-kit).
10
+
11
+ - **Mint safe auth keys:** single-use, pre-approved, short-lived (15 min by default), ephemeral or tagged.
12
+ - **Join a container:** `pod/bootstrap.sh` runs tailscaled in userspace mode (no TUN device). The key goes to tailscale through a 0600 file, **never argv**, and is never printed.
13
+ - **Find, wait for, and remove devices** by hostname. Tailscale's `-1` duplicate suffixes are handled.
14
+ - **Verify revocation properly.** The API keeps revoked keys readable (HTTP 200 with `"invalid": true`), so tailscalekit checks the flag, not the status code.
15
+ - **Check your policy** for the default allow-everything ACL before you expose a service.
16
+
17
+ ## Install
18
+
19
+ ```bash
20
+ pipx install tailscalekit # CLI
21
+ python3 -m pip install tailscalekit # library, inside a venv
22
+ ```
23
+
24
+ For 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.
25
+
26
+ ## Credentials
27
+
28
+ tailscalekit reads credentials from the environment only. There are no key flags, so a credential never lands in argv or shell history.
29
+
30
+ | Variables | Use |
31
+ | --- | --- |
32
+ | `TS_OAUTH_CLIENT_ID` + `TS_OAUTH_CLIENT_SECRET` | **Recommended.** An [OAuth client](https://tailscale.com/kb/1215/oauth-clients) 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. |
33
+ | `TS_API_KEY` | A personal API key (`tskey-api-…`). Simpler, but it is full-admin and expires within 90 days. |
34
+ | `TS_TAILNET` | Tailnet name; defaults to `-` (the credential's own tailnet). |
35
+
36
+ Letting an AI coding agent drive this? Store the credential in [cred-broker](https://github.com/kcherry497/cred-broker) and run `cred exec tailscale -- tailscalekit …`. The agent uses the credential without ever seeing it.
37
+
38
+ ## Quick start
39
+
40
+ **Put a container on the tailnet**
41
+
42
+ ```bash
43
+ # on your machine: mint a single-use key for one container (expires in 15 minutes)
44
+ KEY=$(tailscalekit authkey --tag tag:llm-starter)
45
+
46
+ # in the container (image with curl; static tailscale is downloaded and sha256-checked if missing)
47
+ TS_AUTHKEY="$KEY" TS_HOSTNAME=llm-pod1 bash "$(tailscalekit pod-bootstrap)"
48
+ # TAILSCALEKIT TAILNET_UP ip=100.x.y.z hostname=llm-pod1
49
+
50
+ # back on your machine
51
+ tailscalekit wait-online llm-pod1 # prints the tailnet IP once it is connected
52
+ tailscalekit delete llm-pod1 # when you're done
53
+ ```
54
+
55
+ **Python**
56
+
57
+ ```python
58
+ from tailscalekit import Tailscale, device_ip
59
+
60
+ ts = Tailscale() # env credentials
61
+ key = ts.create_auth_key(tags=["tag:llm-starter"], expiry_seconds=600)
62
+ # … hand key["key"] to the machine (e.g. as a pod environment variable) …
63
+ device = ts.wait_online("llm-pod1", timeout=300)
64
+ print(device_ip(device))
65
+ ts.revoke_key(key["id"]); assert ts.key_revoked(key["id"])
66
+ ```
67
+
68
+ **Bash**
69
+
70
+ ```bash
71
+ . "$(tailscalekit bash-lib)"
72
+ ip=$(ts_wait_online llm-pod1 300) && curl "http://$ip:11434/api/tags"
73
+ ts_delete llm-pod1
74
+ ```
75
+
76
+ ## Lock it down: the tailnet policy
77
+
78
+ The 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:
79
+
80
+ ```jsonc
81
+ {
82
+ "tagOwners": { "tag:llm-starter": ["autogroup:admin"] },
83
+ "grants": [
84
+ // your own devices may reach the service port on tagged machines…
85
+ { "src": ["autogroup:member"], "dst": ["tag:llm-starter"], "ip": ["tcp:11434"] }
86
+ // …and nothing is granted FROM tag:llm-starter, so the pod can't reach your devices.
87
+ ]
88
+ }
89
+ ```
90
+
91
+ 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.
92
+
93
+ ## Reference
94
+
95
+ ### Python (`tailscalekit.Tailscale`)
96
+
97
+ | Method | Result |
98
+ | --- | --- |
99
+ | `list_devices()` | All devices (dicts) |
100
+ | `find_device(hostname, created_after=None, tag=None)` | Newest exact match (then `hostname-N` duplicates), or `None` |
101
+ | `get_device(id)` / `delete_device(id)` | Device or `None` on 404 / HTTP status (404 = already gone) |
102
+ | `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 |
103
+ | `list_keys()` / `get_key(id)` | Key metadata, never values |
104
+ | `revoke_key(id)` / `key_revoked(id)` | HTTP status / `True` once the key is unusable |
105
+ | `get_policy()` | The tailnet policy as JSON |
106
+ | `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` |
107
+
108
+ 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-…`).
109
+
110
+ ### CLI
111
+
112
+ | Command | Output | Exit |
113
+ | --- | --- | --- |
114
+ | `devices [--all-fields]` | JSON; node, machine and lock keys hidden by default | 0 |
115
+ | `device HOST\|ID [--all-fields]` | Device JSON | 0, or 3 if not found |
116
+ | `ip HOST\|ID [--ipv6]` | Tailnet IP | 0, or 3 if not found |
117
+ | `authkey [--tag T]… [--reusable] [--no-ephemeral] [--no-preauthorized] [--expiry S] [--description D] [--json]` | The key, or `{"id","key","expires"}` | 0 |
118
+ | `keys` | Key metadata JSON | 0 |
119
+ | `revoke KEYID` | HTTP status; then verifies the key is invalid | 0, or 1 if still valid |
120
+ | `delete HOST\|ID` | HTTP status | 0, or 3 if not found |
121
+ | `wait-online HOST [--timeout N] [--after ISO] [--tag T] [--json]` | IP or device JSON | 0, or 3 on timeout |
122
+ | `policy-check` | `default-allow` or `restricted` | 0 |
123
+ | `bash-lib` / `pod-bootstrap` / `version` / `--version` | Path / path / version | 0 |
124
+
125
+ All commands also use 1 for errors (one `tailscalekit:` line on stderr, secrets redacted), 2 for usage errors, and 130 on Ctrl-C.
126
+
127
+ ### Bash library
128
+
129
+ `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.
130
+
131
+ ### Pod bootstrap (`tailscalekit pod-bootstrap`)
132
+
133
+ | Variable | Default | Meaning |
134
+ | --- | --- | --- |
135
+ | `TS_AUTHKEY` | – | Used only if the node isn't already authenticated; unset immediately and passed via a 0600 file |
136
+ | `TS_HOSTNAME` | `$RUNPOD_POD_ID`, else `hostname` | Tailnet hostname |
137
+ | `TS_STATE_DIR` | `/workspace/tailscale` | Keep it on a persistent volume so a restarted container rejoins without a new key |
138
+ | `TS_VERSION` | `1.104.7` | Static build to install if tailscale is missing (sha256-pinned for amd64) |
139
+
140
+ 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.
141
+
142
+ ## Security notes
143
+
144
+ - Keys come from the environment only. Error output redacts the configured secret and **any** `tskey-…` token.
145
+ - 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.
146
+ - `authkey` prints the minted key, on purpose: piping it to a machine is its job.
147
+ - Tests are offline; every unmocked network call fails the test.
148
+
149
+ ## Development
150
+
151
+ ```bash
152
+ python3 -m unittest discover -s tests -v
153
+ TAILSCALEKIT_TEST_BASHES=/path/to/bash3.2:/bin/bash python3 -m unittest tests.test_bash -v
154
+ ```
155
+
156
+ ## License
157
+
158
+ MIT. See [LICENSE](LICENSE). Not affiliated with or endorsed by Tailscale Inc.
@@ -0,0 +1,18 @@
1
+ # Security policy
2
+
3
+ ## Supported versions
4
+
5
+ Security fixes go into the latest release.
6
+
7
+ ## Reporting a vulnerability
8
+
9
+ Please **do not** open a public issue for security problems. Use GitHub's private vulnerability reporting instead: **Security → Report a vulnerability** on this repository.
10
+
11
+ Things worth reporting include:
12
+
13
+ - any path where the API key could reach argv, logs, error messages, or output;
14
+ - any path where a minted auth key could reach argv, logs or output other than `authkey`'s intended stdout;
15
+ - any way `pod-bootstrap` could leave the key on disk or in a process environment;
16
+ - anything in `install.sh` that writes outside the documented locations.
17
+
18
+ You should get a reply within a few days.
@@ -0,0 +1,137 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ # Report all installation failures consistently.
5
+ die() {
6
+ printf 'install.sh: %s\n' "$*" >&2
7
+ exit 1
8
+ }
9
+
10
+ # Keep the invoked interpreter path intact, including venv symlinks.
11
+ resolve_python() {
12
+ local resolved directory
13
+ resolved=$(command -v -- "$1") || die "interpreter not found: $1"
14
+ [ -f "$resolved" ] && [ -x "$resolved" ] || die "interpreter not executable: $1"
15
+ directory=$(cd -- "$(dirname -- "$resolved")" && pwd -P) || die "cannot resolve interpreter: $1"
16
+ printf '%s/%s\n' "$directory" "$(basename -- "$resolved")"
17
+ }
18
+
19
+ # Validate the version and query installation metadata in one interpreter call.
20
+ python_info() {
21
+ "$1" -c 'import os, sys, sysconfig
22
+ if sys.version_info < (3, 9):
23
+ sys.exit(1)
24
+ in_venv = sys.prefix != sys.base_prefix
25
+ print(int(in_venv))
26
+ print(sysconfig.get_path("purelib"))
27
+ print(int(not in_venv and os.path.isfile(os.path.join(sysconfig.get_path("stdlib"), "EXTERNALLY-MANAGED"))))
28
+ ' || die "cannot inspect $1; Python >= 3.9 is required"
29
+ }
30
+
31
+ # Select only the venv site, writable unmanaged site, or interpreter user site.
32
+ pth_dir_for() {
33
+ local py=$1 in_venv=$2 purelib=$3 managed=$4 directory
34
+ if [ "$in_venv" = 1 ]; then
35
+ directory=$purelib
36
+ elif [ "$managed" = 0 ] && [ -d "$purelib" ] && [ -w "$purelib" ]; then
37
+ directory=$purelib
38
+ else
39
+ if [ "$managed" = 0 ]; then
40
+ printf 'install.sh: %s: purelib unavailable or not writable; using user site\n' "$py" >&2
41
+ fi
42
+ # The site CLI also returns a nonzero status when user sites are disabled.
43
+ if directory=$("$py" -m site --user-site); then
44
+ :
45
+ elif [ -z "$directory" ]; then
46
+ die "cannot determine user site for $py"
47
+ fi
48
+ fi
49
+ [ -n "$directory" ] || die "empty installation directory for $py"
50
+ mkdir -p -- "$directory" || die "cannot create directory: $directory"
51
+ [ -w "$directory" ] || die "directory not writable: $directory"
52
+ printf '%s\n' "$directory"
53
+ }
54
+
55
+ # Replace a destination with a complete, correctly permissioned sibling file.
56
+ write_atomic() {
57
+ local destination=$1 mode=$2 directory name temporary
58
+ directory=$(dirname -- "$destination")
59
+ name=$(basename -- "$destination")
60
+ [ ! -d "$destination" ] || die "destination is a directory: $destination"
61
+ temporary=$(mktemp "$directory/.$name.XXXXXX") || die "cannot create temporary file in $directory"
62
+ if ! cat > "$temporary" || ! chmod "$mode" "$temporary" || ! mv -f -- "$temporary" "$destination"; then
63
+ rm -f -- "$temporary"
64
+ die "cannot write $destination"
65
+ fi
66
+ }
67
+
68
+ # Quote literal paths for a POSIX shell, including embedded apostrophes.
69
+ shell_quote() {
70
+ local value=$1
71
+ value=${value//\'/\'\\\'\'}
72
+ printf "'%s'" "$value"
73
+ }
74
+
75
+ # Publish a launcher that works even when the selected site is disabled.
76
+ write_launcher() {
77
+ local directory=$1 py=$2
78
+ mkdir -p -- "$directory" || die "cannot create launcher directory: $directory"
79
+ directory=$(cd -- "$directory" && pwd -P) || die "cannot resolve launcher directory: $directory"
80
+ printf '%s\n' '#!/bin/sh' \
81
+ "PYTHONPATH=$(shell_quote "$repo_dir")\${PYTHONPATH:+:\$PYTHONPATH}" \
82
+ 'export PYTHONPATH' \
83
+ "exec $(shell_quote "$py") -m tailscalekit \"\$@\"" |
84
+ write_atomic "$directory/tailscalekit" 755
85
+ printf 'tailscalekit launcher: %s/tailscalekit\n' "$directory"
86
+ case ":${PATH:-}:" in
87
+ *":$directory:"*) ;;
88
+ *) printf 'Hint: add %s to PATH\n' "$directory" ;;
89
+ esac
90
+ }
91
+
92
+ # Check import visibility from a neutral working directory and warn on mismatch.
93
+ verify_import() {
94
+ local py=$1 actual
95
+ if actual=$(cd / && "$py" -c 'import tailscalekit, os; print(os.path.dirname(os.path.dirname(os.path.abspath(tailscalekit.__file__))))' 2>/dev/null) &&
96
+ [ "$actual" = "$repo_dir" ]; then
97
+ return 0
98
+ fi
99
+ printf 'install.sh: WARNING: %s import did not resolve to %s (reported: %s); user site may be disabled\n' \
100
+ "$py" "$repo_dir" "${actual:-import failed}" >&2
101
+ }
102
+
103
+ for argument in "$@"; do
104
+ case "$argument" in
105
+ --help|-h)
106
+ printf 'Usage: ./install.sh [PYTHON ...]\nDefault interpreter: python3\n'
107
+ exit 0
108
+ ;;
109
+ esac
110
+ done
111
+
112
+ repo_dir=$(cd -- "$(dirname -- "$0")" && pwd -P) || die 'cannot resolve repository directory'
113
+ if [ "$#" -eq 0 ]; then
114
+ set -- python3
115
+ fi
116
+ first_python=
117
+ for argument in "$@"; do
118
+ py=$(resolve_python "$argument")
119
+ [ -n "$first_python" ] || first_python=$py
120
+ info=$(python_info "$py")
121
+ {
122
+ IFS= read -r in_venv
123
+ IFS= read -r purelib
124
+ IFS= read -r externally_managed
125
+ } <<< "$info"
126
+ directory=$(pth_dir_for "$py" "$in_venv" "$purelib" "$externally_managed")
127
+ printf '%s\n' "$repo_dir" | write_atomic "$directory/tailscalekit.pth" 644
128
+ verify_import "$py"
129
+ printf 'tailscalekit: %s → %s/tailscalekit.pth\n' "$py" "$directory"
130
+ done
131
+
132
+ bin_dir=${TAILSCALEKIT_BIN:-}
133
+ if [ -z "$bin_dir" ]; then
134
+ [ -n "${HOME:-}" ] || die 'HOME must be set when TAILSCALEKIT_BIN is unset'
135
+ bin_dir=$HOME/.local/bin
136
+ fi
137
+ write_launcher "$bin_dir" "$first_python"
@@ -0,0 +1,47 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "tailscalekit"
7
+ version = "0.1.0"
8
+ description = "Dependency-free Tailscale API control for Python, Bash and the CLI: devices, single-use auth keys, container join"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ authors = [{name = "Kevin Cherry"}]
13
+ requires-python = ">=3.9"
14
+ dependencies = []
15
+ keywords = ["tailscale", "vpn", "wireguard", "auth-keys", "containers", "cli"]
16
+ classifiers = [
17
+ "Development Status :: 4 - Beta",
18
+ "Environment :: Console",
19
+ "Intended Audience :: Developers",
20
+ "Operating System :: POSIX",
21
+ "Programming Language :: Python :: 3",
22
+ "Programming Language :: Python :: 3 :: Only",
23
+ "Programming Language :: Python :: 3.9",
24
+ "Programming Language :: Python :: 3.10",
25
+ "Programming Language :: Python :: 3.11",
26
+ "Programming Language :: Python :: 3.12",
27
+ "Programming Language :: Python :: 3.13",
28
+ "Programming Language :: Python :: 3.14",
29
+ "Programming Language :: Python :: 3.15",
30
+ "Programming Language :: Unix Shell",
31
+ "Topic :: System :: Networking",
32
+ "Topic :: System :: Systems Administration",
33
+ ]
34
+
35
+ [project.urls]
36
+ Homepage = "https://github.com/kcherry497/tailscale-kit"
37
+ Issues = "https://github.com/kcherry497/tailscale-kit/issues"
38
+ Changelog = "https://github.com/kcherry497/tailscale-kit/blob/main/CHANGELOG.md"
39
+
40
+ [project.scripts]
41
+ tailscalekit = "tailscalekit.cli:main"
42
+
43
+ [tool.setuptools.packages.find]
44
+ include = ["tailscalekit*"]
45
+
46
+ [tool.setuptools.package-data]
47
+ tailscalekit = ["lib/tailscale.sh", "pod/bootstrap.sh"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,18 @@
1
+ """tailscalekit: dependency-free Tailscale API control for Python, Bash and the CLI."""
2
+
3
+ __version__ = "0.1.0"
4
+
5
+ from .client import ( # noqa: E402
6
+ Tailscale,
7
+ TailscaleError,
8
+ TailscaleTimeoutError,
9
+ device_ip,
10
+ policy_allows_all,
11
+ public_device,
12
+ redact,
13
+ )
14
+
15
+ __all__ = [
16
+ "Tailscale", "TailscaleError", "TailscaleTimeoutError",
17
+ "device_ip", "policy_allows_all", "public_device", "redact", "__version__",
18
+ ]
@@ -0,0 +1,3 @@
1
+ from .cli import main
2
+
3
+ raise SystemExit(main())