Check a change locally
About 807 words
backstage-tailscale-diff renders a policy the way Backstage would, from local checkouts of your catalog repositories, and compares it with a policy file. Use it to see what a change to an entity or annotation does to the tailnet before you push it, or to check that moving an existing tailnet into the catalog keeps access the same.
It ships with the backend package. You don't need a running Backstage.
Run it
Pass the policy file to compare with, then one or more directories that hold catalog files:
npx -p @spechtlabs/backstage-plugin-tailscale-backend backstage-tailscale-diff \
~/src/acme/network/tailscale/policy.hujson \
~/src/acme/network ~/src/acme/catalogEach directory must be inside a git working tree, because the command lists files with git ls-files. It reads tracked and untracked files and skips the ones git ignores, so a new entity file you haven't committed yet counts.
Every .yaml or .yml document whose apiVersion starts with backstage.io/ or specht-labs.de/ is an entity; Location entities are skipped. An entity defined twice keeps its first definition, with a warning.
Read the output
Our tailnet: 20 entities, 10 parts, 81 lines -> /tmp/rendered.hujson
Services: svc:grafana, svc:payments
peer meshes: tag:batch
devices: tag:server
warning: tailscale:default/tag-server: tag:server is reached as a device, not a Service (tailscale:default/grant-admins-servers): move the traffic to a Service, or say why on its tag entity (specht-labs.de/tailnet-device-reason)
grants:
- group:admins -> svc:payments tcp:443 (only in policy.hujson)
+ group:admins -> tag:server tcp:443 (only rendered)
+ tag:batch -> tag:batch * (only rendered)
3 differencesThe first block is about the rendered policy: how many entities were read, how many parts the policy has, how long the file is, then each destination class and every problem.
After that come the differences, section by section. A - line is something only the policy file you passed allows; a + line is something only the rendered policy allows. With no differences, the last line says No differences: the rendered policy allows what policy.hujson allows.
What counts as a difference
The comparison looks at what each section allows, not at the text:
- Grants are split into single
source -> destination portentries, with anyapp,viaandsrcPostureattached. The same access split across grants differently, or in another order, compares equal. - A grant to a Service on
*counts as the ports the catalog's APIs list for that Service (theirspecht-labs.de/tailnet-ports), since a Service offers only the ports it serves. groups,hosts,tagOwnersandautoApproverscompare entry by entry;testsandsshTestsby each accept, deny and check;nodeAttrsandsshby whole entry, with list order ignored.- Every other top-level key compares as a setting.
Comments and formatting never count.
Pick a policy and keep the output
| Flag | Effect |
|---|---|
--policy <name> | render the policy entity with this metadata.name; without it, the first policy by name |
--out <file> | write the rendered policy file |
--json <file> | write what GET /api/tailscale/overview would serve, without the publishing status |
--json is the way to see catalog.missingSource and catalog.invalid, which list consumptions without a source tag and annotations the plugin can't read.
Exit status
| Status | Meaning |
|---|---|
| 0 | no differences and no errors |
| 1 | the files differ, or the policy has errors (warnings don't count) |
| 2 | bad arguments: a missing path, a directory that isn't one, a policy file that doesn't parse, an unknown --policy |
Use it in CI
Because the exit status is 1 on any difference, the command can guard a catalog repository: compare the catalog on a pull request with the policy file on the policy repository's main branch, and fail when they differ unexpectedly. One way, in a GitHub Actions job that has both repositories checked out:
- run: |
npx -p @spechtlabs/backstage-plugin-tailscale-backend backstage-tailscale-diff \
network/tailscale/policy.hujson network catalogWhether a difference should fail the build is your call. During a migration it's useful as a report; afterwards, every expected change shows up as a difference until Backstage's pull request is merged.
Where it differs from Backstage
The command rebuilds the relations the catalog would add from the specs: consumesApis, providesApis, dependsOn, a User's memberOf, and the Tailscale relations. It doesn't run the catalog's processors, so:
- group membership comes only from Users'
spec.memberOf, not from a Group'sspec.members; dependsOnentries without a kind default to Component, so writeresource:prod-clusterin full;- entities from other sources (an identity provider sync, a GitHub org provider) are missing unless they're in the directories you pass.
The rendered file has no link to the policy entity in its header, because there's no app.baseUrl.
