middleware

package
v0.0.0-...-19d8ef3 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const AgentRoutePrefix = "/v1/agent/"

AgentRoutePrefix is the only route prefix an agent-session credential may reach. Everything outside it is denied outright for agent tokens.

View Source
const AgentScopeDenyMessage = "agent session token is scoped to its own incident's /v1/agent/* tool surface"

AgentScopeDenyMessage is the 403 reason returned when an agent-session token is used on any route outside its incident's /v1/agent/* tool surface (a non-agent route, or a different incident's agent route). Exported so the auth and integration tests assert against the single source of truth.

View Source
const ApprovalAgentTokenDenyMessage = "agent session tokens may not approve or reject remediation actions"

ApprovalAgentTokenDenyMessage is the 403 reason returned when a per-session agent token (Stream C1) attempts to approve or reject a tier-3 remediation action. An agent may NEVER approve its own proposed action — tier 3 always terminates at a human. Exported so the auth and integration tests assert against the single source of truth.

View Source
const ContextKeyAllowedJobAliases = "auth.allowed_job_aliases"

ContextKeyAllowedJobAliases stores the scoped job aliases available to list endpoints.

View Source
const ContextKeyAuth = "auth"

ContextKeyAuth is the key used to store the authenticated API key in the Echo context.

View Source
const ContextKeyCSRFToken = "auth.csrf_token"

ContextKeyCSRFToken stores the resolved session's CSRF token for handlers.

View Source
const ContextKeyPrincipal = "auth.principal"

ContextKeyPrincipal stores the unified authenticated identity for the request.

View Source
const ContractsGraphScopedDenyMessage = "contracts graph is a global cross-job query and requires an unscoped principal"

ContractsGraphScopedDenyMessage is the 403 reason returned to a scoped principal on the global, cross-job /v1/contracts/graph route.

View Source
const EventsScopedDenyMessage = "event stream requires an in-scope run_id for scoped principals"

EventsScopedDenyMessage is returned when a scoped principal attempts to open the global event stream without a run_id filter. Scoped event subscriptions must resolve to one run owner before any events are streamed.

View Source
const LineageImpactScopedDenyMessage = "lineage impact is a global cross-job query and requires an unscoped principal"

LineageImpactScopedDenyMessage is the 403 reason returned to a scoped principal on the global, cross-job /v1/lineage/impact route. Exported so the auth and integration tests assert against the single source of truth.

Variables

This section is empty.

Functions

func Auth

Auth returns Echo middleware that enforces API-key or session-cookie authentication and RBAC.

func EnforceSessionCSRF

func EnforceSessionCSRF(c *echo.Context, expected string) error

EnforceSessionCSRF validates the synchronizer CSRF token for cookie-authenticated unsafe requests. Bearer/API-key requests are exempt at the auth middleware call site because they are not ambient browser credentials.

func GetAllowedJobAliases

func GetAllowedJobAliases(c *echo.Context) []string

GetAllowedJobAliases returns the scoped aliases injected by the auth middleware.

func GetAuthKey

func GetAuthKey(c *echo.Context) *models.APIKey

GetAuthKey extracts the authenticated API key from the Echo context. Returns nil if no key is present (e.g. unauthenticated endpoints).

func GetCSRFToken

func GetCSRFToken(c *echo.Context) string

GetCSRFToken returns the session CSRF token stashed by auth middleware, or "".

func GetPrincipal

func GetPrincipal(c *echo.Context) *auth.Principal

GetPrincipal returns the unified authenticated identity, or nil if unauthenticated.

func IsPublicAuthPath

func IsPublicAuthPath(path string) bool

IsPublicAuthPath reports whether path is intentionally reachable without the Auth middleware enforcing credentials. Keep RBAC completeness tests on this helper so their public-route exclusions match the middleware.

func NormalizeRoutePath

func NormalizeRoutePath(path string) string

NormalizeRoutePath returns the policy lookup path used by RBAC for Echo route patterns or raw request paths.

func ParseTrustedProxyRanges

func ParseTrustedProxyRanges(raw string) []*net.IPNet

ParseTrustedProxyRanges parses a comma-separated proxy allowlist into IP ranges. Entries may be CIDR ranges or individual IP addresses.

func ParseTrustedProxyRangesStrict

func ParseTrustedProxyRangesStrict(raw string) ([]*net.IPNet, error)

ParseTrustedProxyRangesStrict parses a proxy allowlist and rejects invalid entries. Use it when a proxy list is part of startup security validation.

func RequestIsSecure

func RequestIsSecure(r *http.Request, trustedProxies []*net.IPNet) bool

RequestIsSecure reports whether the original request is HTTPS. Forwarded protocol headers are trusted only when the immediate peer is allowlisted.

Types

type AuthDeps

type AuthDeps struct {
	Service    *auth.Service
	Auditor    *auth.AuditLogger
	Limiter    *auth.RateLimiter
	Sessions   *auth.SessionStore
	CookieName string
}

AuthDeps bundles the dependencies the auth middleware needs.

type IPRateLimitConfig

type IPRateLimitConfig func() (perMinute int, burst int)

IPRateLimitConfig returns the per-minute rate and burst limit.

type IPRateLimiters

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

IPRateLimiters tracks token buckets by source IP.

func NewIPRateLimiters

func NewIPRateLimiters(staleAge time.Duration, config IPRateLimitConfig) *IPRateLimiters

func (*IPRateLimiters) Allow

func (l *IPRateLimiters) Allow(ip string) bool

Jump to

Keyboard shortcuts

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