pops

package
v0.44.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: Apache-2.0 Imports: 23 Imported by: 1 module, 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.

Documentation

Overview

Package pops holds the public R74 Pop resource types (docs/76): the gawk.ioio.fi/v1alpha1 Pop CR, its -pops-file shape, pairing tokens and credentials. Public, like wire and rooms, so gawk-admin reuses it instead of mirroring it; it depends on apimachinery only.

Index

Constants

View Source
const (
	GroupName = "gawk.ioio.fi"
	Version   = "v1alpha1"
	Kind      = "Pop"
	ListKind  = "PopList"
	// Resource is the plural lowercase resource name.
	Resource = "pops"

	// LabelKey marks a broadcast Lease reserved for, or held through, a PoP
	// (docs/76 item 14); its value is the Pop name, which is why a name is a
	// DNS-1123 label of at most MaxNameLen characters. Equal to
	// internal/cluster.PopLabelKey (pinned by a test there).
	LabelKey   = "gawk/pop"
	MaxNameLen = validation.DNS1123LabelMaxLength

	// Budget and limit defaults (docs/76 §9): a zero field in the CR means
	// these for the uplink and the limits, and "unlimited" for the downlink.
	DefaultUplinkMbps         = 25
	DefaultUplinkStreams      = 3
	DefaultMaxBroadcasts      = 40
	DefaultMaxDownlinkStreams = 20

	// DefaultPairingTTL is how long an unused pairing string can be redeemed
	// (gawk-admin's -pop-pairing-ttl default). It never limits a credential
	// that was paired in time (docs/76 item 8).
	DefaultPairingTTL = 72 * time.Hour

	// PairingPrefix starts every pairing string.
	PairingPrefix = "gawk-pair:"
)

The Pop CRD's group/version/kind (docs/76 §9). Namespaced, beside the relay pods that hold its link, like Rooms and origin Leases.

View Source
const MaxCSRBytes = 4 << 10

MaxCSRBytes bounds a CSR's PEM: a P-256 request with one SAN is under 600 bytes.

Variables

View Source
var (
	ErrBadName              = errors.New("pops: invalid Pop name")
	ErrBadPairing           = errors.New("pops: malformed pairing string")
	ErrPairingUsed          = errors.New("pops: pairing string already used")
	ErrPairingExpired       = errors.New("pops: pairing string expired")
	ErrPairingUnknown       = errors.New("pops: unknown pairing string")
	ErrCredentialNotCurrent = errors.New("pops: credential not current")
	ErrRevoked              = errors.New("pops: PoP revoked")
	ErrExpired              = errors.New("pops: PoP past its end date")
)

Errors. The link and leg routes map them onto statuses (contract §2.4): ErrCredentialNotCurrent → 401, ErrRevoked / ErrExpired → 403; the pairing dial maps ErrPairingUsed / ErrPairingExpired → 410, ErrPairingUnknown → 404.

View Source
var (
	SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
	AddToScheme   = SchemeBuilder.AddToScheme
)

SchemeBuilder / AddToScheme follow the client-go convention.

View Source
var ErrBadCSR = errors.New("pops: bad certificate request")

ErrBadCSR wraps every reason ValidateCSR refuses a request.

View Source
var ErrBadChain = errors.New("pops: bad certificate chain")

ErrBadChain wraps every reason CheckChain refuses an issued chain.

View Source
var GroupVersionResource = SchemeGroupVersion.WithResource(Resource)

GroupVersionResource addresses Pops through a dynamic client.

View Source
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: Version}

SchemeGroupVersion is the group/version this package registers.

Functions

func CSRSHA256

func CSRSHA256(csrPEM string) string

CSRSHA256 is the hex SHA-256 of the request's DER — the value status.tls.issuedForCSR holds. Hashing the DER rather than the text makes PEM framing (line ends, whitespace) irrelevant. "" for anything that is not one PEM CERTIFICATE REQUEST.

func CheckChain

func CheckChain(chainPEM string, csr *x509.CertificateRequest, host string) ([]*x509.Certificate, error)

CheckChain parses an issued PEM chain and checks its leaf answers csr: the same public key, valid for host. It returns the parsed chain, leaf first. It does not verify the issuer: the PoP trusts what its link delivers, and a browser verifies the rest.

