Documentation
¶
Index ¶
- Constants
- func AccountAuthMiddleware(jwtSigner *jwt.Signer) mux.MiddlewareFunc
- func AccountFromRequest(r *http.Request, jwtSigner *jwt.Signer) (*models.Account, bool)
- func AdminAuthMiddleware(jwtSigner *jwt.Signer, fleetManagerToken string) mux.MiddlewareFunc
- func CloneGatewayRequest(r *http.Request) *http.Request
- func CriticalHTTPTraceMiddleware(resolveRoute criticalHTTPRouteResolver) func(http.Handler) http.Handler
- func GatewayForwardResponseTraceOption() func(context.Context, http.ResponseWriter, proto.Message) error
- func GetAccountFromContext(ctx context.Context) (*models.Account, bool)
- func GetEffectiveAccountFromContext(ctx context.Context) (*models.Account, bool)
- func GetScopedTokenClaimsFromContext(ctx context.Context) (*jwt.ScopedTokenClaims, bool)
- func GetUserFromContext(ctx context.Context) (*models.User, bool)
- func IsFleetManagerRequest(ctx context.Context) bool
- func IsOwnerSetupRequired() bool
- func IsSupportSessionActive(r *http.Request) bool
- func LoggingMiddleware(logger *log.Logger) mux.MiddlewareFunc
- func MarkOwnerSetupCompleted()
- func OrganizationAuthMiddleware(jwtSigner *jwt.Signer) mux.MiddlewareFunc
- func OwnerSetupEnabled() bool
- func RedirectInsecureForwardedHTTP(next http.Handler) http.Handler
- func RejectSupportSessionWrite(w http.ResponseWriter, r *http.Request, info *SupportSessionInfo) bool
- func RequestIDFromContext(ctx context.Context) string
- func RequireInstallationAdmin() mux.MiddlewareFunc
- func ResetOwnerSetupStateForTests()
- func SetRequestLogAccount(ctx context.Context, account *models.Account)
- func SetRequestLogSupportAdmin(ctx context.Context, adminAccountID string)
- func SetRequestLogUser(ctx context.Context, user *models.User)
- func SetServerError(ctx context.Context, err error, tags map[string]string)
- func ShowFullLogs() bool
- func TraceGatewayServe(ctx context.Context, w http.ResponseWriter, gateway http.Handler, ...)
- type SupportSessionInfo
Constants ¶
const AccountContextKey contextKey = "account"
const AccountNotFoundError string = "account_not_found_error"
const EffectiveAccountContextKey contextKey = "effective_account"
const OrganizationNotFoundError string = "organization_not_found_error"
const ScopedTokenClaimsContextKey contextKey = "scopedTokenClaims"
const SupportSessionContextKey contextKey = "support_session"
const SupportSessionReadOnlyMessage = "This action is not available in a read-only support session"
const UserContextKey contextKey = "user"
Variables ¶
This section is empty.
Functions ¶
func AccountAuthMiddleware ¶
func AccountAuthMiddleware(jwtSigner *jwt.Signer) mux.MiddlewareFunc
func AccountFromRequest ¶
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 ¶
* 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 GetEffectiveAccountFromContext ¶ added in v0.14.0
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 IsFleetManagerRequest ¶
func IsOwnerSetupRequired ¶
func IsOwnerSetupRequired() bool
func IsSupportSessionActive ¶
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 ¶
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 ¶
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 ¶
SetRequestLogAccount records the authenticated account for the access log.
func SetRequestLogSupportAdmin ¶
SetRequestLogSupportAdmin records the admin account that started the support session.
func SetRequestLogUser ¶
SetRequestLogUser records the organization, user, and account for the access log.
func SetServerError ¶
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 ¶
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)