middleware

package
v1.19.23 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultBodyIdle  = 30 * time.Second
	DefaultBodyTotal = 10 * time.Minute
)
View Source
const OrganizationIdContextKey = "organizationId"
View Source
const ProjectContextKey = "project"
View Source
const ProjectIdContextKey = "project_id"
View Source
const RunnerContextKey = "syntheticRunner"
View Source
const RunnerNameHeader = "X-Traceway-Runner-Name"

RunnerNameHeader identifies the runner instance. Runners self-register under this name on first contact; it doubles as their claim identity.

View Source
const RunnerVersionHeader = "X-Traceway-Runner-Version"

RunnerVersionHeader lets the runner binary report its version.

View Source
const SetupOrganizationIdContextKey = "setupOrganizationId"
View Source
const SetupScopeContextKey = "setupScope"
View Source
const UserEmailContextKey = "userEmail"
View Source
const UserIdContextKey = "userId"
View Source
const UserOrgRoleContextKey = "userOrgRole"

Variables

View Source
var (
	CORSReport    = cors("POST, OPTIONS", "Content-Type, Content-Encoding, Authorization", "", "")
	MCPCors       = cors("GET, POST, DELETE, OPTIONS", mcpAllowHeaders, "Mcp-Session-Id, WWW-Authenticate", "600")
	WellKnownCors = cors("GET, OPTIONS", mcpAllowHeaders, "", "600")
	OAuthCors     = cors("POST, OPTIONS", mcpAllowHeaders, "", "600")
)
View Source
var ErrBodyTimedOut = fmt.Errorf("request body timed out: %w", os.ErrDeadlineExceeded)

The raw deadline error is a *net.OpError naming the listener address, and handlers echo bind errors verbatim, so it is replaced before it leaves Read.

View Source
var ErrBodyTooSlow = errors.New("request body delivered too slowly")
View Source
var ErrInvalidBearer = errors.New("invalid bearer token")
View Source
var ErrProjectIdNotInContext = errors.New("projectId not found in context - ensure RequireProjectAccess middleware is applied")
View Source
var RequireAdminAccess gin.HandlerFunc
View Source
var RequireOrganizationAccess gin.HandlerFunc

RequireOrganizationAccess mirrors RequireAdminAccess but accepts any org role (readonly included): it only requires membership in the :organizationId organization. Sets the same context keys.

View Source
var RequireProjectAccess gin.HandlerFunc

RequireProjectAccess middleware validates that the authenticated user has access to the requested project. A user can access a project if they are a member of the project's organization. This middleware should be applied AFTER UseAppAuth.

View Source
var RequireWriteAccess gin.HandlerFunc

RequireWriteAccess middleware checks if the user has write access to the project's organization. It blocks access for users with 'readonly' role. This middleware should be applied AFTER UseAppAuth.

View Source
var UseAppAuth func(c *gin.Context)
View Source
var UseClientAuth func(c *gin.Context)
View Source
var UseRunnerAuth func(c *gin.Context)
View Source
var UseSourceMapAuth func(c *gin.Context)

Functions

func BodyReadError added in v1.9.24

func BodyReadError(err error) (status int, message string, ok bool)

func BufferAuthBody added in v1.9.24

func BufferAuthBody(c *gin.Context)

func GetOrganizationId

func GetOrganizationId(c *gin.Context) int

func GetProjectId

func GetProjectId(c *gin.Context) (uuid.UUID, error)

GetProjectId retrieves the project ID from the Gin context

func GetRunner added in v1.9.13

func GetRunner(c *gin.Context) (*models.SyntheticRunner, bool)

GetRunner returns the authenticated runner set by UseRunnerAuth.

func GetSetupOrganizationId added in v1.9.19

func GetSetupOrganizationId(c *gin.Context) int

func GetUserEmail

func GetUserEmail(c *gin.Context) string

func GetUserId

func GetUserId(c *gin.Context) int

func GetUserOrgRole

func GetUserOrgRole(c *gin.Context) string

func GuardBodyRead added in v1.9.24

func GuardBodyRead(c *gin.Context, idle, total time.Duration)

func GuardBodyReads added in v1.9.24

func GuardBodyReads(idle, total time.Duration) gin.HandlerFunc

func IngestAdmission added in v1.9.5

func IngestAdmission(c *gin.Context)

func InitRequireAdminAccess

func InitRequireAdminAccess()

func InitRequireOrganizationAccess added in v1.9.10