func CredentialSHA256

func CredentialSHA256(cred string) string

CredentialSHA256 is the stored hash of a credential (hex).

func FormatPairing

func FormatPairing(endpoint, token string) string

FormatPairing builds the pairing string an operator copies once: "gawk-pair:" + the home relay endpoint (host:port) + "/" + token.

func NewCredential

func NewCredential() (string, error)

NewCredential mints a PoP credential: 256 random bits, base64url without padding.

func NewPairingToken

func NewPairingToken() (string, error)

NewPairingToken returns a fresh pairing token: 128 random bits, RFC 4648 base32 without padding, upper case, a '-' every five characters so a human can read it aloud ("K7M2Q-9XDA4-…"). Every call is random, so two Re-pairs in the same second differ (docs/76 item 9).

func ParsePairing

func ParsePairing(s string) (endpoint, token string, err error)

ParsePairing splits a pasted pairing string into the home endpoint (host:port, brackets kept for IPv6) and the canonical token (upper case, grouped). It tolerates surrounding whitespace, lower case and missing dashes, and refuses anything that is not exactly 128 bits of base32.

func TokenSHA256

func TokenSHA256(token string) string

TokenSHA256 is the stored hash of a pairing token: hex SHA-256 of the token with its dashes stripped, upper-cased, so the presentation never changes the hash.

func ValidateCSR

func ValidateCSR(csrPEM, host string) (*x509.CertificateRequest, error)

ValidateCSR parses csrPEM and checks it is what a PoP may ask for: a valid self-signature, a P-256 key, exactly one SAN — the DNS name host, which gawk-admin assigned — and no other name of any kind (a subject CN, if present, must be the same host). Anything else is ErrBadCSR.

func ValidateName

func ValidateName(name string) error

ValidateName checks a Pop name: a DNS-1123 label of at most MaxNameLen characters, because it is also the gawk/pop label value.

func ValidateWallCode

func ValidateWallCode(code string) error

ValidateWallCode checks a wall room code: an ordinary static room code (rooms.NormalizeCode) that is not dynamic-shaped. A Pop name can be up to 63 characters and a room code only 32, so a long or six-character broadcast-alphabet name needs an explicit wall code.

Types

type Budget

type Budget struct {
	MaxMbps    int `json:"maxMbps,omitempty"`
	MaxStreams int `json:"maxStreams,omitempty"`
}

Budget is a Mbps and stream ceiling. 0 means the default (uplink) or unlimited (downlink).

type Credential

type Credential struct {
	SHA256             string       `json:"sha256,omitempty"`
	PairingTokenSHA256 string       `json:"pairingTokenSHA256,omitempty"`
	PairedAt           *metav1.Time `json:"pairedAt,omitempty"`
}

Credential records the PoP's credential by its SHA-256 only, never the credential itself (the R42 creatorTokenFingerprint precedent), and the pairing string it was minted under.

func (*Credential) DeepCopyInto

func (in *Credential) DeepCopyInto(out *Credential)

DeepCopyInto copies the receiver into out.

type FilePop

type FilePop struct {
	Name string `json:"name"`
	// UID is the PoP's stable handle (a UUID), what a CR's metadata.uid is
	// in cluster mode (docs/76 item 41).
	UID              string     `json:"uid"`
	DisplayName      string     `json:"displayName,omitempty"`
	CredentialSHA256 string     `json:"credentialSHA256"`
	NotAfter         *time.Time `json:"notAfter,omitempty"`
	Revoked          bool       `json:"revoked,omitempty"`
	Uplink           Budget     `json:"uplink,omitempty"`
	Downlink         Budget     `json:"downlink,omitempty"`
	Limits           Limits     `json:"limits,omitempty"`
	Guests           Guests     `json:"guests,omitempty"`
	Wall             *Wall      `json:"wall,omitempty"`
}

FilePop is one -pops-file entry: the shape an operator writes by hand where there is no Kubernetes API (the docs/42 / -rooms-file posture). There is no pairing: CredentialSHA256 is the credential, and rotating it means editing the file (docs/76 item 9).

func (FilePop) ToPop

func (f FilePop) ToPop() Pop

