audit

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxFileSize                   = 1 << 21 // 2MB
	DefaultLogDirMode fs.FileMode = 0755
)

Variables

View Source
var (
	ChunkSize = 4096
)
View Source
var (
	// Default is the global object to simplify the cost of use, instead of frequently passing objects.
	Default = NewEmptyAuditor()
)

Functions

func HttpHandler

func HttpHandler() func(http.ResponseWriter, *http.Request)

HttpHandler return the http handler to read audit events with the `Default` auditor.

func SetupDefaultAuditor

func SetupDefaultAuditor(c *Config, stopCh <-chan struct{})

SetupDefaultAuditor initialize the `Default` auditor.

Types

type Auditor

type Auditor interface {
	Run(stopCh <-chan struct{}) error
	LoggerWriter() EventFluentWriter
	HttpHandler() func(http.ResponseWriter, *http.Request)
}

func NewAuditor

func NewAuditor(c *Config) Auditor

func NewEmptyAuditor

func NewEmptyAuditor() Auditor

type Config

type Config struct {
	LogDir               string
	Verbose              int
	MaxDiskSpaceMB       int
	MaxConcurrentReaders int
	ActiveReaderTTL      time.Duration
	DefaultEventsLimit   int
	MaxEventsLimit       int
	TickerDuration       time.Duration
}

func NewDefaultConfig

func NewDefaultConfig() *Config

func (*Config) InitFlags

func (c *Config) InitFlags(fs *flag.FlagSet)

type Event

type Event struct {
	CreatedAt time.Time `json:"createdAt,omitempty"`
	Type      string    `json:"type,omitempty"`
	Level     string    `json:"level,omitempty"`
	Namespace string    `json:"namespace,omitempty"`
	Name      string    `json:"name,omitempty"`
	Container string    `json:"container,omitempty"`
	Reason    string    `json:"reason,omitempty"`
	Message   string    `json:"message,omitempty"`
}

Event captures all the information that can be included in an API audit log.

type EventFluentWriter

type EventFluentWriter interface {
	// V create an eventHelper with Level verbose
	V(verbose int) *EventHelper

	// Flush flush events to the underly storage
	Flush() error

	// Close close the underly writer
	Close() error
}

Fluent APIs to support log in one line: logger.V(1).WithNode().WithReason().Do()

func NewFluentEventLogger

func NewFluentEventLogger(dir string, sizeMB int, verbose int) EventFluentWriter

NewFluentEventLogger create an EventFluentWriter to simplify the audit.

type EventHelper

type EventHelper struct {
	Event
	// contains filtered or unexported fields
}

EventHelper is a helper struct use to support fluent APIs

func V

func V(verbose int) *EventHelper

V create an EventHelper with Level verbose to record audit events with the `Default` auditor.

func (*EventHelper) Container

func (e *EventHelper) Container(name string) *EventHelper

Container set the event container to name

func (*EventHelper) Do

func (e *EventHelper) Do() error

Do write the event to the writer

func (*EventHelper) Group

func (e *EventHelper) Group(name string) *EventHelper

Group set the event type to resource

func (*EventHelper) Message

func (e *EventHelper) Message(format string, args ...interface{}) *EventHelper

Message set the message as the inputs

func (*EventHelper) Node

func (e *EventHelper) Node() *EventHelper

Node set the event type to 'node'

func (*EventHelper) Pod

func (e *EventHelper) Pod(ns string, name string) *EventHelper

Pod set the event type to 'pod'

func (*EventHelper) Reason

func (e *EventHelper) Reason(reason string) *EventHelper

Reason set the event reason to reason

func (*EventHelper) Unknown

func (e *EventHelper) Unknown(name string) *EventHelper

Unknown set the event type to unknown object(pod, node or something else)

type EventIterator

type EventIterator interface {
	Next() (*Event, error)
	Close() error
}

EventInterator is an interator to tail the event log

type EventReader

type EventReader interface {
	NewReverseInterator() EventIterator
}

EventReader is used to manager the event interators

func NewEventReader

func NewEventReader(dir string) EventReader

type EventWriter

type EventWriter interface {
	// Log write an event to the underly storage
	Log(verbose int, event *Event) error

	// Flush flush events to the underly storage
	Flush() error

	// Close close the writer
	Close() error
}

EventWriter is used to record events to audit key changes

func NewEventLogger

func NewEventLogger(dir string, sizeMB int, verbose int) EventWriter

NewEventLogger create an EventWriter, it won't open the underly file until do a log call. verbose=0 means no restrictions on verbose

type JsonResponse

type JsonResponse struct {
	NextPageToken string
	Events        []*Event
}

type LogReader

type LogReader interface {
	Read() ([]byte, error)
	Offset() int
	Close() error
}

func OpenlogReader

func OpenlogReader(name string) (LogReader, error)

type LogWriter

type LogWriter interface {
	Append([]byte) error
	Size() int
	Flush() error
	Close() error
}

func OpenLogWriter

func OpenLogWriter(name string) (LogWriter, error)

Jump to

Keyboard shortcuts

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