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

Integrating new Config Profile changes + Add support in scanners exclusions through profile #314

Open
wants to merge 23 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
80d6632
Adding specific scanners exclusions fields to Jas Scanner + adding an…
eranturgeman Feb 25, 2025
99b7758
Adding the scanner specific exclude patterns to general exclusions fo…
eranturgeman Feb 25, 2025
0fa5863
Comment to delete at the end
eranturgeman Feb 25, 2025
726f423
Updated access to new field location + added a comment to delete at t…
eranturgeman Feb 25, 2025
defd8cd
Added a call for getting scanners-specific exclusions in JasRunner cr…
eranturgeman Feb 25, 2025
e274874
comments in tests files
eranturgeman Feb 25, 2025
c198447
Moved CC from AuditParams to AuditBasicParams + added Getter and Sett…
eranturgeman Feb 25, 2025
9237951
Updated calls due to CC location change
eranturgeman Feb 25, 2025
b4784bb
Added fetch for specific scanners exclusion in GetExcludePattern
eranturgeman Feb 25, 2025
76d56e7
Updated calls due to CC location change
eranturgeman Feb 25, 2025
3dbf559
updating test file
eranturgeman Feb 26, 2025
2a3cd45
Merge branch 'dev' of https://github.com/jfrog/jfrog-cli-security int…
eranturgeman Feb 26, 2025
ad85125
deleted commented check
eranturgeman Feb 26, 2025
e231741
deleted commented check + added CA enablement verification
eranturgeman Feb 26, 2025
eb99e1b
changing GetConfigProfileByName and GetConfigProfileByUrl to be restr…
eranturgeman Feb 26, 2025
0107d0f
updating config profile tests
eranturgeman Feb 26, 2025
c6971e4
added testcase to TestGetExcludePattern
eranturgeman Feb 26, 2025
726b6ff
fixed func name
eranturgeman Feb 26, 2025
d8c657f
updated TestFilterUniqueAndConvertToFilesExcludePatterns
eranturgeman Feb 26, 2025
82df9dd
added test cases for scanners exclusions - NEEDS TO BE COMPLETED
eranturgeman Feb 26, 2025
51fe596
go mod
eranturgeman Feb 26, 2025
fae59c3
.
eranturgeman Feb 26, 2025
bb5a205
CR fixes
eranturgeman Feb 27, 2025
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
4 changes: 3 additions & 1 deletion commands/audit/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ func RunJasScans(auditParallelRunner *utils.SecurityParallelRunner, auditParams
),
auditParams.Exclusions()...,
)
jas.UpdateJasScannerWithExcludePatternsFromProfile(jasScanner, auditParams.AuditBasicParams.GetConfigProfile())

