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

feat(config): added config to avoid exit code 1 for scan failure #102

Merged
merged 1 commit into from
Feb 7, 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
2 changes: 2 additions & 0 deletions docs/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ Usage of go-earlybird:
Certificate file for TLS
-https-key string
Private key file for TLS
-ignore-failure
Avoid the exit code 1 in case of scanner finds valid findings and meets fail threshold
-ignore-fp-rules
Ignore the false positive post-process rules
-ignorefile string
Expand Down
7 changes: 4 additions & 3 deletions pkg/config/structures.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package cfgreader

import "regexp"

//ServerConfig is the timeout configuration for the Earlybird REST API server
// ServerConfig is the timeout configuration for the Earlybird REST API server
type ServerConfig struct {
WriteTimeout int `json:"write-timeout"`
ReadTimeout int `json:"read-timeout"`
Expand All @@ -37,7 +37,7 @@ type AdjustedSeverityCategory struct {
// If UseFileName and UseLine value are either both false or undefined the match defaults to hit.MatchValue
}

//Configs is the result of earlybird.json
// Configs is the result of earlybird.json
type Configs struct {
LevelConfigs []struct {
Name string `json:"level_name"`
Expand Down Expand Up @@ -66,7 +66,7 @@ type ModuleConfigs struct {
Modules map[string]ModuleConfig `json:"modules"`
}

//EarlybirdConfig is the overall scan configs from config file and cli params
// EarlybirdConfig is the overall scan configs from config file and cli params
type EarlybirdConfig struct {
AvailableModules []string
RuleModulesFilenameMap map[string]string
Expand All @@ -79,6 +79,7 @@ type EarlybirdConfig struct {
OutputFormat string
OutputFile string
IgnoreFile string
IgnoreFailure bool
SeverityFailLevel int
SeverityDisplayLevel int
ConfidenceFailLevel int
Expand Down
1 change: 1 addition & 0 deletions pkg/core/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ var (
ptrWithConsole = flag.Bool("with-console", false, "While using --format, this flag will help to print findings in console")
ptrOutputFile = flag.String("file", "", "Output file -- e.g., 'go-earlybird --file=/home/jdoe/myfile.csv'")
ptrIgnoreFile = flag.String("ignorefile", userHomeDir+string(os.PathSeparator)+".ge_ignore", "Patterns File (including wildcards) for files to ignore. (e.g. *.jpg)")
ptrIgnoreFailure = flag.Bool("ignore-failure", false, "Avoid the exit code 1 in case of scanner finds valid findings and meets fail threshold")
ptrFailSeverityThreshold = flag.String("fail-severity", cfgreader.Settings.TranslateLevelID(cfgreader.Settings.FailThreshold), "Lowest severity level at which to fail "+levelOptions)
ptrDisplaySeverityThreshold = flag.String("display-severity", cfgreader.Settings.TranslateLevelID(cfgreader.Settings.DisplayThreshold), "Lowest severity level to display "+levelOptions)
ptrDisplayConfidenceThreshold = flag.String("display-confidence", cfgreader.Settings.TranslateLevelID(cfgreader.Settings.DisplayConfidenceThreshold), "Lowest confidence level to display "+levelOptions)
Expand Down
17 changes: 10 additions & 7 deletions pkg/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import (
"golang.org/x/net/http2"
)

//GitClone clones git repositories into a temporary directory
// GitClone clones git repositories into a temporary directory
func (eb *EarlybirdCfg) GitClone(ptr PTRGitConfig) {
var scanRepos []string
gitPassword := os.Getenv("gitpassword")
Expand Down Expand Up @@ -90,7 +90,7 @@ func (eb *EarlybirdCfg) GitClone(ptr PTRGitConfig) {
}
}

//StartHTTP spins up the Earlybird REST API server
// StartHTTP spins up the Earlybird REST API server
func (eb *EarlybirdCfg) StartHTTP(ptr PTRHTTPConfig) {
// Set up http server
r := mux.NewRouter()
Expand Down Expand Up @@ -166,7 +166,7 @@ func (eb *EarlybirdCfg) GetRuleModulesMap() (err error) {
return err
}

//ConfigInit loads in the earlybird configuration and CLI flags
// ConfigInit loads in the earlybird configuration and CLI flags
func (eb *EarlybirdCfg) ConfigInit() {
// Set the version from ldflags
eb.Config.Version = buildflags.Version
Expand Down Expand Up @@ -200,6 +200,7 @@ func (eb *EarlybirdCfg) ConfigInit() {
eb.Config.OutputFile = *ptrOutputFile
eb.Config.SearchDir = *ptrPath
eb.Config.IgnoreFile = *ptrIgnoreFile
eb.Config.IgnoreFailure = *ptrIgnoreFailure
eb.Config.GitStream = *ptrGitStreamInput
eb.Config.RulesOnly = *ptrRulesOnly
eb.Config.SkipComments = *ptrSkipComments
Expand Down Expand Up @@ -282,7 +283,7 @@ func (eb *EarlybirdCfg) getDefaultModuleSettings() {
}
}

//Scan Runs the scan by kicking off the different modules as go routines
// Scan Runs the scan by kicking off the different modules as go routines
func (eb *EarlybirdCfg) Scan() {
// Validate the path passed in as the target directory to scan
start := time.Now()
Expand All @@ -301,11 +302,13 @@ func (eb *EarlybirdCfg) Scan() {
if eb.Config.OutputFormat == "console" {
fmt.Fprintln(os.Stderr, "Scan detected findings above the accepted threshold -- Failing.")
}
os.Exit(1)
if !eb.Config.IgnoreFailure {
os.Exit(1)
}
}
}

//FileContext provides an inclusive file system context of our scan
// FileContext provides an inclusive file system context of our scan
func (eb *EarlybirdCfg) FileContext() (fileContext file.Context, err error) {
cfg := eb.Config
if cfg.SearchDir != "" {
Expand All @@ -330,7 +333,7 @@ func (eb *EarlybirdCfg) FileContext() (fileContext file.Context, err error) {
return fileContext, nil
}

//WriteResults reads hits from the channel to the console or target file
// WriteResults reads hits from the channel to the console or target file
func (eb *EarlybirdCfg) WriteResults(start time.Time, HitChannel chan scan.Hit, fileContext file.Context) {
// Send output to a writer
var err error
Expand Down
Loading