Skip to content

Reduce scanning time and memory pressure by disabling active vuln mgmt #1190

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

Merged
merged 2 commits into from
Jun 7, 2023
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
2 changes: 2 additions & 0 deletions chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ spec:
value: "true"
- name: ROX_RHCOS_NODE_SCANNING
value: "true"
- name: ROX_ACTIVE_VULN_MGMT
value: "true"
resources:
limits:
cpu: 2
Expand Down
4 changes: 4 additions & 0 deletions pkg/env/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ var (

// NodeScanningMaxBackoff is the upper boundary of backoff. Defaults to 5m in seconds, being 50% of Kubernetes restart policy stability timer.
NodeScanningMaxBackoff = registerDurationSetting("ROX_NODE_SCANNING_MAX_BACKOFF", 300*time.Second)

// ActiveVulnMgmt is the same flag in Central that determines if active vulnerability management should be
// enabled and executables should be pulled from the database
ActiveVulnMgmt = RegisterBooleanSetting("ROX_ACTIVE_VULN_MGMT", false)
)
47 changes: 26 additions & 21 deletions pkg/tarutil/tarutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/stackrox/rox/pkg/utils"
"github.com/stackrox/scanner/pkg/analyzer"
"github.com/stackrox/scanner/pkg/elf"
"github.com/stackrox/scanner/pkg/env"
"github.com/stackrox/scanner/pkg/fsutil/fileinfo"
"github.com/stackrox/scanner/pkg/ioutils"
"github.com/stackrox/scanner/pkg/matcher"
Expand All @@ -44,6 +45,8 @@ var (
xzHeader = []byte{0xfd, 0x37, 0x7a, 0x58, 0x5a, 0x00}
shebangHeader = []byte{0x23, 0x21}
shebangHeaderSize = len(shebangHeader)

parseExecutables = env.ActiveVulnMgmt.Enabled()
)

// ExtractFiles decompresses and extracts only the specified files from an
Expand Down Expand Up @@ -114,30 +117,33 @@ func ExtractFiles(r io.Reader, filenameMatcher matcher.Matcher) (LayerFiles, err
case tar.TypeReg, tar.TypeLink:
var fileData analyzer.FileData

executable := fileinfo.IsFileExecutable(hdr.FileInfo())
if hdr.Size > analyzer.GetMaxELFExecutableFileSize() {
log.Warnf("Skipping ELF executable check for file %q (%d bytes) because it is larger than the configured maxELFExecutableFileSize of %d MiB",
filename, hdr.Size, analyzer.GetMaxELFExecutableFileSize()/1024/1024)
} else {
if hdr.Size >= analyzer.ElfHeaderSize { // Only bother attempting to get ELF metadata if the file is large enough for the ELF header.
fileData.ELFMetadata, err = elf.GetExecutableMetadata(contents)
if err != nil {
log.Errorf("Failed to get dependencies for %s: %v", filename, err)
}
}
if executable && hdr.Typeflag != tar.TypeLink && fileData.ELFMetadata == nil {
// If the type is a hard link then we will not be able to read it.
// Keep it as an executable in order to not introduce false negatives.
shebangBytes := make([]byte, shebangHeaderSize)
if hdr.Size > int64(shebangHeaderSize) {
_, err := contents.ReadAt(shebangBytes, 0)
if parseExecutables {
executable := fileinfo.IsFileExecutable(hdr.FileInfo())
if hdr.Size > analyzer.GetMaxELFExecutableFileSize() {
log.Warnf("Skipping ELF executable check for file %q (%d bytes) because it is larger than the configured maxELFExecutableFileSize of %d MiB",
filename, hdr.Size, analyzer.GetMaxELFExecutableFileSize()/1024/1024)
} else {
if hdr.Size >= analyzer.ElfHeaderSize { // Only bother attempting to get ELF metadata if the file is large enough for the ELF header.
fileData.ELFMetadata, err = elf.GetExecutableMetadata(contents)
if err != nil {
log.Errorf("unable to read first two bytes of file %s: %v", filename, err)
continue
log.Errorf("Failed to get dependencies for %s: %v", filename, err)
}
}
if executable && hdr.Typeflag != tar.TypeLink && fileData.ELFMetadata == nil {
// If the type is a hard link then we will not be able to read it.
// Keep it as an executable in order to not introduce false negatives.
shebangBytes := make([]byte, shebangHeaderSize)
if hdr.Size > int64(shebangHeaderSize) {
_, err := contents.ReadAt(shebangBytes, 0)
if err != nil {
log.Errorf("unable to read first two bytes of file %s: %v", filename, err)
continue
}
}
executable = bytes.Equal(shebangBytes, shebangHeader)
}
executable = bytes.Equal(shebangBytes, shebangHeader)
}
fileData.Executable = executable
}

if extractContents {
Expand All @@ -160,7 +166,6 @@ func ExtractFiles(r io.Reader, filenameMatcher matcher.Matcher) (LayerFiles, err
numExtractedContentBytes += len(d)
}
}
fileData.Executable = executable
files.data[filename] = fileData
case tar.TypeSymlink:
if path.IsAbs(hdr.Linkname) {
Expand Down