Documentation
¶
Overview ¶
Package writeaudit carries authenticated, non-secret request provenance to business transactions, and owns the rules for recording it and its read models. It does not authorize requests or replace principals. persistence/postgres/auditpg stores it.
Index ¶
- Variables
- func ValidResourceType(value string) bool
- func ValidText(value string, max int, required bool) bool
- func ValidateOwnerQuery(resourceType string, resourceIDs []string) error
- func ValidateRecord(source Source, tenant string, action Action, resources []Resource) error
- func WithSource(ctx context.Context, source Source) context.Context
- type APIKey
- type Action
- type Filter
- type Operation
- type Page
- type Resource
- type ResourceOwner
- type ResourceType
- type Source
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidQuery = errors.New("invalid write audit query")
ErrInvalidQuery reports a provenance query with an invalid tenant, filter, page size or cursor.
var ErrInvalidSource = errors.New("invalid write audit source")
ErrInvalidSource reports a write audit record that cannot be recorded: malformed provenance, or an action or resource outside the audit vocabulary. The write it belongs to fails closed.
Functions ¶
func ValidResourceType ¶
ValidResourceType reports whether value is an audited resource type. The list is closed; recording and owner queries share it.
func ValidText ¶
ValidText reports whether value is valid UTF-8 of at most max runes without control characters, and nonempty when required. Every recorded or queried audit string passes it.
func ValidateOwnerQuery ¶
ValidateOwnerQuery checks a batch creator lookup of one to 100 resources of one audited type.
func ValidateRecord ¶
ValidateRecord checks a write record in tenant: source must be well-formed provenance from tenant, action an audited write action, and every resource an audited resource.
Types ¶
type APIKey ¶
type APIKey struct {
ID string `json:"id" binding:"required"`
Name string `json:"name" binding:"required"`
Prefix string `json:"prefix" binding:"required"`
Kind string `json:"kind" enums:"issued" binding:"required"`
RevokedAt *time.Time `json:"revoked_at" extensions:"x-nullable" binding:"required"`
}
APIKey is the recorded identity of the key that made a write, with its current revocation time.
type Filter ¶
type Filter struct {
KeyID, ResourceType, ResourceID, After string
CreatedAfter, CreatedBefore *time.Time
Limit int
}
Filter selects committed writes, newest first. A zero Limit is the default page size.
type Operation ¶
type Operation struct {
ID string `json:"id" binding:"required"`
Action Action `json:"action" binding:"required"`
ResourceType ResourceType `json:"resource_type" binding:"required"`
ResourceID string `json:"resource_id" binding:"required"`
ParentID string `json:"parent_id" binding:"required"`
RequestID string `json:"request_id" binding:"required"`
TraceID string `json:"trace_id" binding:"required"`
APIKey APIKey `json:"api_key" binding:"required"`
CreatedAt time.Time `json:"created_at" binding:"required"`
}
Operation is one committed write.
type Resource ¶
type Resource struct {
Type ResourceType
ID, ParentID string
}
Resource identifies a resource genuinely created by the current transaction.
type ResourceOwner ¶
type ResourceOwner struct {
ResourceID string `json:"resource_id" binding:"required"`
APIKey *APIKey `json:"api_key" extensions:"x-nullable" binding:"required"`
}
ResourceOwner is the recorded creator of one resource. APIKey is null for a resource without recorded creation provenance.
type ResourceType ¶ added in v0.0.10
type ResourceType string
const ( ResourceAgent ResourceType = "agent" ResourceSession ResourceType = "session" ResourceEnvironment ResourceType = "environment" ResourceEnvironmentTemplate ResourceType = "environment_template" ResourceSkill ResourceType = "skill" ResourceSkillVersion ResourceType = "skill_version" ResourceFile ResourceType = "file" ResourceVault ResourceType = "vault" ResourceCredential ResourceType = "credential" ResourceArtifact ResourceType = "artifact" )
type Source ¶
type Source struct {
KeyID string `json:"key_id"`
Name string `json:"name"`
Prefix string `json:"prefix"`
Kind string `json:"kind"`
TenantID string `json:"tenant_id"`
RequestID string `json:"request_id"`
TraceID string `json:"trace_id"`
}
Source contains no bearer token, payload, file path or native credentials. RequestID is server-generated; TraceID may be shared by related requests.