func InitRequireOrganizationAccess()

func InitRequireProjectAccess

func InitRequireProjectAccess()

func InitRequireWriteAccess

func InitRequireWriteAccess()

func InitUseAppAuth

func InitUseAppAuth()

func InitUseClientAuth

func InitUseClientAuth()

func InitUseRunnerAuth added in v1.9.13

func InitUseRunnerAuth()

InitUseRunnerAuth authenticates runners with the shared SYNTHETICS_RUNNER_SECRET. Runners are operator infrastructure configured at deploy time, not tenant-managed identities, so there are no per-runner credentials: any holder of the secret may poll, and the runner self-registers a liveness row under its reported name (touched at most once a minute).

func InitUseSourceMapAuth

func InitUseSourceMapAuth()

func IsSetupScope added in v1.9.19

func IsSetupScope(c *gin.Context) bool

func OnCommit added in v1.9.10

func OnCommit(c *gin.Context, fn func())

OnCommit queues fn to run after the Transactional middleware successfully commits the request transaction; queued fns are dropped on rollback. Use it for side effects that must only fire once the transaction's writes are visible to other connections (e.g. waking the outbox drain worker, which would otherwise poll before the enqueued row exists and go back to sleep).

func RateLimitOAuthTokenPerIP added in v1.9.24

func RateLimitOAuthTokenPerIP(maxRequests int, window time.Duration) gin.HandlerFunc

func RateLimitPerIP added in v1.8.14

func RateLimitPerIP(maxRequests int, window time.Duration) gin.HandlerFunc

RateLimitPerIP returns a fixed-window per-IP rate limiter for unauthenticated endpoints that persist state per request (e.g. the device-authorize endpoint, which inserts a main-DB row per call).

func RateLimitPerUser added in v1.9.10

func RateLimitPerUser(maxRequests int, window time.Duration) gin.HandlerFunc

RateLimitPerUser keys the limit by the authenticated user (UseAppAuth must run first), so users behind a shared NAT don't exhaust each other's budget and an attacker cannot widen theirs by rotating IPs. Requests without a resolved user fall back to the client IP so the limit still holds.

func RejectBindError added in v1.9.24

func RejectBindError(c *gin.Context, err error, fallback string)

func RejectIngestBindError added in v1.9.24

func RejectIngestBindError(c *gin.Context, err error, fallback string)

OTLP exporters retry a 503 but treat a 408 as permanent and drop the batch, so a stalled ingest body is turned away as retryable. The Traceway SDKs re-queue a failed batch whatever the status, so this changes nothing for them.

func SecurityHeaders added in v1.9.24

func SecurityHeaders(c *gin.Context)

func Transactional

func Transactional(c *gin.Context)

func UploadAdmission added in v1.9.24

func UploadAdmission(c *gin.Context)

func UseGzip

func UseGzip(c *gin.Context)

func UseHealthDeepToken added in v1.9.13

func UseHealthDeepToken(c *gin.Context)

UseHealthDeepToken guards the operator health endpoint. Its payload is instance-wide (cross-tenant queue depth, runner fleet size, storage engine stats), so it is gated on the HEALTH_DEEP_TOKEN deploy secret rather than any dashboard role; unset disables the endpoint entirely.

func UseSetupAuth added in v1.9.19

func UseSetupAuth(c *gin.Context)

Types

type BearerIdentity added in v1.8.15

type BearerIdentity struct {
	UserId  int
	Email   string
	Expires time.Time
}

func AuthenticateBearer added in v1.8.15

func AuthenticateBearer(tokenString string) (*BearerIdentity, error)

type FixedWindowLimiter added in v1.9.10

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

FixedWindowLimiter is a fixed-window in-memory rate limiter keyed by an arbitrary string (IP, user id, phone number, ...). Stale buckets are swept on each call, so the map stays bounded by the number of distinct keys seen within one window.

func NewFixedWindowLimiter added in v1.9.10

func NewFixedWindowLimiter(maxRequests int, window time.Duration) *FixedWindowLimiter

func (*FixedWindowLimiter) Allow added in v1.9.10

func (l *FixedWindowLimiter) Allow(key string) bool

Allow consumes one slot for key and reports whether the request is within the limit.

func (*FixedWindowLimiter) Take added in v1.9.24

func (l *FixedWindowLimiter) Take(key string) (bool, time.Duration)

Jump to

Keyboard shortcuts

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