Peios Learn
Documentation

Peios

Peios Peios Kernel Universal Directory Project

Developer Tools

Trail Acta Provium clackatoo CAF GCSL Pekit

Applications

Framewright

Standards and Conventions

Standards and Conventions Peios Specifications
Peios

Go SDK Reference

The pure-Go Peios SDK: package conventions and native security-descriptor operations.

Single-page view · as markdown

1.1 Overview

Peios / Developing for Peios / Go SDK Reference / Go SDK Conventions

The Go SDK uses Go values and interfaces for portable formats and native Peios operations. Its package documentation describes each public API; this chapter explains the ownership and authority rules shared by them.

1.1.1 Packages and authority #

Security formats and MessagePack codecs run without a Peios kernel. Native file, token, socket, process, registry, and event operations target Linux on x86-64 with the Peios kernel interface. Compiling on another Linux system does not supply those operations.

Native errors use syscall.Errno and support errors.Is. An access check reports a decision; the kernel still checks authority when you perform the operation. Process creation uses Go's os/exec and normal kernel inheritance. Activating process mitigations cannot clear existing bits.

1.1.2 Handles and buffers #

Close owned token, key, transaction, and file handles. Operations accepting syscall.Conn protect a descriptor from concurrent close and reuse during the call. A raw directory descriptor remains your responsibility: keep it open throughout the operation.

Descriptor parsers and event readers return owned data. Borrowed MessagePack cursor views remain tied to the caller's input buffer. MessagePack maps preserve pair order and duplicate keys. Decoder position advances only after a successful decode.

1.1.3 Identity scopes #

Token.Impersonate runs its callback on a dedicated, locked thread. The scope restores identity before returning and retires the thread if restoration fails. A callback panic is rethrown after cleanup.

WithIdentityThread supports repeated identity changes within one locked thread. The scope rejects calls after the callback or from another thread. Neither API transfers its identity to goroutines created by the callback. Installing a process token is a separate operation.

1.1.4 Security formats #

Binary descriptors retain entry order, unknown entry bodies, and metadata that text cannot express. Text formatting rejects unsupported entries rather than discarding them. An absent discretionary access control list (DACL) differs from an empty one. The present-null form is rejected.

Conditions have a 128-level expression limit, including long AND or OR chains. Parsing rejects deeper expressions with EINVAL, matching the formatter. Nested operands also have a depth bound.

Inheritance resolves creator identities and generic rights for the receiving object. It preserves explicit entries and protected lists. Stripping inherited entries preserves descriptor metadata and revision floors. Parsed lists can retain exact revision bytes during serialization.

1.2 Registry and Event Lifetimes

Peios / Developing for Peios / Go SDK Reference / Go SDK Conventions

Registry keys and event rings expose state that can change while your application reads it. The Go SDK gives returned data an explicit lifetime and reports changes that prevent a complete read.

1.2.1 Registry values and sources #

Registry writes use the base layer when Layer is empty. A nil or zero expected sequence disables compare-and-set. Delete operations reject an expected sequence because their kernel operation has no comparison field. Notifications are armed and read on the same key handle.

Allocating value helpers have a 16 MiB limit. QueryInto, ValuesInto, and ValueAtInto accept caller buffers; a nil buffer probes the required size and returns ERANGE. Batch counts are meaningful on success, and a size probe can report zero records.

TakeFile and TakeTransactionFile transfer descriptor ownership into registry handles. Close the resulting handle rather than closing its adopted descriptor separately.

registry/source.Source.Serve bounds concurrent handlers and serializes response writes. It closes the source on return or cancellation, waits for workers, and reports transport errors. Handlers must observe cancellation and provide storage and transaction semantics. Decoders permit trailing extension fields; the handler chooses its version policy.

1.2.2 Events and waits #

AttachAll visits the complete CPU slot range and skips empty slots. Each reader begins at its oldest surviving record and follows resizes. Returned events own their data and survive subsequent reads or closure.

Drain Next until no event is available, then wait with Wait(ctx). Cancellation or close can take up to 50 ms to interrupt a futex wait. Lost counts observed sequence gaps, not losses before attachment. Readers do not establish an ordering between different CPUs.

Low-level attachments and mappings have separate lifetimes: close both. EventAt returns owned data and a wire size, or EAGAIN for an empty, overwritten, or changed slot. Advance the absolute cursor by the wire size. A generation change requires a fresh attachment and mapping.

