relaykey

package
v0.9.21 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: Apache-2.0 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.

Documentation

Overview

Package relaykey is the domain layer for the RelayKey entity — an inbound API key the relay issues to a client. Authentication only: plaintext is never stored, only sha256(KeyHash) plus a short display Prefix.

Each RelayKey belongs to exactly one Policy via Spec.PolicyID. Policy selection at request time is keyed off the authenticated RelayKey, not the model — the Policy then dictates the allowed Models and the ProviderKey pool.

store.go is the data-access layer for RelayKey. Same shape as the other entity stores; sha256(plaintext) is the caller's responsibility — the plaintext never enters this package.

Index

Constants

View Source
const TokenPrefix = "sk-wr-"

TokenPrefix is the literal prefix every relay-issued bearer token starts with. The leading "sk-" matches the LLM-API convention so the token visually scans as a secret credential in logs.

Variables

This section is empty.

Functions

This section is empty.

Types

type Generated

type Generated struct {
	Plaintext string
	KeyHash   string
	Prefix    string
}

Generated carries the result of Generate. Plaintext is the only field the server ever sees in cleartext; it is returned to the caller exactly once and never persisted.

func Generate

func Generate() (Generated, error)

Generate produces a fresh relay-key plaintext and the derived KeyHash + display Prefix. The plaintext is `sk-wr-<base64url(48 random bytes)>`. Callers store KeyHash + Prefix and return Plaintext to the user once.

type RelayKey

type RelayKey struct {
	Meta meta.Metadata `json:"metadata" yaml:"metadata"`
	Spec Spec          `json:"spec"     yaml:"spec"`
}

RelayKey is an inbound bearer credential.

func (*RelayKey) IsActive

func (k *RelayKey) IsActive() bool

IsActive returns true when the key is enabled and not revoked.

func (*RelayKey) IsEnabled

func (k *RelayKey) IsEnabled() bool

IsEnabled returns true when Enabled is unset or explicitly true.

func (*RelayKey) Validate

func (k *RelayKey) Validate() error

Validate runs intra-row rules via the shared meta.Validator and enforces:

  • Owner.Kind is user (RelayKeys are operator-issued).

type Spec

type Spec struct {
	// PolicyID is the Policy this RelayKey serves under. **Optional** —
	// when empty, the key is "policy-less" and the relay's behavior is
	// controlled by the inference settings section
	// (AllowMissingPolicy). A policy-less key with that flag on is
	// allowed to reach any model served by any host the relay has
	// hostkeys for, with no policy-level rate limits. With the flag off,
	// such requests are rejected.
	PolicyID string `json:"policyId,omitempty" yaml:"policyId,omitempty" validate:"omitempty,uuid"`

	// KeyHash is sha256(plaintext) hex. Required and immutable after create.
	KeyHash string `json:"keyHash" yaml:"keyHash" validate:"required,len=64,hexadecimal"`

	// Prefix is the leading visible portion of the token (e.g. "rk_a8b3f2")
	// retained so the UI can show a recognisable identifier without ever
	// holding the plaintext.
	Prefix string `json:"prefix,omitempty" yaml:"prefix,omitempty"`

	// RevokedAt, when non-nil, marks the key as rejected at auth time.
	RevokedAt *time.Time `json:"revokedAt,omitempty" yaml:"revokedAt,omitempty"`

	// Enabled defaults to true when nil.
	Enabled *bool `json:"enabled,omitempty" yaml:"enabled,omitempty"`

	// PassthroughAllowed, when true, permits this key to forward an upstream
	// Authorization header verbatim to the provider. Gated by the relay's
	// global passthrough mode — when that mode is off the flag is moot.
	PassthroughAllowed bool `json:"passthroughAllowed,omitempty" yaml:"passthroughAllowed,omitempty"`

	// PayloadLoggingEnabled opts requests authenticated by this key into
	// full request/response body capture by the payloadlog observer. Off
	// by default. Independent of the policy-level flag — either enables
	// capture.
	PayloadLoggingEnabled bool `json:"payloadLoggingEnabled,omitempty" yaml:"payloadLoggingEnabled,omitempty"`
}

Spec carries the auth material and gating flags. KeyHash is the sha256 hex of the bearer token (lowercase, 64 chars); the plaintext is never stored anywhere.

type Store

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

Store is the RelayKey data-access type.

func NewStore

func NewStore(q *gen.Queries) *Store

NewStore constructs a Store from an existing sqlc Queries handle.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, id string) error

Delete removes a RelayKey by id.

func (*Store) Get

func (s *Store) Get(ctx context.Context, id string) (*RelayKey, error)

Get returns the RelayKey with the given id, or (nil, nil) if not found.

func (*Store) List

func (s *Store) List(ctx context.Context) ([]*RelayKey, error)

List returns every RelayKey row.

func (*Store) Upsert

func (s *Store) Upsert(ctx context.Context, k *RelayKey) error

Upsert writes k. Caller is responsible for stamping Meta.ID and for computing Spec.KeyHash from the plaintext.

Jump to

Keyboard shortcuts

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