Tailscale Tailnet administration CLI tool
Project description
tailnet-admin-cli
Tailscale Tailnet administration CLI tool. This tool provides a command-line interface for managing your Tailscale tailnet.
Installation
pip install tailnet-admin-cli
Or using uv:
uv pip install tailnet-admin-cli
Usage
Authentication
Before using the tool, you need to authenticate with the Tailscale API. You'll need to create an API client in the Tailscale admin console to get a client ID and client secret.
You can authenticate using command-line options:
tailnet-admin-cli auth --client-id YOUR_CLIENT_ID --client-secret YOUR_CLIENT_SECRET --tailnet your-tailnet.example.com
Or using environment variables:
export TAILSCALE_CLIENT_ID=YOUR_CLIENT_ID
export TAILSCALE_CLIENT_SECRET=YOUR_CLIENT_SECRET
export TAILSCALE_TAILNET=your-tailnet.example.com
tailnet-admin-cli auth
You can also mix environment variables and command-line options. Command-line options take precedence over environment variables.
Commands
Check authentication status:
tailnet-admin-cli status
Check OAuth token scopes and permissions:
tailnet-admin-cli scopes
Debug authentication issues:
tailnet-admin-cli debug-auth
List all devices in your tailnet:
tailnet-admin-cli devices
List all API keys:
tailnet-admin-cli keys
# Show detailed API response
tailnet-admin-cli keys --verbose
# Show raw key IDs for easier copying
tailnet-admin-cli keys --raw-ids
Get information about a specific API key:
tailnet-admin-cli debug-key YOUR_KEY_ID
# Show additional debug information
tailnet-admin-cli debug-key YOUR_KEY_ID --verbose
Log out and clear authentication data:
tailnet-admin-cli logout
Tag Management
tailnet-admin-cli includes powerful tag management capabilities for bulk operations on your Tailscale devices.
List all tags in your tailnet:
tailnet-admin-cli tag list
List all devices with their tags:
tailnet-admin-cli tag device-tags
Bulk Tag Operations
Rename a tag on all devices:
tailnet-admin-cli tag rename old-tag new-tag
Add a tag to devices that have another specific tag:
tailnet-admin-cli tag add-if-has existing-tag new-tag
Add a tag to devices that are missing a specific tag:
tailnet-admin-cli tag add-if-missing missing-tag new-tag
Remove a tag from devices (all devices or specific ones):
# Remove from all devices
tailnet-admin-cli tag remove tag-to-remove
# Remove from specific devices
tailnet-admin-cli tag remove tag-to-remove --device device1 --device laptop2
Add tags to specific devices (preserves existing tags):
tailnet-admin-cli tag add device1,laptop2 --tag tag1 --tag tag2
Set specific tags for specific devices (replaces all existing tags):
tailnet-admin-cli tag set device1,laptop2 --tag tag1 --tag tag2
All tag commands support the following options:
--act/-a: Actually apply the changes (default is dry run mode)
All commands accept both device names and device IDs for identifying devices. Tags can be specified with or without the tag: prefix.
Creating Tailscale OAuth Clients
To use this tool, you need to create an OAuth client in the Tailscale admin console:
- Log in to the Tailscale admin console
- Navigate to Settings > OAuth clients
- Click "Create OAuth client"
- Provide a name for your client (e.g., "tailnet-admin CLI")
- Select the required scopes:
devices:read- Access device informationdevices:write- Modify device information (required for tag management)keys:read- Access API keys information- Or use the
allscope, but note that you may still need to specify individual scopes during token exchange
- Click "Create client"
- Save the generated client ID and client secret securely
The client secret is only shown once when created, so make sure to copy it immediately.
This tool uses the OAuth 2.0 client credentials grant type as described in the Tailscale OAuth documentation.
OAuth Scope Issues
If you encounter 403 Forbidden errors when trying to update device tags, it's likely due to missing the devices:write scope in your OAuth token. This can happen even if your OAuth client has the all scope in the Tailscale admin console.
To troubleshoot scope issues:
- Run
tailnet-admin-cli scopesto check which permissions your current token has - If permissions are missing, re-authenticate with
tailnet-admin-cli auth - If that doesn't work, create a new OAuth client with explicit scopes rather than the
allscope
The OAuth token exchange requires specific scopes to be requested, even if your client has the all scope. This is why we explicitly request devices:read devices:write keys:read tailnet:devices during authentication.
Environment Variables
The following environment variables are supported:
| Variable | Description |
|---|---|
TAILSCALE_CLIENT_ID |
Your Tailscale API client ID |
TAILSCALE_CLIENT_SECRET |
Your Tailscale API client secret |
TAILSCALE_TAILNET |
Your Tailnet name (e.g., example.com) |
You can set these variables in several ways:
-
In your shell session:
export TAILSCALE_CLIENT_ID=your-client-id
-
In your shell profile (e.g.,
~/.bashrc,~/.zshrc) for persistent configuration. -
In a
.envfile in the current directory:TAILSCALE_CLIENT_ID=your-client-id TAILSCALE_CLIENT_SECRET=your-client-secret TAILSCALE_TAILNET=your-tailnet.example.comA template
.env.examplefile is provided - copy it to.envand add your credentials.
API Documentation
This tool uses the Tailscale API. For more information, see the Tailscale API documentation.
API Key Endpoints
According to the Tailscale API documentation, the endpoint for getting API key information is:
GET /api/v2/tailnet/{tailnet}/keys/{keyID}
If you're experiencing issues with API key access, you can use the debug-key command to diagnose the problem:
tailnet-admin-cli debug-key YOUR_KEY_ID --verbose
This command will try different endpoint patterns and show detailed information about the requests and responses.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tailnet_admin_cli-0.1.0.tar.gz.
File metadata
- Download URL: tailnet_admin_cli-0.1.0.tar.gz
- Upload date:
- Size: 50.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0e24767ff16d271afabca27bb5ceb8dd3985d01aebd2baad432750b0f235b51
|
|
| MD5 |
5d7225bbac09f3b5ed8c240dc5fab4da
|
|
| BLAKE2b-256 |
17d84ad23008b945347c3dfc410f14448fc806a5b01f2f9784129abe40716a58
|
File details
Details for the file tailnet_admin_cli-0.1.0-py3-none-any.whl.
File metadata
- Download URL: tailnet_admin_cli-0.1.0-py3-none-any.whl
- Upload date:
- Size: 20.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
71de26d1a7851eaa3193607c067b9c7a74c528f706fac6b0e8fa7f9528888ec4
|
|
| MD5 |
50453b125b5f2127a640579d1c731871
|
|
| BLAKE2b-256 |
d798c54d3b5004700cc70b512ce0c2b981d81b388037473c4c8fcac5e6e858b9
|