auditParallelRunner.ResultsMu.Unlock()
if err != nil {
generalError = fmt.Errorf("failed to create jas scanner: %s", err.Error())
Expand Down Expand Up @@ -349,7 +351,7 @@ func createJasScansTasks(auditParallelRunner *utils.SecurityParallelRunner, scan
ServerDetails: serverDetails,
Scanner: scanner,
Module: *module,
ConfigProfile: auditParams.configProfile,
ConfigProfile: auditParams.AuditBasicParams.GetConfigProfile(),
ScansToPerform: auditParams.ScansToPerform(),
SecretsScanType: secrets.SecretsScannerType,
DirectDependencies: auditParams.DirectDependencies(),
Expand Down
224 changes: 208 additions & 16 deletions commands/audit/audit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,12 @@ func TestAuditWithConfigProfile(t *testing.T) {
ModuleName: "only-sca-module",
PathFromRoot: ".",
ScanConfig: services.ScanConfig{
EnableScaScan: true,
EnableContextualAnalysisScan: false,
ScaScannerConfig: services.ScaScannerConfig{
EnableScaScan: true,
},
ContextualAnalysisScannerConfig: services.CaScannerConfig{
EnableCaScan: false,
},
SastScannerConfig: services.SastScannerConfig{
EnableSastScan: false,
},
Expand All @@ -258,6 +262,38 @@ func TestAuditWithConfigProfile(t *testing.T) {
},
expectedScaIssues: 15,
},
{
name: "Sca scanner enabled with exclusions",
testDirPath: filepath.Join("..", "..", "tests", "testdata", "projects", "jas", "jas"),
configProfile: services.ConfigProfile{
ProfileName: "Sca-exclude-dirs",
Modules: []services.Module{{
ModuleId: 1,
ModuleName: "Sca-exclude-dirs-module",
PathFromRoot: ".",
ScanConfig: services.ScanConfig{
ScaScannerConfig: services.ScaScannerConfig{
EnableScaScan: true,
ExcludePatterns: []string{"*.*"},
},
ContextualAnalysisScannerConfig: services.CaScannerConfig{
EnableCaScan: false,
},
SastScannerConfig: services.SastScannerConfig{
EnableSastScan: false,
},
SecretsScannerConfig: services.SecretsScannerConfig{
EnableSecretsScan: false,
},
IacScannerConfig: services.IacScannerConfig{
EnableIacScan: false,
},
},
}},
IsDefault: false,
},
expectedScaIssues: 0,
},
{
name: "Enable Sca and Applicability scanners",
testDirPath: filepath.Join("..", "..", "tests", "testdata", "projects", "jas", "jas"),
Expand All @@ -268,8 +304,12 @@ func TestAuditWithConfigProfile(t *testing.T) {
ModuleName: "sca-and-applicability",
PathFromRoot: ".",
ScanConfig: services.ScanConfig{
EnableScaScan: true,
EnableContextualAnalysisScan: true,
ScaScannerConfig: services.ScaScannerConfig{
EnableScaScan: true,
},
ContextualAnalysisScannerConfig: services.CaScannerConfig{
EnableCaScan: true,
},
SastScannerConfig: services.SastScannerConfig{
EnableSastScan: false,
},
Expand All @@ -288,6 +328,7 @@ func TestAuditWithConfigProfile(t *testing.T) {
expectedCaNotCovered: 4,
expectedCaNotApplicable: 2,
},
// TODO Add testcase for Sca and Applicability with exclusions after resolving the Glob patterns issues
{
name: "Enable only secrets scanner",
testDirPath: filepath.Join("..", "..", "tests", "testdata", "projects", "jas", "jas"),
Expand All @@ -298,8 +339,12 @@ func TestAuditWithConfigProfile(t *testing.T) {
ModuleName: "only-secrets-module",
PathFromRoot: ".",
ScanConfig: services.ScanConfig{
EnableScaScan: false,
EnableContextualAnalysisScan: false,
ScaScannerConfig: services.ScaScannerConfig{
EnableScaScan: false,
},
ContextualAnalysisScannerConfig: services.CaScannerConfig{
EnableCaScan: false,
},
SastScannerConfig: services.SastScannerConfig{
EnableSastScan: false,
},
Expand All @@ -316,7 +361,39 @@ func TestAuditWithConfigProfile(t *testing.T) {
expectedSecretsIssues: 16,
},
{
name: "Enable only sast scanner",
name: "Secrets scanner is enabled with exclusions",
testDirPath: filepath.Join("..", "..", "tests", "testdata", "projects", "jas", "jas"),
configProfile: services.ConfigProfile{
ProfileName: "secrets-with-exclusions",
Modules: []services.Module{{
ModuleId: 1,
ModuleName: "secrets-with-exclusions-module",
PathFromRoot: ".",
ScanConfig: services.ScanConfig{
ScaScannerConfig: services.ScaScannerConfig{
EnableScaScan: false,
},
ContextualAnalysisScannerConfig: services.CaScannerConfig{
EnableCaScan: false,
},
SastScannerConfig: services.SastScannerConfig{
EnableSastScan: false,
},
SecretsScannerConfig: services.SecretsScannerConfig{
EnableSecretsScan: true,
ExcludePatterns: []string{"*api_secrets*"},
},
IacScannerConfig: services.IacScannerConfig{
EnableIacScan: false,
},
},
}},
IsDefault: false,
},
expectedSecretsIssues: 7,
},
{
name: "Enable only Sast scanner",
testDirPath: filepath.Join("..", "..", "tests", "testdata", "projects", "jas", "jas"),
configProfile: services.ConfigProfile{
ProfileName: "only-sast",
Expand All @@ -325,8 +402,12 @@ func TestAuditWithConfigProfile(t *testing.T) {
ModuleName: "only-sast-module",
PathFromRoot: ".",
ScanConfig: services.ScanConfig{
EnableScaScan: false,
EnableContextualAnalysisScan: false,
ScaScannerConfig: services.ScaScannerConfig{
EnableScaScan: false,
},
ContextualAnalysisScannerConfig: services.CaScannerConfig{
EnableCaScan: false,
},
SastScannerConfig: services.SastScannerConfig{
EnableSastScan: true,
},
Expand All @@ -342,6 +423,38 @@ func TestAuditWithConfigProfile(t *testing.T) {
},
expectedSastIssues: 3,
},
{
name: "Sast scanner is enabled with exclusions",
testDirPath: filepath.Join("..", "..", "tests", "testdata", "projects", "jas", "jas"),
configProfile: services.ConfigProfile{
ProfileName: "sast-with-exclusions",
Modules: []services.Module{{
ModuleId: 1,
ModuleName: "sast-with-exclusions-module",
PathFromRoot: ".",
ScanConfig: services.ScanConfig{
ScaScannerConfig: services.ScaScannerConfig{
EnableScaScan: false,
},
ContextualAnalysisScannerConfig: services.CaScannerConfig{
EnableCaScan: false,
},
SastScannerConfig: services.SastScannerConfig{
EnableSastScan: true,
ExcludePatterns: []string{"*flask_webgoat*"},
},
SecretsScannerConfig: services.SecretsScannerConfig{
EnableSecretsScan: false,
},
IacScannerConfig: services.IacScannerConfig{
EnableIacScan: false,
},
},
}},
IsDefault: false,
},
expectedSastIssues: 0,
},
{
name: "Enable only IaC scanner",
testDirPath: filepath.Join("..", "..", "tests", "testdata", "projects", "jas", "jas"),
Expand All @@ -352,8 +465,12 @@ func TestAuditWithConfigProfile(t *testing.T) {
ModuleName: "only-iac-module",
PathFromRoot: ".",
ScanConfig: services.ScanConfig{
EnableScaScan: false,
EnableContextualAnalysisScan: false,
ScaScannerConfig: services.ScaScannerConfig{
EnableScaScan: false,
},
ContextualAnalysisScannerConfig: services.CaScannerConfig{
EnableCaScan: false,
},
SastScannerConfig: services.SastScannerConfig{
EnableSastScan: false,
},
Expand All @@ -369,6 +486,38 @@ func TestAuditWithConfigProfile(t *testing.T) {
},
expectedIacIssues: 9,
},
{
name: "Iac is enabled with exclusions",
testDirPath: filepath.Join("..", "..", "tests", "testdata", "projects", "jas", "jas"),
configProfile: services.ConfigProfile{
ProfileName: "iac-with-exclusions",
Modules: []services.Module{{
ModuleId: 1,
ModuleName: "iac-with-exclusions-module",
PathFromRoot: ".",
ScanConfig: services.ScanConfig{
ScaScannerConfig: services.ScaScannerConfig{
EnableScaScan: false,
},
ContextualAnalysisScannerConfig: services.CaScannerConfig{
EnableCaScan: false,
},
SastScannerConfig: services.SastScannerConfig{
EnableSastScan: false,
},
SecretsScannerConfig: services.SecretsScannerConfig{
EnableSecretsScan: false,
},
IacScannerConfig: services.IacScannerConfig{
EnableIacScan: true,
ExcludePatterns: []string{"*iac/gcp*"},
},
},
}},
IsDefault: false,
},
expectedIacIssues: 0,
},
{
name: "Enable All Scanners",
testDirPath: filepath.Join("..", "..", "tests", "testdata", "projects", "jas", "jas"),
Expand All @@ -379,8 +528,12 @@ func TestAuditWithConfigProfile(t *testing.T) {
ModuleName: "all-jas-module",
PathFromRoot: ".",
ScanConfig: services.ScanConfig{
EnableScaScan: true,
EnableContextualAnalysisScan: true,
ScaScannerConfig: services.ScaScannerConfig{
EnableScaScan: true,
},
ContextualAnalysisScannerConfig: services.CaScannerConfig{
EnableCaScan: true,
},
SastScannerConfig: services.SastScannerConfig{
EnableSastScan: true,
},
Expand All @@ -402,6 +555,45 @@ func TestAuditWithConfigProfile(t *testing.T) {
expectedCaNotCovered: 4,
expectedCaNotApplicable: 2,
},
{
name: "All scanners enabled but some with exclude patterns",
testDirPath: filepath.Join("..", "..", "tests", "testdata", "projects", "jas", "jas"),
configProfile: services.ConfigProfile{
ProfileName: "some-scanners-with-exclusions",
Modules: []services.Module{{
ModuleId: 1,
ModuleName: "some-scanners-with-exclusions-module",
PathFromRoot: ".",
ScanConfig: services.ScanConfig{
ScaScannerConfig: services.ScaScannerConfig{
EnableScaScan: true,
},
ContextualAnalysisScannerConfig: services.CaScannerConfig{
EnableCaScan: true,
},
SastScannerConfig: services.SastScannerConfig{
EnableSastScan: true,
ExcludePatterns: []string{"*flask_webgoat*"},
},
SecretsScannerConfig: services.SecretsScannerConfig{
EnableSecretsScan: true,
ExcludePatterns: []string{"*api_secrets*"},
},
IacScannerConfig: services.IacScannerConfig{
EnableIacScan: true,
},
},
}},
IsDefault: false,
},
expectedSastIssues: 0,
expectedSecretsIssues: 7,
expectedIacIssues: 9,
expectedCaApplicable: 3,
expectedCaUndetermined: 6,
expectedCaNotCovered: 4,
expectedCaNotApplicable: 2,
},
}

for _, testcase := range testcases {
Expand All @@ -413,19 +605,19 @@ func TestAuditWithConfigProfile(t *testing.T) {
defer createTempDirCallback()
assert.NoError(t, biutils.CopyDir(testcase.testDirPath, tempDirPath, true, nil))

configProfile := testcase.configProfile
auditBasicParams := (&utils.AuditBasicParams{}).
SetServerDetails(serverDetails).
SetXrayVersion(utils.EntitlementsMinVersion).
SetXscVersion(services.ConfigProfileMinXscVersion).
SetOutputFormat(format.Table).
SetUseJas(true)
SetUseJas(true).
SetConfigProfile(&configProfile)

configProfile := testcase.configProfile
auditParams := NewAuditParams().
SetWorkingDirs([]string{tempDirPath}).
SetMultiScanId(validations.TestMsi).
SetGraphBasicParams(auditBasicParams).
SetConfigProfile(&configProfile).
SetResultsContext(results.ResultContext{IncludeVulnerabilities: true})

auditParams.SetWorkingDirs([]string{tempDirPath}).SetIsRecursiveScan(true)
Expand Down
7 changes: 0 additions & 7 deletions commands/audit/auditparams.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/jfrog/jfrog-cli-security/utils/results"
"github.com/jfrog/jfrog-cli-security/utils/severityutils"
"github.com/jfrog/jfrog-client-go/xray/services"
xscservices "github.com/jfrog/jfrog-client-go/xsc/services"
)

type AuditParams struct {
Expand All @@ -22,7 +21,6 @@ type AuditParams struct {
// Include third party dependencies source code in the applicability scan.
thirdPartyApplicabilityScan bool
threads int
configProfile *xscservices.ConfigProfile
scanResultsOutputDir string
startTime time.Time
}
Expand Down Expand Up @@ -112,11 +110,6 @@ func (params *AuditParams) SetResultsContext(resultsContext results.ResultContex
return params
}

func (params *AuditParams) SetConfigProfile(configProfile *xscservices.ConfigProfile) *AuditParams {
params.configProfile = configProfile
return params
}

func (params *AuditParams) SetScansResultsOutputDir(outputDir string) *AuditParams {
params.scanResultsOutputDir = outputDir
return params
Expand Down
4 changes: 4 additions & 0 deletions commands/audit/sca/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ var CurationErrorMsgToUserTemplate = "Failed to retrieve the dependencies tree f

func GetExcludePattern(params utils.AuditParams) string {
exclusions := params.Exclusions()
if configProfile := params.GetConfigProfile(); configProfile != nil {
exclusions = append(exclusions, configProfile.Modules[0].ScanConfig.ScaScannerConfig.ExcludePatterns...)
}

if len(exclusions) == 0 {
exclusions = append(exclusions, utils.DefaultScaExcludePatterns...)
}
Expand Down
Loading
Loading