apiaudit

package
v0.0.53 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: Apache-2.0 Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package apiaudit records mecak8s's own audit events in Mecatl's AuditEvent profile (docs/drafts/agent-identity/audit.md, "AuditEvent profile" and "Producers"): each request its API admits or refuses, each check that the caller owns a host session, and each deletion of a host session with its cause. It writes them through the identity broker's audit destination, so one file holds both components' records.

Index

Constants

View Source
const (
	// TypeAPIRequest records one API request: whether the API admitted it,
	// and who it was admitted for. It does not record what the request did.
	TypeAPIRequest = "mecatl_api_request"
	// TypeSessionOwnershipCheck records one check that the caller owns a
	// host session, made for an API request.
	TypeSessionOwnershipCheck = "mecatl_session_ownership_check"
	// TypeSessionDeleted records the deletion of one host session, its
	// transcript included, and why it was deleted (audit.md, "Transcript
	// retention").
	TypeSessionDeleted = "mecatl_session_deleted"
)

The event types mecak8s records.

View Source
const (
	// DeletionOwner is a delete the session's owner asked for.
	DeletionOwner = "owner_delete"
	// DeletionRetention is a delete by session retention: the automatic
	// sweep, or a cleanup an API request started.
	DeletionRetention = "retention"
)

The causes of a host session's deletion.

View Source
const Component = ib.ComponentMecak8s

Component is the Component, and the clock, of every event this package records; it is the component reported:mecak8s names.

Variables

This section is empty.

Functions

func RequestRecord

func RequestRecord(ctx context.Context) string

RequestRecord returns the AuditID of the API request ctx serves; empty when ctx serves none, as for the harness's own work.

func WithRequest

func WithRequest(ctx context.Context, auditID string) context.Context

WithRequest returns ctx carrying auditID, the record of the API request it serves, for the events recorded while serving it to reference.

func WithoutRequest

func WithoutRequest(ctx context.Context) context.Context

WithoutRequest returns ctx serving no API request, for work the server owns after accepting one: what it records references no request.

Types

type EventWriter

type EventWriter interface {
	AppendEvent(ctx context.Context, ev *audit.AuditEvent) error
}

EventWriter appends one event to the audit destination without waiting for it to be synced, as the identity broker's sink does (auditsink.Sink.AppendEvent): nothing waits on mecak8s's events.

type Origin

type Origin struct {
	Replica    string
	Deployment string
}

Origin says where the recorder records: the recording replica and the deployment. An empty field is recorded as unavailable. mecak8s has no SPIFFE identity of its own, so no trust domain is recorded.

type Recorder

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

Recorder records mecak8s's events. It never waits on the destination: events are queued in order and written one at a time, and one dropped or not written is reported to the diagnostics. A nil *Recorder records nothing, so callers need not check whether auditing is on.

func New

func New(w EventWriter, origin Origin, diag port.Diagnostics) *Recorder

New returns a Recorder writing to w, recorded at origin, reporting events it could not write to diag.

func (*Recorder) APIRequest

func (r *Recorder) APIRequest(req Request) string

APIRequest records req and returns its AuditID, or "" when r is nil.

func (*Recorder) Close

func (r *Recorder) Close(ctx context.Context)

Close stops accepting events and writes those queued until ctx ends; each left unwritten then is reported to the diagnostics.

func (*Recorder) SessionDeleted

func (r *Recorder) SessionDeleted(ctx context.Context, d SessionDeletion)

SessionDeleted records that a host session was deleted, with its cause. It names the API request that deleted it, if one did; the automatic retention sweep serves none. The record is queued, never waited for: a delete is not held back for its record.

func (*Recorder) SessionOwnership

func (r *Recorder) SessionOwnership(ctx context.Context, hostSessionID string, owned bool)

SessionOwnership records that the caller of ctx's API request was found to own host session hostSessionID, or not. It records nothing for a context that serves no API request, such as the harness's own work.

type Request

type Request struct {
	// Transport is "grpc" or "http".
	Transport string
	// Method is the gRPC full method, or the HTTP method.
	Method string
	// Path is the HTTP request path; empty for gRPC.
	Path string
	// Peer is the network address the request came from.
	Peer string
	// Outcome is audit.OutcomeSuccess when the API admitted the request,
	// audit.OutcomeDenied when it refused it, and audit.OutcomeError when it
	// could not check it.
	Outcome string
	// Code is a fixed code saying why the request was refused or could not
	// be checked, such as "expired"; empty when it was admitted.
	Code string
	// Owner is the verified caller sessions are owned by; nil when none.
	Owner *session.Principal
	// Token is the verified access token's own identity.
	Token TokenIdentity
}

Request is one API request at mecak8s's edge.

type SessionDeletion

type SessionDeletion struct {
	// HostSessionID and Incarnation name the deleted host session; a
	// session created again under the same ID has another incarnation.
	HostSessionID string
	Incarnation   string
	// Kind is the session's kind (session.SessionKind), such as main,
	// scheduled, subagent, parallel_branch, or team_member.
	Kind string
	// Owner is the session's owner, as mecak8s stored it when the session
	// was created; nil when the session has none. The record marks it
	// reported:mecak8s: no token is verified for a deletion.
	Owner *session.Principal
	// Cause is DeletionOwner or DeletionRetention, and RetentionReason, for
	// a retention delete, the limit that selected it: sessionretention's
	// ReasonAge ("age") or ReasonCap ("cap").
	Cause           string
	RetentionReason string
}

SessionDeletion is one deleted host session.

type TokenIdentity

type TokenIdentity struct {
	Issuer, Subject, ClientID, ID string
}

TokenIdentity is the verified access token's own identity, as the validator that verified it read it: its issuer and subject, the client it was issued to, and its token ID, which joins the request to the broker's session open that converted the same token. A zero field is unavailable.

Jump to

Keyboard shortcuts

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