gate

package
v1.2.9 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ApprovalReasonMissingToken      = "approval_token_missing"
	ApprovalReasonGranted           = "approval_granted"
	ApprovalReasonChainInsufficient = "approval_chain_insufficient"
	ApprovalReasonDistinctApprovers = "approval_distinct_approvers_required"
	ApprovalCodeSchemaInvalid       = "approval_token_invalid"
	ApprovalCodeSignatureMiss       = "approval_token_signature_missing"
	ApprovalCodeSignatureFailed     = "approval_token_signature_invalid"
	ApprovalCodeExpired             = "approval_token_expired"
	ApprovalCodeIntentMismatch      = "approval_token_intent_mismatch"
	ApprovalCodePolicyMismatch      = "approval_token_policy_mismatch"
	ApprovalCodeDelegationMismatch  = "approval_token_delegation_binding_mismatch"
	ApprovalCodeScopeMismatch       = "approval_token_scope_mismatch"
)
View Source
const (
	DelegationCodeSchemaInvalid   = "delegation_token_invalid"
	DelegationCodeSignatureMiss   = "delegation_token_signature_missing"
	DelegationCodeSignatureFailed = "delegation_token_signature_invalid"
	DelegationCodeExpired         = "delegation_token_expired"
	DelegationCodeDelegatorMis    = "delegation_token_delegator_mismatch"
	DelegationCodeDelegateMis     = "delegation_token_delegate_mismatch"
	DelegationCodeScopeMismatch   = "delegation_token_scope_mismatch"
	DelegationCodeIntentMismatch  = "delegation_token_intent_mismatch"
	DelegationCodePolicyMismatch  = "delegation_token_policy_mismatch"
)
View Source
const (
	SayTokenCodeSchemaInvalid   = "say_token_invalid"
	SayTokenCodeSignatureMiss   = "say_token_signature_missing"
	SayTokenCodeSignatureFailed = "say_token_signature_invalid"
	SayTokenCodeExpired         = "say_token_expired"
	SayTokenCodeIntentMismatch  = "say_token_intent_mismatch"
	SayTokenCodePolicyMismatch  = "say_token_policy_mismatch"
	SayTokenCodeCallMismatch    = "say_token_call_binding_mismatch"
	SayTokenCodeClassMismatch   = "say_token_class_mismatch"
)

Variables

This section is empty.

Functions

func ApplyWrkrContext added in v1.2.8

func ApplyWrkrContext(intent *schemagate.IntentRequest, toolName string, inventory map[string]WrkrToolMetadata) bool

func ApprovalContext

func ApprovalContext(policy Policy, intent schemagate.IntentRequest) (string, string, []string, error)

func ApprovedScriptDigest added in v1.2.8

func ApprovedScriptDigest(input schemagate.ApprovedScriptEntry) (string, error)

func ArgsDigest

func ArgsDigest(args map[string]any) (string, error)

func DelegationBindingDigest

func DelegationBindingDigest(intent schemagate.IntentRequest) (string, error)

func DelegationDigest

func DelegationDigest(delegation schemagate.IntentDelegation) (string, error)

func Evaluate

func Evaluate(policy Policy, intent schemagate.IntentRequest, options EvalOptions) (schemagate.GateResult, error)

Evaluate is a stable alias for policy evaluation used by integration callers.

func EvaluatePolicy

func EvaluatePolicy(policy Policy, intent schemagate.IntentRequest, opts EvalOptions) (schemagate.GateResult, error)

func IntentDigest

func IntentDigest(input schemagate.IntentRequest) (string, error)

func IsCommitmentClass

func IsCommitmentClass(value string) bool

func NormalizeApprovedScriptEntry added in v1.2.8

func NormalizeApprovedScriptEntry(input schemagate.ApprovedScriptEntry) (schemagate.ApprovedScriptEntry, error)

func NormalizedIntentBytes

func NormalizedIntentBytes(input schemagate.IntentRequest) ([]byte, error)

func PolicyDigest

func PolicyDigest(policy Policy) (string, error)

func PolicyHasHighRiskUnbrokeredActions

func PolicyHasHighRiskUnbrokeredActions(policy Policy) bool

