selftests

package
v0.0.0-...-8dae9f9 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package selftests holds selftests related files

Package selftests holds selftests related files

Index

Constants

View Source
const (

	// DefaultTimeout default timeout
	DefaultTimeout = 30 * time.Second

	// PolicyProviderType name of the self test policy provider
	PolicyProviderType = "selfTesterPolicyProvider"
)

Variables

This section is empty.

Functions

func CreateTargetDir

func CreateTargetDir() (string, error)

CreateTargetDir creates temporary directory

func NewSelfTestEvent

func NewSelfTestEvent(acc *events.AgentContainerContext, success []eval.RuleID, fails []eval.RuleID, testEvents map[eval.RuleID]*serializers.EventSerializer) (*rules.Rule, *events.CustomEvent)

NewSelfTestEvent returns the rule and the result of the self test

Types

type ChmodSelfTest

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

ChmodSelfTest defines a chmod self test

func (*ChmodSelfTest) GenerateEvent

func (o *ChmodSelfTest) GenerateEvent() error

GenerateEvent generate an event

func (*ChmodSelfTest) GetRuleDefinition

func (o *ChmodSelfTest) GetRuleDefinition() *rules.RuleDefinition

GetRuleDefinition returns the rule

func (*ChmodSelfTest) HandleEvent

func (o *ChmodSelfTest) HandleEvent(event selfTestEvent)

HandleEvent handles self test events

func (*ChmodSelfTest) IsSuccess

func (o *ChmodSelfTest) IsSuccess() bool

IsSuccess return the state of the test

type ChownSelfTest

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

ChownSelfTest defines a chown self test

func (*ChownSelfTest) GenerateEvent

func (o *ChownSelfTest) GenerateEvent() error

GenerateEvent generate an event

func (*ChownSelfTest) GetRuleDefinition

func (o *ChownSelfTest) GetRuleDefinition() *rules.RuleDefinition

GetRuleDefinition returns the rule

func (*ChownSelfTest) HandleEvent

func (o *ChownSelfTest) HandleEvent(event selfTestEvent)

HandleEvent handles self test events

func (*ChownSelfTest) IsSuccess

func (o *ChownSelfTest) IsSuccess() bool

IsSuccess return the state of the test

type EBPFLessSelfTest

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

EBPFLessSelfTest defines an ebpf less self test

func (*EBPFLessSelfTest) GenerateEvent

func (o *EBPFLessSelfTest) GenerateEvent() error

GenerateEvent generate an event

func (*EBPFLessSelfTest) GetRuleDefinition

func (o *EBPFLessSelfTest) GetRuleDefinition() *rules.RuleDefinition

GetRuleDefinition returns the rule

func (*EBPFLessSelfTest) HandleEvent

func (o *EBPFLessSelfTest) HandleEvent(event selfTestEvent)

HandleEvent handles self test events

func (*EBPFLessSelfTest) IsSuccess

func (o *EBPFLessSelfTest) IsSuccess() bool

IsSuccess return the state of the test

type OpenSelfTest

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

OpenSelfTest defines an open self test

func (*OpenSelfTest) GenerateEvent

func (o *OpenSelfTest) GenerateEvent() error

GenerateEvent generate an event

func (*OpenSelfTest) GetRuleDefinition

func (o *OpenSelfTest) GetRuleDefinition() *rules.RuleDefinition

GetRuleDefinition returns the rule

func (*OpenSelfTest) HandleEvent

func (o *OpenSelfTest) HandleEvent(event selfTestEvent)

HandleEvent handles self test events

func (*OpenSelfTest) IsSuccess

func (o *OpenSelfTest) IsSuccess() bool

IsSuccess return the state of the test

type SelfTest

type SelfTest interface {
	GetRuleDefinition() *rules.RuleDefinition
	GenerateEvent() error
	HandleEvent(selfTestEvent)
	IsSuccess() bool
}

SelfTest represent one self test

type SelfTestEvent

type SelfTestEvent struct {
	events.CustomEventCommonFields
	Success    []eval.RuleID                                `json:"succeeded_tests"`
	Fails      []eval.RuleID                                `json:"failed_tests"`
	TestEvents map[eval.RuleID]*serializers.EventSerializer `json:"test_events"`
}

SelfTestEvent is used to report a self test result

func (SelfTestEvent) ToJSON

func (t SelfTestEvent) ToJSON() ([]byte, error)

ToJSON marshal using json format

type SelfTester

type SelfTester struct {
	sync.Mutex
	// contains filtered or unexported fields
}

SelfTester represents all the state needed to conduct rule injection test at startup

func NewSelfTester

func NewSelfTester(cfg *config.RuntimeSecurityConfig, probe *probe.Probe) (*SelfTester, error)

NewSelfTester returns a new SelfTester, enabled or not

func (*SelfTester) Close

func (t *SelfTester) Close() error

Close removes temp directories and files used by the self tester

func (*SelfTester) EventDiscarderFound

func (t *SelfTester) EventDiscarderFound(_ *rules.RuleSet, _ eval.Event, _ eval.Field, _ eval.EventType)

EventDiscarderFound implement the rule engine interface

func (*SelfTester) GetStatus

func (t *SelfTester) GetStatus() *api.SelfTestsStatus

GetStatus returns the result of the last performed self tests

func (*SelfTester) IsExpectedEvent

func (t *SelfTester) IsExpectedEvent(rule *rules.Rule, event eval.Event, _ *probe.Probe) bool

IsExpectedEvent sends an event to the tester

func (*SelfTester) LoadPolicies

func (t *SelfTester) LoadPolicies(_ []rules.MacroFilter, _ []rules.RuleFilter) ([]*rules.Policy, *multierror.Error)

LoadPolicies implements the PolicyProvider interface

func (*SelfTester) RuleMatch

func (t *SelfTester) RuleMatch(rule *rules.Rule, event eval.Event) bool

RuleMatch implement the rule engine interface

func (*SelfTester) RunSelfTest

func (t *SelfTester) RunSelfTest(timeout time.Duration) error

RunSelfTest runs the self test and return the result

func (*SelfTester) SetOnNewPoliciesReadyCb

func (t *SelfTester) SetOnNewPoliciesReadyCb(_ func())

SetOnNewPoliciesReadyCb implements the PolicyProvider interface

func (*SelfTester) Start

func (t *SelfTester) Start()

Start implements the policy provider interface

func (*SelfTester) Type

func (t *SelfTester) Type() string

Type return the type of this policy provider

func (*SelfTester) WaitForResult

func (t *SelfTester) WaitForResult(cb func(success []eval.RuleID, fails []eval.RuleID, events map[eval.RuleID]*serializers.EventSerializer))

WaitForResult wait for self test results

Jump to

Keyboard shortcuts

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