ToPop converts a file entry into the Pop every consumer reads. The credential is current by construction: both pairing hashes are empty.

type Guests

type Guests struct {
	AutoSwitch *bool `json:"autoSwitch,omitempty"`
}

Guests holds the guest-side options. AutoSwitch nil means true.

func (*Guests) DeepCopyInto

func (in *Guests) DeepCopyInto(out *Guests)

DeepCopyInto copies the receiver into out.

type Lease

type Lease struct {
	Holder     string       `json:"holder,omitempty"`
	Addr       string       `json:"addr,omitempty"`
	Generation int64        `json:"generation,omitempty"`
	RenewedAt  *metav1.Time `json:"renewedAt,omitempty"`
}

Lease is the link-home record with the R17 generation-CAS semantics.

func (*Lease) DeepCopyInto

func (in *Lease) DeepCopyInto(out *Lease)

DeepCopyInto copies the receiver into out.

type Limits

type Limits struct {
	MaxBroadcasts      int `json:"maxBroadcasts,omitempty"`
	MaxDownlinkStreams int `json:"maxDownlinkStreams,omitempty"`
}

Limits are enforced at home; 0 means the default.

type Link struct {
	Connected    bool         `json:"connected,omitempty"`
	Since        *metav1.Time `json:"since,omitempty"`
	Version      string       `json:"version,omitempty"`
	Proto        int          `json:"proto,omitempty"`
	PublicAddrs  []string     `json:"publicAddrs,omitempty"`
	LanAddr      string       `json:"lanAddr,omitempty"`
	PinnedHashes []string     `json:"pinnedHashes,omitempty"`
}

Link is what the PoP reported on its live link. It carries addresses: the Kubernetes API is internal, and no event ever copies them (docs/76 §8).

func (*Link) DeepCopyInto

func (in *Link) DeepCopyInto(out *Link)

DeepCopyInto copies the receiver into out.

type NamedAddress

type NamedAddress struct {
	Enabled bool `json:"enabled,omitempty"`
}

NamedAddress turns on the named tier (docs/76 §6.11).

type Pairing

type Pairing struct {
	TokenSHA256 string       `json:"tokenSHA256,omitempty"`
	IssuedAt    *metav1.Time `json:"issuedAt,omitempty"`
	ExpiresAt   *metav1.Time `json:"expiresAt,omitempty"`
}

Pairing is the stored half of a pairing string: its hash, never the string (docs/76 item 7).

func (*Pairing) DeepCopyInto

func (in *Pairing) DeepCopyInto(out *Pairing)

DeepCopyInto copies the receiver into out.

type Pop