func PolicyRequiresBrokerForHighRisk

func PolicyRequiresBrokerForHighRisk(policy Policy) bool

func ReadApprovalToken

func ReadApprovalToken(path string) (schemagate.ApprovalToken, error)

func ReadApprovedScriptRegistry added in v1.2.8

func ReadApprovedScriptRegistry(path string) ([]schemagate.ApprovedScriptEntry, error)

func ReadDelegationToken

func ReadDelegationToken(path string) (schemagate.DelegationToken, error)

func ReadSayToken

func ReadSayToken(path string) (schemavoice.SayToken, error)

func ReadTraceRecord

func ReadTraceRecord(path string) (schemagate.TraceRecord, error)

func ScriptHash added in v1.2.8

func ScriptHash(input schemagate.IntentRequest) (string, error)

func SignApprovedScriptEntry added in v1.2.8

func SignApprovedScriptEntry(input schemagate.ApprovedScriptEntry, privateKey ed25519.PrivateKey) (schemagate.ApprovedScriptEntry, error)

func ValidateApprovalToken

func ValidateApprovalToken(token schemagate.ApprovalToken, publicKey ed25519.PublicKey, opts ApprovalValidationOptions) error

func ValidateDelegationToken

func ValidateDelegationToken(token schemagate.DelegationToken, publicKey ed25519.PublicKey, opts DelegationValidationOptions) error

func ValidateSayToken

func ValidateSayToken(token schemavoice.SayToken, publicKey ed25519.PublicKey, opts SayTokenValidationOptions) error

func VerifyApprovedScriptEntry added in v1.2.8

func VerifyApprovedScriptEntry(input schemagate.ApprovedScriptEntry, publicKey ed25519.PublicKey, now time.Time) error

func VerifyTraceRecordSignature

func VerifyTraceRecordSignature(trace schemagate.TraceRecord, publicKey ed25519.PublicKey) (bool, error)

func WriteApprovalAuditRecord

func WriteApprovalAuditRecord(path string, record schemagate.ApprovalAuditRecord) error

func WriteApprovalToken

func WriteApprovalToken(path string, token schemagate.ApprovalToken) error

func WriteApprovedScriptRegistry added in v1.2.8

func WriteApprovedScriptRegistry(path string, entries []schemagate.ApprovedScriptEntry) error

func WriteBrokerCredentialRecord

func WriteBrokerCredentialRecord(path string, record schemagate.BrokerCredentialRecord) error

func WriteDelegationAuditRecord

func WriteDelegationAuditRecord(path string, record schemagate.DelegationAuditRecord) error

func WriteDelegationToken

func WriteDelegationToken(path string, token schemagate.DelegationToken) error

func WriteSayToken

func WriteSayToken(path string, token schemavoice.SayToken) error

func WriteTraceRecord

func WriteTraceRecord(path string, trace schemagate.TraceRecord) error

Types

type ApprovalTokenError

type ApprovalTokenError struct {
	Code string
	Err  error
}

func (*ApprovalTokenError) Error

func (e *ApprovalTokenError) Error() string

func (*ApprovalTokenError) Unwrap

func (e *ApprovalTokenError) Unwrap() error

type ApprovalValidationOptions

type ApprovalValidationOptions struct {
	Now                             time.Time
	ExpectedIntentDigest            string
	ExpectedPolicyDigest            string
	ExpectedDelegationBindingDigest string
	RequiredScope                   []string
}

type ApprovedScriptMatch added in v1.2.8

type ApprovedScriptMatch struct {
	Matched   bool
	PatternID string
	Reason    string
}

func MatchApprovedScript added in v1.2.8

func MatchApprovedScript(intent schemagate.IntentRequest, policyDigest string, entries []schemagate.ApprovedScriptEntry, now time.Time) (ApprovedScriptMatch, error)

type BuildApprovalAuditOptions

type BuildApprovalAuditOptions struct {
	CreatedAt         time.Time
	ProducerVersion   string
	TraceID           string
	ToolName          string
	IntentDigest      string
	PolicyDigest      string
	RequiredApprovals int
	Entries           []schemagate.ApprovalAuditEntry
}

type BuildBrokerCredentialRecordOptions

