Files
zeekay ea80dc3638 feat: Add new Dockerfiles and improve containerization
- Add main Dockerfile for production builds
- Add Dockerfile.runtime for secure code execution
- Add Dockerfile.runtime.fixed with improved configuration
- Include .dockerignore for build optimization
- Add integration documentation and publishing guides
- Update API and CLI components for better runtime support
- Enhance sandbox and container management features
2025-08-16 23:03:39 -05:00

51 lines
1.2 KiB
Go

// Copyright 2025 Hanzo Industries Inc.
// SPDX-License-Identifier: AGPL-3.0
package middlewares
import (
"errors"
"os"
"strings"
"github.com/hanzoai/runner/internal/constants"
"github.com/hanzoai/runner/pkg/common"
"github.com/gin-gonic/gin"
)
func AuthMiddleware() gin.HandlerFunc {
return func(ctx *gin.Context) {
authHeader := ctx.GetHeader(constants.RUNTIME_AUTHORIZATION_HEADER)
if authHeader == "" {
authHeader = ctx.GetHeader(constants.AUTHORIZATION_HEADER)
}
ctx.Request.Header.Del(constants.RUNTIME_AUTHORIZATION_HEADER)
if authHeader == "" {
ctx.Error(common.NewUnauthorizedError(errors.New("authorization header required")))
ctx.Abort()
return
}
// Split "Bearer <token>"
parts := strings.Split(authHeader, " ")
if len(parts) != 2 || parts[0] != constants.BEARER_AUTH_HEADER {
ctx.Error(common.NewUnauthorizedError(errors.New("invalid authorization header format")))
ctx.Abort()
return
}
token := parts[1]
// Compare with API token from environment variable
if token != os.Getenv("API_TOKEN") {
ctx.Error(common.NewUnauthorizedError(errors.New("invalid token")))
ctx.Abort()
return
}
// Authentication successful, continue to the next handler
ctx.Next()
}
}