Skip to main content

internal/api/admission.go

internal/api · 121 lines · 10 declarations · source

Declarations

type Admission

type Admission struct {
mu sync.Mutex
workLimit, projectLimit, credentialLimit, authLimit int
work, auth, audit int
projects, credentials map[string]int
updated time.Time
tokens float64
refused, accepted, auditSuppressed uint64
}

Admission bounds this process's HTTP work. It never queues requests, stores raw credentials or retains inactive project keys. Multiple API processes have independent gates; deployment-wide backlog capacity and upstream denial-of-service protection remain separate controls.

source

const authRequestsPerSecond

const authRequestsPerSecond = 128

source

const authRequestBurst

const authRequestBurst = 256

source

func NewAdmission

func NewAdmission(memoryConnections, registryConnections int32) (*Admission, error)

NewAdmission reserves one memory connection outside HTTP work and limits each project to at most half of the remaining slots. Credential rotation cannot evade the project bound. Pool capacities below three cannot reserve room for another project and background work.

source

method Admission.authenticate

func (a *Admission) authenticate(now time.Time) (func(), bool)

source

method Admission.acquire

func (a *Admission) acquire(project, credential string) (func(), bool)

source

method Admission.acquireAudit

func (a *Admission) acquireAudit() (func(), bool)

Anonymous audit shares the memory-work ceiling, with at most one audit write at once. Failing to acquire is best-effort audit suppression, not a reason to queue or block authentication.

source

type AdmissionStats

type AdmissionStats struct {
Accepted, Refused uint64
ActiveRequests, ActiveAuthentication int
AuditSuppressed uint64
}

AdmissionStats contains fixed aggregate fields only, suitable for operator logs without introducing a metric series for each project, credential or attacker-supplied header.

source

method Admission.Stats

func (a *Admission) Stats() AdmissionStats

source

func writeAdmissionRefusal

func writeAdmissionRefusal(w http.ResponseWriter)

source