type BuildBrokerCredentialRecordOptions struct {
	CreatedAt       time.Time
	ProducerVersion string
	TraceID         string
	ToolName        string
	Identity        string
	Broker          string
	Reference       string
	Scope           []string
	CredentialRef   string
	IssuedAt        time.Time
	ExpiresAt       time.Time
	TTLSeconds      int64
}

type BuildDelegationAuditOptions

type BuildDelegationAuditOptions struct {
	CreatedAt          time.Time
	ProducerVersion    string
	TraceID            string
	ToolName           string
	IntentDigest       string
	PolicyDigest       string
	DelegationRequired bool
	DelegationRef      string
	Entries            []schemagate.DelegationAuditEntry
}

type DataflowPolicy

type DataflowPolicy struct {
	Enabled               bool     `yaml:"enabled"`
	TaintedSources        []string `yaml:"tainted_sources"`
	DestinationKinds      []string `yaml:"destination_kinds"`
	DestinationValues     []string `yaml:"destination_values"`
	DestinationOperations []string `yaml:"destination_operations"`
	Action                string   `yaml:"action"`
	ReasonCode            string   `yaml:"reason_code"`
	Violation             string   `yaml:"violation"`
}

type DelegationTokenError

type DelegationTokenError struct {
	Code string
	Err  error
}

func (*DelegationTokenError) Error

func (e *DelegationTokenError) Error() string

func (*DelegationTokenError) Unwrap

func (e *DelegationTokenError) Unwrap() error

type DelegationValidationOptions

type DelegationValidationOptions struct {
	Now                  time.Time
	ExpectedDelegator    string
	ExpectedDelegate     string
	RequiredScope        []string
	ExpectedIntentDigest string
	ExpectedPolicyDigest string
}

type EmitTraceOptions

type EmitTraceOptions struct {
	ProducerVersion       string
	CorrelationID         string
	ApprovalTokenRef      string
	DelegationTokenRef    string
	DelegationReasonCodes []string
	LatencyMS             float64
	ContextSource         string
	CompositeRiskClass    string
	StepVerdicts          []schemagate.TraceStepVerdict
	PreApproved           bool
	PatternID             string
	RegistryReason        string
	SigningPrivateKey     ed25519.PrivateKey
	TracePath             string
}

type EmitTraceResult

type EmitTraceResult struct {
	Trace        schemagate.TraceRecord
	TracePath    string
	PolicyDigest string
	IntentDigest string
}

func EmitSignedTrace

func EmitSignedTrace(policy Policy, intent schemagate.IntentRequest, gateResult schemagate.GateResult, opts EmitTraceOptions) (EmitTraceResult, error)

type EndpointPolicy

type EndpointPolicy struct {
	Enabled           bool     `yaml:"enabled"`
	PathAllowlist     []string `yaml:"path_allowlist"`
	PathDenylist      []string `yaml:"path_denylist"`
	DomainAllowlist   []string `yaml:"domain_allowlist"`
	DomainDenylist    []string `yaml:"domain_denylist"`
	EgressClasses     []string `yaml:"egress_classes"`
	Action            string   `yaml:"action"`
	DestructiveAction string   `yaml:"destructive_action"`
	ReasonCode        string   `yaml:"reason_code"`
	Violation         string   `yaml:"violation"`
}

type EvalOptions

type EvalOptions struct {
	ProducerVersion string
	WrkrInventory   map[string]WrkrToolMetadata
	WrkrSource      string
}

type EvalOutcome

type EvalOutcome struct {
	Result                   schemagate.GateResult
	MatchedRule              string
	MinApprovals             int
	RequireDistinctApprovers bool
	RequireBrokerCredential  bool
	RequireDelegation        bool
	BrokerReference          string
	BrokerScopes             []string
	RateLimit                RateLimitPolicy
	DataflowTriggered        bool
	Script                   bool
	StepCount                int
	ScriptHash               string
	CompositeRiskClass       string
	StepVerdicts             []schemagate.TraceStepVerdict
	ContextSource            string
	PreApproved              bool
	PatternID                string
	RegistryReason           string
}

func EvaluatePolicyDetailed

func EvaluatePolicyDetailed(policy Policy, intent schemagate.IntentRequest, opts EvalOptions) (EvalOutcome, error)

