registry

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 16 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

Index

Constants

View Source
const (
	// DefaultNamespace is the Kubernetes namespace for registry secrets.
	DefaultNamespace = "bridge-system"
	// SecretPrefix is the prefix for secret file names.
	SecretPrefix = "bridge-client-"
	// PublicKeyField is the key name within the secret data.
	PublicKeyField = "jwt-public-key.pem"
)
View Source
const (
	// MaxKeyUploadBytes limits the size of a public key upload body.
	MaxKeyUploadBytes = 4096
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientKey

type ClientKey struct {
	Issuer    string
	PublicKey ed25519.PublicKey
}

ClientKey holds a registered client's public key and metadata.

type Config

type Config struct {
	Listen  string        `yaml:"listen"`
	TLS     TLSConfig     `yaml:"tls"`
	Storage StorageConfig `yaml:"storage"`
	Servers []ServerEntry `yaml:"servers"`
}

Config holds the registry service configuration.

func LoadConfig

func LoadConfig(path string) (*Config, error)

LoadConfig reads and parses a registry config YAML file.

func (*Config) BuildServerConfig

func (c *Config) BuildServerConfig() ServerConfig

BuildServerConfig converts the config's server entries to a ServerConfig.

type Handler

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

Handler implements the HTTP handlers for the key registry.

func NewHandler

func NewHandler(store Store, cfg ServerConfig, logger *slog.Logger) *Handler

NewHandler creates a new Handler with the given store and config.

func (*Handler) GetJWKS

func (h *Handler) GetJWKS(w http.ResponseWriter, r *http.Request)

GetJWKS handles GET /v1/servers/{server_id}/jwks.json. Returns only the keys for issuers allowed on the given server.

func (*Handler) Health

func (h *Handler) Health(w http.ResponseWriter, _ *http.Request)

Health returns a simple health check response.

func (*Handler) RegisterRoutes

func (h *Handler) RegisterRoutes(mux *http.ServeMux)

RegisterRoutes registers all handler routes on the given mux.

func (*Handler) UploadKey

func (h *Handler) UploadKey(w http.ResponseWriter, r *http.Request)

UploadKey handles POST /v1/clients/{issuer}/jwt-public-key. It requires mTLS — the client certificate CN must match the issuer path param.

type JWK

type JWK struct {
	Kty string `json:"kty"`
	Crv string `json:"crv"`
	X   string `json:"x"`
	Kid string `json:"kid"`
	Use string `json:"use"`
}

JWK represents a single JSON Web Key (RFC 7517).

func Ed25519ToJWK

func Ed25519ToJWK(pubKey ed25519.PublicKey, kid string) JWK

Ed25519ToJWK converts an Ed25519 public key and issuer ID to a JWK.

type JWKS

type JWKS struct {
	Keys []JWK `json:"keys"`
}

JWKS represents a JSON Web Key Set (RFC 7517).

func ClientKeysToJWKS

func ClientKeysToJWKS(keys []ClientKey) JWKS

ClientKeysToJWKS converts a slice of ClientKey to a JWKS.

type K8sStore

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

K8sStore implements Store by reading and writing files in a directory structured as one subdirectory per issuer. In a Kubernetes deployment, a persistent volume or emptyDir backs the directory. Outside Kubernetes, it operates as a plain file-backed store.

func NewK8sStore

func NewK8sStore(baseDir string, logger *slog.Logger) (*K8sStore, error)

NewK8sStore creates a file-backed store at the given directory.

func (*K8sStore) DeleteKey

func (s *K8sStore) DeleteKey(_ context.Context, issuer string) error

DeleteKey removes the issuer directory and its key.

func (*K8sStore) GetKey

func (s *K8sStore) GetKey(_ context.Context, issuer string) (ed25519.PublicKey, error)

GetKey reads the public key PEM for the given issuer.

func (*K8sStore) ListKeys

func (s *K8sStore) ListKeys(_ context.Context) ([]ClientKey, error)

ListKeys enumerates all stored client keys.

func (*K8sStore) PutKey

func (s *K8sStore) PutKey(_ context.Context, issuer string, pubKey ed25519.PublicKey) error

PutKey stores the public key as a PEM file under the issuer directory.

type MemoryStore

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

MemoryStore is an in-memory implementation of Store for testing and non-Kubernetes environments.

func NewMemoryStore

func NewMemoryStore() *MemoryStore

NewMemoryStore creates a new in-memory store.

func (*MemoryStore) DeleteKey

func (s *MemoryStore) DeleteKey(_ context.Context, issuer string) error

DeleteKey removes the key for the given issuer.

func (*MemoryStore) GetKey

func (s *MemoryStore) GetKey(_ context.Context, issuer string) (ed25519.PublicKey, error)

GetKey retrieves the public key for the given issuer.

func (*MemoryStore) ListKeys

func (s *MemoryStore) ListKeys(_ context.Context) ([]ClientKey, error)

ListKeys returns all registered client keys.

func (*MemoryStore) PutKey

func (s *MemoryStore) PutKey(_ context.Context, issuer string, pubKey ed25519.PublicKey) error

PutKey stores or replaces the public key for the given issuer.

type ServerConfig

type ServerConfig struct {
	AllowedIssuers map[string][]string // server_id -> []issuer
}

ServerConfig maps server IDs to their allowed issuers.

type ServerEntry

type ServerEntry struct {
	ID             string   `yaml:"id"`
	AllowedIssuers []string `yaml:"allowed_issuers"`
}

ServerEntry maps a server ID to its allowed issuers.

type StorageConfig

type StorageConfig struct {
	Type    string `yaml:"type"`     // "memory" or "file"
	BaseDir string `yaml:"base_dir"` // required when type=file
}

StorageConfig selects and configures the storage backend.

type Store

type Store interface {
	// PutKey stores or replaces the public key for the given issuer.
	PutKey(ctx context.Context, issuer string, pubKey ed25519.PublicKey) error

	// GetKey retrieves the public key for the given issuer.
	// Returns nil, nil if the issuer is not found.
	GetKey(ctx context.Context, issuer string) (ed25519.PublicKey, error)

	// ListKeys returns all registered client keys.
	ListKeys(ctx context.Context) ([]ClientKey, error)

	// DeleteKey removes the key for the given issuer.
	DeleteKey(ctx context.Context, issuer string) error
}

Store defines the interface for persisting and retrieving client public keys.

type TLSConfig

type TLSConfig struct {
	CABundle string `yaml:"ca_bundle"`
	Cert     string `yaml:"cert"`
	Key      string `yaml:"key"`
}

TLSConfig holds TLS certificate paths for mTLS.

Jump to

Keyboard shortcuts

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