userkeyhttp

package
v1.132.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package userkeyhttp serves the self-scoped API key routes a person manages their own keys through (#1759).

It registers onto the portal's authenticated mux through a registrar hook (the notifyhttp pattern) rather than owning a server of its own, and it is server-side self-scoped: the authenticated caller's address is the only account it ever issues a key against, lists keys for, or revokes a key of. A person cannot name whose key they are making, and cannot widen one -- a key they issue authenticates as them and carries the roles they hold, which is what makes it the same identity as their signed-in session rather than a second one they could grant themselves more through.

The list is every key that authenticates as the caller, whether they issued it here or an administrator issued it against their account: seeing every credential that can act as you is the honest answer, and withdrawing one is theirs to do. Scoping is by ownership, checked against the inventory on every read and every revoke, so a name that is not theirs is not found.

Key names are unique across the deployment, so one a person chooses here is stored under a name scoped to them: two people may both call a key "laptop", and neither learns the other's exists.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoSuchKey = errors.New("no such key")

ErrNoSuchKey is what Revoke reports for a key the store does not hold. The composition root translates the store's own sentinel into it, so this surface answers 404 without naming the store it asked.

Functions

This section is empty.

Types

type API

type API struct {
	// Issuer mints and stores a key. It is the same core the admin route
	// issues through, so a key a person makes for themselves comes into being
	// by the same rules.
	Issuer *apikeyissue.Issuer
	// Keys is the deployment's key inventory, read to list a person's own.
	Keys KeyLister
	// Revoke removes a key from the store by its stored name, reporting
	// ErrNoSuchKey when the store holds none.
	Revoke func(r *http.Request, storedName string) error
	// Sync brings this replica's copy up to the key store before it is read.
	// Without it a key another replica wrote a moment ago is absent here, and
	// its owner is told they have no such key (#1715).
	Sync func(r *http.Request)
	// Refresh brings this replica's copy up to the store and tells the others,
	// so a revoked key stops authenticating everywhere at once.
	Refresh func(r *http.Request)
	// Caller resolves the authenticated caller: the address they are known by,
	// and how they authenticated. Both are needed -- the address says whose
	// keys these are, and the auth type says whether they may manage keys at
	// all. It answers "" for an unauthenticated request.
	Caller func(*http.Request) (email, authType string)
}

API serves the self-scoped key routes.

func (*API) Register

func (a *API) Register(mux *http.ServeMux)

Register mounts the self-scoped key routes on mux.

type KeyLister

type KeyLister interface {
	ListKeys() []auth.APIKeySummary
}

KeyLister is what this surface reads to answer a person's own key list. Implemented by *auth.APIKeyAuthenticator.

Jump to

Keyboard shortcuts

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