type FailClosedPolicy

type FailClosedPolicy struct {
	Enabled        bool     `yaml:"enabled"`
	RiskClasses    []string `yaml:"risk_classes"`
	RequiredFields []string `yaml:"required_fields"`
}

type MintApprovalTokenOptions

type MintApprovalTokenOptions struct {
	ProducerVersion         string
	ApproverIdentity        string
	ReasonCode              string
	IntentDigest            string
	PolicyDigest            string
	DelegationBindingDigest string
	Scope                   []string
	TTL                     time.Duration
	Now                     time.Time
	SigningPrivateKey       ed25519.PrivateKey
	TokenPath               string
}

type MintApprovalTokenResult

type MintApprovalTokenResult struct {
	Token     schemagate.ApprovalToken
	TokenPath string
}

type MintDelegationTokenOptions

type MintDelegationTokenOptions struct {
	ProducerVersion   string
	DelegatorIdentity string
	DelegateIdentity  string
	Scope             []string
	ScopeClass        string
	IntentDigest      string
	PolicyDigest      string
	TTL               time.Duration
	Now               time.Time
	SigningPrivateKey ed25519.PrivateKey
	TokenPath         string
}

type MintDelegationTokenResult

type MintDelegationTokenResult struct {
	Token     schemagate.DelegationToken
	TokenPath string
}

type MintSayTokenOptions

type MintSayTokenOptions struct {
	ProducerVersion    string
	CommitmentClass    string
	IntentDigest       string
	PolicyDigest       string
	CallID             string
	TurnIndex          int
	CallSeq            int
	Currency           string
	QuoteMinCents      int64
	QuoteMaxCents      int64
	RefundCeilingCents int64
	TTL                time.Duration
	Now                time.Time
	SigningPrivateKey  ed25519.PrivateKey
	TokenPath          string
}

type MintSayTokenResult

type MintSayTokenResult struct {
	Token     schemavoice.SayToken
	TokenPath string
}

func MintSayToken

func MintSayToken(opts MintSayTokenOptions) (MintSayTokenResult, error)

type Policy

type Policy struct {
	SchemaID       string           `yaml:"schema_id"`
	SchemaVersion  string           `yaml:"schema_version"`
	DefaultVerdict string           `yaml:"default_verdict"`
	DefaultAction  string           `yaml:"default_action"`
	Scripts        ScriptPolicy     `yaml:"scripts"`
	FailClosed     FailClosedPolicy `yaml:"fail_closed"`
	Rules          []PolicyRule     `yaml:"rules"`
}

func LoadPolicyFile

func LoadPolicyFile(path string) (Policy, error)

func ParsePolicyYAML

func ParsePolicyYAML(data []byte) (Policy, error)

type PolicyMatch

type PolicyMatch struct {
	ToolName                   string              `yaml:"tool_name"`
	ToolNames                  []string            `yaml:"tool_names"`
	RiskClasses                []string            `yaml:"risk_classes"`
	TargetKinds                []string            `yaml:"target_kinds"`
	TargetValues               []string            `yaml:"target_values"`
	EndpointClass              []string            `yaml:"endpoint_class"`
	EndpointClasses            []string            `yaml:"endpoint_classes"`
	DiscoveryMethods           []string            `yaml:"discovery_method"`
	ToolAnnotations            ToolAnnotationMatch `yaml:"tool_annotations"`
	SkillPublishers            []string            `yaml:"skill_publishers"`
	SkillSources               []string            `yaml:"skill_sources"`
	DataClasses                []string            `yaml:"data_classes"`
	DestinationKinds           []string            `yaml:"destination_kinds"`
	DestinationValues          []string            `yaml:"destination_values"`
	DestinationOps             []string            `yaml:"destination_operations"`
	ProvenanceSources          []string            `yaml:"provenance_sources"`
	Identities                 []string            `yaml:"identities"`
	WorkspacePrefixes          []string            `yaml:"workspace_prefixes"`
	ContextToolNames           []string            `yaml:"context_tool_names"`
	ContextDataClasses         []string            `yaml:"context_data_classes"`
	ContextEndpointClasses     []string            `yaml:"context_endpoint_classes"`
	ContextAutonomyLevels      []string            `yaml:"context_autonomy_levels"`
	RequireDelegation          bool                `yaml:"require_delegation"`
	AllowedDelegatorIdentities []string            `yaml:"allowed_delegator_identities"`
	AllowedDelegateIdentities  []string            `yaml:"allowed_delegate_identities"`
	DelegationScopes           []string            `yaml:"delegation_scopes"`
	MaxDelegationDepth         *int                `yaml:"max_delegation_depth"`
}

