Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore at large #3979

Merged
merged 7 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions pkg/cmd/cobra/cobra.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,12 @@ func GetTraceeRunner(c *cobra.Command, version string) (cmd.Runner, error) {
}
cfg.Output = output.TraceeConfig

if err != nil {
return runner, err
}
cfg.Output = output.TraceeConfig

// Create printer

p, err := printer.NewBroadcast(output.PrinterConfigs, cmd.GetContainerMode(cfg))
p, err := printer.NewBroadcast(
output.PrinterConfigs,
cmd.GetContainerMode(policies.ContainerFilterEnabled(), cfg.NoContainersEnrich),
)
if err != nil {
return runner, err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/flags/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ func PrepareFilterMapsFromPolicies(policies []k8s.PolicyInterface) (PolicyScopeM
return nil, nil, errfmt.Errorf("no policies provided")
}

if len(policies) > policy.MaxPolicies {
return nil, nil, errfmt.Errorf("too many policies provided, there is a limit of %d policies", policy.MaxPolicies)
if len(policies) > policy.PolicyMax {
return nil, nil, errfmt.Errorf("too many policies provided, there is a limit of %d policies", policy.PolicyMax)
}

policyNames := make(map[string]bool)
Expand Down
24 changes: 9 additions & 15 deletions pkg/cmd/tracee.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,24 +120,18 @@ func (r Runner) Run(ctx context.Context) error {
return err
}

func GetContainerMode(cfg config.Config) config.ContainerMode {
containerMode := config.ContainerModeDisabled

for it := cfg.Policies.CreateAllIterator(); it.HasNext(); {
p := it.Next()
if p.ContainerFilterEnabled() {
// Container Enrichment is enabled by default ...
containerMode = config.ContainerModeEnriched
if cfg.NoContainersEnrich {
// ... but might be disabled as a safeguard measure.
containerMode = config.ContainerModeEnabled
}
func GetContainerMode(containerFilterEnabled, noContainersEnrich bool) config.ContainerMode {
if !containerFilterEnabled {
return config.ContainerModeDisabled
}

break
}
// If "no-containers" enrichment is set, return just enabled mode ...
if noContainersEnrich {
return config.ContainerModeEnabled
}

return containerMode
// ... otherwise return enriched mode as default.
return config.ContainerModeEnriched
}

const pidFileName = "tracee.pid"
Expand Down
5 changes: 4 additions & 1 deletion pkg/cmd/urfave/urfave.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ func GetTraceeRunner(c *cli.Context, version string) (cmd.Runner, error) {
cfg.Policies = policies
policy.Snapshots().Store(cfg.Policies)

broadcast, err := printer.NewBroadcast(output.PrinterConfigs, cmd.GetContainerMode(cfg))
broadcast, err := printer.NewBroadcast(
output.PrinterConfigs,
cmd.GetContainerMode(policies.ContainerFilterEnabled(), cfg.NoContainersEnrich),
)
if err != nil {
return runner, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/ebpf/events_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ func (t *Tracee) processEvents(ctx context.Context, in <-chan *trace.Event) (
}

// Get a bitmap with all policies containing container filters
policiesWithContainerFilter := policies.ContainerFilterEnabled()
policiesWithContainerFilter := policies.WithContainerFilterEnabled()

// Filter out events that don't have a container ID from all the policies that
// have container filters. This will guarantee that any of those policies
Expand Down
16 changes: 8 additions & 8 deletions pkg/ebpf/policy_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestPolicyManagerEnableAndDisableRuleConcurrent(t *testing.T) {

wg.Add(1)
go func() {
for i := 0; i < policy.MaxPolicies; i++ {
for i := 0; i < policy.PolicyMax; i++ {
for _, e := range eventsToEnable {
policyManager.EnableRule(i, e)
}
Expand All @@ -93,7 +93,7 @@ func TestPolicyManagerEnableAndDisableRuleConcurrent(t *testing.T) {

wg.Add(1)
go func() {
for i := 0; i < policy.MaxPolicies; i++ {
for i := 0; i < policy.PolicyMax; i++ {
for _, e := range eventsToDisable {
policyManager.DisableRule(i, e)
}
Expand All @@ -103,12 +103,12 @@ func TestPolicyManagerEnableAndDisableRuleConcurrent(t *testing.T) {

wg.Wait()

for i := 0; i < policy.MaxPolicies; i++ {
for i := 0; i < policy.PolicyMax; i++ {
for _, e := range eventsToEnable {
assert.True(t, policyManager.IsRuleEnabled(policy.AllPoliciesOn, e))
assert.True(t, policyManager.IsRuleEnabled(policy.PolicyAll, e))
}
for _, e := range eventsToDisable {
assert.False(t, policyManager.IsRuleEnabled(policy.AllPoliciesOn, e))
assert.False(t, policyManager.IsRuleEnabled(policy.PolicyAll, e))
}
}
}
Expand Down Expand Up @@ -182,7 +182,7 @@ func TestPolicyManagerEnableAndDisableEventConcurrent(t *testing.T) {

wg.Add(1)
go func() {
for i := 0; i < policy.MaxPolicies; i++ {
for i := 0; i < policy.PolicyMax; i++ {
for _, e := range eventsToEnable {
policyManager.EnableEvent(e)
}
Expand All @@ -192,7 +192,7 @@ func TestPolicyManagerEnableAndDisableEventConcurrent(t *testing.T) {

wg.Add(1)
go func() {
for i := 0; i < policy.MaxPolicies; i++ {
for i := 0; i < policy.PolicyMax; i++ {
for _, e := range eventsToDisable {
policyManager.DisableEvent(e)
}
Expand All @@ -202,7 +202,7 @@ func TestPolicyManagerEnableAndDisableEventConcurrent(t *testing.T) {

wg.Wait()

for i := 0; i < policy.MaxPolicies; i++ {
for i := 0; i < policy.PolicyMax; i++ {
for _, e := range eventsToEnable {
assert.True(t, policyManager.IsEventEnabled(e))
}
Expand Down
11 changes: 1 addition & 10 deletions pkg/ebpf/tracee.go
Original file line number Diff line number Diff line change
Expand Up @@ -779,15 +779,6 @@ func (t *Tracee) initDerivationTable() error {
return nil
}

// RegisterEventDerivation registers an event derivation handler for tracee to use in the event pipeline
func (t *Tracee) RegisterEventDerivation(deriveFrom events.ID, deriveTo events.ID, deriveCondition func() bool, deriveLogic derive.DeriveFunction) error {
if t.eventDerivations == nil {
return errfmt.Errorf("tracee not initialized yet")
}

return t.eventDerivations.Register(deriveFrom, deriveTo, deriveCondition, deriveLogic)
geyslan marked this conversation as resolved.
Show resolved Hide resolved
}

// options config should match defined values in ebpf code
const (
optExecEnv uint32 = 1 << iota
Expand Down Expand Up @@ -1715,7 +1706,7 @@ func (t *Tracee) triggerMemDumpCall(address uint64, length uint64, eventHandle u

// SubscribeAll returns a stream subscribed to all policies
func (t *Tracee) SubscribeAll() *streams.Stream {
return t.subscribe(policy.AllPoliciesOn)
return t.subscribe(policy.PolicyAll)
}

// Subscribe returns a stream subscribed to selected policies
Expand Down
8 changes: 4 additions & 4 deletions pkg/policy/ebpf.go
Original file line number Diff line number Diff line change
Expand Up @@ -917,10 +917,10 @@ func (ps *Policies) computePoliciesConfig() *PoliciesConfig {
cfg.EnabledScopes |= 1 << offset
}

cfg.UidMax = ps.UIDFilterMax()
cfg.UidMin = ps.UIDFilterMin()
cfg.PidMax = ps.PIDFilterMax()
cfg.PidMin = ps.PIDFilterMin()
cfg.UidMax = ps.uidFilterMax
cfg.UidMin = ps.uidFilterMin
cfg.PidMax = ps.pidFilterMax
cfg.PidMin = ps.pidFilterMin

return cfg
}
4 changes: 2 additions & 2 deletions pkg/policy/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ func PolicyNilError() error {
}

func PoliciesMaxExceededError() error {
return fmt.Errorf("policies maximum exceeded [%d]", MaxPolicies)
return fmt.Errorf("policies maximum exceeded [%d]", PolicyMax)
}

func PoliciesOutOfRangeError(idx int) error {
return fmt.Errorf("policies index [%d] out-of-range [0-%d]", idx, MaxPolicies-1)
return fmt.Errorf("policies index [%d] out-of-range [0-%d]", idx, PolicyMax-1)
}

func PolicyAlreadyExistsError(name string, idx int) error {
Expand Down
Loading
Loading