How catalog grants are merged
About 724 words
A catalog with fifty Components consuming a dozen APIs would give fifty-odd grants if every consumption got its own. The plugin merges them into as few grants as it can without changing what they allow, and leaves out the ones a grant entity already covers. This page explains the steps, in the order the backend takes them.
1. Find the edges
An edge is one reason for traffic across the tailnet, with sources, destinations and ports:
- A consumption. A Component consumes (
consumesApis) an API that hasspecht-labs.de/tailnet-dst. The sources are the API'stailnet-client-tagif it has one, otherwise the Component'stailnet-srctags. The destinations and ports are the API'stailnet-dstandtailnet-ports. - An allow. An API's
specht-labs.de/tailnet-allow. The sources are the names it lists, and the destinations and ports are the API's.
A consumption isn't an edge when the consumer and every provider of the API depend on the same kubernetes-cluster Resource: that traffic stays on the pod network. A consumption without any source tag isn't an edge either; it's recorded under catalog.missingSource.
2. Drop what a grant entity covers
Each edge is split into single flows, one per source, destination and port. A flow is covered when one grant entity has all of these:
- a source that is the flow's source, or
*, orautogroup:taggedwhen the flow's source is a tag; - a destination with the flow's destination as its exact name;
- an
ipentry whose ports include the flow's port.
If every flow of an edge is covered, the edge gets no grant and goes on the Already allowed list, with the grant entities that cover it. If even one flow isn't covered, the whole edge stays.
A grant entity whose destination is * covers nothing, because no flow's destination is named *. A break-glass grant to everything doesn't make the specific grants disappear, so removing the break-glass grant later doesn't silently cut anyone off.
3. Same destinations and ports: one grant, every source
The edges that remain are grouped by their destinations and ports. Each group becomes one grant whose sources are every source in the group.
Three Components, reporting, billing-batch and billing, consume payments-api (svc:payments, tcp:443) as tag:reporting, tag:batch and tag:billing. They give one grant from all three tags.
4. Same sources and destinations: one grant, every port
Grants from step 3 that ended up with the same sources and the same destinations are merged, and their ports are combined. Ports are sorted by protocol, then by number, so tcp:443 comes before tcp:5001.
If the same Components also consume payments-grpc on svc:payments, tcp:8443, steps 3 and 4 give a single grant:
// From the catalog: payments-api, payments-grpc
// Consumed by billing, billing-batch, reporting.
{
"src": ["tag:batch", "tag:billing", "tag:reporting"],
"dst": ["svc:payments"],
"ip": ["tcp:443", "tcp:8443"],
},Change one source on one API (an allow for group:admins on payments-api only, say), and the two groups no longer have the same sources. They stay two grants: one on port 443 with the admins, one on port 8443 without them. Merging further would grant the admins port 8443, which no edge asks for.
5. Name and order the grants
Each catalog grant's comment names the APIs it's made of, and who it's for: the consuming Components, and the names from tailnet-allow. Catalog grants come after the grant entities in the file, sorted by destination and then by source.
Why this order
Merging by destination and ports first, then by sources, never produces a grant that allows more than its edges did. Every source in a grant reaches every destination on every port of that grant, and each of those combinations comes from some edge. That keeps the rendered file readable without making the catalog grant broader than what the catalog says.
The console keeps the edges behind each catalog grant, so a grant made of five consumptions still shows which Components and APIs it came from.
