server

package
v5.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package server composes explicit authentication/browser admission and an HTTP server lifecycle. New takes a preconfigured listener and handler; Run owns one Serve loop and bounded graceful shutdown on cancellation, with force-close fallback. It does not supply TLS, supervise workers or shut down borrowed application/telemetry/database collaborators.

Index

Constants

View Source
const (
	// APIKeyIDHeader carries the non-secret static key identifier.
	// #nosec G101 -- public HTTP header name, not a credential; credential values come from caller-owned authentication
	APIKeyIDHeader = "X-Queue-Control-Key-ID"
	// APIKeySecretHeader carries the static key credential.
	// #nosec G101 -- public HTTP header name, not a credential; credential values come from caller-owned authentication
	APIKeySecretHeader = "X-Queue-Control-Key"
)

Variables

View Source
var ErrInvalidAccessDocument = errors.New("server: invalid access document")

ErrInvalidAccessDocument is a secret-safe static access configuration error.

View Source
var ErrInvalidConfiguration = errors.New("server: invalid configuration")

ErrInvalidConfiguration reports an invalid listener, handler or timeout bound.

Functions

func NewAdministrativeHandler

func NewAdministrativeHandler(
	api http.Handler,
	extractor authhttp.CredentialExtractor,
	authenticator authentication.Authenticator,
	challenge authentication.Challenge,
	securityConfig apihttp.SecurityConfig,
) (http.Handler, error)

NewAdministrativeHandler composes browser admission and fail-closed authentication middleware around the administrative API. Missing credentials become an explicit anonymous principal so health endpoints can remain public; administrative endpoints still reject that principal.

Types

type Config

type Config struct {
	// ReadHeaderTimeout bounds header reads; zero selects five seconds and
	// negative values fail.
	ReadHeaderTimeout time.Duration
	// ReadTimeout bounds request reads; zero selects fifteen seconds and
	// negative values fail.
	ReadTimeout time.Duration
	// WriteTimeout bounds response writes; zero selects thirty seconds and
	// negative values fail.
	WriteTimeout time.Duration
	// IdleTimeout bounds keep-alive waits; zero selects sixty seconds and
	// negative values fail.
	IdleTimeout time.Duration
	// ShutdownTimeout bounds graceful shutdown after cancellation; zero selects
	// ten seconds before force-close fallback.
	ShutdownTimeout time.Duration
	// MaxHeaderBytes bounds accepted headers; zero selects 1 MiB and negative
	// values fail.
	MaxHeaderBytes int
}

Config bounds HTTP admission and graceful shutdown.

type Server

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

Server serves one preconfigured listener without supervising other processes.

func New

func New(listener net.Listener, handler http.Handler, config Config) (*Server, error)

New creates a bounded administrative HTTP server.

func (*Server) Run

func (server *Server) Run(ctx context.Context) error

Run serves until listener failure or ctx cancellation. Use one nonnil context and one Run invocation per Server; zero values and concurrent Run calls are unsupported. Cancellation starts a fresh background shutdown budget, then force-closes on failure and joins the Serve loop, not arbitrary handler work.

type StaticAccess

type StaticAccess struct {
	// Extractor reads the static key headers; it does not itself authenticate
	// credentials.
	Extractor *authhttp.Extractor
	// Authenticator verifies startup-configured key material; the bundle
	// supplies it to middleware.
	Authenticator authentication.Authenticator
	// Authorizer applies deny-overrides tenant/resource ACL decisions to
	// authenticated actors.
	Authorizer *controlauthz.Authorizer
	// Challenge is the public authentication challenge, not stored credential
	// material.
	Challenge authentication.Challenge
}

StaticAccess is a coherent authentication and authorization configuration.

func LoadStaticAccess

func LoadStaticAccess(reader io.Reader, maxBytes int64) (*StaticAccess, error)

LoadStaticAccess reads one strict, bounded JSON access document without retaining or formatting its source bytes in errors.

func LoadStaticAccessFile

func LoadStaticAccessFile(path string, maxBytes int64) (*StaticAccess, error)

LoadStaticAccessFile opens one access document without disclosing its path or contents through returned errors.

func NewStaticAccess

func NewStaticAccess(keys []apikey.Entry, entries []acl.Entry) (*StaticAccess, error)

NewStaticAccess builds bounded API-key authentication and deny-overrides ACL authorization from immutable startup configuration.

Jump to

Keyboard shortcuts

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