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

Running jas scanners in parallel #33

Merged
merged 70 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
9c46c81
Running jas scanners in parallel
orz25 Mar 3, 2024
4f8d68d
running scanners in parallel - second commit
orz25 Mar 21, 2024
75b5d25
Merge remote-tracking branch 'upstream/dev'
orz25 Mar 21, 2024
0b3a836
go sec fixes
orz25 Mar 21, 2024
ef6ccd7
third commit
orz25 Mar 31, 2024
69a3a0d
Merge remote-tracking branch 'upstream/dev'
orz25 Mar 31, 2024
adabfef
4th commit
orz25 Apr 3, 2024
834fdaa
fix unit test
orz25 Apr 3, 2024
2f86fb4
unit tests fix, progress bar changes and adding a threads flag
orz25 Apr 4, 2024
c3ce949
fix static analysis checks
orz25 Apr 4, 2024
8dbe5d3
fix unit test
orz25 Apr 14, 2024
646479c
Merge branch 'dev' of https://github.com/jfrog/jfrog-cli-security int…
orz25 Apr 14, 2024
93af954
merge fixes
orz25 Apr 15, 2024
de6c6fb
Merge remote-tracking branch 'upstream/dev' into run-jas-scanners-in-…
orz25 Apr 16, 2024
c14d30c
Merge remote-tracking branch 'upstream/dev' into run-jas-scanners-in-…
orz25 Apr 16, 2024
70d4794
Cr fixes
orz25 May 5, 2024
a571d87
Merge remote-tracking branch 'upstream/dev' into run-jas-scanners-in-…
orz25 May 5, 2024
5405e6d
Cr fixes
orz25 May 12, 2024
6899581
cr fixes
orz25 Jun 5, 2024
8b7136d
Merge remote-tracking branch 'upstream/dev' into run-jas-scanners-in-…
orz25 Jun 6, 2024
dad5eb1
cr fix
orz25 Jun 6, 2024
4f59024
Merge remote-tracking branch 'upstream/dev' into run-jas-scanners-in-…
orz25 Jun 6, 2024
85ea02c
Merge remote-tracking branch 'upstream/dev' into run-jas-scanners-in-…
orz25 Jun 6, 2024
2561860
add debug flag
orz25 Jun 6, 2024
63f7188
fix tests
orz25 Jun 6, 2024
08ea3cd
change xray results to pointers array
orz25 Jun 6, 2024
1ee4f40
change xray results to pointers array
orz25 Jun 6, 2024
9b84810
fix pointers issue
orz25 Jun 7, 2024
2f03385
Merge remote-tracking branch 'upstream/dev' into run-jas-scanners-in-…
orz25 Jun 7, 2024
955299d
change direct dependency to pointer
orz25 Jun 7, 2024
afa3010
fix unit test
orz25 Jun 8, 2024
a565415
cr changes
orz25 Jun 10, 2024
98f195a
Merge remote-tracking branch 'upstream/dev' into run-jas-scanners-in-…
orz25 Jun 10, 2024
917871e
add wg
orz25 Jun 10, 2024
ce5c1f4
add debug logs
orz25 Jun 10, 2024
2475521
add more debug logs
orz25 Jun 10, 2024
79a97b1
create sca tasks first
orz25 Jun 11, 2024
12a3f2c
remove sca scan as task
orz25 Jun 12, 2024
9866706
remove sca scan as task 2
orz25 Jun 12, 2024
17cbfbc
bring back sca scan as task
orz25 Jun 12, 2024
d312338
create jfrogAppsConfig at beginning of audit
orz25 Jun 13, 2024
b3cb67d
adding debugs logs
orz25 Jun 13, 2024
b02eb22
adding debugs logs 2
orz25 Jun 13, 2024
e0b19f7
more logs
orz25 Jun 13, 2024
59ce3b7
more logs
orz25 Jun 13, 2024
23f003d
more logs with current dir
orz25 Jun 13, 2024
749cfc6
more logs with current dir 2
orz25 Jun 13, 2024
6da2edd
more logs with current dir 2
orz25 Jun 13, 2024
81e8908
add wait group before running scanners
orz25 Jun 13, 2024
c5b3cca
remove logs and move jas scanner location
orz25 Jun 13, 2024
2986a0d
rollback to sca scan not as task
orz25 Jun 15, 2024
affc60e
add mutex to results
orz25 Jun 15, 2024
021a5d1
add mutex to results
orz25 Jun 15, 2024
e9787db
add mutex to results
orz25 Jun 15, 2024
4250a6c
add mutex to results
orz25 Jun 15, 2024
28f8c33
add mutex to results
orz25 Jun 15, 2024
212d4fb
create audit parallel runner in Run func
orz25 Jun 16, 2024
cb2ac87
move back parallelRunner to runAudit
orz25 Jun 16, 2024
5752db7
change to select
orz25 Jun 16, 2024
cfaa371
fix err handle
orz25 Jun 16, 2024
cd11c22
add mutex before accessing results struct
orz25 Jun 16, 2024
c1f79a8
new mutex only for err handling
orz25 Jun 16, 2024
196c6fa
add mutex to all results.ScanErr
orz25 Jun 16, 2024
423a4a4
add wg for errors
orz25 Jun 16, 2024
1de40e7
remove all mutex to results object
orz25 Jun 16, 2024
699fc36
add errWg outside new go routine
orz25 Jun 16, 2024
4def17c
remove format parameter from audit jas tests
orz25 Jun 16, 2024
cad75b1
use for loop instead of select
orz25 Jun 16, 2024
dbc7a82
remove mutex
orz25 Jun 16, 2024
68eeb28
Merge remote-tracking branch 'upstream/dev' into run-jas-scanners-in-…
orz25 Jun 18, 2024
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 .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
env:
GOPROXY: direct
GRADLE_OPTS: -Dorg.gradle.daemon=false
CI: true
JFROG_CLI_LOG_LEVEL: DEBUG
steps:
# Install dependencies
- name: Install Go
Expand Down
4 changes: 2 additions & 2 deletions artifactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func TestDownloadAnalyzerManagerIfNeeded(t *testing.T) {
defer setEnvCallBack()

// Download
err := utils.DownloadAnalyzerManagerIfNeeded()
err := utils.DownloadAnalyzerManagerIfNeeded(0)
assert.NoError(t, err)

// Validate Analyzer manager app & checksum.sh2 file exist
Expand All @@ -236,7 +236,7 @@ func TestDownloadAnalyzerManagerIfNeeded(t *testing.T) {
// Validate no second download occurred
firstFileStat, err := os.Stat(amPath)
assert.NoError(t, err)
err = utils.DownloadAnalyzerManagerIfNeeded()
err = utils.DownloadAnalyzerManagerIfNeeded(0)
assert.NoError(t, err)
secondFileStat, err := os.Stat(amPath)
assert.NoError(t, err)
Expand Down
33 changes: 28 additions & 5 deletions audit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,22 +435,27 @@ func addDummyPackageDescriptor(t *testing.T, hasPackageJson bool) {
// JAS

func TestXrayAuditJasSimpleJson(t *testing.T) {
output := testXrayAuditJas(t, string(format.SimpleJson), filepath.Join("jas", "jas"))
output := testXrayAuditJas(t, filepath.Join("jas", "jas"), "3")
securityTestUtils.VerifySimpleJsonJasResults(t, output, 1, 9, 6, 3, 0, 2, 2)
}

func TestXrayAuditJasSimpleJsonWithOneThread(t *testing.T) {
output := testXrayAuditJas(t, filepath.Join("jas", "jas"), "1")
securityTestUtils.VerifySimpleJsonJasResults(t, output, 1, 9, 6, 3, 0, 2, 2)
}

func TestXrayAuditJasSimpleJsonWithConfig(t *testing.T) {
output := testXrayAuditJas(t, string(format.SimpleJson), filepath.Join("jas", "jas-config"))
output := testXrayAuditJas(t, filepath.Join("jas", "jas-config"), "3")
securityTestUtils.VerifySimpleJsonJasResults(t, output, 0, 0, 1, 3, 0, 2, 2)
}

func TestXrayAuditJasNoViolationsSimpleJson(t *testing.T) {
output := testXrayAuditJas(t, string(format.SimpleJson), filepath.Join("package-managers", "npm", "npm"))
output := testXrayAuditJas(t, filepath.Join("package-managers", "npm", "npm"), "3")
securityTestUtils.VerifySimpleJsonScanResults(t, output, 0, 1, 0)
securityTestUtils.VerifySimpleJsonJasResults(t, output, 0, 0, 0, 0, 0, 0, 1)
}

func testXrayAuditJas(t *testing.T, format string, project string) string {
func testXrayAuditJas(t *testing.T, project string, threads string) string {
securityTestUtils.InitSecurityTest(t, scangraph.GraphScanMinXrayVersion)
tempDirPath, createTempDirCallback := coreTests.CreateTempDirWithCallbackAndAssert(t)
defer createTempDirCallback()
Expand All @@ -464,7 +469,7 @@ func testXrayAuditJas(t *testing.T, format string, project string) string {
assert.NoError(t, err)
chdirCallback := clientTests.ChangeDirWithCallback(t, baseWd, tempDirPath)
defer chdirCallback()
return securityTests.PlatformCli.WithoutCredentials().RunCliCmdWithOutput(t, "audit", "--format="+format)
return securityTests.PlatformCli.WithoutCredentials().RunCliCmdWithOutput(t, "audit", "--format="+string(format.SimpleJson), "--threads="+threads)
}

func TestXrayAuditDetectTech(t *testing.T) {
Expand Down Expand Up @@ -553,3 +558,21 @@ func validateAnalyticsBasicEvent(t *testing.T, output string) {
assert.NotEmpty(t, event.TotalScanDuration)
assert.True(t, event.TotalFindings > 0)
}

func TestAuditOnEmptyProject(t *testing.T) {
securityTestUtils.InitSecurityTest(t, scangraph.GraphScanMinXrayVersion)
tempDirPath, createTempDirCallback := coreTests.CreateTempDirWithCallbackAndAssert(t)
defer createTempDirCallback()
projectDir := filepath.Join(filepath.FromSlash(securityTestUtils.GetTestResourcesPath()), filepath.Join("projects", "empty_project", "python_project_with_no_deps"))
// Copy the multi project from the testdata to a temp dir
assert.NoError(t, biutils.CopyDir(projectDir, tempDirPath, true, nil))
// Configure a new server named "default"
securityTestUtils.CreateJfrogHomeConfig(t, true)
defer securityTestUtils.CleanTestsHomeEnv()
baseWd, err := os.Getwd()
assert.NoError(t, err)
chdirCallback := clientTests.ChangeDirWithCallback(t, baseWd, tempDirPath)
defer chdirCallback()
output := securityTests.PlatformCli.WithoutCredentials().RunCliCmdWithOutput(t, "audit", "--format="+string(format.SimpleJson))
securityTestUtils.VerifySimpleJsonJasResults(t, output, 0, 0, 0, 0, 0, 0, 0)
}
10 changes: 4 additions & 6 deletions cli/docs/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
pluginsCommon "github.com/jfrog/jfrog-cli-core/v2/plugins/common"
"github.com/jfrog/jfrog-cli-core/v2/plugins/components"
"github.com/jfrog/jfrog-cli-security/commands/audit/sca"
"github.com/jfrog/jfrog-cli-security/commands/curation"
"github.com/jfrog/jfrog-cli-security/commands/xray/offlineupdate"
)

Expand Down Expand Up @@ -105,8 +104,7 @@ const (
WorkingDirs = "working-dirs"

// Unique curation flags
CurationOutput = "curation-format"
CurationThreads = "curation-threads"
CurationOutput = "curation-format"
)

// Mapping between security commands (key) and their flags (key).
Expand All @@ -125,10 +123,11 @@ var commandFlags = map[string][]string{
},
Audit: {
url, user, password, accessToken, ServerId, InsecureTls, Project, Watches, RepoPath, Licenses, OutputFormat, ExcludeTestDeps,
useWrapperAudit, DepType, RequirementsFile, Fail, ExtendedTable, WorkingDirs, ExclusionsAudit, Mvn, Gradle, Npm, Pnpm, Yarn, Go, Nuget, Pip, Pipenv, Poetry, MinSeverity, FixableOnly, ThirdPartyContextualAnalysis,
useWrapperAudit, DepType, RequirementsFile, Fail, ExtendedTable, WorkingDirs, ExclusionsAudit, Mvn, Gradle, Npm,
Pnpm, Yarn, Go, Nuget, Pip, Pipenv, Poetry, MinSeverity, FixableOnly, ThirdPartyContextualAnalysis, Threads,
},
CurationAudit: {
CurationOutput, WorkingDirs, CurationThreads, RequirementsFile,
CurationOutput, WorkingDirs, Threads, RequirementsFile,
},
// TODO: Deprecated commands (remove at next CLI major version)
AuditMvn: {
Expand Down Expand Up @@ -219,7 +218,6 @@ var flagsMap = map[string]components.Flag{
components.SetHiddenBoolFlag(),
),
RequirementsFile: components.NewStringFlag(RequirementsFile, "[Pip] Defines pip requirements file name. For example: 'requirements.txt'."),
CurationThreads: components.NewStringFlag(Threads, "Number of working threads.", components.WithIntDefaultValue(curation.TotalConcurrentRequests)),
CurationOutput: components.NewStringFlag(OutputFormat, "Defines the output format of the command. Acceptable values are: table, json.", components.WithStrDefaultValue("table")),
}

Expand Down
19 changes: 12 additions & 7 deletions cli/scancommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,12 @@ func AuditCmd(c *components.Context) error {
}
}
auditCmd.SetTechnologies(technologies)
threads, err := pluginsCommon.GetThreadsCount(c)
if err != nil {
return err
}
auditCmd.SetThreads(threads)
err = progressbar.ExecWithProgress(auditCmd)

// Reporting error if Xsc service is enabled
reportErrorIfExists(err, auditCmd)
return err
Expand Down Expand Up @@ -428,11 +432,7 @@ func AuditSpecificCmd(c *components.Context, technology techutils.Technology) er
}

func CurationCmd(c *components.Context) error {
threadsFlag, err := c.GetIntFlagValue(flags.Threads)
if err != nil {
return err
}
threads, err := curation.DetectNumOfThreads(threadsFlag)
threads, err := pluginsCommon.GetThreadsCount(c)
if err != nil {
return err
}
Expand Down Expand Up @@ -470,6 +470,10 @@ func DockerScan(c *components.Context, image string) error {
return printHelp()
}
// Run the command
threads, err := pluginsCommon.GetThreadsCount(c)
if err != nil {
return err
}
serverDetails, err := createServerDetailsWithConfigOffer(c)
if err != nil {
return err
Expand Down Expand Up @@ -498,7 +502,8 @@ func DockerScan(c *components.Context, image string) error {
SetPrintExtendedTable(c.GetBoolFlagValue(flags.ExtendedTable)).
SetBypassArchiveLimits(c.GetBoolFlagValue(flags.BypassArchiveLimits)).
SetFixableOnly(c.GetBoolFlagValue(flags.FixableOnly)).
SetMinSeverityFilter(minSeverity)
SetMinSeverityFilter(minSeverity).
SetThreads(threads)
if c.GetStringFlagValue(flags.Watches) != "" {
containerScanCommand.SetWatches(splitByCommaAndTrim(c.GetStringFlagValue(flags.Watches)))
}
Expand Down
Loading
Loading