@tailworks/tailnet
v0.2.0
Published
Verified tailnet caller identity and per-object egress for tailworks Workers and Durable Objects
Maintainers
Readme
@tailworks/tailnet
The tailnet side of a tailworks Worker or Durable Object: who is calling (verified over WireGuard), and egress from the workload's or the object's own tailnet node.
import { getCaller, tailnet, isTailnetError } from "@tailworks/tailnet";
export default {
async fetch(req: Request, env: Env, ctx: ExecutionContext) {
const who = getCaller(req); // nodeId, node, tags, user, caps()
return Response.json({ hello: who.node });
},
};getCaller(req),getRequester(req),principalKey(caller): the verified caller of a request.tailnet(ctx):ctx.tailnet(fetch,spawn,kill,self,audit), or a typedno_identityerror off tailworks.TailnetError,isTailnetError,fromResponse: tailworks' typed errors and their catalog.@tailworks/tailnet/testing:withCallerand a fakectx.tailnetfor unit tests;@tailworks/tailnet/testing/dev: black-box tests againsttw dev.
Add "@tailworks/tailnet" to compilerOptions.types in tsconfig.json
(next to @cloudflare/workers-types) to type ctx.tailnet. Every tw init
template does this.
Docs: testing, errors, wrangler compatibility.
