Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

fix: lynis testDB path #886

Merged
merged 1 commit into from
Nov 2, 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
7 changes: 4 additions & 3 deletions pkg/shared/families/misconfiguration/lynis/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"os"
"os/exec"
"path"
"path/filepath"
"strings"

"github.com/openclarity/kubeclarity/shared/pkg/job_manager"
Expand Down Expand Up @@ -135,15 +136,15 @@ func (a *Scanner) Run(sourceType utils.SourceType, userInput string) error {
a.sendResults(retResults, fmt.Errorf("failed to run command: %w", err))
return
}
lynisDBDir := string(out)
lynisDBDir := filepath.Clean(strings.TrimSpace(string(out)))

testdb, err := NewTestDB(a.logger, lynisDBDir)
testDB, err := NewTestDB(a.logger, lynisDBDir)
if err != nil {
a.sendResults(retResults, fmt.Errorf("failed to load lynis test DB: %w", err))
return
}

reportParser := NewReportParser(testdb)
reportParser := NewReportParser(testDB)
retResults.Misconfigurations, err = reportParser.ParseLynisReport(userInput, reportPath)
if err != nil {
a.sendResults(retResults, fmt.Errorf("failed to parse report file %v: %w", reportPath, err))
Expand Down
4 changes: 2 additions & 2 deletions pkg/shared/families/misconfiguration/lynis/testdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"bufio"
"fmt"
"os"
"path"
"path/filepath"
"strings"

log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -48,7 +48,7 @@ type TestDB struct {
func NewTestDB(logger *log.Entry, lynisDBDir string) (*TestDB, error) {
// Comes from the Lynis install:
// https://github.com/CISOfy/lynis/blob/master/db/tests.db
lynisTestDBPath := path.Join(lynisDBDir, "tests.db")
lynisTestDBPath := filepath.Join(lynisDBDir, "tests.db")
if _, err := os.Stat(lynisTestDBPath); err != nil {
return nil, fmt.Errorf("failed to find DB @ %v: %w", lynisTestDBPath, err)
}
Expand Down