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 ¶
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.
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.
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 ¶
RequestRecord returns the AuditID of the API request ctx serves; empty when ctx serves none, as for the harness's own work.
func WithRequest ¶
WithRequest returns ctx carrying auditID, the record of the API request it serves, for the events recorded while serving it to reference.
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 ¶
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 ¶
APIRequest records req and returns its AuditID, or "" when r is nil.
func (*Recorder) Close ¶
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 ¶
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.