policy

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 7 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

Overview

Package policy is the gate every operation passes through.

The policy file is written by the deployer and is read-only to the agent (in a Pod it is a ConfigMap mount). The effective mode for an operation is the lower of the policy mode and the mode the account logged in with, so a policy can never grant more than the token's scopes and a token can never be used beyond what the policy allows.

Index

Constants

View Source
const DefaultSignoff = "\n\n-- \nSent by an automated assistant"

DefaultSignoff is appended to agent-written bodies unless the policy sets `signoff` explicitly (an empty string disables it).

Variables

This section is empty.

Functions

func DefaultPath

func DefaultPath(configDir string) string

DefaultPath resolves the policy file: $EMAIL_POLICY_FILE, else <configDir>/policy.toml.

func IsWrite

func IsWrite(op Op) bool

IsWrite reports whether op changes mailbox state (and is therefore audited).

Types

type Decision

type Decision struct {
	Allowed       bool   `json:"allowed"`
	Op            Op     `json:"op"`
	EffectiveMode Mode   `json:"effective_mode"`
	Reason        string `json:"reason,omitempty"`
}

type DefaultSection

type DefaultSection struct {
	Mode    Mode    `toml:"mode" json:"mode"`
	Signoff *string `toml:"signoff" json:"signoff"`
}

type DeleteSection

type DeleteSection struct {
	Enabled bool `toml:"enabled" json:"enabled"`
}

type Mode

type Mode int
const (
	ModeNone Mode = iota
	ModeRead
	ModeDraft
	ModeSend
)

func ParseMode

func ParseMode(s string) (Mode, error)

func (Mode) MarshalText

func (m Mode) MarshalText() ([]byte, error)

func (Mode) String

func (m Mode) String() string

func (*Mode) UnmarshalText

func (m *Mode) UnmarshalText(b []byte) error

type Op

type Op string

Op is an operation the CLI can perform.

const (
	OpList           Op = "list"
	OpSearch         Op = "search"
	OpGet            Op = "get"
	OpThread         Op = "thread"
	OpAttachmentList Op = "attachments.list"
	OpAttachmentGet  Op = "attachments.download"
	OpSync           Op = "sync"
	OpDraftList      Op = "draft.list"
	OpDraftGet       Op = "draft.get"
	OpDraftCreate    Op = "draft.create"
	OpDraftReply     Op = "draft.reply"
	OpDraftForward   Op = "draft.forward"
	OpDraftUpdate    Op = "draft.update"
	OpDraftDelete    Op = "draft.delete"
	OpMove           Op = "move"
	OpLabel          Op = "label"
	OpMark           Op = "mark"
	OpSend           Op = "send"
	OpAPI            Op = "api"
)

type Policy

type Policy struct {
	Default DefaultSection `toml:"default" json:"default"`
	Send    SendSection    `toml:"send" json:"send"`
	Delete  DeleteSection  `toml:"delete" json:"delete"`
	Watch   WatchSection   `toml:"watch" json:"watch"`

	Source string `toml:"-" json:"source"` // file path, or "builtin"
}

func Builtin

func Builtin() *Policy

Builtin is used when no policy file exists: read-only, which is the safe failure mode for a missing or mis-mounted ConfigMap.

func Load

func Load(path string) (*Policy, error)

Load reads the policy at path. A missing file yields Builtin(); a file that exists but fails to parse, or has unknown keys, is an error — a typo in a security config must not silently fall back to defaults.

func (*Policy) Check

func (p *Policy) Check(req Request) Decision

Check decides whether req is allowed.

func (*Policy) EffectiveMode

func (p *Policy) EffectiveMode(accountMode Mode) Mode

func (*Policy) Signoff

func (p *Policy) Signoff() string

Signoff returns the text to append to agent-written bodies.

type Request

type Request struct {
	Op            Op
	AccountMode   Mode     // mode the account logged in with (bounds the token's scopes)
	AccountDomain string   // domain of the logged-in mailbox, used as "internal" when no allowlist is set
	Recipients    []string // email addresses the operation would address
	Dest          string   // move destination
	AddLabels     []string // label additions
	HasReplyCtx   bool     // send: the draft is a reply/forward of an existing message
	APIMethod     string
	APIPath       string
}

Request describes one operation to be checked.

type SendSection

type SendSection struct {
	AllowedRecipientDomains []string `toml:"allowed_recipient_domains" json:"allowed_recipient_domains"`
	MaxRecipients           int      `toml:"max_recipients" json:"max_recipients"` // 0 = unlimited
	BlockExternalForward    bool     `toml:"block_external_forward" json:"block_external_forward"`
	RequireReplyContext     bool     `toml:"require_reply_context" json:"require_reply_context"`
}

type WatchSection

type WatchSection struct {
	IgnoreSenders  []string `toml:"ignore_senders" json:"ignore_senders"`
	IgnoreSubjects []string `toml:"ignore_subjects" json:"ignore_subjects"`
	// OnlyUnread skips mail already read (on the phone, say) by the time
	// watch sees it.
	OnlyUnread bool `toml:"only_unread" json:"only_unread"`
}

WatchSection filters what `email watch` notifies about. Entries match as case-insensitive substrings: "noreply@" or a "@domain" suffix.

Jump to

Keyboard shortcuts

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