Grants from the catalog
About 1097 words
The catalog already knows which Component consumes which API. With a few annotations it also knows where each API is reached on the tailnet and which tag a Component's traffic carries. From that, the plugin writes a grant for every consumption that crosses the tailnet, so service owners keep their own access up to date by keeping their catalog entries right.
Turn it on
Catalog grants are off until the policy entity asks for them:
apiVersion: specht-labs.de/v1alpha1
kind: Tailscale
metadata:
name: my-tailnet
spec:
type: policy
owner: group:platform
catalogGrants: trueThe backend reads every Component, API and kubernetes-cluster Resource in the catalog for this. If several policies turn catalog grants on, each of them gets every catalog grant.
Say where an API is reached
Annotate the API with its destination and its ports:
apiVersion: backstage.io/v1alpha1
kind: API
metadata:
name: payments-api
annotations:
specht-labs.de/tailnet-dst: svc:payments
specht-labs.de/tailnet-ports: tcp:443
spec:
type: openapi
lifecycle: production
owner: group:platform
definition: '{}'specht-labs.de/tailnet-dstis one or more destinations, comma-separated. Each issvc:<name>ortag:<name>, in lowercase letters, digits and hyphens. A tag here must be declared by a tag entity in the policy. Prefer a Tailscale Service; Destinations explains why.specht-labs.de/tailnet-portsis required next to it: one or more ports, comma-separated, such astcp:443, tcp:8080or3493. Each must be concrete.*andudp:*aren't accepted here, because a catalog grant should say exactly what the API needs.
Say where a Component's traffic comes from
Annotate each consuming Component with the tags its traffic carries, such as the tag of its egress proxy or of the host it runs on:
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
name: reporting
annotations:
specht-labs.de/tailnet-src: tag:reporting
spec:
type: service
lifecycle: production
owner: group:platform
consumesApis: [payments-api]specht-labs.de/tailnet-src takes tags only, comma-separated. Every tag must be declared by a tag entity in the policy, like any other tag a rule uses.
A Component that consumes an annotated API across the tailnet but has no tailnet-src gets no grant. The backend records it under catalog.missingSource in /api/tailscale/overview.
Consumers in the same cluster get no grant
Traffic between two workloads in one Kubernetes cluster goes over the pod network, not the tailnet. The plugin recognises that from dependsOn relations to Resources of spec.type: kubernetes-cluster:
apiVersion: backstage.io/v1alpha1
kind: Resource
metadata:
name: prod-cluster
spec:
type: kubernetes-cluster
owner: group:platform
---
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
name: payments
spec:
type: service
lifecycle: production
owner: group:platform
providesApis: [payments-api]
dependsOn: [resource:prod-cluster]
---
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
name: checkout
spec:
type: service
lifecycle: production
owner: group:platform
consumesApis: [payments-api]
dependsOn: [resource:prod-cluster]checkout and every provider of payments-api depend on prod-cluster, so checkout gets no grant. The console's From the catalog card lists such consumptions under Inside a cluster. If even one provider runs outside the consumer's cluster, the consumption counts as crossing the tailnet.
Let people and devices use an API
Some users of an API aren't Components: people, or devices the catalog doesn't model. List them on the API:
metadata:
annotations:
specht-labs.de/tailnet-dst: svc:payments
specht-labs.de/tailnet-ports: tcp:443
specht-labs.de/tailnet-allow: group:admins, user:alice, tag:debug-boxspecht-labs.de/tailnet-allow takes groups, users (user:<name> or a login such as alice@github), autogroups and tags. Each gets a grant to the API's destinations on its ports. Groups and users resolve as in Users and groups.
When consuming is what earns the tag
Sometimes the tag a consumer reaches an API as belongs to the act of using that API, not to the consumer. An identity provider that admits any device tagged tag:idp-client is one example. Put that tag on the API:
metadata:
annotations:
specht-labs.de/tailnet-dst: tag:idp
specht-labs.de/tailnet-ports: tcp:443
specht-labs.de/tailnet-client-tag: tag:idp-clientEvery consumer of this API then reaches it as tag:idp-client, whatever its own tailnet-src says. A consumer doesn't need a tailnet-src in that case. The annotation takes exactly one tag.
What gets rendered
With payments-api (port 443, tailnet-allow: group:admins) and payments-grpc (port 8443) both on svc:payments, and reporting (tag:reporting) and billing-batch (tag:batch) consuming both, the plugin renders:
"grants": [
// From the catalog: payments-api
// Consumed by billing-batch, reporting. Used by group:admins (tailnet-allow).
{
"src": ["group:admins", "tag:batch", "tag:reporting"],
"dst": ["svc:payments"],
"ip": ["tcp:443"],
},
// From the catalog: payments-grpc
// Consumed by billing-batch, reporting.
{
"src": ["tag:batch", "tag:reporting"],
"dst": ["svc:payments"],
"ip": ["tcp:8443"],
},
],Consumptions with the same destinations and ports share a grant. Grants that end up with the same sources and destinations are then merged into one with every port. Here the sources differ (only port 443 has group:admins), so there are two grants. How catalog grants are merged goes through the rules.
Grant entities take precedence
If a grant entity already allows a consumption by naming its destination, the consumption gets no grant of its own. For example:
spec:
type: grant
target: tailscale:my-tailnet
owner: group:platform
src: [tag:reporting]
dst: [svc:payments]
ip: ['*']This covers both of reporting's consumptions, so the catalog grants above lose tag:reporting. The console's From the catalog card lists the consumption under Already allowed, with the grant entity that allows it. A grant whose destination is * covers nothing: a break-glass grant to everything shouldn't make the catalog's grants disappear.
When an annotation is wrong
A malformed annotation drops the whole API or Component from catalog grants:
- an API with any tailnet annotation but no
tailnet-dst; - a
tailnet-dstthat isn'tsvc:…ortag:…; - a missing
tailnet-ports, or a port that isn't concrete; - a
tailnet-allowentry that isn't a group, user, autogroup, tag or login; - a
tailnet-client-tagthat isn't one tag; - a
tailnet-srcentry that isn't a tag.
The backend records these under catalog.invalid in /api/tailscale/overview. The console doesn't show catalog.invalid or catalog.missingSource yet, so check them through the API or with backstage-tailscale-diff --json when a grant you expect is missing.
Annotations has the exact syntax of each annotation.
