Documentation
¶
Overview ¶
Package session is the brief session relay's front door (itd-2610091016262335, spc-2610141709430146 step 1): the HTTP handler `abcd session serve` listens with. It serves these routes and nothing else:
- /session, the WebSocket every participant's page holds, handed frame by frame to the transport-agnostic relay in internal/core/session;
- /auth/callback, the web sign-in's callback the team's GitHub App registers: GitHub returns the person here, and the relay sends them on to the session page, naming itself (callback.go);
- /auth/token, the sign-in exchange: the page posts GitHub's code and its PKCE verifier, and the relay adds the sign-in app's secret and asks GitHub for the token (the token-mediating backend of the IETF's browser-based-apps guidance), for a code given for its own callback alone;
- /auth/device, /auth/device/token and /auth/device/cancel, the device sign-in of a local session (device.go);
- /config, the sign-in app's public client id: always a GitHub App's;
- /healthz, for the host's health check.
It is abcd's second listener, admitted by adr-2610032150581128's amendment of 2026-10-14: started on purpose, on loopback unless an address is chosen, and reached on a person's machine through Tailscale Serve only. It writes nothing to disk and logs nothing: no token, no secret, no brief text.
Index ¶
- Constants
- Variables
- func Listen(addr netip.AddrPort) (net.Listener, error)
- func LoopbackListener() (net.Listener, error)
- func OwnerIsOrganisation(ctx context.Context, c *http.Client, api, owner string) (bool, error)
- func ParseListen(s string) (netip.AddrPort, error)
- type AppSetup
- type Config
- type GitHub
- type Server
Constants ¶
const ( DefaultGitHubAPI = "https://api.github.com" DefaultGitHubWeb = "https://github.com" )
The GitHub endpoints the relay talks to unless a test names others.
const ( // SweepInterval is how often the relay looks for idle sessions. SweepInterval = time.Minute // DefaultCloseGrace is how long a connection the relay closed may take // to end before its socket is torn down: its close may wait behind // frames a page is slow to read, and the connection is counted until it // ends. DefaultCloseGrace = 5 * time.Second // DefaultReplayWithin bounds one log replay: 8 MiB, the most a log // holds, in a minute is about 1.1 Mbit/s. DefaultReplayWithin = 60 * time.Second )
The server's own bounds.
const AppTypeGitHubApp = "github-app"
AppTypeGitHubApp is the one kind of GitHub sign-in app the relay takes. A GitHub App's user access token holds only the permissions both the app and the person have, on the repositories the app is installed on, and its authorization takes no scope: "GitHub Apps do not request scopes during authorization to decide which resources the resulting token can access" (https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/generating-a-user-access-token-for-a-github-app). An OAuth app's repo scope reaches every repository the person can, so a relay named by a stranger's repository could collect a token for all of them; GitHub recommends Apps over OAuth apps for the same reason (https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/differences-between-github-apps-and-oauth-apps).
const CallbackPath = "/auth/callback"
CallbackPath is the web sign-in's callback on the relay.
const DefaultListen = "127.0.0.1:8787"
DefaultListen is where the relay listens unless --listen names another address: this computer alone (adr-2610032150581128, as amended 2026-10-14).
const DefaultOrigin = "https://abcdesign.app"
DefaultOrigin is the page's own origin. With loopback pages, for a page run locally, it is the default allowlist, which Config.Origins replaces.
Variables ¶
var ErrNoRepositories = errors.New("a relay listening beyond this computer serves only the repositories it is given; name at least one")
ErrNoRepositories is New's refusal of a relay beyond loopback that names no repository to serve.
Functions ¶
func Listen ¶
Listen opens the relay's listener: abcd's second, admitted by adr-2610032150581128's amendment of 2026-10-14.
func LoopbackListener ¶
LoopbackListener opens the listener on this computer's loopback address that GitHub's answer to the app manifest returns to. It lives here, in a package the listener boundary admits (adr-2610032150581128, as amended 2026-10-14), so the setup verb opens no listener of its own.
func OwnerIsOrganisation ¶
OwnerIsOrganisation asks GitHub whether owner is an organisation, whose apps are registered on the organisation's own page, or a person.
Types ¶
type AppSetup ¶
type AppSetup struct {
// Manifest is the app to register; Run sets its redirect to itself.
Manifest coresession.AppManifest
// FormURL is GitHub's new-app page the form posts to, carrying state.
FormURL func(state string) string
// API is GitHub's REST origin.
API string
// Client asks GitHub.
Client *http.Client
}
AppSetup is one run of the manifest flow.
func (*AppSetup) Run ¶
func (s *AppSetup) Run(ctx context.Context, ln net.Listener, opened func(string)) (coresession.CreatedApp, error)
Run serves the flow on ln until GitHub's redirect brings a code that converts, ctx ends, or the conversion fails maxConversionTries times. opened is told the address to open, once the server is listening. Every request must name ln's own address as its host, so a page on another name cannot drive it (the relay's DNS-rebinding guard, here too). Both pages live under a path drawn at random for this run and printed in that address alone, so a program on this computer that was not handed the address can neither read the state nor bring back a code of its own.
type Config ¶
type Config struct {
// Origins, each an exact scheme://host[:port], replace the default
// allowlist (DefaultOrigin and any loopback page) when given: a relay
// serving a page from its own origin admits nothing else. An entry may
// go on to name the page's base path, as `abcd session page --base-path`
// writes it (https://host/abcdesign/): the web sign-in's callback then
// forwards only to a session page under exactly that path on that origin.
// An entry without one, and every default, is the page at the root.
Origins []string
// BehindProxy trusts the last X-Forwarded-For entry as the client's
// address, which is right only behind a proxy that sets it.
BehindProxy bool
// LoopbackOnly says the listener is bound to loopback alone: the host's
// own machine, reached through Tailscale Serve. Then, and only for a
// loopback peer, the tailnet address Serve forwards is the client's.
LoopbackOnly bool
// Repos (owner/name) and Owners are the repositories the relay serves
// sessions for (core.Options). A relay that is not LoopbackOnly must be
// given at least one: otherwise anyone signed in to GitHub could hold
// its sessions with a repository of their own.
Repos []string
Owners []string
// ClientID is the team's GitHub sign-in app's public id.
ClientID string
// ClientSecret is that app's secret, read from the environment by the
// caller. It never leaves the relay but in the exchange with GitHub. The
// app is a GitHub App: the relay takes no other kind.
ClientSecret string
// GitHubAPI and GitHubWeb default to GitHub's own.
GitHubAPI string
GitHubWeb string
// HTTPClient talks to GitHub; nil is a client with a timeout.
HTTPClient *http.Client
Limits core.Limits
Now func() time.Time
Rand io.Reader
// CloseGrace is how long a connection the relay closed may take to end:
// past it the socket is torn down, whatever it was still writing. Zero
// is DefaultCloseGrace.
CloseGrace time.Duration
// ReplayWithin bounds one log replay: a connection that has not taken
// the whole log within it is ended. Zero is DefaultReplayWithin.
ReplayWithin time.Duration
// ServePage serves the session page from the relay itself: a local
// session (`abcd session start`), where nothing goes to abcdesign.app.
ServePage bool
// Hosts, when given, are the only Host headers the relay answers, each a
// host or host:port; any other is refused with 421 before anything is
// read. A local session names its tailnet name and its loopback address.
Hosts []string
}
Config is what the front door needs.
type GitHub ¶
GitHub is the relay's Verifier: it asks GitHub's API who a token belongs to and whether that login may push to the repository.
func (GitHub) Verify ¶
Verify answers the login and the repository's permissions.push. A repository GitHub hides from the token (404) is no push, not an error.
It takes only a GitHub App's user access token, refusing any other before GitHub is asked: nobody pastes a token (adr-2610161400542916), and a GitHub App's token reaches only the repositories the app is installed on.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the relay's HTTP handler.
func New ¶
New builds the handler, refusing an origin that is not an exact scheme://host[:port] over http or https, a repository that is not owner/name, an owner that is not a GitHub name, and a relay beyond loopback with neither.
func (*Server) Run ¶
Run serves the relay on ln until ctx ends, purging idle sessions as it goes. The server's own error log goes nowhere: the relay logs nothing.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package web is the brief session's page (itd-2610091016262335, spc-2610141709430146 step 3): the static files `abcd session page` writes, embedded in the binary.
|
Package web is the brief session's page (itd-2610091016262335, spc-2610141709430146 step 3): the static files `abcd session page` writes, embedded in the binary. |