type Pop struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`

	Spec   PopSpec   `json:"spec"`
	Status PopStatus `json:"status,omitempty"`
}

Pop is one PoP relay a home fleet accepts links from (docs/76 §9). spec is written by gawk-admin (or kubectl); status has two writers on disjoint paths, see PopStatus.

func (*Pop) AutoSwitch

func (p *Pop) AutoSwitch() bool

AutoSwitch reports whether home offers this PoP to matching guests (docs/76 item 41); unset means true.

func (*Pop) CheckCredential

func (p *Pop) CheckCredential(cred string, now time.Time) error

CheckCredential authenticates a presented credential. The hash is compared first, in constant time, so a wrong credential learns nothing about the Pop's state: it is ErrCredentialNotCurrent (401) whether the Pop is revoked or not. A matching one is then ErrRevoked or ErrExpired (403) when the Pop says so, and ErrCredentialNotCurrent when a Re-pair superseded the string it was paired with.

func (*Pop) CredentialCurrent

func (p *Pop) CredentialCurrent() bool

CredentialCurrent reports whether the recorded credential was paired with the current pairing string (docs/76 item 9). A -pops-file Pop has neither hash, so its credential is always current.

func (*Pop) DeepCopy

func (in *Pop) DeepCopy() *Pop

DeepCopy returns a deep copy.

func (*Pop) DeepCopyInto

func (in *Pop) DeepCopyInto(out *Pop)

DeepCopyInto copies the receiver into out.

func (*Pop) DeepCopyObject

func (in *Pop) DeepCopyObject() runtime.Object

DeepCopyObject satisfies runtime.Object.

func (*Pop) EffectiveLimits

func (p *Pop) EffectiveLimits() Limits

EffectiveLimits is the limits block with zero fields defaulted.

func (p *Pop) EffectiveUplink() Budget

EffectiveUplink is the uplink budget with zero fields defaulted.

func (*Pop) Redeemable

func (p *Pop) Redeemable(tokenSHA string, now time.Time) error

Redeemable reports whether a pairing token (by its TokenSHA256) may be redeemed now: it must be the current string (else ErrPairingUnknown), not already redeemed (ErrPairingUsed), not past spec.pairing.expiresAt (ErrPairingExpired), and the Pop must be neither revoked nor past its end date. expiresAt limits only redemption, never a credential (item 8).

type PopList

type PopList struct {
	metav1.TypeMeta `json:",inline"`
	metav1.ListMeta `json:"metadata,omitempty"`

	Items []Pop `json:"items"`
}

PopList is the list type for the Pop kind.

func (*PopList) DeepCopy

func (in *PopList) DeepCopy() *PopList

DeepCopy returns a deep copy.

func (*PopList) DeepCopyInto

func (in *PopList) DeepCopyInto(out *PopList)

DeepCopyInto copies the receiver into out.

func (*PopList) DeepCopyObject

func (in *PopList) DeepCopyObject() runtime.Object

DeepCopyObject satisfies runtime.Object.

type PopSpec

type PopSpec struct {
	DisplayName string `json:"displayName"`
	// NotAfter, when set, refuses links and legs after it (ErrExpired).
	NotAfter *metav1.Time `json:"notAfter,omitempty"`
	// Revoked refuses links and legs (ErrRevoked), docs/76 §6.9.
	Revoked bool `json:"revoked,omitempty"`
	// Pairing is the current pairing string's hash. A Re-pair writes a new
	// one and nothing else, which makes every older credential not current.
	Pairing Pairing `json:"pairing,omitempty"`
	// Uplink is the PoP → home budget; a zero field is the default.
	Uplink Budget `json:"uplink,omitempty"`
	// Downlink is the home → PoP budget; a zero field is unlimited.
	Downlink     Budget       `json:"downlink,omitempty"`
	Limits       Limits       `json:"limits,omitempty"`
	Guests       Guests       `json:"guests,omitempty"`
	Wall         *Wall        `json:"wall,omitempty"`
	NamedAddress NamedAddress `json:"namedAddress,omitempty"`
}

PopSpec mirrors the YAML in docs/76 §9.

func (*PopSpec) DeepCopyInto

func (in *PopSpec) DeepCopyInto(out *PopSpec)

DeepCopyInto copies the receiver into out.

type PopStatus

type PopStatus struct {
	Credential *Credential `json:"credential,omitempty"`
	Lease      *Lease      `json:"lease,omitempty"`
	Link       *Link       `json:"link,omitempty"`
	TLS        *TLS        `json:"tls,omitempty"`
}

PopStatus has two writers on disjoint paths, so their merge patches never collide (docs/76 §9):

  • the relays (the link-home pod) own Credential, Lease, Link and TLS.CSR;
  • gawk-admin owns TLS.Host, TLS.Certificate, TLS.IssuedForCSR and TLS.NotAfter.

gawk-admin never writes Credential: invalidation goes through spec.

func (*PopStatus) DeepCopyInto

func (in *PopStatus) DeepCopyInto(out *PopStatus)

DeepCopyInto copies the receiver into out.

type TLS

type TLS struct {
	Host         string       `json:"host,omitempty"`
	CSR          string       `json:"csr,omitempty"`
	Certificate  string       `json:"certificate,omitempty"`
	IssuedForCSR string       `json:"issuedForCSR,omitempty"`
	NotAfter     *metav1.Time `json:"notAfter,omitempty"`
}

TLS is the named tier's certificate state. CSR is the relays'; the rest is gawk-admin's.

func (*TLS) DeepCopyInto

func (in *TLS) DeepCopyInto(out *TLS)

DeepCopyInto copies the receiver into out.

type Wall

type Wall struct {
	RoomCode string `json:"roomCode"`
}

Wall names the party wall room (docs/76 §6.10); absent = no wall.

Jump to

Keyboard shortcuts

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