← All Modules

assay.tailscale

Tailscale REST API client. OAuth2 client_credentials flow with cached bearer tokens, mint short-lived auth keys, list/find devices, manage device key expiry, set tags, authorize, delete, and ACL preview.

local tailscale = require("assay.tailscale")

-- env: TS_CLIENT_ID / TS_CLIENT_SECRET
local ts = tailscale.client()

-- or explicit
local ts = tailscale.client({
  client_id     = "...",
  client_secret = "...",
  tailnet       = "-",                            -- default "-"
  base_url      = "https://api.tailscale.com",   -- override for tests
  scope         = "all:write",                    -- default
})

The token is fetched lazily on first call, cached in the client closure, and refreshed automatically when os.time() >= expires_at - 30 (30s skew margin). Every authed call sends Authorization: Bearer <token>.

Auth keys

local key = ts:mint_key({
  reusable       = false,
  ephemeral      = false,
  preauthorized  = true,
  tags           = { "tag:server" },
  expiry_seconds = 600,
  description    = "ansible mint for hostname-x",
})

Devices

Per-device operations

ACL preview

Errors

Every HTTP non-2xx (including the OAuth token exchange) raises tailscale.<fn>: <reason>; nothing silently returns nil on a network or auth failure.