Skip to content
Open
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
23 changes: 4 additions & 19 deletions pkg/cmd/cobra/cobra.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,15 @@
return runner, err
}

enrichmentConfig, err := flags.PrepareEnrichment(enrichmentFlags)
enrichmentFlagsConfig, err := flags.PrepareEnrichment(enrichmentFlags)

Check warning on line 164 in pkg/cmd/cobra/cobra.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmd/cobra/cobra.go#L164

Added line #L164 was not covered by tests
if err != nil {
return runner, err
}

sockets, err := enrichmentConfig.GetRuntimeSockets()
cfg.Enrichment, err = enrichmentFlagsConfig.GetEnrichmentConfig()

Check warning on line 169 in pkg/cmd/cobra/cobra.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmd/cobra/cobra.go#L169

Added line #L169 was not covered by tests
if err != nil {
return runner, err
}
cfg.Sockets = sockets
cfg.EnrichmentEnabled = enrichmentConfig.Container.Enabled
cfg.CgroupFSPath = enrichmentConfig.Container.Cgroupfs.Path
cfg.CgroupFSForce = enrichmentConfig.Container.Cgroupfs.Force

// Stores command line flags
storesFlags, err := flags.GetFlagsFromViper(flags.StoresFlag)
Expand Down Expand Up @@ -292,26 +288,15 @@
}

containerMode := cmd.GetContainerMode(
containerFilterEnabled(), cfg.EnrichmentEnabled)
containerFilterEnabled(), cfg.Enrichment.EnrichContainers())

Check warning on line 291 in pkg/cmd/cobra/cobra.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmd/cobra/cobra.go#L291

Added line #L291 was not covered by tests

output, err := flags.PrepareOutput(outputFlags, containerMode)
output, err := flags.PrepareOutput(outputFlags, containerMode, cfg.Enrichment)

Check warning on line 293 in pkg/cmd/cobra/cobra.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmd/cobra/cobra.go#L293

Added line #L293 was not covered by tests
if err != nil {
return runner, err
}

cfg.Output = output

// Apply enrichment config to output config
// TODO: refactor it to maybe encapsulate enrichemnt as part of the output config,
// or as its own field on the config struct
cfg.Output.Environment = enrichmentConfig.Environment
cfg.Output.UserStack = enrichmentConfig.UserStack
cfg.Output.FdPaths = enrichmentConfig.FdPaths
cfg.Output.DecodedData = enrichmentConfig.DecodedData
if enrichmentConfig.ExecutableHash.Enabled || enrichmentConfig.ExecutableHash.Mode != "" {
cfg.Output.CalcHashes = enrichmentConfig.GetCalcHashesOption()
}

// Check kernel lockdown
lockdown, err := environment.Lockdown()
if err != nil {
Expand Down
30 changes: 28 additions & 2 deletions pkg/cmd/flags/enrichment.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/aquasecurity/tracee/common/digest"
"github.com/aquasecurity/tracee/common/errfmt"
"github.com/aquasecurity/tracee/common/logger"
"github.com/aquasecurity/tracee/pkg/config"
"github.com/aquasecurity/tracee/pkg/datastores/container/runtime"
)

Expand Down Expand Up @@ -114,8 +115,8 @@ func (e *EnrichmentConfig) GetRuntimeSockets() (runtime.Sockets, error) {
return sockets, nil
}

// GetCalcHashesOption converts ExecutableHashConfig to digest.CalcHashesOption
func (e *EnrichmentConfig) GetCalcHashesOption() digest.CalcHashesOption {
// getCalcHashesOption converts ExecutableHashConfig to digest.CalcHashesOption
func (e *EnrichmentConfig) getCalcHashesOption() digest.CalcHashesOption {
if !e.ExecutableHash.Enabled && e.ExecutableHash.Mode == "" {
return digest.CalcHashesNone
}
Expand All @@ -141,6 +142,31 @@ func (e *EnrichmentConfig) GetCalcHashesOption() digest.CalcHashesOption {
}
}

// GetEnrichmentConfig returns the enrichment config with all parsed values
func (e *EnrichmentConfig) GetEnrichmentConfig() (*config.EnrichmentConfig, error) {
sockets, err := e.GetRuntimeSockets()
if err != nil {
return nil, err
}

return &config.EnrichmentConfig{
Container: config.ContainerEnrichmentConfig{
Enabled: e.Container.Enabled,
Cgroupfs: config.ContainerCgroupfsConfig(e.Container.Cgroupfs),
DockerSocket: e.Container.DockerSocket,
ContainerdSocket: e.Container.ContainerdSocket,
CrioSocket: e.Container.CrioSocket,
PodmanSocket: e.Container.PodmanSocket,
},
FdPaths: e.FdPaths,
Environment: e.Environment,
CalcHashes: e.getCalcHashesOption(),
UserStack: e.UserStack,
DecodedData: e.DecodedData,
Sockets: sockets,
}, nil
}

// flags returns the flags for the enrichment configuration
func (e *EnrichmentConfig) flags() []string {
flags := []string{}
Expand Down
Loading