Skip to documentation
SLOP

tiny.sandbox.policy

Reference tiny.sandbox policy

Defined in tiny.sandbox.

API (5)

Actions

Public operations.

Types and contracts

Public types and contracts.

No direct callersNo direct callstiny.sandboxpolicy
Static calls · unresolved targets: unknown · external targets: unknown.

Source

Called byCallsNo direct callsPolicyvalidatepolicyfilesystemIsolated
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callsPolicyvalidatepolicynetworkIsolated
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callsPolicyvalidatepolicyprocessIsolated
Static calls · unresolved targets: 0 · external targets: 0.

Source: lib/sandbox/src/policy.zig

zig
const std = @import("std");const audit_data = @import("audit.zig");pub const Preference = enum {    allow_inherited,    prefer_isolated,    require_isolated,};/// States what isolation a run has to have before the run starts: the policy/// records what the caller asks of the filesystem, process, and network/// dimensions, each judged on its own. A required dimension rejects an audit/// weaker than isolated, returning `error.UnmetFilesystemIsolation` ,/// `error.UnmetProcessIsolation` , or `error.UnmetNetworkIsolation` before the/// child runs. By contrast, a preferred dimension records what the caller wants/// and admits every audit, which backend selection reads to pick a runner. Both/// filesystem values count as isolated, so requiring the filesystem dimension/// admits every audit the package can produce. The environment dimension/// appears in the audit and has no entry here, so a policy constrains it in no/// way.pub const Policy = struct {    filesystem: Preference = .require_isolated,    process: Preference = .allow_inherited,    network: Preference = .allow_inherited,    pub fn validate(self: Policy, audit: audit_data.Audit) !void {        if (self.filesystem == .require_isolated and !filesystemIsolated(audit.filesystem)) return error.UnmetFilesystemIsolation;        if (self.process == .require_isolated and !processIsolated(audit.process)) return error.UnmetProcessIsolation;        if (self.network == .require_isolated and !networkIsolated(audit.network)) return error.UnmetNetworkIsolation;    }    pub fn prefersFilesystemIsolation(self: Policy) bool {        return self.filesystem != .allow_inherited;    }    pub fn prefersProcessIsolation(self: Policy) bool {        return self.process != .allow_inherited;    }    pub fn prefersNetworkIsolation(self: Policy) bool {        return self.network != .allow_inherited;    }};pub fn filesystemIsolated(value: audit_data.Filesystem) bool {    return switch (value) {        .copied, .overlay => true,    };}pub fn processIsolated(value: audit_data.Process) bool {    return switch (value) {        .host => false,        .bubblewrap_namespace => true,    };}pub fn networkIsolated(value: audit_data.Network) bool {    return switch (value) {        .inherited => false,        .bubblewrap_namespace => true,    };}test "policy validates required isolation dimensions" {    const inherited = audit_data.Audit{};    try (Policy{}).validate(inherited);    try std.testing.expectError(error.UnmetProcessIsolation, (Policy{ .process = .require_isolated }).validate(inherited));    try std.testing.expectError(error.UnmetNetworkIsolation, (Policy{ .network = .require_isolated }).validate(inherited));    const inherited_bwrap = audit_data.Audit{        .runner = .bubblewrap_overlay,        .filesystem = .overlay,        .process = .bubblewrap_namespace,        .network = .inherited,    };    try (Policy{ .process = .require_isolated }).validate(inherited_bwrap);    try std.testing.expectError(        error.UnmetNetworkIsolation,        (Policy{ .network = .require_isolated }).validate(inherited_bwrap),    );    var isolated_bwrap = inherited_bwrap;    isolated_bwrap.network = .bubblewrap_namespace;    try (Policy{ .network = .require_isolated }).validate(isolated_bwrap);}test "policy exposes preferences without enforcing them" {    const policy = Policy{        .filesystem = .prefer_isolated,        .process = .prefer_isolated,        .network = .allow_inherited,    };    try policy.validate(.{});    try std.testing.expect(policy.prefersFilesystemIsolation());    try std.testing.expect(policy.prefersProcessIsolation());    try std.testing.expect(!policy.prefersNetworkIsolation());}

Source: lib/sandbox/src/root.zig:39

zig
pub const policy = @import("policy.zig");

Audit

Definitions4
Public names4
Members0
Version26.7.0
Revisiondaab053ee433