Documentation
¶
Overview ¶
Package api is a small client for the Tailscale HTTP API (v2). It authenticates with OAuth client credentials and currently supports creating and revoking auth keys and reading the tailnet policy.
The package never logs, and every secret value is a Secret so that it cannot leak through formatting.
Index ¶
- Variables
- type ACLRule
- type APIError
- type Client
- func (c *Client) CreateKey(ctx context.Context, spec KeySpec) (Key, error)
- func (c *Client) DeleteDevice(ctx context.Context, id string) error
- func (c *Client) GetPolicy(ctx context.Context) (Policy, error)
- func (c *Client) GoString() string
- func (c *Client) ListDevices(ctx context.Context) ([]Device, error)
- func (c *Client) RevokeKey(ctx context.Context, id string) error
- func (c *Client) String() string
- func (c *Client) Token(ctx context.Context) (string, error)
- type Device
- type Grant
- type Key
- type KeySpec
- type Policy
- type SSHRule
- type Secret
Constants ¶
This section is empty.
Variables ¶
var ( // ErrForbidden matches HTTP 403 responses. ErrForbidden = errors.New("forbidden") // ErrNotFound matches HTTP 404 responses. ErrNotFound = errors.New("not found") ErrUnauthorized = errors.New("unauthorized") )
Sentinel errors matched by errors.Is against an APIError.
var ErrNoCredentials = errors.New("tailscale oauth credentials missing")
ErrNoCredentials is returned when OAuth credentials are missing.
Functions ¶
This section is empty.
Types ¶
type ACLRule ¶
type ACLRule struct {
Action string `json:"action"`
Src []string `json:"src"`
Dst []string `json:"dst"`
}
ACLRule is one entry of the policy's acls section (only the fields provr inspects).
type Client ¶
type Client struct {
// BaseURL is the API root; override in tests.
BaseURL string
// HTTP is the HTTP client used for all requests.
HTTP *http.Client
// ClientID is the OAuth client ID.
ClientID string
// ClientSecret is the OAuth client secret.
ClientSecret Secret
// contains filtered or unexported fields
}
Client talks to the Tailscale API. Create it with New or NewFromEnv.
func NewFromEnv ¶
NewFromEnv builds a Client from TS_OAUTH_CLIENT_ID and TS_OAUTH_CLIENT_SECRET. The returned error names missing variables only.
func (*Client) DeleteDevice ¶
DeleteDevice removes a device from the tailnet. A device that no longer exists is not an error.
func (*Client) GetPolicy ¶
GetPolicy reads the tailnet policy. A 403 (missing policy_file:read scope) satisfies errors.Is(err, ErrForbidden).
func (*Client) ListDevices ¶
ListDevices returns the devices in the token's tailnet.
func (*Client) RevokeKey ¶
RevokeKey deletes an auth key. A key that no longer exists is not an error.
type Device ¶
type Device struct {
ID string `json:"id"`
// Name is the MagicDNS FQDN, e.g. "host.tail1234.ts.net".
Name string `json:"name"`
// Hostname is the OS hostname.
Hostname string `json:"hostname"`
Tags []string `json:"tags"`
LastSeen time.Time `json:"lastSeen"`
ConnectedToControl bool `json:"connectedToControl"`
}
Device is a machine in the tailnet.
type Grant ¶
Grant is one entry of the policy's grants section. The ip and app capabilities are ignored: provr only needs to know who a grant reaches.
type KeySpec ¶
type KeySpec struct {
// Tags are the ACL tags applied to devices using the key (required).
Tags []string
Reusable bool
Ephemeral bool
// Expiry is the key lifetime; zero means one hour.
Expiry time.Duration
Description string
}
KeySpec describes an auth key to create.
type Policy ¶
type Policy struct {
TagOwners map[string][]string `json:"tagOwners"`
SSH []SSHRule `json:"ssh"`
ACLs []ACLRule `json:"acls"`
Grants []Grant `json:"grants"`
}
Policy is the subset of the tailnet policy file that provr inspects.
type SSHRule ¶
type SSHRule struct {
Action string `json:"action"`
Src []string `json:"src"`
Dst []string `json:"dst"`
Users []string `json:"users"`
}
SSHRule is one entry of the policy's ssh section.
type Secret ¶
type Secret string
Secret is a string that must never be printed or logged. Callers must convert it explicitly with string(s) to use the value.
func (Secret) MarshalJSON ¶
MarshalJSON encodes a redacted placeholder.