mirror of
https://github.com/hanzoai/runtime.git
synced 2026-10-30 18:23:13 +00:00
Every sandbox was created privileged under the daemon's default runtime, and the setting that would have changed it defaulted to an empty string that silently meant runc. For a service whose whole premise is running code somebody else wrote, that is not a boundary. An org sets its isolation and the create request carries it, so a sandbox records what it was made with: changing the policy moves new sandboxes and leaves running ones alone. gvisor is the default. firecracker is delivered through kata's shim, which is why it is one name rather than two. runc is refused unless the runner names that org, and an empty list names nobody. Absent means the default, unknown is a refusal, and a runtime the daemon does not have is a refusal. Nothing substitutes quietly. The runner took an organization in a field called UserId with a note beside it saying so. Deciding who may have runc through a field named after something else is not reviewable. Privileged is replaced by dropping everything and granting the eight the daemon uses. Nothing the sandbox does broke; what stopped working is mount, mknod, raw sockets, chroot, writing to proc, and seeing the host's disks. AUDIT_WRITE is among them because without it sudo works and complains every time. The creation histogram's lowest bucket was a tenth of a second, so the metric could not observe the claim the product makes about its own speed. It can now, and it carries the isolation, so comparing them is a query. Co-authored-by: Hanzo Dev <[email protected]>
95 lines
3.0 KiB
Go
95 lines
3.0 KiB
Go
// Copyright 2025 Hanzo Industries Inc.
|
|
// SPDX-License-Identifier: AGPL-3.0
|
|
|
|
package controllers
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"net/url"
|
|
"regexp"
|
|
"strings"
|
|
|
|
proxy "github.com/hanzoai/runtime/libs/common-go/pkg/proxy"
|
|
"github.com/hanzoai/runtime/apps/runner/pkg/common"
|
|
"github.com/hanzoai/runtime/apps/runner/pkg/runner"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// ProxyRequest handles proxying requests to a sandbox's container
|
|
//
|
|
// @Tags toolbox
|
|
// @Summary Proxy requests to the sandbox toolbox
|
|
// @Description Forwards the request to the specified sandbox's container
|
|
// @Param sandboxId path string true "Sandbox ID"
|
|
// @Param path path string true "Path to forward"
|
|
// @Success 200 {object} any "Proxied response"
|
|
// @Failure 400 {object} string "Bad request"
|
|
// @Failure 401 {object} string "Unauthorized"
|
|
// @Failure 404 {object} string "Sandbox container not found"
|
|
// @Failure 409 {object} string "Sandbox container conflict"
|
|
// @Failure 500 {object} string "Internal server error"
|
|
// @Router /sandboxes/{sandboxId}/toolbox/{path} [get]
|
|
// @Router /sandboxes/{sandboxId}/toolbox/{path} [post]
|
|
// @Router /sandboxes/{sandboxId}/toolbox/{path} [delete]
|
|
func ProxyRequest(ctx *gin.Context) {
|
|
if regexp.MustCompile(`^/process/session/.+/command/.+/logs$`).MatchString(ctx.Param("path")) {
|
|
if ctx.Query("follow") == "true" {
|
|
ProxyCommandLogsStream(ctx)
|
|
return
|
|
}
|
|
}
|
|
|
|
proxy.NewProxyRequestHandler(getProxyTarget)(ctx)
|
|
}
|
|
|
|
func getProxyTarget(ctx *gin.Context) (*url.URL, map[string]string, error) {
|
|
runner := runner.GetInstance(nil)
|
|
|
|
sandboxId := ctx.Param("sandboxId")
|
|
if sandboxId == "" {
|
|
ctx.Error(common.NewBadRequestError(errors.New("sandbox ID is required")))
|
|
return nil, nil, errors.New("sandbox ID is required")
|
|
}
|
|
|
|
// Get container details
|
|
container, err := runner.Docker.ContainerInspect(ctx.Request.Context(), sandboxId)
|
|
if err != nil {
|
|
ctx.Error(common.NewNotFoundError(fmt.Errorf("sandbox container not found: %w", err)))
|
|
return nil, nil, fmt.Errorf("sandbox container not found: %w", err)
|
|
}
|
|
|
|
var containerIP string
|
|
for _, network := range container.NetworkSettings.Networks {
|
|
containerIP = network.IPAddress
|
|
break
|
|
}
|
|
|
|
if containerIP == "" {
|
|
ctx.Error(common.NewBadRequestError(errors.New("container has no IP address, it might not be running")))
|
|
return nil, nil, errors.New("container has no IP address, it might not be running")
|
|
}
|
|
|
|
// Build the target URL
|
|
targetURL := fmt.Sprintf("http://%s:2280", containerIP)
|
|
|
|
// Get the wildcard path and normalize it
|
|
path := ctx.Param("path")
|
|
|
|
// Ensure path always has a leading slash but not duplicate slashes
|
|
if path == "" {
|
|
path = "/"
|
|
} else if !strings.HasPrefix(path, "/") {
|
|
path = "/" + path
|
|
}
|
|
|
|
// Create the complete target URL with path
|
|
target, err := url.Parse(fmt.Sprintf("%s%s", targetURL, path))
|
|
if err != nil {
|
|
ctx.Error(common.NewBadRequestError(fmt.Errorf("failed to parse target URL: %w", err)))
|
|
return nil, nil, fmt.Errorf("failed to parse target URL: %w", err)
|
|
}
|
|
|
|
return target, nil, nil
|
|
}
|