authenticated

command
v0.28.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 16, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

authenticated — the identity seam

Shows how the hub derives a peer's identity from a credential instead of trusting the handshake. Two peers attach with different bearer tokens; the hub reaches each by the identity its token proved, and a peer with no token is rejected before it ever lands in the registry.

go run ./examples/authenticated

Output:

hub → alice   ⇒  "hello from alice"
hub → bob     ⇒  "hello from bob"
hub → unknown ⇒  attached=false (rejected at the upgrade)

The mechanism:

  1. Plain HTTP middleware validates the Authorization header on the WebSocket upgrade request and stamps the resolved peer ID onto the request context. (A real hub validates a JWT signature or an mTLS certificate here, the demo uses a token→name map.)
  2. The hub's Identity func reads that context value. Because the ID comes from the authenticated credential and never from the handshake, a peer cannot claim to be someone else.
  3. registry.RoundTripper(peerID) is therefore keyed by a trusted identity — dialing "alice" reaches the process that authenticated as alice, nothing else.

This is exactly how openotters wires it: the agent's JWT agent_ref claim is the peer ID, pinned by the same middleware that guards every other daemon endpoint.

Documentation

Overview

Command authenticated shows the identity seam: the hub derives each peer's ID from a bearer token (a stand-in for a JWT claim or mTLS SAN), so the RoundTripper is keyed by an authenticated identity the peer cannot spoof (the attach upgrade carries no identity at all).

Two peers attach with different tokens; the hub reaches each by the identity its token established, and an unauthenticated attach is rejected.

Run:

go run ./examples/authenticated

Expected output:

hub → alice   ⇒  "hello from alice"
hub → bob     ⇒  "hello from bob"
hub → unknown ⇒  not attached (rejected at the upgrade)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL