resources

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: Apache-2.0 Imports: 30 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const ActorSPIFFETrustDomain = "substrate-actor.local"

ActorSPIFFETrustDomain is the trust domain of the SPIFFE ID an actor's certificate carries as its URI SAN.

TODO(identity): Must be configurable per-install, so that each install can set it to a unique value.

View Source
const FSCheckpointSubdir = "fs"

FSCheckpointSubdir is the subdirectory under the checkpoint directory where durable-dir filesystem checkpoint files are stored.

View Source
const (
	// ResourceNameRegexPattern is the regular expression pattern for a valid
	// Substrate resource name.
	ResourceNameRegexPattern = `[a-z0-9]([-a-z0-9]*[a-z0-9])?`
)
View Source
const RootfsCheckpointSubdir = "rootfs"

RootfsCheckpointSubdir is the subdirectory under the checkpoint directory where container rootfs filesystem checkpoint files are stored.

View Source
const SingletonName = "default"

SingletonName is the name of every singleton subresource, such as an Actor's EgressPolicy.

Variables

View Source
var AllowedAddCapabilities = sets.New(
	"AUDIT_WRITE", "CHOWN", "DAC_OVERRIDE", "FOWNER", "FSETID", "KILL",
	"NET_BIND_SERVICE", "SETFCAP", "SETGID", "SETPCAP", "SETUID", "SYS_CHROOT",
)

AllowedAddCapabilities are the capabilities a container may add.

TransferStates are the states in which a node may be moving the actor's snapshot between itself and object storage:

  • RESUMING: a resume fetches the snapshot.
  • RUNNING: the actor keeps the credentials its resume minted.
  • SUSPENDING: a suspend uploads the snapshot.
  • SUSPENDED: a background upload of a local snapshot runs.

In every other state no node acts for the actor, so no node may hold a credential for its snapshots. The mint's host check and the objectstore plugin's credential exchange both refuse the other states, and read the list here so they cannot disagree.

Functions

func ActorSPIFFEID

func ActorSPIFFEID(r ActorRef) *url.URL

ActorSPIFFEID returns "spiffe://substrate-actor.local/actor/<atespace>/<name>", which ateapi mints into the actor certificate's URI SAN.

func AddToAllocated

func AddToAllocated(total *ateapi.WorkerResources, assignment *ateapi.ActorAssignment, sign int64) *ateapi.WorkerResources

AddToAllocated adjusts allocation by an assignment; sign is 1 or -1. It returns nil when allocation reaches zero.

func CPUMemory

func CPUMemory(cpuMilli, memoryBytes int64) *ateapi.Resources

CPUMemory returns the Resources for cpuMilli and memoryBytes, or nil when both are zero, so an emptied total compares equal to an absent one.

func Covers

func Covers(have, want *ateapi.Resources) bool

Covers reports whether have leaves room for want in every dimension. A dimension want leaves at zero asks for nothing.

func DeepEqual

func DeepEqual[T any](a, b T) bool

DeepEqual compares two values of any type, using proto.Equal if both are proto messages, and reflect.DeepEqual otherwise. Declarative validation's generated code reaches it through each generating package's ateDeepEqual.

func Free

func Free(capacity, allocated *ateapi.WorkerResources) *ateapi.Resources

Free is what a Worker has left after what its Actors hold. It goes negative once a Worker is overcommitted.

func IsValidResourceName

func IsValidResourceName(name string) bool

IsValidResourceName reports whether name is a valid Substrate resource name (a DNS-1123 label; see ValidateResourceName for the rules). Use this for internal, non-proto checks where a plain predicate is wanted; to validate a proto request field with structured field-path errors, use ValidateResourceName. Empty is not a valid name.

func NetworkPolicyName

func NetworkPolicyName(wpName string) string

NetworkPolicyName returns the NetworkPolicy name for a WorkerPool. It keeps the whole pool name, so each pool gets its own policy. The policy also uses the pool name as its ate.dev/worker-pool label value, which Kubernetes caps at 63 characters, so the result never needs truncating.

func NewSnapshotName

func NewSnapshotName() string

NewSnapshotName returns a unique name for a new snapshot, durable or node-local.

func SumAllocated

func SumAllocated(assignments []*ateapi.ActorAssignment) *ateapi.WorkerResources

SumAllocated is what a set of assignments takes from a Worker, or nil for none. Rebuilds the total rather than adjusting it, which is what the checks holding AddToAllocated to the assignments it counts compare against.

func ToAPIError

func ToAPIError(errs field.ErrorList) error

ToAPIError turns validation errors into the InvalidArgument error an RPC handler responds with, or nil if errs is empty.

func ToGRPCStatusError

func ToGRPCStatusError(errs field.ErrorList) error

ToGRPCStatusError turns validation errors into the InvalidArgument error an RPC handler responds with. Callers check len(errs) > 0 first.

TODO: Delete once atelet's WorkerSupport server returns apierrors, and use ToAPIError instead.

func ToInternalError

func ToInternalError(errs field.ErrorList) error

ToInternalError turns validation errors on an object the server built, such as the final value about to be stored, into an Internal error. Callers check len(errs) > 0 first.

func ValidateActorDirs

func ValidateActorDirs(actorDirs *ateworkerpb.ActorDirs, fldPath *field.Path) field.ErrorList

ValidateActorDirs checks that every directory atelet passes to the worker is absolute and clean. Presence is enforced by the tags on the message; it backs the ateworkerpb.ActorDirs custom validation hook.

func ValidateAddCapabilities added in v1.0.0

func ValidateAddCapabilities(fldPath *field.Path, caps []string) field.ErrorList

ValidateAddCapabilities accepts only AllowedAddCapabilities.

func ValidateCSIMap

func ValidateCSIMap(fldPath *field.Path, m map[string]string) field.ErrorList

ValidateCSIMap bounds a map a CSI driver produced (a volume or publish context) at csiMapMaxBytes, counting keys and values. The entries are the driver's own and are not validated further.

func ValidateDropCapabilities added in v1.0.0

func ValidateDropCapabilities(fldPath *field.Path, caps []string) field.ErrorList

ValidateDropCapabilities accepts "ALL" and any Linux capability name.

func ValidateEnvVarName

func ValidateEnvVarName(fldPath *field.Path, name string) field.ErrorList

ValidateEnvVarName checks an environment variable name.

func ValidateHTTPGetPath

func ValidateHTTPGetPath(fldPath *field.Path, p string) field.ErrorList

ValidateHTTPGetPath checks a wakeup probe's HTTP path.

func ValidateHostPort

func ValidateHostPort(fldPath *field.Path, value string) field.ErrorList

ValidateHostPort requires "host:port", where host is an IP address or a DNS subdomain name (a trailing dot, marking it fully qualified, is allowed) and port is a number in 1..65535.

func ValidateIP

func ValidateIP(ip string, fldPath *field.Path) field.ErrorList

ValidateIP checks that the given string is a valid IP address, is not an IPv4-mapped IPv6 address, and is in canonical form.

func ValidateMountPath

func ValidateMountPath(fldPath *field.Path, p string) field.ErrorList

ValidateMountPath requires a clean absolute Unix path that starts with '/', is not '/', and contains no ':', '.' or '..' segments, '//', trailing '/', or control characters. It also rejects /dev, and /dev/pts, /proc, /sys and the paths under them.

func ValidateNestedMountPaths

func ValidateNestedMountPaths(fldPath *field.Path, paths []string) field.ErrorList

ValidateNestedMountPaths rejects mount paths that nest under or over one another: volumes cannot mount onto other volumes. paths[i] is reported at fldPath[i].mount_path. Identical paths are left to the list-key uniqueness check.

func ValidateNestedMountPathsAt

func ValidateNestedMountPathsAt(paths []string, at func(i int) *field.Path) field.ErrorList

ValidateNestedMountPathsAt is ValidateNestedMountPaths for paths gathered from more than one list: at(i) is where paths[i] is reported.

func ValidatePinnedImage

func ValidatePinnedImage(fldPath *field.Path, value string) field.ErrorList

ValidatePinnedImage requires a well-formed OCI image reference pinned by digest (e.g. "name@sha256:..."): changing the image content under a fixed reference invalidates snapshots. It parses with the same grammar the container runtimes use, so a malformed digest is rejected rather than treated as pinned.

func ValidateProjectedPath

func ValidateProjectedPath(fldPath *field.Path, p string) field.ErrorList

ValidateProjectedPath applies volumepath.ValidateProjected to a file path projected into a system-info volume. atelet re-checks it before writing to the host.

func ValidateResourceName

func ValidateResourceName(name string, fldPath *field.Path) field.ErrorList

ValidateResourceName checks that a string conforms to Agent Substrate's rules for a resource name, which is a subset of the rules for an RFC-1123 DNS label. This does not check for zero-length strings, which callers may want to handle differently (e.g., by returning a "required" error).

func ValidateRuntimeAssetPath

func ValidateRuntimeAssetPath(root, p string, fldPath *field.Path) field.ErrorList

ValidateRuntimeAssetPath ensures p is a regular file under root, with no symlinks worker runs these as root, so they must be assets atelet fetched into root

func ValidateSandboxAssetsDir

func ValidateSandboxAssetsDir(actorUID, dir string, fldPath *field.Path) field.ErrorList

ValidateSandboxAssetsDir requires dir, the sandbox_assets_dir a request names, to be the actor's own, nodepath.ActorSandboxAssetsDir(actorUID), so a request cannot point a worker at binaries staged for another actor or anywhere else on the node. The actor UID is checked first: it becomes a path element, and must be a plain label rather than a traversal.

func ValidateSandboxClass

func ValidateSandboxClass(fldPath *field.Path, value string) field.ErrorList

ValidateSandboxClass requires one of the sandboxclass values. An empty value is left to the required tag.

func ValidateSnapshotFidelity

func ValidateSnapshotFidelity(fidelity ateworkerpb.SnapshotFidelity, supported []ateworkerpb.SnapshotFidelity, fldPath *field.Path) field.ErrorList

ValidateSnapshotFidelity rejects a checkpoint or restore request whose fidelity the calling sandbox runtime cannot serve. Each runtime passes the levels it implements; anything else, including an unset fidelity, is refused before the request touches the guest.

func ValidateSnapshotFileNames

func ValidateSnapshotFileNames(files []string) error

ValidateSnapshotFileNames requires each name to be a distinct plain file name in the checkpoint directory or its "fs" or "rootfs" subdirectories. Actual file access must still use os.Root so symlinks cannot escape that directory.

func ValidateSnapshotLocation

func ValidateSnapshotLocation(location string) error

ValidateSnapshotLocation checks ate-api-server's --snapshot-location, an ActorTemplate's snapshotConfig.storageLocation on create, and the location a tag is created under. The location must be a URI with a bucket, so a bad location fails fast instead of deep inside an object-storage call. It does not restrict the scheme or the bucket: the storage layer uses only the host (bucket) and path, and which schemes are acceptable is a storage-backend policy.

Each path segment must match snapshotLocationSegmentRE and must not be "atespaces" in any letter case, so a location cannot sit inside the <location>/atespaces/... prefix another location builds.

func ValidateStorageVolumeID

func ValidateStorageVolumeID(fldPath *field.Path, id string) field.ErrorList

ValidateStorageVolumeID rejects control characters (U+0000-U+0008, U+000B, U+000C, U+000E-U+001F, U+007F-U+009F) in an external volume's storage ID.

func ValidateUUID

func ValidateUUID(uuid string, fldPath *field.Path) field.ErrorList

ValidateUUID verifies that the specified value is a valid UUID (RFC 4122).

  • must be 36 characters long
  • must be in the normalized form `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`
  • must use only lowercase hexadecimal characters

func ValidateVolumeType

func ValidateVolumeType(fldPath *field.Path, volumeType string) field.ErrorList

ValidateVolumeType allows an optional "substrate.io/" prefix, followed by a valid DNS-1123 subdomain.

func ValidateWorkerPodUID

func ValidateWorkerPodUID(workerPodUID string) error

ValidateWorkerPodUID rejects a worker pod UID that could escape the host path built from it: the worker control socket (.../workers/<uid>/worker.sock). Kubernetes pod UIDs are UUIDs, which are valid DNS-1123 labels, so a label check accepts every legitimate value while rejecting separators and "..".

func WorkerForActorSPIFFEID

func WorkerForActorSPIFFEID(r ActorRef) *url.URL

WorkerForActorSPIFFEID returns "spiffe://substrate-actor.local/worker-for-actor/<atespace>/<name>", which ateapi mints into the actor certificate's URI SAN.

Types

type ActorAttribution

type ActorAttribution struct {
	Ref              ActorRef
	UID              string
	TemplateAtespace string
	TemplateName     string
}

ActorAttribution is what telemetry about an actor is attributed to: an ActorRef plus the two things a ref does not carry, the server-assigned uid and the template the actor was built from. Shared by ateattr, actorlog, and worker's usage sampling so those producers cannot drift apart.

Unrelated to the credential sense of "actor identity" elsewhere in the repo (ateapi's ActorIdentity service, substratex509) — nothing here is a secret or is presented as proof of anything.

func ActorAttributionFromActor

func ActorAttributionFromActor(a *ateapi.Actor) ActorAttribution

ActorAttributionFromActor builds the attribution for a loaded Actor. Nil-safe; a nil Actor yields zero-valued fields.

type ActorRef

type ActorRef = ResourceRef[*ateapi.Actor]

ActorRef identifies an actor by the (atespace, name).

func ActorRefFromActor

func ActorRefFromActor(a *ateapi.Actor) ActorRef

ActorRefFromActor returns the reference addressing the given actor.

func ActorRefFromActorSPIFFEID

func ActorRefFromActorSPIFFEID(id string) (ActorRef, error)

ActorRefFromActorSPIFFEID parses an ID built by ActorSPIFFEID.

func ActorRefFromActorSPIFFEURL

func ActorRefFromActorSPIFFEURL(u *url.URL) (ActorRef, error)

func ActorRefFromObjectRef

func ActorRefFromObjectRef(ref *ateapi.ObjectRef) ActorRef

ActorRefFromObjectRef converts a wire reference to an ActorRef.

func ActorRefFromWorkerForActorSPIFFEID

func ActorRefFromWorkerForActorSPIFFEID(id string) (ActorRef, error)

ActorRefFromWorkerForActorSPIFFEID parses an ID built by WorkerForActorSPIFFEID.

func ActorRefFromWorkerForActorSPIFFEURL

func ActorRefFromWorkerForActorSPIFFEURL(u *url.URL) (ActorRef, error)

type ActorTemplateRef

type ActorTemplateRef = ResourceRef[*ateapi.ActorTemplate]

ActorTemplateRef identifies an ActorTemplate by the (atespace, name).

func ActorTemplateRefFromActorTemplate

func ActorTemplateRefFromActorTemplate(t *ateapi.ActorTemplate) ActorTemplateRef

ActorTemplateRefFromActorTemplate returns the reference addressing the given template.

func ActorTemplateRefFromObjectRef

func ActorTemplateRefFromObjectRef(ref *ateapi.ObjectRef) ActorTemplateRef

ActorTemplateRefFromObjectRef converts a wire reference to an ActorTemplateRef.

type Resource

type Resource interface {
	GetMetadata() *ateapi.ResourceMetadata
}

Resource is any Atespaced resource message carrying the common metadata.

type ResourceRef

type ResourceRef[R Resource] struct {
	// Atespace is the isolation boundary the resource was created into. Required.
	Atespace string
	// Name is the resource's name, unique within Atespace. Required.
	Name string
}

ResourceRef identifies an Atespaced resource by the (atespace, name).

func (ResourceRef[R]) LogValue

func (r ResourceRef[R]) LogValue() slog.Value

LogValue implements slog.LogValuer so that slog.Any("template", ref) records the two components as a group ("template.atespace", "template.name") rather than flattening them into one opaque string.

func (ResourceRef[R]) String

func (r ResourceRef[R]) String() string

func (ResourceRef[R]) ToObjectRef

func (r ResourceRef[R]) ToObjectRef() *ateapi.ObjectRef

ToObjectRef converts the reference to its wire form.

type SnapshotOwner

type SnapshotOwner struct {
	// contains filtered or unexported fields
}

SnapshotOwner is the resource whose objects a snapshot's prefix holds: the Actor that took it, or the Tag that copied it. Deletion is expressed as "collect everything under my own prefix", so an owner cannot name another's objects, and a borrowed snapshot is recognized by the URI alone rather than by a flag the two have to keep in sync.

func ActorSnapshotOwner

func ActorSnapshotOwner(atespace, actorUID string) SnapshotOwner

ActorSnapshotOwner returns the owner of the snapshots an Actor takes. It is keyed on the UID rather than the name so that an Actor recreated under the same name never inherits its predecessor's objects.

func TagSnapshotOwner

func TagSnapshotOwner(atespace, tagUID string) SnapshotOwner

TagSnapshotOwner returns the owner of the one snapshot a Tag holds. It is keyed on the UID so a recreated tag never inherits its predecessor's objects.

func (SnapshotOwner) Atespace

func (o SnapshotOwner) Atespace() string

Atespace returns the atespace the owner belongs to.

func (SnapshotOwner) IsZero

func (o SnapshotOwner) IsZero() bool

IsZero reports whether o is the zero SnapshotOwner.

func (SnapshotOwner) Prefix

func (o SnapshotOwner) Prefix(location string) (StoragePrefix, error)

Prefix returns the prefix holding every object this owner's snapshots are made of, under an ActorTemplate's snapshotConfig.location.

func (SnapshotOwner) String

func (o SnapshotOwner) String() string

type SnapshotURI

type SnapshotURI struct {
	// contains filtered or unexported fields
}

SnapshotURI is where one external snapshot's objects live in object storage: an ActorTemplate's snapshotConfig.location, plus the prefix of the resource that owns the snapshot.

gs://bucket/root                                                    location
gs://bucket/root/atespaces/team-a/actors/<uid>                      an Actor's prefix
gs://bucket/root/atespaces/team-a/actors/<uid>/snapshots/<name>     one of its snapshots
gs://bucket/root/atespaces/team-a/tags/<uid>                        a tag's prefix, and
                                                                    its only snapshot

func NewActorSnapshotURI

func NewActorSnapshotURI(location, atespace, actorUID, name string) (SnapshotURI, error)

NewActorSnapshotURI returns the URI of a snapshot an Actor took, stored under an ActorTemplate's snapshotConfig.location.

func NewTagSnapshotURI

func NewTagSnapshotURI(location, atespace, tagUID string) (SnapshotURI, error)

NewTagSnapshotURI returns the URI of the snapshot a Tag owns, stored under an ActorTemplate's snapshotConfig.location. The tag's prefix and its snapshot's are the same: a tag holds exactly one snapshot.

func ParseSnapshotURI

func ParseSnapshotURI(uri string) (SnapshotURI, error)

ParseSnapshotURI parses a given snapshot URI.

func (SnapshotURI) Atespace

func (u SnapshotURI) Atespace() string

Atespace returns the atespace of the resource that owns the snapshot.

func (SnapshotURI) IsZero

func (u SnapshotURI) IsZero() bool

IsZero reports whether u is the zero SnapshotURI.

func (SnapshotURI) Location

func (u SnapshotURI) Location() string

Location returns the ActorTemplate snapshotConfig.location this snapshot is stored under.

func (SnapshotURI) Name

func (u SnapshotURI) Name() string

Name returns the snapshot's resource name.

func (SnapshotURI) ObjectURI

func (u SnapshotURI) ObjectURI(name string) (string, error)

ObjectURI returns the address of a single object stored within the snapshot.

func (SnapshotURI) OwnedBy

func (u SnapshotURI) OwnedBy(o SnapshotOwner) bool

OwnedBy reports whether the snapshot is owned by o. A collector asks this before deleting: an Actor whose snapshot came from a tag does not own it, and releasing it would break every other Actor cloned from that tag.

func (SnapshotURI) Owner

func (u SnapshotURI) Owner() SnapshotOwner

Owner returns the resource whose prefix the snapshot lives under.

func (SnapshotURI) OwnerPrefix

func (u SnapshotURI) OwnerPrefix() StoragePrefix

OwnerPrefix returns the prefix of the resource that owns the snapshot, holding this snapshot and every other that owner wrote. Collecting an owner takes only a URI it recorded, with no need to resolve its ActorTemplate for the storage location.

func (SnapshotURI) Prefix

func (u SnapshotURI) Prefix() StoragePrefix

Prefix returns the prefix holding this one snapshot's objects.

func (SnapshotURI) String

func (u SnapshotURI) String() string

type StoragePrefix

type StoragePrefix struct {
	// contains filtered or unexported fields
}

StoragePrefix is a validated object-storage prefix: a scheme, a bucket and a path, with no query, fragment or userinfo. Every object below this prefix has a name starting with its path, so deleting the prefix collects all of them.

func ParseStoragePrefix

func ParseStoragePrefix(uri string) (StoragePrefix, error)

ParseStoragePrefix parses a storage prefix received as a string, such as a snapshot URI or an owner's prefix. It rejects a bare bucket, so a prefix can never name every object in a bucket.

func (StoragePrefix) IsZero

func (p StoragePrefix) IsZero() bool

IsZero reports whether p is empty

func (StoragePrefix) String

func (p StoragePrefix) String() string

type TagRef

type TagRef = ResourceRef[*ateapi.Tag]

TagRef identifies a Tag by the (atespace, name).

func TagRefFromObjectRef

func TagRefFromObjectRef(ref *ateapi.ObjectRef) TagRef

TagRefFromObjectRef converts an ObjectRef to a TagRef.

func TagRefFromTag

func TagRefFromTag(t *ateapi.Tag) TagRef

TagRefFromTag returns the reference addressing the given tag.

Jump to

Keyboard shortcuts

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