middleware

package
v0.0.0-...-3400737 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MultiAuthMiddleware

func MultiAuthMiddleware(iamService iam.Service) func(http.Handler) http.Handler

MultiAuthMiddleware is the Phase 3 unified authentication middleware.

This middleware:

  1. Extracts headers and cookies from HTTP request
  2. Calls iamService.AuthenticateRequest() which tries all authenticators
  3. Sets Principal in context if authentication succeeds
  4. Continues to next handler (authentication failure handled by authz)

Authentication flow:

  • SessionAuthenticator checks grid.session cookie
  • JWTAuthenticator checks Authorization: Bearer header
  • First successful authenticator wins
  • If all return (nil, nil): unauthenticated request (allowed)
  • If any returns (nil, error): authentication failed (401)

This replaces the old authn.go middleware which had 7 steps with database queries and Casbin mutation. The new flow delegates everything to the IAM service which uses the immutable cache for lock-free role resolution.

func NewAuthzInterceptor

func NewAuthzInterceptor(deps AuthzDependencies) connect.UnaryInterceptorFunc

NewAuthzInterceptor creates a Connect UnaryInterceptor that enforces Casbin policies. It checks permissions for each RPC call, including loading resource-specific attributes like state labels when necessary for a policy decision.

func NewAuthzMiddleware

func NewAuthzMiddleware(deps AuthzDependencies) (func(http.Handler) http.Handler, error)

NewAuthzMiddleware constructs a Chi middleware that enforces Casbin policies for HTTP requests. This middleware is focused on the Terraform HTTP backend; Connect RPC enforcement is handled via interceptors.

func NewMultiAuthInterceptor

func NewMultiAuthInterceptor(iamService iam.Service) connect.UnaryInterceptorFunc

NewMultiAuthInterceptor is the Phase 3 unified authentication interceptor for Connect RPC.

This interceptor:

  1. Extracts headers and metadata from Connect request
  2. Calls iamService.AuthenticateRequest() which tries all authenticators
  3. Sets Principal in context if authentication succeeds
  4. Continues to next handler (authentication failure handled by authz)

Authentication flow:

  • SessionAuthenticator checks grid.session cookie (via Connect metadata)
  • JWTAuthenticator checks Authorization: Bearer header
  • First successful authenticator wins
  • If all return (nil, nil): unauthenticated request (allowed)
  • If any returns (nil, error): authentication failed (401)

This replaces the old session_interceptor.go and jwt_interceptor.go which had scattered authentication logic and Casbin mutation.

Types

type AuthnDependencies

AuthnDependencies provides repository access for authentication operations.

Phase 6 Note: This struct is deprecated and will be removed in Phase 6. It's currently still used by auth handlers (HandleInternalLogin, HandleSSOCallback, HandleWhoAmI, HandleLogout) which will be refactored to use the IAM service instead.

New code should use the IAM service (services/iam) instead of this struct.

type AuthzDependencies

type AuthzDependencies struct {
	Enforcer     casbin.IEnforcer
	StateService *statepkg.Service
	IAMService   iam.Service // Phase 4: IAM service for read-only authorization
}

AuthzDependencies provides the collaborators needed for authorization decisions.

Jump to

Keyboard shortcuts

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