The policy and its parts
About 1109 words
This guide shows how to split an existing tailnet policy file into kind: Tailscale entities: one policy entity, and one part for each grant, SSH rule, tag, node attribute, auto approver block or set of tests. Every field is listed in kind: Tailscale.
Start with the policy entity
The policy entity is the file as a whole. Put the things here that don't belong to any one rule:
apiVersion: specht-labs.de/v1alpha1
kind: Tailscale
metadata:
name: my-tailnet
title: Our tailnet
description: The production tailnet.
spec:
type: policy
owner: group:platform
tailnet: example.ts.net
# Grants from the APIs Components consume (see "Grants from the catalog").
catalogGrants: true
hosts:
build-box: 100.64.0.10
office: 192.168.10.0/24
# Every other top-level key of the file, rendered as it is.
settings:
randomizeClientPort: true
ipsets:
ipset:office-printers: [192.168.10.20, 192.168.10.21]
# Where the rendered file goes (see "Publish to GitHub").
publish:
repo: acme/network
path: tailscale/policy.hujsonsettings takes any top-level key of a policy file except the ones the parts render: groups, hosts, tagOwners, nodeAttrs, autoApprovers, ssh, grants, acls, tests and sshTests. Putting one of those in settings is an error, and the key isn't rendered. Settings come last in the file, in the order you wrote them.
You can have more than one policy in a catalog, for example one per tailnet. Each renders on its own, and the console has a picker for them.
One part per rule
Every other Tailscale entity is a part, and names its policy in spec.target:
apiVersion: specht-labs.de/v1alpha1
kind: Tailscale
metadata:
name: grant-ci-artifacts
title: CI runners upload artifacts
description: The runners push build artifacts to the artifact store.
spec:
type: grant
target: tailscale:my-tailnet
owner: group:platform
system: ci
appliesTo: [resource:ci-runners]
src: [tag:ci-runner]
dst: [svc:artifacts]
ip: [tcp:443]spec.target is an entity reference. Its kind defaults to tailscale and its namespace to the part's own, so my-tailnet and tailscale:default/my-tailnet mean the same here. A part whose target isn't a policy in the catalog renders nowhere; the console lists it as a problem.
Four fields are the same on every type:
| Field | Required | Meaning |
|---|---|---|
owner | yes | The entity that owns the part, like any catalog entity's owner. Defaults to kind Group. |
target | on parts | The policy this part belongs to. |
system | no | The System the part is part of. |
appliesTo | no | Catalog entities the part is about, such as the Resource a tag's devices are, or the Component a grant serves. Defaults to kind Component. Their pages list the part. |
The rest of the spec is Tailscale's, written as in the file. Which fields a type takes, and which section it renders to:
spec.type | Renders to | Fields |
|---|---|---|
grant | one entry of grants | src, dst, ip, app, via, srcPosture |
ssh | one entry of ssh | action, src, dst, users, checkPeriod, acceptEnv, recorder, enforceRecorder |
tag | one tag of tagOwners | tag, owners |
nodeAttr | one entry of nodeAttrs | nodes (the file's target), attr, app, ipPool |
autoApprovers | part of autoApprovers | routes, services, exitNode |
test | entries of tests and sshTests | tests, sshTests: one test or a list |
How the file is put together
Within each section, parts are ordered by metadata.name, so a naming scheme such as grant-…, ssh-…, tag-… keeps related rules together. Grants from the catalog come after the grant entities.
Each part's metadata.title and metadata.description become a comment above the lines it renders to. A part that renders more than one item (a test with several tests, say) gets one comment above the first.
Examples for each type
Tags
spec:
type: tag
target: tailscale:my-tailnet
owner: group:platform
tag: tag:ci-runner
owners: [group:platform, tag:ci-controller]
appliesTo: [resource:ci-runners]Declare every tag a rule uses. A rule that names an undeclared tag is an error, and so is a second entity declaring the same tag. A tag no rule names is fine.
Grants
spec:
type: grant
target: tailscale:my-tailnet
owner: group:platform
src: [group:sso-users]
dst: [tag:tsidp]
ip: [tcp:443]
app:
tailscale.com/cap/tsidp:
- users: [group:admins]
resources: ['*']A grant needs ip, app or both. Capability names in app must look like <domain>/cap/<name>, and each capability's value is a list of objects.
Tailscale SSH
spec:
type: ssh
target: tailscale:my-tailnet
owner: group:platform
action: accept
src: [group:admins]
dst: [tag:server]
users: [autogroup:nonroot]
recorder: [tag:recorder]
enforceRecorder: trueNode attributes
The file calls the devices of a node attribute target. Since spec.target already names the policy, the entity calls them nodes:
spec:
type: nodeAttr
target: tailscale:my-tailnet
owner: group:platform
nodes: [tag:server]
attr: [funnel]It renders as { "target": ["tag:server"], "attr": ["funnel"] }. A node attribute needs attr, app or both.
Auto approvers
spec:
type: autoApprovers
target: tailscale:my-tailnet
owner: group:platform
routes:
10.20.0.0/16: [tag:router]
services:
svc:grafana: [tag:grafana]
exitNode: [tag:exit]Several entities can approve the same route or Service. The file then lists that target once, with every entity's approvers. Service names must be svc: followed by lowercase letters, digits and hyphens.
Tests
spec:
type: test
target: tailscale:my-tailnet
owner: group:platform
tests:
- src: user:alice
accept: ['tag:server:22']
- src: tag:ci-runner
proto: tcp
deny: ['tag:server:22']
sshTests:
src: user:alice
dst: [tag:server]
accept: [root]tests and sshTests take one test or a list. A test needs src, and either accept or deny. In accept and deny, the part before the last : is resolved like any selector, so user:alice:22 and tag:server:22 work, and so do host names from spec.hosts. In sshTests, accept, check and deny are local user names and aren't resolved.
What names may appear in a rule
Sources, destinations, owners, approvers and test sources accept the selectors a policy file does. The plugin checks each one when it renders:
| Written as | Checked against |
|---|---|
group:<name> | a Backstage Group (see Users and groups) |
user:<name> | a Backstage User with a login annotation; renders as the login |
alice@github | nothing; it's used as it is |
tag:<name> | a tag entity in this policy |
svc:<name> | nothing; not allowed as a grant source |
autogroup:<name> | nothing |
ipset:<name> | the policy's settings.ipsets |
| an IP address or CIDR | nothing |
| a host name | the policy's spec.hosts |
* | nothing |
Anything else is an error: <value> is neither a host of this policy nor a selector. Problems lists every message.
