gcpaudit

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 19 Imported by: ? 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 gcpaudit lets GCP emulators record Cloud Audit Logs entries (protoPayload AuditLog) in the Logging emulator, which Eventarc triggers on google.cloud.audit.log.v1.written then match.

Index

Constants

View Source
const DefaultPrincipal = "emulator@gopherstack.iam.gserviceaccount.com"

DefaultPrincipal is the caller recorded when no identity is known: emulator requests are unauthenticated.

Variables

This section is empty.

Functions

func LogID

func LogID(k Kind) string

LogID returns the audit log id of kind, e.g. cloudaudit.googleapis.com/activity.

func LogName

func LogName(project string, k Kind) string

LogName returns projects/{project}/logs/{escaped id} for kind.

func MethodName

func MethodName(fullMethod string) string

MethodName turns a gRPC full method (/pkg.Service/Method) into the audit methodName (pkg.Service.Method).

func ProjectOf

func ProjectOf(name string) string

ProjectOf returns the project of a projects/{p}/... resource name, or "".

func ResourceName

func ResourceName(req, resp proto.Message) string

ResourceName picks the audited resource: the response's name, else the request's name, database or parent.

Types

type Emitter

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

Emitter writes Records to a Sink. The zero value is ready to use and drops records until a sink is set.

func (*Emitter) Emit

func (e *Emitter) Emit(ctx context.Context, r Record)

Emit records r; it is a no-op without a sink or a project. Call it outside backend locks.

func (*Emitter) Enabled

func (e *Emitter) Enabled() bool

Enabled reports whether a sink is set.

func (*Emitter) SetSink

func (e *Emitter) SetSink(s Sink)

SetSink directs records to s; nil stops recording.

func (*Emitter) UnaryInterceptor

func (e *Emitter) UnaryInterceptor(p Policy, now func() time.Time) grpc.UnaryServerInterceptor

UnaryInterceptor records the RPCs selected by p after they run, with their status. Bodies are left out so that secret payloads never reach the log.

type Kind

type Kind int

Kind selects the audit log a record is written to.

const (
	// Activity is an Admin Activity record (log id cloudaudit.googleapis.com/activity).
	Activity Kind = iota
	// DataWrite is a Data Access record for a data write (log id cloudaudit.googleapis.com/data_access).
	DataWrite
	// DataRead is a Data Access record for a data read.
	DataRead
)

type Policy

type Policy struct {
	// NameFunc overrides ResourceName for methods whose resource is not in a top-level name field.
	NameFunc func(req, resp proto.Message) string
	// Data names methods (short, e.g. "Commit") that are Data Access records.
	Data map[string]Kind
	// ResourceType is the monitored resource type recorded; empty uses audited_resource.
	ResourceType string
	// ServiceName is the audit serviceName, e.g. secretmanager.googleapis.com.
	ServiceName string
	// AdminPrefixes are method-name prefixes (Create, Delete, ...) of mutating RPCs.
	AdminPrefixes []string
}

Policy says which RPCs of one gRPC API are audited.

type Record

type Record struct {
	Time         time.Time
	Resource     *monitoredres.MonitoredResource
	Request      *structpb.Struct
	Response     *structpb.Struct
	Failure      *status.Status
	Project      string
	ServiceName  string
	MethodName   string
	ResourceName string
	Principal    string
	Permission   string
	Kind         Kind
}

Record is one audited API call.

func (Record) Entry

func (r Record) Entry() (*loggingpb.LogEntry, error)

Entry builds the LogEntry for r.

type Sink

type Sink interface {
	WriteLogEntries(ctx context.Context, req *loggingpb.WriteLogEntriesRequest) error
}

Sink receives log entries; *gcplogging.InMemoryBackend satisfies it.

Jump to

Keyboard shortcuts

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