Help us shape the future of Go! Take the 2026 Go Developer Survey

auth

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package auth is the two credentials a harness checks. An api key lets a connector call every HTTP route. A join secret lets a machine join the mesh as a worker; it can add a worker and nothing else. Both kinds live hashed in one table in the harness's directory. What a person pastes is a token: the kind, the key of the harness its holder finds through the pointer, and the secret itself.

mp_<kind>_<harness key>.<secret>

Index

Constants

View Source
const (
	Key  = "key"  // a connector's credential: every HTTP route
	Join = "join" // a worker's credential: joining the mesh
)

Variables

This section is empty.

Functions

func Addr added in v0.2.0

func Addr(r *http.Request) string

Addr is who sent r: the client address cloudflared puts in CF-Connecting-IP, else the peer. The harness listens on loopback only, so every peer is cloudflared or this machine, and the header can be trusted.

func Hash

func Hash(secret string) string

func Parse

func Parse(kind, token string) (key, secret string, err error)

Parse is a token's harness key and secret, refused when it is not of kind.

func Token

func Token(kind, key, secret string) string

Types

type Entry

type Entry struct {
	Name      string `json:"name"`
	Hash      string `json:"hash"`
	Ephemeral bool   `json:"ephemeral,omitempty"` // join: its workers leave the mesh when they go quiet
}

type Limit added in v0.2.0

type Limit struct {
	// contains filtered or unexported fields
}

Limit counts refused credentials of both kinds by address, and turns an address away for the rest of a window once it has too many. The window is one for every address, so an address may come back early. It keeps down noise and log spam; a 26-character secret needs no limit against guessing.

func (*Limit) Refused added in v0.2.0

func (l *Limit) Refused(addr string)

Refused counts a refused credential from addr, in a new window once the last has passed.

func (*Limit) Wait added in v0.2.0

func (l *Limit) Wait(addr string) error

Wait is why addr is turned away now, or nil.

type Store

type Store struct{ Path string }

Store is the table as a file, read on every check so a new or revoked entry counts at once.

func (Store) Add added in v0.5.0

func (s Store) Add(kind, name, secret string) error

Add makes secret an entry of kind named name, beside any before it.

func (Store) Bearer

func (s Store) Bearer(l *Limit, next http.Handler) http.Handler

Bearer refuses a request whose Authorization: Bearer is not a live api key, and one from an address l turns away. A request with no key is refused but not counted: it guesses nothing.

func (Store) Check

func (s Store) Check(kind, secret string) bool

Check is whether secret is a live entry of kind.

func (Store) Find added in v0.3.0

func (s Store) Find(kind, secret string) (Entry, bool)

Find is the live entry of kind that secret is, if it is one.

func (Store) Issue

func (s Store) Issue(kind, name string, ephemeral bool) (string, error)

Issue adds an entry and returns its secret: the one time it is in the clear.

func (Store) Load

func (s Store) Load() (Table, error)

func (Store) Revoke

func (s Store) Revoke(kind, name string) error

func (Store) Set added in v0.1.1

func (s Store) Set(kind, name, secret string) error

Set makes secret the entry of kind named name, in place of any before it.

type Table

type Table map[string][]Entry

Table is the live entries by kind. A revoked entry is gone, not marked.

Jump to

Keyboard shortcuts

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