Files
zeekayandHanzo Dev a386271c80 isolation is a value the org sets, and an empty one is not runc
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]>
2026-09-11 13:47:31 -07:00

76 lines
2.4 KiB
Go

// Copyright 2025 Hanzo Industries Inc.
// SPDX-License-Identifier: AGPL-3.0
package docker
import (
"context"
"fmt"
"github.com/hanzoai/runtime/apps/runner/pkg/api/dto"
"github.com/hanzoai/runtime/apps/runner/pkg/common"
"github.com/docker/docker/client"
)
// runtimeFor names the Docker runtime that provides each boundary. These are
// the names the tools register themselves under: `runsc install` writes
// "runsc", and Kata's Firecracker shim registers as "kata-fc".
var runtimeFor = map[dto.Isolation]string{
dto.IsolationGvisor: "runsc",
dto.IsolationFirecracker: "kata-fc",
dto.IsolationRunc: "runc",
}
// Runtimes reports the runtime names the Docker daemon offers, which is what
// decides whether a boundary can be provided on this node.
func Runtimes(ctx context.Context, apiClient client.APIClient) (map[string]bool, error) {
info, err := apiClient.Info(ctx)
if err != nil {
return nil, err
}
names := make(map[string]bool, len(info.Runtimes))
for name := range info.Runtimes {
names[name] = true
}
return names, nil
}
// IsolationRuntime names the Docker runtime that serves a boundary, for
// reporting which boundaries a node can provide.
func IsolationRuntime(iso dto.Isolation) string {
return runtimeFor[iso]
}
// resolveIsolation returns the boundary a sandbox will actually run behind and
// the Docker runtime that serves it.
//
// An absent selection resolves to dto.IsolationDefault, so a caller that says
// nothing is isolated. A boundary the node cannot provide is an error rather
// than a substitution: nothing here returns a weaker runtime than the one that
// was asked for.
func (d *DockerClient) resolveIsolation(iso dto.Isolation, orgId string) (dto.Isolation, string, error) {
if iso == "" {
iso = dto.IsolationDefault
}
runtime, known := runtimeFor[iso]
if !known {
return "", "", common.NewBadRequestError(fmt.Errorf("unknown isolation %q", iso))
}
// runc has no boundary against code that attacks the kernel, so it is
// reachable only by the organizations this runner names, and the empty
// list names nobody.
if iso == dto.IsolationRunc && !d.runcOrgs[orgId] {
return "", "", common.NewBadRequestError(fmt.Errorf("isolation %q is not available to organization %q on this runner", iso, orgId))
}
if !d.runtimes[runtime] {
return "", "", common.NewBadRequestError(fmt.Errorf("isolation %q needs the %q runtime, which this runner does not have", iso, runtime))
}
return iso, runtime, nil
}