middleware

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const AccountContextKey contextKey = "account"
View Source
const AccountNotFoundError string = "account_not_found_error"
View Source
const EffectiveAccountContextKey contextKey = "effective_account"
View Source
const OrganizationNotFoundError string = "organization_not_found_error"
View Source
const ScopedTokenClaimsContextKey contextKey = "scopedTokenClaims"
View Source
const SupportSessionContextKey contextKey = "support_session"
View Source
const SupportSessionReadOnlyMessage = "This action is not available in a read-only support session"
View Source
const UserContextKey contextKey = "user"

Variables

This section is empty.

Functions

func AccountAuthMiddleware

func AccountAuthMiddleware(jwtSigner *jwt.Signer) mux.MiddlewareFunc

func AccountFromRequest

func AccountFromRequest(r *http.Request, jwtSigner *jwt.Signer) (*models.Account, bool)

AccountFromRequest returns the signed-in account when the session cookie is valid. A missing or invalid cookie is not an error.

func AdminAuthMiddleware

func AdminAuthMiddleware(jwtSigner *jwt.Signer, fleetManagerToken string) mux.MiddlewareFunc

AdminAuthMiddleware authenticates admin UI sessions, named personal API tokens, and the single-host Fleet Manager token on fleet routes. Organization API keys and other scoped tokens are not valid admin credentials.

func CloneGatewayRequest

func CloneGatewayRequest(r *http.Request) *http.Request

* CloneGatewayRequest copies the request the gateway handler forwards. * The copy keeps the caller context so a later error report can still find it.

func CriticalHTTPTraceMiddleware added in v0.26.0

func CriticalHTTPTraceMiddleware(resolveRoute criticalHTTPRouteResolver) func(http.Handler) http.Handler

* CriticalHTTPTraceMiddleware starts a server span before the handler runs so * trace context propagates into grpc-gateway and the internal gRPC server. * Only allowlisted routes are traced.

func GatewayForwardResponseTraceOption added in v0.26.0

func GatewayForwardResponseTraceOption() func(context.Context, http.ResponseWriter, proto.Message) error

* GatewayForwardResponseTraceOption starts a marshal span before grpc-gateway * encodes the proto response to JSON. The span ends on the first response write.

func GetAccountFromContext

func GetAccountFromContext(ctx context.Context) (*models.Account, bool)

func GetEffectiveAccountFromContext added in v0.14.0

func GetEffectiveAccountFromContext(ctx context.Context) (*models.Account, bool)

GetEffectiveAccountFromContext returns the target account when a support session is active, otherwise the real account. Use this in handlers that should reflect the target user's data.

func GetScopedTokenClaimsFromContext added in v0.14.0

func GetScopedTokenClaimsFromContext(ctx context.Context) (*jwt.ScopedTokenClaims, bool)

func GetUserFromContext

func GetUserFromContext(ctx context.Context) (*models.User, bool)

func IsFleetManagerRequest

func IsFleetManagerRequest(ctx context.Context) bool

func IsOwnerSetupRequired

func IsOwnerSetupRequired() bool

func IsSupportSessionActive

func IsSupportSessionActive(r *http.Request) bool

IsSupportSessionActive reports whether the request is being served inside a fully validated support session. It relies on the context rather than re-parsing the cookie: the auth middleware has already verified that the cookie is a real support session token issued to *this* admin, that the admin is still an installation admin, and that the session is fresh relative to password rotation. A stale or unrelated cookie that happens to be structurally valid will not produce an Active info here.

func LoggingMiddleware

func LoggingMiddleware(logger *log.Logger) mux.MiddlewareFunc

func MarkOwnerSetupCompleted

func MarkOwnerSetupCompleted()

func OrganizationAuthMiddleware

func OrganizationAuthMiddleware(jwtSigner *jwt.Signer) mux.MiddlewareFunc

func OwnerSetupEnabled

func OwnerSetupEnabled() bool

func RedirectInsecureForwardedHTTP

func RedirectInsecureForwardedHTTP(next http.Handler) http.Handler

RedirectInsecureForwardedHTTP sends browser and API requests that arrived as HTTP through a TLS-terminating proxy to HTTPS.

GCE FrontendConfig redirect applies to every request on port 80. Let's Encrypt HTTP-01 uses that same port, so the load balancer redirect stays off for cert-manager. This wrapper redirects the application instead. Health checks and the ACME challenge path are left on HTTP.

func RejectSupportSessionWrite

func RejectSupportSessionWrite(w http.ResponseWriter, r *http.Request, info *SupportSessionInfo) bool

RejectSupportSessionWrite writes a 403 response and returns true when the request is a write inside an active support session.

func RequestIDFromContext

func RequestIDFromContext(ctx context.Context) string

RequestIDFromContext returns the id assigned to this HTTP request.

func RequireInstallationAdmin added in v0.14.0

func RequireInstallationAdmin() mux.MiddlewareFunc

RequireInstallationAdmin is a middleware that ensures the request is from an authenticated installation admin. Non-admin requests receive a 404 to avoid leaking the existence of admin endpoints.

func ResetOwnerSetupStateForTests

func ResetOwnerSetupStateForTests()

func SetRequestLogAccount

func SetRequestLogAccount(ctx context.Context, account *models.Account)

SetRequestLogAccount records the authenticated account for the access log.

func SetRequestLogSupportAdmin

func SetRequestLogSupportAdmin(ctx context.Context, adminAccountID string)

SetRequestLogSupportAdmin records the admin account that started the support session.

func SetRequestLogUser

func SetRequestLogUser(ctx context.Context, user *models.User)

SetRequestLogUser records the organization, user, and account for the access log.

func SetServerError

func SetServerError(ctx context.Context, err error, tags map[string]string)

SetServerError records a handler error for the HTTP Sentry report. LoggingMiddleware seeds the holder. A later handler fills it.

func ShowFullLogs

func ShowFullLogs() bool

func TraceGatewayServe added in v0.26.0

func TraceGatewayServe(ctx context.Context, w http.ResponseWriter, gateway http.Handler, r *http.Request)

* TraceGatewayServe wraps grpc-gateway handling so the encode/write tail after * the gRPC round trip is visible separately from the otelgrpc client span. * Only allowlisted routes are traced, matching CriticalHTTPTraceMiddleware.

Types

type SupportSessionInfo

type SupportSessionInfo struct {
	AdminAccountID string
	Active         bool
	UserName       string
}

SupportSessionInfo is stored in the request context when an admin has a read-only support session for another user.

func GetSupportSessionFromContext

func GetSupportSessionFromContext(ctx context.Context) (*SupportSessionInfo, bool)

Jump to

Keyboard shortcuts

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