A context deadline bounds Ring.Wait. A canceled context permits a nonblocking readiness check; available data takes precedence over cancellation in that low-level method.

Emission policy is read afresh for each call. Essential events bypass registry policy; other tiers use defaults and the deepest valid Enabled value. This avoids retained watch handles at the cost of registry work on each policy check.

1.2.3 Messages and sessions #

A received socket message owns its delivered handles. Call Message.Close when finished. Receive closes all delivered handles if control data is truncated. ReceivePartial keeps handles that fit, closes excess handles, and reports truncation flags for the caller to assess.

A partial send does not resend ancillary data. Zero-length sequence-packet messages can transfer handles without an extra payload byte.

OpenSessions returns a snapshot reader. Next returns io.EOF at the end; a malformed line returns EPROTO and is consumed so reading can continue. Closing the last token destroys a used dynamic session. DestroyEmptySession handles an unused session. Session enumeration requires the appropriate classified securityfs mount and access rights.

2.1 Security Descriptors and Selectors

Peios / Developing for Peios / Go SDK Reference / Go SDK Security

security.SecurityInformation is the bitmask that selects components of a security descriptor. Use its named constants with file and registry descriptor operations:

ConstantValueSelected component
security.InfoOwner0x01Owner SID.
security.InfoGroup0x02Group SID.
security.InfoDACL0x04Discretionary ACL.
security.InfoSACL0x08Full system ACL.
security.InfoLabel0x10Mandatory-integrity label within the SACL.

Combine selectors with |, for example security.InfoOwner | security.InfoDACL. InfoLabel can accompany owner, group, or DACL selection, but must not be combined with InfoSACL; the kernel rejects that combination with EINVAL.

InfoLabel reads or writes a descriptor containing the label ACE in its SACL. Its payload is not a raw integrity SID. Reading the label requires READ_CONTROL; writing it requires WRITE_OWNER. Raising a label above the caller's integrity also requires SeRelabelPrivilege. Selecting the full SACL instead requires ACCESS_SYSTEM_SECURITY, gated by SeSecurityPrivilege.

Updates preserve components that were not selected. In particular, selecting only InfoLabel changes the mandatory label without replacing the other SACL entries. All selected components must pass their applicable authorization checks.

2.1.1 File descriptors #

file.GetDescriptor(f, info) returns owned descriptor bytes; file.SetDescriptor(f, info, sd) applies selected components from binary descriptor bytes. Both accept syscall.Conn, including *os.File. The path-relative variants are file.GetDescriptorAt(dirfd, path, info, flags) and file.SetDescriptorAt(dirfd, path, info, sd, flags).

For example, read and parse the mandatory label:

package example

import (
    "os"

    "github.com/peios/peios-go/file"
    "github.com/peios/peios-go/security"
)

func readLabel(f *os.File) (security.Descriptor, error) {
    wire, err := file.GetDescriptor(f, security.InfoLabel)
    if err != nil {
        return security.Descriptor{}, err
    }
    return security.ParseDescriptor(wire)
}

To request a medium-integrity, no-write-up label, build the descriptor and select only its label:

func setMediumLabel(f *os.File) error {
    sd, err := security.ParseSDDL("S:(ML;;NW;;;ME)")
    if err != nil {
        return err
    }
    wire, err := sd.MarshalBinary()
    if err != nil {
        return err
    }
    return file.SetDescriptor(f, security.InfoLabel, wire)
}

The second example uses the first example's imports. These functions perform native Peios operations and still depend on the caller's authority; constructing valid SDDL does not grant permission to set it.

2.1.2 Registry keys #

(*registry.Key).GetDescriptor(info) returns binary descriptor bytes, and (*registry.Key).SetDescriptor(info, sd, tx) writes selected components. They use the same security.Info* selectors, including InfoLabel, and the same prohibition on combining label and full-SACL selection. Pass a *registry.Transaction for a transactional update, or nil for an update without an explicit transaction.

Use security.ParseDescriptor to decode returned bytes and Descriptor.MarshalBinary to encode a descriptor for an update. security.ParseSDDL is available when constructing a descriptor from text. An absent DACL and an empty DACL are different: preserve that distinction when building or rewriting descriptors.

Peios Learn — documentation for Peios software.

Built with Trail.