policy

package
v0.1.19 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package policy enforces data egress decisions. Every external call must pass through a Policy before any data leaves the machine. The default mode is Strict, which denies all egress.

Index

Constants

This section is empty.

Variables

View Source
var ErrEgressDenied = errors.New("policy: egress denied")

ErrEgressDenied indicates the policy forbade an external call.

View Source
var ErrLocked = errors.New("policy: locked")

ErrLocked indicates an attempt to change a pinned policy.

View Source
var ErrUnknownMode = errors.New("policy: unknown mode")

ErrUnknownMode indicates an unrecognized policy mode name.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Mode is the egress mode name: strict, redacted, or open.
	Mode string `json:"mode"`
	// Locked pins the policy so user flags cannot change it.
	Locked bool `json:"locked"`
	// PrivateChannels is "allow" or "deny" for private-channel ingest.
	PrivateChannels string `json:"private_channels"`
}

Config is the on-disk policy an organization can ship to pin behavior. When Locked is true, user flags cannot loosen it.

func Load

func Load(path string) (cfg Config, found bool, err error)

Load reads a policy Config from path. found is false when the file is absent; an unreadable or malformed file is an error.

func (Config) Policy

func (c Config) Policy() (Policy, error)

Policy builds an enforced Policy from the config.

type Mode

type Mode int

Mode is a data egress posture.

const (
	// Strict forbids all egress: nothing leaves the machine.
	Strict Mode = iota
	// Redacted permits egress only after the caller has redacted the payload.
	Redacted
	// Open permits egress without restriction.
	Open
)

func ParseMode

func ParseMode(s string) (Mode, error)

ParseMode parses a mode name, defaulting to Strict on empty input.

func (Mode) String

func (m Mode) String() string

String returns the lowercase name of the mode.

type Policy

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

Policy decides whether data may leave the machine. A locked policy is pinned by an organization and cannot be loosened by user flags.

func Default

func Default() Policy

Default returns the deny-all Strict policy.

func New

func New(mode Mode, locked bool) Policy

New returns a Policy with the given mode and lock state.

func (Policy) AllowEgress

func (p Policy) AllowEgress(dest string, nbytes int) error

AllowEgress reports whether sending nbytes to dest is permitted. Strict always denies. Under Redacted and Open it permits; a Redacted caller is responsible for redacting the payload before calling.

func (Policy) AllowPrivateChannels

func (p Policy) AllowPrivateChannels() bool

AllowPrivateChannels reports whether ingesting private channels is permitted. An organization can pin this off; user flags then cannot enable it.

func (Policy) Locked

func (p Policy) Locked() bool

Locked reports whether the policy is pinned and cannot be loosened.

func (Policy) Mode

func (p Policy) Mode() Mode

Mode returns the policy's current mode.

func (Policy) WithMode

func (p Policy) WithMode(mode Mode) (Policy, error)

WithMode returns a copy at the requested mode. A locked policy cannot change to a different mode and returns ErrLocked.

func (Policy) WithoutPrivateChannels

func (p Policy) WithoutPrivateChannels() Policy

WithoutPrivateChannels returns a copy that forbids private-channel ingest. This is how an organization pins private ingest off.

Jump to

Keyboard shortcuts

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