api.md: format API docs with prettier

Mostly inconsequential minor fixes for consistency.  A couple of changes
to actual JSON examples, but all still very readable, so I think it's
fine.

Updates #cleanup

Signed-off-by: Will Norris <will@tailscale.com>
This commit is contained in:
Will Norris 2024-03-19 08:34:08 -07:00 committed by Will Norris
parent b0c3e6f6c5
commit 349799a1ba
1 changed files with 188 additions and 200 deletions

140
api.md
View File

@ -38,7 +38,7 @@ In addition to the status code, errors may include additional information in the
```jsonc
{
"message": "additional error information"
"message": "additional error information",
}
```
@ -49,6 +49,7 @@ The Tailscale API does not currently support pagination. All results are returne
# APIs
**[Device](#device)**
- Get a device: [`GET /api/v2/device/{deviceid}`](#get-device)
- Delete a device: [`DELETE /api/v2/device/{deviceID}`](#delete-device)
- Expire device key: [`POST /api/v2/device/{deviceID}/expire`](#expire-device-key)
@ -65,6 +66,7 @@ The Tailscale API does not currently support pagination. All results are returne
- Set device IPv4 address: [`POST /api/v2/device/{deviceID}/ip`](#set-device-ipv4-address)
**[Tailnet](#tailnet)**
- [**Policy File**](#policy-file)
- Get policy file: [`GET /api/v2/tailnet/{tailnet}/acl`](#get-policy-file)
- Update policy file: [`POST /api/v2/tailnet/{tailnet}/acl`](#update-policy-file)
@ -106,10 +108,7 @@ You can also [list all devices in the tailnet](#list-tailnet-devices) to get the
// addresses (array of strings) is a list of Tailscale IP
// addresses for the device, including both IPv4 (formatted as 100.x.y.z)
// and IPv6 (formatted as fd7a:115c:a1e0:a:b:c:d:e) addresses.
"addresses": [
"100.87.74.78",
"fd7a:115c:a1e0:ac82:4843:ca90:697d:c36e"
],
"addresses": ["100.87.74.78", "fd7a:115c:a1e0:ac82:4843:ca90:697d:c36e"],
// id (string) is the legacy identifier for a device; you
// can supply this value wherever {deviceId} is indicated in the
@ -188,29 +187,19 @@ You can also [list all devices in the tailnet](#list-tailnet-devices) to get the
// enabledRoutes (array of strings) are the subnet routes for this
// device that have been approved by the tailnet admin.
// Learn more about subnet routes at https://tailscale.com/kb/1019/.
"enabledRoutes" : [
"10.0.0.0/16",
"192.168.1.0/24",
],
"enabledRoutes": ["10.0.0.0/16", "192.168.1.0/24"],
// advertisedRoutes (array of strings) are the subnets this device
// intends to expose.
// Learn more about subnet routes at https://tailscale.com/kb/1019/.
"advertisedRoutes" : [
"10.0.0.0/16",
"192.168.1.0/24",
],
"advertisedRoutes": ["10.0.0.0/16", "192.168.1.0/24"],
// clientConnectivity provides a report on the device's current physical
// network conditions.
"clientConnectivity": {
// endpoints (array of strings) Client's magicsock UDP IP:port
// endpoints (IPv4 or IPv6)
"endpoints":[
"199.9.14.201:59128",
"192.68.0.21:59128"
],
"endpoints": ["199.9.14.201:59128", "192.68.0.21:59128"],
// mappingVariesByDestIP (boolean) is 'true' if the host's NAT mappings
// vary based on the destination IP.
@ -221,17 +210,16 @@ You can also [list all devices in the tailnet](#list-tailnet-devices) to get the
// server for incoming traffic.
"latency": {
"Dallas": {
"latencyMs":60.463043
"latencyMs": 60.463043,
},
"New York City": {
"preferred": true,
"latencyMs":31.323811
"latencyMs": 31.323811,
},
},
// clientSupports (JSON object) identifies features supported by the client.
"clientSupports": {
// hairpinning (boolean) is 'true' if your router can route connections
// from endpoints on your LAN back to your LAN using those endpoints
// globally-mapped IPv4 addresses/ports
@ -256,7 +244,7 @@ You can also [list all devices in the tailnet](#list-tailnet-devices) to get the
// upnp (boolean) is 'true' if UPnP port-mapping service exists
// on your router.
"upnp":false
"upnp": false,
},
},
@ -266,9 +254,7 @@ You can also [list all devices in the tailnet](#list-tailnet-devices) to get the
// A single node can have multiple tags assigned. This value is empty for
// external devices.
// Learn more about tags at https://tailscale.com/kb/1068/.
"tags": [
"tag:golink"
],
"tags": ["tag:golink"],
// tailnetLockError (string) indicates an issue with the tailnet lock
// node-key signature on this device.
@ -287,8 +273,8 @@ You can also [list all devices in the tailnet](#list-tailnet-devices) to get the
// will contain {"disabled": true}.
// Learn more about posture identity at https://tailscale.com/kb/1326/device-identity
"postureIdentity": {
"serialNumbers": ["CP74LFQJXM"]
}
"serialNumbers": ["CP74LFQJXM"],
},
}
```
@ -301,6 +287,7 @@ Learn more about [subnet routers](https://tailscale.com/kb/1019).
A device can act as a subnet router if its subnet routes are both advertised and enabled.
This is a two-step process, but the steps can occur in any order:
- The device that intends to act as a subnet router exposes its routes by **advertising** them.
This is done in the Tailscale command-line interface.
- The tailnet admin must approve the routes by **enabling** them.
@ -311,6 +298,7 @@ If a device has advertised routes, they are not exposed to traffic until they ar
Conversely, if a tailnet admin pre-approves certain routes by enabling them, they are not available for routing until the device in question has advertised them.
The API exposes two methods for dealing with subnet routes:
- Get routes: [`GET /api/v2/device/{deviceID}/routes`](#get-device-routes) to fetch lists of advertised and enabled routes for a device
- Set routes: [`POST /api/v2/device/{deviceID}/routes`](#set-device-routes) to set enabled routes for a device
@ -335,6 +323,7 @@ The ID of the device.
Controls whether the response returns **all** object fields or only a predefined subset of fields.
Currently, there are two supported options:
- **`all`:** return all object fields in the response
- **`default`:** return all object fields **except**:
- `enabledRoutes`
@ -455,6 +444,7 @@ GET /api/v2/device/{deviceID}/routes
```
Retrieve the list of [subnet routes](#subnet-routes) that a device is advertising, as well as those that are enabled for it:
- **Enabled routes:** The subnet routes for this device that have been approved by the tailnet admin.
- **Advertised routes:** The subnets this device intends to expose.
@ -477,11 +467,8 @@ Returns the enabled and advertised subnet routes for a device.
```jsonc
{
"advertisedRoutes" : [
"10.0.0.0/16",
"192.168.1.0/24"
],
"enabledRoutes" : []
"advertisedRoutes": ["10.0.0.0/16", "192.168.1.0/24"],
"enabledRoutes": [],
}
```
@ -508,7 +495,7 @@ The new list of enabled subnet routes.
```jsonc
{
"routes": ["10.0.0.0/16", "192.168.1.0/24"]
"routes": ["10.0.0.0/16", "192.168.1.0/24"],
}
```
@ -526,14 +513,8 @@ Returns the enabled and advertised subnet routes for a device.
```jsonc
{
"advertisedRoutes" : [
"10.0.0.0/16",
"192.168.1.0/24"
],
"enabledRoutes" : [
"10.0.0.0/16",
"192.168.1.0/24"
]
"advertisedRoutes": ["10.0.0.0/16", "192.168.1.0/24"],
"enabledRoutes": ["10.0.0.0/16", "192.168.1.0/24"],
}
```
@ -560,10 +541,9 @@ The ID of the device.
Specify whether the device is authorized. False to deauthorize an authorized device, and true to authorize a new device or to re-authorize a previously deauthorized device.
```jsonc
{
"authorized": true
"authorized": true,
}
```
@ -612,7 +592,7 @@ The new list of tags for the device.
```jsonc
{
"tags": ["tag:foo", "tag:bar"]
"tags": ["tag:foo", "tag:bar"],
}
```
@ -632,7 +612,7 @@ If the tags supplied in the `POST` call do not exist in the tailnet policy file,
```jsonc
{
"message": "requested tags [tag:madeup tag:wrongexample] are invalid or not permitted"
"message": "requested tags [tag:madeup tag:wrongexample] are invalid or not permitted",
}
```
@ -664,7 +644,7 @@ You can then call this method again with `"keyExpiryDisabled": false` to re-enab
```jsonc
{
"keyExpiryDisabled": true
"keyExpiryDisabled": true,
}
```
@ -713,7 +693,7 @@ This endpoint can be used to replace the existing IPv4 address with a specific v
```jsonc
{
"ipv4": "100.80.0.1"
"ipv4": "100.80.0.1",
}
```
@ -796,6 +776,7 @@ Request a detailed description of the tailnet policy file by providing `details=
If using this, do not supply an `Accept` parameter in the header.
The response will contain a JSON object with the fields:
- **tailnet policy file:** a base64-encoded string representation of the huJSON format
- **warnings:** array of strings for syntactically valid but nonsensical entries
- **errors:** an array of strings for parsing failures
@ -1006,7 +987,7 @@ A successful response returns an HTTP status of '200' and the modified tailnet p
// Match absolutely everything. Comment out this section if you want
// to define specific ACL restrictions.
{ "action": "accept", "users": ["*"], "ports": ["*:*"] },
]
],
}
```
@ -1033,6 +1014,7 @@ A successful response returns an HTTP status of '200' and the modified tailnet p
```http
POST /api/v2/tailnet/{tailnet}/acl/preview
```
When given a user or IP port to match against, returns the tailnet policy rules that
apply to that resource without saving the policy file to the server.
@ -1096,6 +1078,7 @@ curl "https://api.tailscale.com/api/v2/tailnet/example.com/acl/preview?previewFo
A successful response returns an HTTP status of '200' and a list of rules that apply to the resource supplied as a list of matches as JSON objects.
Each match object includes:
- `users`: array of strings indicating source entities affected by the rule
- `ports`: array of strings representing destinations that can be accessed
- `lineNumber`: integer indicating the rule's location in the policy file
@ -1187,6 +1170,7 @@ curl "https://api.tailscale.com/api/v2/tailnet/example.com/acl/validate" \
The HTTP status code will be '200' if the request was well formed and there were no server errors, even in the case of failing tests or an invalid ACL.
Look at the response body to determine whether there was a problem within your ACL or tests:
- If the tests are valid, an empty body or a JSON object with no `message` is returned.
- If there's a problem, the response body will be a JSON object with a non-empty `message` property and optionally additional details in `data`:
@ -1196,9 +1180,9 @@ Look at the response body to determine whether there was a problem within your A
"data": [
{
"user": "user1@example.com",
"errors":["address \"2.2.2.2:22\": want: Drop, got: Accept"]
}
]
"errors": ["address \"2.2.2.2:22\": want: Drop, got: Accept"],
},
],
}
```
@ -1211,9 +1195,11 @@ any groups that are used in the policy file that are not being synced from SCIM.
"data": [
{
"user": "group:unknown@example.com",
"warnings":["group is not syncing from SCIM and will be ignored by rules in the policy file"]
}
]
"warnings": [
"group is not syncing from SCIM and will be ignored by rules in the policy file",
],
},
],
}
```
@ -1238,11 +1224,12 @@ The tailnet organization name.
Controls whether the response returns **all** fields or only a predefined subset of fields.
Currently, there are two supported options:
- **`all`:** return all fields in the response
- **`default`:** return all fields **except**:
* `enabledRoutes`
* `advertisedRoutes`
* `clientConnectivity` (which contains the following fields: `mappingVariesByDestIP`, `derp`, `endpoints`, `latency`, and `clientSupports`)
- `enabledRoutes`
- `advertisedRoutes`
- `clientConnectivity` (which contains the following fields: `mappingVariesByDestIP`, `derp`, `endpoints`, `latency`, and `clientSupports`)
If the `fields` parameter is not supplied, then the default (limited fields) option is used.
@ -1342,6 +1329,7 @@ GET /api/v2/tailnet/{tailnet}/keys
```
Returns a list of active auth keys and API access tokens. The set of keys returned depends on the access token used to make the request:
- If the API call is made with a user-owned API access token, this returns only the keys owned by that user.
- If the API call is made with an access token derived from an OAuth client, this returns all keys owned directly by the tailnet.
@ -1363,12 +1351,14 @@ curl "https://api.tailscale.com/api/v2/tailnet/example.com/keys" \
Returns a JSON object with the IDs of all active keys.
```jsonc
{"keys": [
{
"keys": [
{ "id": "XXXX14CNTRL" },
{ "id": "XXXXZ3CNTRL" },
{ "id": "XXXX43CNTRL" },
{"id": "XXXXgj1CNTRL"}
]}
{ "id": "XXXXgj1CNTRL" },
],
}
```
<a href="tailnet-keys-post"></a>
@ -1408,6 +1398,7 @@ Note the following about required vs. optional values:
- **`devices`:** A `devices` object is required within `capabilities`, but can be an empty JSON object.
- **`tags`:** Whether tags are required or optional depends on the owner of the auth key:
- When creating an auth key _owned by the tailnet_ (using OAuth), it must have tags.
The auth tags specified for that new auth key must exactly match the tags that are on the OAuth client used to create that auth key (or they must be tags that are owned by the tags that are on the OAuth client used to create the auth key).
- When creating an auth key _owned by a user_ (using a user's access token), tags are optional.
@ -1460,11 +1451,11 @@ It holds the capabilities specified in the request and can no longer be retrieve
"reusable": false,
"ephemeral": false,
"preauthorized": false,
"tags": [ "tag:example" ]
}
}
"tags": ["tag:example"],
},
"description": "dev access"
},
},
"description": "dev access",
}
```
@ -1510,14 +1501,11 @@ The response is a JSON object with information about the key supplied.
"reusable": false,
"ephemeral": true,
"preauthorized": false,
"tags": [
"tag:bar",
"tag:foo"
]
}
}
"tags": ["tag:bar", "tag:foo"],
},
"description": "dev access"
},
},
"description": "dev access",
}
```
@ -1529,7 +1517,7 @@ Response for a revoked (deleted) or expired key will have an `invalid` field set
"created": "2022-05-05T18:55:44Z",
"expires": "2022-08-03T18:55:44Z",
"revoked": "2023-04-01T20:50:00Z",
"invalid": true
"invalid": true,
}
```
@ -1627,7 +1615,7 @@ The new list of DNS nameservers in JSON.
```jsonc
{
"dns":["8.8.8.8"]
"dns": ["8.8.8.8"],
}
```
@ -1734,7 +1722,7 @@ The DNS preferences in JSON. Currently, MagicDNS is the only setting available:
```jsonc
{
"magicDNS": true
"magicDNS": true,
}
```
@ -1752,7 +1740,7 @@ If there are no DNS servers, this returns an error message:
```jsonc
{
"message":"need at least one nameserver to enable MagicDNS"
"message": "need at least one nameserver to enable MagicDNS",
}
```
@ -1817,7 +1805,7 @@ Specify a list of search paths in a JSON object:
```jsonc
{
"searchPaths": ["user1.example.com", "user2.example.com"]
"searchPaths": ["user1.example.com", "user2.example.com"],
}
```