Documentation
¶
Overview ¶
Package middleware provides E2B-compatible authentication middleware. It supports both X-API-Key (E2B standard) and AGENTBOX-API-KEY (backward-compatible).
Index ¶
Constants ¶
const ( // E2BAPIKeyHeader is the E2B standard API key header. E2BAPIKeyHeader = "X-API-Key" // LegacyAPIKeyHeader is the legacy AgentBox API key header. LegacyAPIKeyHeader = "AGENTBOX-API-KEY" // AuthContextKey is the gin context key used to store AuthInfo. AuthContextKey = "auth" // ImpersonateTeamHeader and ImpersonateUserHeader let an admin caller act // on behalf of another user, exactly as on the native API. The console // needs it here too: its user switcher has to change whose sandboxes and // whose credentials are addressed, and an increasing share of what it does // goes through this surface rather than the native one. // // The credential stays the admin's own key, so the audit trail records who // really acted. Borrowing the target user's key would erase that. ImpersonateTeamHeader = "X-Impersonate-Team" ImpersonateUserHeader = "X-Impersonate-User" // DefaultNamespace is the default namespace when none is specified. DefaultNamespace = "default" )
Variables ¶
This section is empty.
Functions ¶
func AuthFromContext ¶
AuthFromContext retrieves AuthInfo from the gin context. Falls back to a default with Namespace="default" if not set.
func NewE2BAuthMiddleware ¶
func NewE2BAuthMiddleware(adminKeyMgr *apikey.AdminKeyManager, keyStore apikey.KeyStore, iamSvc service.IAMService) gin.HandlerFunc
NewE2BAuthMiddleware returns a gin.HandlerFunc that validates the API key using E2B-compatible header names and injects AuthInfo into the request context.
It accepts both X-API-Key (E2B standard) and AGENTBOX-API-KEY (backward-compatible). When adminKeyMgr is nil, the middleware runs in dev mode and grants anonymous-admin access.
iamSvc is used to resolve the namespace for global API keys (those with an empty namespace in the Secret). When non-nil and the key's namespace is empty, the middleware derives the effective namespace from the key's team+user metadata via IAM. This mirrors the behaviour of the native AgentBox auth middleware.
Types ¶
This section is empty.