Help us shape the future of Go! Take the 2026 Go Developer Survey

policy

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: EUPL-1.2 Imports: 17 Imported by: 0

Documentation

Overview

Package policy contient le moteur de permissions : chaque appel d'outil y est vérifié avant exécution.

Index

Constants

This section is empty.

Variables

View Source
var ErrJurisdiction = errors.New("fournisseur hors UE sans consentement")

ErrJurisdiction is returned when a non-EU provider has no recorded consent.

Functions

This section is empty.

Types

type Call

type Call struct {
	Tool   string
	Risk   tools.Risk
	Target tools.Target
}

Call décrit un appel d'outil à vérifier.

type Decision

type Decision int

Decision est le verdict du moteur pour un appel.

const (
	Allow Decision = iota
	Ask
	Deny
)

func ParseDecision

func ParseDecision(s string) (Decision, error)

ParseDecision accepte exactement "allow", "ask" ou "deny".

func (Decision) String

func (d Decision) String() string

type Outbound

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

Outbound gates and redacts every message sent to an LLM provider.

func NewOutbound

func NewOutbound(r *Redactor) *Outbound

NewOutbound returns an Outbound using r for masking.

func (*Outbound) Check

func (o *Outbound) Check(p llm.ProviderInfo, msgs []llm.Message) ([]llm.Message, map[string]int, error)

Check enforces the jurisdiction rule, then returns a redacted deep copy of msgs with the number of masks per type. The input is never modified. Only EU and local providers pass freely; any other jurisdiction (including an empty one) requires consent.

func (*Outbound) Consent

func (o *Outbound) Consent(providerID string)

Consent records that the user accepted sending data to providerID.

type Permissions

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

Permissions évalue les appels selon les règles et le confinement au projet.

func NewPermissions

func NewPermissions(root string, rules []Rule) (*Permissions, error)

NewPermissions résout root via EvalSymlinks.

func (*Permissions) Check

func (p *Permissions) Check(c Call) Decision

Check applique l'algorithme : deny, validation forcée (ForceAsk), confinement/fichiers sensibles, ask du projet, allow, ask, défaut.

type RedactionRule

type RedactionRule struct{ Name, Pattern string }

RedactionRule is a user-defined masking rule. Matches are masked under the type strings.ToUpper(Name).

type Redactor

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

Redactor masks secrets and personal data. It is stateful (same value, same marker) and safe for concurrent use.

func NewRedactor

func NewRedactor(custom []RedactionRule) (*Redactor, error)

NewRedactor builds a Redactor with the built-in rules followed by custom.

func (*Redactor) AddKeyringSecret

func (r *Redactor) AddKeyringSecret(value string)

AddKeyringSecret masks a key read from the system keyring: its decoded value and the encoded forms go-keyring stores on macOS (and that the keychain tools print): "go-keyring-base64:"+base64, "go-keyring-encoded:"+hex and the bare base64. Each form shorter than 8 bytes is ignored.

func (*Redactor) AddLiteral

func (r *Redactor) AddLiteral(value string)

AddLiteral masks every exact occurrence of value as SECRET (e.g. a provider API key without a recognisable prefix). Literal steps run before the pattern rules. An empty value is ignored.

func (*Redactor) Redact

func (r *Redactor) Redact(s string) (string, map[string]int)

Redact masks s and returns the masked text with the number of masks per type.

func (*Redactor) RedactJSON

func (r *Redactor) RedactJSON(s string) (string, map[string]int)

RedactJSON masks a JSON payload and returns the masked text with the number of masks per type. Each string is masked once decoded: in raw JSON text a newline is the two characters `\n`, so line-anchored rules (KEY=value alone on its line) would not apply. Values under a secret-looking key are masked whole. The re-encoded text then goes through raw masking (patterns spanning a key and its value); if that pass breaks the JSON, the per-string result is kept. Text that is not a single JSON value is masked raw.

func (*Redactor) Reserve

func (r *Redactor) Reserve(kind string, n int)

Reserve marks the markers [kind_1]..[kind_n] as used: the next new value of that kind gets [kind_n+1]. Used on resume, so that a new secret never reuses a marker already present in the loaded session. Never decreases.

type Rule

type Rule struct {
	Tool, Match string
	Decision    Decision
	Project     bool
}

Rule associe un outil ("*" = tous) et un motif à une décision. Project indique une règle de la config projet (.tenon/config.toml) : le projet ne peut que restreindre, ses règles ask priment donc les allow globales.

Jump to

Keyboard shortcuts

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