Repository navigation
Conversation
Signed-off-by: Oli Strik <strik@olii.nl>
The placeholder returned a bare map[string]any, which caddy.ToString
formats with %+v, so `header_up X {tailscale.grants}` sent Go debug
output such as `map[example.com/app:[map[admin:true]]]`.
Return a named Grants map type that implements fmt.Stringer. CEL still
sees a map, while headers and other string contexts get the same JSON
object that tailscale serve sends in Tailscale-App-Capabilities, or {}
when there are no grants. Non-ASCII characters are escaped as \uXXXX
so the header value is always ASCII and valid JSON.
The tailscale_grants user metadata now uses the same encoding, and the
tests exercise the real replacer func instead of a copy of it.
Signed-off-by: olistrik <strik@olii.nl>
olistrik
force-pushed
the
tailscale-grants
branch
from
November 9, 2026 14:37
16af7c6 to
d4cc2ad
Compare
Signed-off-by: olistrik <strik@olii.nl>
olistrik
force-pushed
the
tailscale-grants
branch
from
November 9, 2026 14:38
d4cc2ad to
accb17d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #93.
Exposes Tailscale application capabilities (grants) from the peer's
CapMapas the{tailscale.grants}placeholder, and as{http.auth.user.tailscale_grants}in the user metadata.expressionmatchers) it is a map, so you can index into it and usein.header_up) it renders as a JSON object. This is the same shape as theTailscale-App-Capabilitiesheader fromtailscale serve: each capability name maps to an array of its values.{}as a string.Changes
auth.goWhoIsCapMap and parses each value as JSON (non-JSON values are kept as strings).Grantsmap type with aString()method that renders JSON with non-ASCII escaped as\uXXXX, so it is always a valid header value.{tailscale.grants}and setstailscale_grantsin the user metadata.cel_test.go: tests for CEL use (indexing,in, deep field access, empty grants), header rendering (including empty, non-JSON and non-ASCII values), and a non-ASCII round trip.README.md: new "Application Capabilities" section with CEL and header examples, anduser.tailscale_grantsadded to the user fields list..gitignore: ignore*.testand*.test.exefromgo test -c.Differences from
tailscale serve{tailscale.grants}contains all of the peer's capabilities.tailscale serveonly forwards those in--accept-app-caps.\uXXXX), not RFC 2047 Q-encoded. The value is plain ASCII and valid JSON, and decoding it as RFC 2047 leaves it unchanged.String(). Q-encoding there would make the value invalid JSON until decoded, and consumers that parse the header as JSON (like a JSONPath extractor) would have to decode it first. The earlier discussion on expose Tailscale App Capabilities (grants) using caddy.Replacer #93 also suggested that header encoding is arguably out of scope for caddy-tailscale and could be left to Caddy.tailscale serve(a header value that is always ASCII), while staying valid JSON. A backend written fortailscale servethat Q-decodes and then JSON-parses should work unchanged, since the escaped value has nothing for the Q-decoder to change. That is untested, see below.tailscale servestrips client-sentTailscale-*headers. Hereheader_upoverwrites the header, but routes that skiptailscale_authshould strip them (e.g.header_up -Tailscale-*). This is documented in the README.I've been running this on my homelab for a couple of months now, also with both applications that are simply gated with it, and also one that consumes the grants from the forwarded headers and extracts them with
JSONPath. I haven't tested it with a backend written fortailscale serve, nor with non-ASCII values in my own grants.Usage