Documentation
¶
Overview ¶
internal/db/effects/alias.go
internal/db/effects/effect.go
internal/db/effects/object.go
internal/db/effects/resolution.go
internal/db/effects/statement.go
internal/db/effects/subtype.go
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BulkOpKind ¶
type BulkOpKind uint8
BulkOpKind classifies whether a statement initiates a wire-protocol COPY stream the proxy must follow. COPY to/from server paths or PROGRAM forms do not set this because no client-side CopyData stream follows the Q frame.
const ( BulkOpNone BulkOpKind = iota BulkOpIn BulkOpOut )
func (BulkOpKind) MarshalJSON ¶
func (b BulkOpKind) MarshalJSON() ([]byte, error)
func (BulkOpKind) String ¶
func (b BulkOpKind) String() string
func (*BulkOpKind) UnmarshalJSON ¶
func (b *BulkOpKind) UnmarshalJSON(bs []byte) error
type ClassifiedStatement ¶
type ClassifiedStatement struct {
Effects []Effect `json:"effects"`
RawVerb string `json:"raw_verb,omitempty"`
ParserBackend ParserBackend `json:"parser_backend,omitempty"`
Error string `json:"error,omitempty"`
// SourceStart / SourceEnd are byte offsets into the original SQL input
// (Plan 04c needs these to slice per-stmt text under RedactionFull). Both
// zero when the parser cannot supply them (e.g. unknown-statement path).
SourceStart int32 `json:"source_start,omitempty"`
SourceEnd int32 `json:"source_end,omitempty"`
// PreparedName is populated for PREPARE / EXECUTE / DEALLOCATE classifications.
// Empty for any other verb. For DEALLOCATE ALL, PreparedName is "" (the
// proxy's sqlprepared.Intercept distinguishes by RawVerb).
PreparedName string `json:"prepared_name,omitempty"`
// BulkOp is non-None for COPY statements that open a CopyData stream the
// proxy must follow.
BulkOp BulkOpKind `json:"bulk_op,omitempty"`
}
ClassifiedStatement is the output of the Postgres classifier (Plan 03) and the input to the policy evaluator (Plan 02). Effects must be in canonical order per Order(); the first entry is the primary effect.
func (ClassifiedStatement) FoldResolution ¶
func (s ClassifiedStatement) FoldResolution() Resolution
FoldResolution returns the worst (least-confident) Resolution across all effects, per §6.2. Returns ResolutionQualified if Effects is empty.
func (ClassifiedStatement) Primary ¶
func (s ClassifiedStatement) Primary() (Effect, bool)
Primary returns the first (canonical) effect. ok=false on empty effects list.
type Effect ¶
type Effect struct {
Group Group
Subtype Subtype
Objects []ObjectRef
ResolvedObjects []ResolvedObjectRef `json:"resolved_objects,omitempty"`
Resolution Resolution
// HasWhere is observed statement-shape metadata. It is set only on
// mutation effects whose owning statement has a top-level WHERE clause.
HasWhere bool `json:"has_where,omitempty"`
// FunctionOID is populated for procedural effects with Subtype
// SubtypeFunctionCallProtocol (the Postgres 'F' FunctionCall frame) or
// SubtypeEscalatedFunctionCall (when classifier escalation produced
// the effect). Pointer so JSON omits zero.
FunctionOID *int32 `json:"function_oid,omitempty"`
}
Effect is one classified consequence of a statement, per §5.2.
type Group ¶
type Group uint8
Group identifies an operation taxonomy bucket per §5 of the spec.
const ( GroupRead Group = 1 GroupWrite Group = 2 GroupModify Group = 3 GroupDelete Group = 4 GroupBulkLoad Group = 5 GroupBulkExport Group = 6 GroupSchemaCreate Group = 7 GroupSchemaAlter Group = 8 GroupSchemaDestroy Group = 9 GroupPrivilege Group = 10 GroupTransaction Group = 11 GroupSession Group = 12 GroupMaintenance Group = 13 GroupLock Group = 14 GroupNotify Group = 15 GroupProcedural Group = 16 GroupUnsafeIO Group = 17 GroupUnknown Group = 18 )
IDs match the spec table 1..18 so `group_id` in DBEvent is stable.
func ExpandAlias ¶
ExpandAlias resolves an operator-written token to a list of canonical Groups. Accepts uppercase aliases ("READ", "MUTATE", "DANGEROUS"), the wildcard "*" (all groups except GroupUnknown), or canonical lowercase group names ("read"). Returns ok=false on unknown tokens.
func ParseGroup ¶
ParseGroup parses the canonical lowercase group name. Returns ok=false on unknown input.
type ObjectKind ¶
type ObjectKind uint8
ObjectKind identifies the schema of an ObjectRef per §6.4.
const ( ObjectTable ObjectKind = iota + 1 ObjectView ObjectFunction ObjectSchema ObjectIndex ObjectSequence ObjectExternalEndpoint ObjectFilesystemPath ObjectProgram ObjectSubscription ObjectPublication ObjectServer ObjectUserMapping ObjectTablespace ObjectGUC ObjectRole )
func (ObjectKind) String ¶
func (k ObjectKind) String() string
type ObjectRef ¶
type ObjectRef struct {
Kind ObjectKind
Schema string // table/view/function/index/sequence
Name string // any named object
Host string // external_endpoint
Port int // external_endpoint
Path string // filesystem_path
Argv0 string // program
}
ObjectRef references one named object referenced by an Effect, per §6.4. Fields are kind-specific; consumers should read only those for the active Kind. JSON encoding emits only fields populated for the active Kind.
Note: for unqualified table references the spec calls for schema=null in JSON (§6.1). Phase 1 emits the field as absent (omitempty) — the null-vs-absent distinction is finalized in Plan 04 when DBEvent JSON ships.
func (ObjectRef) MarshalJSON ¶
MarshalJSON emits only the fields meaningful for r.Kind.
func (*ObjectRef) UnmarshalJSON ¶
UnmarshalJSON parses the kind-discriminated form back into an ObjectRef.
type ParserBackend ¶
type ParserBackend uint8
ParserBackend identifies which parser produced a classification, per §7.8.
const ( ParserBackendUnknown ParserBackend = iota ParserBackendLibPgQuery ParserBackendPureGo )
func (ParserBackend) String ¶
func (b ParserBackend) String() string
type Resolution ¶
type Resolution uint8
Resolution tags an Effect's object set with a confidence level per §6.1.
const ( ResolutionQualified Resolution = iota ResolutionUnqualified ResolutionAmbiguousAfterSearchPath ResolutionMaybeTempShadowed ResolutionUnresolved ResolutionCatalogResolved ResolutionCatalogUnresolved )
func Fold ¶
func Fold(rs []Resolution) Resolution
Fold returns the worst (least-confident) Resolution in the set, per §6.2. Empty input returns ResolutionQualified (no objects = no doubt).
func ParseResolution ¶
func ParseResolution(name string) (Resolution, bool)
ParseResolution parses the canonical lowercase resolution-tag name. Returns ok=false on unknown input (including the empty string).
func (Resolution) String ¶
func (r Resolution) String() string
type ResolvedObjectKind ¶
type ResolvedObjectKind string
const ( ResolvedObjectRelation ResolvedObjectKind = "relation" ResolvedObjectFunction ResolvedObjectKind = "function" )
type ResolvedObjectRef ¶
type ResolvedObjectRef struct {
Source ResolvedObjectSource `json:"source,omitempty"`
Kind ResolvedObjectKind `json:"kind,omitempty"`
OID uint32 `json:"oid,omitempty"`
Schema string `json:"schema,omitempty"`
Name string `json:"name,omitempty"`
RelationKind string `json:"relation_kind,omitempty"`
FunctionIdentityArgs string `json:"function_identity_args,omitempty"`
FunctionVolatility string `json:"function_volatility,omitempty"`
UnresolvedReason string `json:"unresolved_reason,omitempty"`
}
func (ResolvedObjectRef) CanonicalName ¶
func (r ResolvedObjectRef) CanonicalName() string
type ResolvedObjectSource ¶
type ResolvedObjectSource string
const (
ResolvedObjectSourceCatalog ResolvedObjectSource = "catalog"
)
type RiskTier ¶
type RiskTier uint8
RiskTier orders operation groups by severity. Critical is the highest tier.
type Subtype ¶
type Subtype uint8
Subtype is an optional refinement on a Group, per §5.1. SubtypeNone (zero value) means "no subtype, group-level only".
const ( SubtypeNone Subtype = iota // session subtypes SubtypeSet SubtypeSetSearchPath SubtypeSetRole SubtypeSetSessionAuthorization SubtypeSetLocal SubtypeReset SubtypeResetAll SubtypeDiscard SubtypeDiscardAll SubtypeDiscardTemp SubtypeDiscardPlans SubtypeDiscardSequences SubtypeCancelRequest // schema_create SubtypeCreateTable SubtypeCreateIndex SubtypeCreateView SubtypeCreateSchema SubtypeCreateFunction SubtypeCreateMaterializedView SubtypeCreateExtension SubtypeCreateDatabase SubtypeCreatePublication // schema_alter SubtypeAlterPublication // schema_destroy SubtypeDropTable SubtypeDropDatabase SubtypeDropSchema SubtypeDropIndex SubtypeDropView SubtypeDropFunction SubtypeDropPublication SubtypeTruncate // privilege SubtypeGrant SubtypeRevoke SubtypeAlterRole SubtypeCreateRole SubtypeDropRole SubtypeAlterSystem SubtypeSecurityLabel // bulk_load SubtypeCopyFromStdin SubtypeCopyFromS3 // bulk_export SubtypeCopyToStdout SubtypeUnloadToS3 // procedural SubtypeFunctionCallProtocol SubtypeEscalatedFunctionCall SubtypeCall SubtypeDo SubtypeAnonymousBlock SubtypeDoOrAnon // unsafe_io SubtypeCreateSubscription SubtypeAlterSubscription SubtypeDropSubscription SubtypeCreateServer SubtypeAlterServer SubtypeDropServer SubtypeCreateUserMapping SubtypeAlterUserMapping SubtypeDropUserMapping SubtypeCreateTablespace SubtypeAlterTablespace SubtypeDropTablespace SubtypeCopyToPath SubtypeCopyFromPath SubtypeCopyToProgram SubtypeCopyFromProgram SubtypeLargeObjectIO SubtypeServerFileRead SubtypeDblinkCall SubtypeFdwAccess )
func ParseSubtype ¶
ParseSubtype parses the canonical lowercase subtype name. The empty string returns (SubtypeNone, false) — operators wishing to match group-level only should leave the rule's subtypes clause absent. Returns ok=false on unknown.