type PolicyRule

type PolicyRule struct {
	Name                        string          `yaml:"name"`
	Priority                    int             `yaml:"priority"`
	Effect                      string          `yaml:"effect"`
	Action                      string          `yaml:"action"`
	Match                       PolicyMatch     `yaml:"match"`
	Endpoint                    EndpointPolicy  `yaml:"endpoint"`
	ReasonCodes                 []string        `yaml:"reason_codes"`
	Violations                  []string        `yaml:"violations"`
	MinApprovals                int             `yaml:"min_approvals"`
	RequireDistinctApprovers    bool            `yaml:"require_distinct_approvers"`
	RequireContextEvidence      bool            `yaml:"require_context_evidence"`
	RequiredContextEvidenceMode string          `yaml:"required_context_evidence_mode"`
	MaxContextAgeSeconds        int64           `yaml:"max_context_age_seconds"`
	RequireBrokerCredential     bool            `yaml:"require_broker_credential"`
	BrokerReference             string          `yaml:"broker_reference"`
	BrokerScopes                []string        `yaml:"broker_scopes"`
	RateLimit                   RateLimitPolicy `yaml:"rate_limit"`
	Dataflow                    DataflowPolicy  `yaml:"dataflow"`
}

type RateLimitDecision

type RateLimitDecision struct {
	Allowed   bool   `json:"allowed"`
	Limit     int    `json:"limit"`
	Used      int    `json:"used"`
	Remaining int    `json:"remaining"`
	Scope     string `json:"scope"`
	Key       string `json:"key"`
}

func EnforceRateLimit

func EnforceRateLimit(statePath string, limit RateLimitPolicy, intent schemagate.IntentRequest, now time.Time) (RateLimitDecision, error)

type RateLimitPolicy

type RateLimitPolicy struct {
	Requests int    `yaml:"requests"`
	Window   string `yaml:"window"`
	Scope    string `yaml:"scope"`
}

type SayTokenError

type SayTokenError struct {
	Code string
	Err  error
}

func (*SayTokenError) Error

func (e *SayTokenError) Error() string

func (*SayTokenError) Unwrap

func (e *SayTokenError) Unwrap() error

type SayTokenValidationOptions

type SayTokenValidationOptions struct {
	Now                     time.Time
	ExpectedIntentDigest    string
	ExpectedPolicyDigest    string
	ExpectedCallID          string
	ExpectedTurnIndex       int
	ExpectedCallSeq         int
	ExpectedCommitmentClass string
}

type ScriptPolicy added in v1.2.8

type ScriptPolicy struct {
	MaxSteps             int  `yaml:"max_steps"`
	RequireApprovalAbove int  `yaml:"require_approval_above"`
	BlockMixedRisk       bool `yaml:"block_mixed_risk"`
}

type ToolAnnotationMatch added in v1.2.9

type ToolAnnotationMatch struct {
	ReadOnlyHint    *bool `yaml:"readOnlyHint"`
	DestructiveHint *bool `yaml:"destructiveHint"`
	IdempotentHint  *bool `yaml:"idempotentHint"`
	OpenWorldHint   *bool `yaml:"openWorldHint"`
}

type WrkrInventory added in v1.2.8

type WrkrInventory struct {
	Path    string
	ModTime time.Time
	Tools   map[string]WrkrToolMetadata
}

func LoadWrkrInventory added in v1.2.8

func LoadWrkrInventory(path string) (WrkrInventory, error)

type WrkrToolMetadata added in v1.2.8

type WrkrToolMetadata struct {
	ToolName      string
	DataClass     string
	EndpointClass string
	AutonomyLevel string
}

Jump to

Keyboard shortcuts

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