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

policy

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: EUPL-1.2 Imports: 20 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 ErrAllowlist = errors.New("allowlist violation")

ErrAllowlist est renvoyée quand l'hôte du fournisseur n'est pas dans une liste blanche (provider_allowlist).

View Source
var ErrJurisdiction = errors.New("non-EU provider without consent")

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

Functions

func MatchWildcard added in v0.7.0

func MatchWildcard(pattern, s string) bool

MatchWildcard rapporte si s correspond à pattern. `*` correspond à toute suite de caractères (espaces et `/` compris) ; le reste est littéral.

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, in order: the compliance profile (its error wraps profile.ErrProfile), the policy host allowlist, the provider allowlists, then the jurisdiction rule. A recorded consent never bypasses the first three. It 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.

func (*Outbound) SetAllowlists added in v0.7.0

func (o *Outbound) SetAllowlists(lists []hostmatch.List)

SetAllowlists fixe les listes blanches d'hôtes (globale, projet) revérifiées avant chaque envoi ; chacune doit accepter l'hôte (vide : aucune restriction).

func (*Outbound) SetHostPolicy added in v0.7.0

func (o *Outbound) SetHostPolicy(p *orgpolicy.Policy)

SetHostPolicy fixe la politique d'organisation dont la liste blanche d'hôtes est revérifiée avant chaque envoi (nil : aucune restriction).

func (*Outbound) SetProfile added in v0.7.0

func (o *Outbound) SetProfile(n profile.Name)

SetProfile sets the compliance profile re-checked before every send (defense in depth: the CLI already refuses a non-compliant provider).

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.

func (*Permissions) Decide added in v0.5.0

func (p *Permissions) Decide(c Call) (d Decision, liftable bool)

Decide applique l'algorithme de Check et indique en plus si un Ask peut être levé par un hook : liftable vaut true seulement pour un Ask issu d'une règle ask globale ou du défaut selon le risque.

func (*Permissions) DecideNet added in v0.7.0

func (p *Permissions) DecideNet(c Call) (d Decision, liftable, network bool)

DecideNet applique Decide et renvoie en plus le drapeau Network de la règle allow ou ask retenue (false pour un deny, un Ask imposé ou un 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
	Network     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. Network ouvre le réseau à la commande shell isolée quand la règle allow correspond, ou quand l'utilisateur accepte la demande d'une règle ask.

Jump to

Keyboard shortcuts

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