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

Add Violations support for JAS scanners #241

Open
wants to merge 132 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 128 commits
Commits
Show all changes
132 commits
Select commit Hold shift + click to select a range
650cc2b
comments
eranturgeman Nov 17, 2024
8c2e4bd
Added new field for violation results to ApplicabilityScanManager + a…
eranturgeman Nov 18, 2024
7a4f5a1
Added new field for violation results to IacScanManager + added the n…
eranturgeman Nov 18, 2024
c664895
Added new field for violation results to SastScanManager + added the …
eranturgeman Nov 18, 2024
dcd923e
Added new field for violation results to SecretScanManager + added th…
eranturgeman Nov 18, 2024
03d0904
added parsing and processing for violations results (similar to vulne…
eranturgeman Nov 18, 2024
a16d7f2
updated all Run***Scan functions to return the violation results + ad…
eranturgeman Nov 18, 2024
8d3cd77
simplified interface calls
eranturgeman Nov 18, 2024
2c0b972
deleted un-used field from sastScanManager and fixed all tests refere…
eranturgeman Nov 19, 2024
748a9b0
deleted un-used field from applicabilityScanManager and fixed all tes…
eranturgeman Nov 19, 2024
20eba2b
deleted un-used field from iacScanManager and fixed all tests references
eranturgeman Nov 19, 2024
1c43d27
deleted un-used field from SecretScanManager and fixed all tests refe…
eranturgeman Nov 19, 2024
cc4720c
fixed broken tests dur to changes
eranturgeman Nov 19, 2024
6065dd2
remove comment
eranturgeman Nov 19, 2024
bb89eec
simplified interface and added temp func for testing
eranturgeman Nov 19, 2024
49617de
adjusted all functions to new interface changes and logic changes
eranturgeman Nov 19, 2024
256064d
added new struct to replace the old JasScansResults and re-wrote all …
eranturgeman Nov 19, 2024
5a7bf61
removed comment
eranturgeman Nov 19, 2024
88074b8
Merge branch 'dev' of https://github.com/jfrog/jfrog-cli-security int…
eranturgeman Nov 19, 2024
42b2fde
updated applicability scanner to ignore violations logic since this s…
eranturgeman Nov 19, 2024
0698069
comments
eranturgeman Nov 19, 2024
10e85c0
starting to replace all old JasScansResults references (struct is onl…
eranturgeman Nov 19, 2024
586aaa3
replaced old functions usages and commented all old functions (need t…
eranturgeman Nov 19, 2024
1a9f913
fixing breaks after structs changes and started initial changes in pa…
eranturgeman Nov 19, 2024
3173b9e
added a new parsing func for jas vuln & violations (parseRequiredJasR…
eranturgeman Nov 21, 2024
638c075
changed name in Sast to SastVulnerabilities in SimpleJsonResults and …
eranturgeman Nov 21, 2024
12ae850
fixed reference in broken test
eranturgeman Nov 21, 2024
1283811
changed name in Iacs to IacsVulnerabilities in SimpleJsonResults and …
eranturgeman Nov 21, 2024
c71e6a1
comment
eranturgeman Nov 21, 2024
6778de2
comment
eranturgeman Nov 21, 2024
7b9a482
comment
eranturgeman Nov 21, 2024
0f94b02
changed name in Secrets to SecretsVulnerabilities in SimpleJsonResult…
eranturgeman Nov 21, 2024
e10abad
minor change in func description
eranturgeman Nov 24, 2024
dac3af2
changing function name
eranturgeman Nov 24, 2024
df8e5c2
applying secrets violations parsing in Simple Json and adding the res…
eranturgeman Nov 24, 2024
f8257b5
applying secrets violations parsing in Table parser
eranturgeman Nov 24, 2024
2588355
applying secrets violations parsing in Summery parser
eranturgeman Nov 24, 2024
72fbe1f
applying secrets violations parsing in Sarif parser
eranturgeman Nov 24, 2024
ffa905f
applied changes of ParseSecrets
eranturgeman Nov 24, 2024
fdd290f
applying Iacs violations parsing in Simple Json parser
eranturgeman Nov 24, 2024
f16184c
applying Iacs violations parsing in Table parser
eranturgeman Nov 24, 2024
dd56650
applying Iacs violations parsing in Summery parser
eranturgeman Nov 24, 2024
e429235
applying Iacs violations parsing in Sarif parser
eranturgeman Nov 24, 2024
468b368
applied changes of ParseIacs
eranturgeman Nov 24, 2024
8ad6e2c
minor fix in Summery ParseIacs
eranturgeman Nov 24, 2024
26a350f
applying Sast violations parsing in Simple Json parser
eranturgeman Nov 24, 2024
ffbf1d0
applying Sast violations parsing in Table parser
eranturgeman Nov 24, 2024
4a2f2e9
applying Sast violations parsing in Summery parser
eranturgeman Nov 24, 2024
87749e0
applying Sast violations parsing in Sarif parser
eranturgeman Nov 24, 2024
154fc6b
applied changes of ParseSast
eranturgeman Nov 24, 2024
04596c4
removing comments
eranturgeman Nov 24, 2024
68f608f
fixing breaks from 'go vet ./..' . TestDetectScansToPreform requires fix
eranturgeman Nov 24, 2024
af658ab
add inject git url content
attiasas Nov 24, 2024
a69b532
fix static
attiasas Nov 24, 2024
892fa96
start cleaning
attiasas Nov 25, 2024
501cdf7
Merge remote-tracking branch 'upstream/dev' into pr/eranturgeman/241
attiasas Nov 25, 2024
2f850a4
update
attiasas Nov 25, 2024
8b7aba3
fmt
attiasas Nov 25, 2024
0c83518
Merge remote-tracking branch 'upstream/dev' into pr/eranturgeman/241
attiasas Nov 25, 2024
9faea6d
update after merge
attiasas Nov 25, 2024
069dbae
update client go
attiasas Nov 25, 2024
98971f6
fix
attiasas Nov 25, 2024
8231b90
ca result are general, clean todo and refactor
attiasas Nov 26, 2024
952d30d
fix for tests
attiasas Nov 26, 2024
e580111
some bug fixes
attiasas Nov 26, 2024
aff7661
parse violations
attiasas Nov 27, 2024
34b3781
Merge remote-tracking branch 'upstream/dev' into pr/eranturgeman/241
attiasas Nov 27, 2024
0a118f4
fix after merge
attiasas Nov 27, 2024
50721c7
fix some tests
attiasas Nov 28, 2024
bb0f250
Merge remote-tracking branch 'upstream/dev' into pr/eranturgeman/241
attiasas Nov 28, 2024
87e3b39
fix vet
attiasas Nov 28, 2024
c5d16fa
remove redundant set
attiasas Nov 28, 2024
e9b5e38
fix logs remove attrib and fix static
attiasas Nov 28, 2024
c5989a8
Merge remote-tracking branch 'upstream/dev' into pr/eranturgeman/241
attiasas Nov 28, 2024
0b8810b
show all errors if fail test
attiasas Nov 28, 2024
c40a287
fix some more tests
attiasas Nov 28, 2024
e277cff
Merge remote-tracking branch 'upstream/dev' into pr/eranturgeman/241
attiasas Nov 28, 2024
f2ed7e9
update client
attiasas Nov 28, 2024
1583071
remove unused jas finding logs func
attiasas Nov 28, 2024
13c5bc3
remove comment
attiasas Nov 28, 2024
b90ff34
fix static
attiasas Nov 28, 2024
c2a2622
add watch attrib to simple-json
attiasas Dec 2, 2024
a10364b
fix spell
attiasas Dec 2, 2024
a20fa43
add LicenseViolationRow
attiasas Dec 3, 2024
f9060e5
Merge remote-tracking branch 'upstream/dev' into pr/eranturgeman/241
attiasas Dec 3, 2024
2e4a959
add violation context and attribs to simple-json and sarif
attiasas Dec 3, 2024
6614703
add status code to each scan and to simple-json
attiasas Dec 3, 2024
5f7f30e
format
attiasas Dec 3, 2024
5910589
improve test to check sub attribs in validations
attiasas Dec 4, 2024
1ab19ef
clean
attiasas Dec 4, 2024
e901cd4
cwe is list
attiasas Dec 4, 2024
82fdf45
bug fixe
eranturgeman Dec 8, 2024
5d48264
bug fix
eranturgeman Dec 8, 2024
099946b
adjusted test json structure according to recent changes
eranturgeman Dec 8, 2024
5d5f8db
fixed prefix in markdown messages counting in sarif validations
eranturgeman Dec 8, 2024
1bd432f
changed all Read***Results to require successful Unmarshal in order t…
eranturgeman Dec 8, 2024
848d30b
fix some bugs
attiasas Dec 11, 2024
7d61201
start tests
attiasas Dec 11, 2024
72c24b1
continue tests
attiasas Dec 11, 2024
d632cb7
fix tests add violation test to parser
attiasas Dec 12, 2024
74fc2ef
fix static
attiasas Dec 12, 2024
baeae02
fix tests, replace client git url input to simplify and avoid race
attiasas Dec 13, 2024
625913e
add general integration test for audit, add xsc ignore rule integrati…
attiasas Dec 13, 2024
430b001
done integration ignore rule violation git repo test
attiasas Dec 14, 2024
58f23a7
update client
attiasas Dec 15, 2024
d288e4c
update for tests
attiasas Dec 15, 2024
c390cd1
fmt
attiasas Dec 15, 2024
2017948
Merge remote-tracking branch 'upstream/dev' into pr/eranturgeman/241
attiasas Dec 15, 2024
3100399
fix some tests
attiasas Dec 15, 2024
3507b9c
Merge remote-tracking branch 'upstream/dev' into pr/eranturgeman/241
attiasas Dec 15, 2024
46019b3
fix tests
attiasas Dec 16, 2024
113b34e
fix more tests
attiasas Dec 16, 2024
994ae2d
try fix some tests
attiasas Dec 16, 2024
8deb9c0
fix tests
attiasas Dec 16, 2024
40f074c
fix ignore creation
attiasas Dec 16, 2024
c5265b1
fix integration test
attiasas Dec 17, 2024
8e4055f
merge dev
attiasas Dec 17, 2024
aab3114
retrive watches from platform and infer result context
attiasas Dec 18, 2024
a87dc1b
Merge remote-tracking branch 'upstream/dev' into pr/eranturgeman/241
attiasas Dec 18, 2024
f6d4b07
fix merge
attiasas Dec 18, 2024
d219f16
implement projectKey for JAS vio, start clean up
attiasas Dec 18, 2024
be4a8e8
remove test
attiasas Dec 18, 2024
bd0bd1b
done cleanup
attiasas Dec 18, 2024
1a010ae
fix tests
attiasas Dec 18, 2024
0421990
Fix - using repo-path in binary scans
attiasas Dec 19, 2024
3e7f307
add project key jas vio tests and watches handling
attiasas Dec 22, 2024
359395f
Merge remote-tracking branch 'upstream/dev' into pr/eranturgeman/241
attiasas Dec 22, 2024
ad9c8da
merge dev
attiasas Dec 22, 2024
b98b4fc
only clean git repo key if watch and project not provided
attiasas Dec 23, 2024
628439e
update client
attiasas Dec 26, 2024
8644e6f
Merge remote-tracking branch 'upstream/dev' into pr/eranturgeman/241
attiasas Dec 26, 2024
3feccb7
merge dev and client
attiasas Dec 26, 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
13 changes: 7 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ go test -v github.com/jfrog/jfrog-cli-security [test-types] [flags]

### The available flags are:

| Flag | Equivalent Env vars | Description |
| ---------------------- | --------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
| `-jfrog.url` | `JFROG_SECURITY_CLI_TESTS_JFROG_URL` | [Default: http://localhost:8083] JFrog platform URL |
| `-jfrog.user` | `JFROG_SECURITY_CLI_TESTS_JFROG_USER` | [Default: admin] JFrog platform username |
| `-jfrog.password` | `JFROG_SECURITY_CLI_TESTS_JFROG_PASSWORD` | [Default: password] JFrog platform password |
| `-jfrog.adminToken` | `JFROG_SECURITY_CLI_TESTS_JFROG_ACCESS_TOKEN` | [Optional] JFrog platform admin token |
| Flag | Equivalent Env vars | Description |
| ---------------------- | ----------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
| `-jfrog.url` | `JFROG_SECURITY_CLI_TESTS_JFROG_URL` | [Default: http://localhost:8083] JFrog platform URL |
| `-jfrog.user` | `JFROG_SECURITY_CLI_TESTS_JFROG_USER` | [Default: admin] JFrog platform username |
| `-jfrog.password` | `JFROG_SECURITY_CLI_TESTS_JFROG_PASSWORD` | [Default: password] JFrog platform password |
| `-jfrog.adminToken` | `JFROG_SECURITY_CLI_TESTS_JFROG_ACCESS_TOKEN` | [Optional] JFrog platform admin token |
| `-jfrog.projectKey` | `JFROG_SECURITY_CLI_TESTS_JFROG_PLATFORM_PROJECT_KEY` | [Optional] JFrog platform project key |
| `-ci.runId` | - | [Optional] A unique identifier used as a suffix to create repositories and builds in the tests. |
| `-jfrog.sshKeyPath` | - | [Optional] Path to the SSH key file. Use this flag only if the Artifactory URL format is `ssh://[domain]:port`. |
| `-jfrog.sshPassphrase` | - | [Optional] Passphrase for the SSH key. |
Expand Down
282 changes: 164 additions & 118 deletions audit_test.go

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions cli/scancommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,15 @@ func ScanCmd(c *components.Context) error {
return err
}
var specFile *spec.SpecFiles
repoPath := ""
if c.IsFlagSet(flags.SpecFlag) && len(c.GetStringFlagValue(flags.SpecFlag)) > 0 {
specFile, err = pluginsCommon.GetFileSystemSpec(c)
if err != nil {
return err
}
} else {
specFile = createDefaultScanSpec(c, addTrailingSlashToRepoPathIfNeeded(c))
repoPath = addTrailingSlashToRepoPathIfNeeded(c)
specFile = createDefaultScanSpec(c, repoPath)
}
err = spec.ValidateSpec(specFile.Files, false, false)
if err != nil {
Expand All @@ -244,6 +246,7 @@ func ScanCmd(c *components.Context) error {
SetSpec(specFile).
SetOutputFormat(format).
SetProject(getProject(c)).
SetBaseRepoPath(repoPath).
SetIncludeVulnerabilities(c.GetBoolFlagValue(flags.Vuln) || shouldIncludeVulnerabilities(c)).
SetIncludeLicenses(c.GetBoolFlagValue(flags.Licenses)).
SetFail(c.GetBoolFlagValue(flags.Fail)).
Expand Down Expand Up @@ -472,7 +475,7 @@ func CreateAuditCmd(c *components.Context) (string, string, *coreConfig.ServerDe

auditCmd.SetTargetRepoPath(addTrailingSlashToRepoPathIfNeeded(c)).
SetProject(getProject(c)).
SetIncludeVulnerabilities(c.GetBoolFlagValue(flags.Vuln) || shouldIncludeVulnerabilities(c)).
SetIncludeVulnerabilities(c.GetBoolFlagValue(flags.Vuln)).
Copy link
Contributor Author

@eranturgeman eranturgeman Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: why did we take off the || shouldIncludeVulnerabilities(c) part only from Audit but not from Scan or DockerScan?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because only in audit we are passing git repo url but you are right, we can remove those as well

SetIncludeLicenses(c.GetBoolFlagValue(flags.Licenses)).
SetFail(c.GetBoolFlagValue(flags.Fail)).
SetPrintExtendedTable(c.GetBoolFlagValue(flags.ExtendedTable)).
Expand All @@ -487,6 +490,8 @@ func CreateAuditCmd(c *components.Context) (string, string, *coreConfig.ServerDe
auditCmd.SetWatches(splitByCommaAndTrim(c.GetStringFlagValue(flags.Watches)))
}

// auditCmd.SetGitRepoHttpsCloneUrl("github.com/jfrog/dummy-repo.git")
attiasas marked this conversation as resolved.
Show resolved Hide resolved

if c.GetStringFlagValue(flags.WorkingDirs) != "" {
auditCmd.SetWorkingDirs(splitByCommaAndTrim(c.GetStringFlagValue(flags.WorkingDirs)))
}
Expand Down Expand Up @@ -728,12 +733,12 @@ func DockerScan(c *components.Context, image string) error {
return err
}
containerScanCommand.SetImageTag(image).
SetTargetRepoPath(addTrailingSlashToRepoPathIfNeeded(c)).
SetServerDetails(serverDetails).
SetXrayVersion(xrayVersion).
SetXscVersion(xscVersion).
SetOutputFormat(format).
SetProject(getProject(c)).
SetBaseRepoPath(addTrailingSlashToRepoPathIfNeeded(c)).
SetIncludeVulnerabilities(c.GetBoolFlagValue(flags.Vuln) || shouldIncludeVulnerabilities(c)).
SetIncludeLicenses(c.GetBoolFlagValue(flags.Licenses)).
SetFail(c.GetBoolFlagValue(flags.Fail)).
Expand Down
114 changes: 87 additions & 27 deletions commands/audit/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ import (
"github.com/jfrog/jfrog-client-go/xray"
"github.com/jfrog/jfrog-client-go/xray/services"
xscservices "github.com/jfrog/jfrog-client-go/xsc/services"
xscutils "github.com/jfrog/jfrog-client-go/xsc/services/utils"
)

type AuditCommand struct {
watches []string
gitRepoHttpsCloneUrl string
projectKey string
targetRepoPath string
IncludeVulnerabilities bool
Expand All @@ -53,6 +55,11 @@ func (auditCmd *AuditCommand) SetWatches(watches []string) *AuditCommand {
return auditCmd
}

func (auditCmd *AuditCommand) SetGitRepoHttpsCloneUrl(gitRepoHttpsCloneUrl string) *AuditCommand {
auditCmd.gitRepoHttpsCloneUrl = gitRepoHttpsCloneUrl
return auditCmd
}

func (auditCmd *AuditCommand) SetProject(project string) *AuditCommand {
auditCmd.projectKey = project
return auditCmd
Expand Down Expand Up @@ -88,16 +95,62 @@ func (auditCmd *AuditCommand) SetThreads(threads int) *AuditCommand {
return auditCmd
}

func (auditCmd *AuditCommand) CreateCommonGraphScanParams() *scangraph.CommonGraphScanParams {
commonParams := &scangraph.CommonGraphScanParams{
RepoPath: auditCmd.targetRepoPath,
Watches: auditCmd.watches,
ScanType: services.Dependency,
func (auditCmd *AuditCommand) CreateAuditResultsContext(serverDetails *config.ServerDetails) (context results.ResultContext) {
Copy link
Contributor Author

@eranturgeman eranturgeman Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can unify CreateAuditResultsContext and CreateResultsContext since CreateResultsContext is called once only and in CreateAuditResultsContext we only passing the params from auditCmd. We can simply extract them to variable and save another function.
If you require using this in the future in another command it should not sit under audit.go

return CreateResultsContext(
serverDetails,
auditCmd.GetXrayVersion(),
auditCmd.watches,
auditCmd.targetRepoPath,
auditCmd.projectKey,
auditCmd.gitRepoHttpsCloneUrl,
auditCmd.IncludeVulnerabilities,
auditCmd.IncludeLicenses,
)
}

// Create a results context based on the provided parameters. resolves conflicts between the parameters based on the retrieved platform watches.
func CreateResultsContext(serverDetails *config.ServerDetails, xrayVersion string, watches []string, artifactoryRepoPath, projectKey, gitRepoHttpsCloneUrl string, includeVulnerabilities, includeLicenses bool) (context results.ResultContext) {
context = results.ResultContext{
RepoPath: artifactoryRepoPath,
Watches: watches,
ProjectKey: projectKey,
IncludeVulnerabilities: shouldIncludeVulnerabilities(includeVulnerabilities, watches, artifactoryRepoPath, projectKey, ""),
IncludeLicenses: includeLicenses,
}
if err := clientutils.ValidateMinimumVersion(clientutils.Xray, xrayVersion, services.MinXrayVersionGitRepoKey); err != nil {
// Git repo key is not supported by the Xray version.
return
}
if gitRepoHttpsCloneUrl == "" {
// No git repo key was provided, no need to check anything else.
log.Debug("Git repo key was not provided, jas violations will not be checked.")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
log.Debug("Git repo key was not provided, jas violations will not be checked.")
log.Debug("Git repo key was not provided, jas violations will not be checked for this resource.")

return
}
// Get the defined and active watches from the platform.
manager, err := xsc.CreateXscService(serverDetails)
if err != nil {
log.Warn(fmt.Sprintf("Failed to create Xray services manager: %s", err.Error()))
return
}
if context.PlatformWatches, err = manager.GetResourceWatches(xscutils.GetGitRepoUrlKey(gitRepoHttpsCloneUrl), projectKey); err != nil {
log.Warn(fmt.Sprintf("Failed to get active defined watches: %s", err.Error()))
return
}
// Set git repo key and check if it has any watches defined in the platform.
context.GitRepoHttpsCloneUrl = gitRepoHttpsCloneUrl
if len(context.PlatformWatches.GitRepositoryWatches) == 0 {
log.Debug(fmt.Sprintf("Git repo key was provided (%s) but no watches were defined in the platform. ignoring git repo key...", context.GitRepoHttpsCloneUrl))
Copy link
Contributor

@orz25 orz25 Dec 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the log should be something like:
"No watches were found in the platform for the given git repo key (%s), and no watches were given by the user (using watches or project flags). Calculating vulnerabilities..."

context.GitRepoHttpsCloneUrl = ""
}
commonParams.ProjectKey = auditCmd.projectKey
commonParams.IncludeVulnerabilities = auditCmd.IncludeVulnerabilities
commonParams.IncludeLicenses = auditCmd.IncludeLicenses
return commonParams
// We calculate again this time also taking into account the final git repo key value.
// (if there are no watches defined on the git repo and no other context was given, we should include vulnerabilities)
context.IncludeVulnerabilities = shouldIncludeVulnerabilities(includeVulnerabilities, watches, artifactoryRepoPath, projectKey, context.GitRepoHttpsCloneUrl)
return
}

// If the user requested to include vulnerabilities, or if the user didn't provide any watches, project key, artifactory repo path or git repo key, we should include vulnerabilities.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the comment here should be:
"If the user requested to include vulnerabilities, or if the user didn't provide any watches, project key, artifactory repo path or no watches configured on the given git repo key, we should include vulnerabilities"

func shouldIncludeVulnerabilities(includeVulnerabilities bool, watches []string, artifactoryRepoPath, projectKey, gitRepoHttpsCloneUrl string) bool {
return includeVulnerabilities || !(len(watches) > 0 || projectKey != "" || artifactoryRepoPath != "" || gitRepoHttpsCloneUrl != "")
}

func (auditCmd *AuditCommand) Run() (err error) {
Expand All @@ -124,7 +177,7 @@ func (auditCmd *AuditCommand) Run() (err error) {
SetMinSeverityFilter(auditCmd.minSeverityFilter).
SetFixableOnly(auditCmd.fixableOnly).
SetGraphBasicParams(auditCmd.AuditBasicParams).
SetCommonGraphScanParams(auditCmd.CreateCommonGraphScanParams()).
SetResultsContext(auditCmd.CreateAuditResultsContext(serverDetails)).
SetThirdPartyApplicabilityScan(auditCmd.thirdPartyApplicabilityScan).
SetThreads(auditCmd.Threads).
SetScansResultsOutputDir(auditCmd.scanResultsOutputDir).SetStartTime(startTime).SetMultiScanId(multiScanId)
Expand All @@ -144,13 +197,10 @@ func (auditCmd *AuditCommand) Run() (err error) {
messages = []string{coreutils.PrintTitle("The ‘jf audit’ command also supports JFrog Advanced Security features, such as 'Contextual Analysis', 'Secret Detection', 'IaC Scan' and ‘SAST’.\nThis feature isn't enabled on your system. Read more - ") + coreutils.PrintLink(utils.JasInfoURL)}
}
if err = output.NewResultsWriter(auditResults).
SetHasViolationContext(auditCmd.HasViolationContext()).
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: er set the Violation context in auditParams, but how does it get passed to the resultsWriter so we know we are in a violation context?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

based on the value in the results - I added ResultsContext struct for this (there is a way to override violation context for build scan only at result writer as well)

SetIncludeVulnerabilities(auditCmd.IncludeVulnerabilities).
SetIncludeLicenses(auditCmd.IncludeLicenses).
SetOutputFormat(auditCmd.OutputFormat()).
SetPrintExtendedTable(auditCmd.PrintExtendedTable).
SetExtraMessages(messages).
SetSubScansPreformed(auditCmd.ScansToPerform()).
SetSubScansPerformed(auditCmd.ScansToPerform()).
PrintScanResults(); err != nil {
return errors.Join(err, auditResults.GetErrors())
}
Expand All @@ -170,10 +220,6 @@ func (auditCmd *AuditCommand) CommandName() string {
return "generic_audit"
}

func (auditCmd *AuditCommand) HasViolationContext() bool {
return len(auditCmd.watches) > 0 || auditCmd.projectKey != "" || auditCmd.targetRepoPath != ""
}

// Runs an audit scan based on the provided auditParams.
// Returns an audit Results object containing all the scan results.
// If the current server is entitled for JAS, the advanced security results will be included in the scan results.
Expand All @@ -192,14 +238,14 @@ func RunAudit(auditParams *AuditParams) (cmdResults *results.SecurityCommandResu
var jasScanner *jas.JasScanner
var generalJasScanErr error
if jasScanner, generalJasScanErr = RunJasScans(auditParallelRunner, auditParams, cmdResults, jfrogAppsConfig); generalJasScanErr != nil {
cmdResults.AddGeneralError(fmt.Errorf("An error has occurred during JAS scan process. JAS scan is skipped for the following directories: %s\n%s", strings.Join(cmdResults.GetTargetsPaths(), ","), generalJasScanErr.Error()), auditParams.AllowPartialResults())
cmdResults.AddGeneralError(fmt.Errorf("error has occurred during JAS scan process. JAS scan is skipped for the following directories: %s\n%s", strings.Join(cmdResults.GetTargetsPaths(), ","), generalJasScanErr.Error()), auditParams.AllowPartialResults())
}
if auditParams.Progress() != nil {
auditParams.Progress().SetHeadlineMsg("Scanning for issues")
}
// The sca scan doesn't require the analyzer manager, so it can run separately from the analyzer manager download routine.
if generalScaScanError := buildDepTreeAndRunScaScan(auditParallelRunner, auditParams, cmdResults); generalScaScanError != nil {
cmdResults.AddGeneralError(fmt.Errorf("An error has occurred during SCA scan process. SCA scan is skipped for the following directories: %s\n%s", strings.Join(cmdResults.GetTargetsPaths(), ","), generalScaScanError.Error()), auditParams.AllowPartialResults())
cmdResults.AddGeneralError(fmt.Errorf("error has occurred during SCA scan process. SCA scan is skipped for the following directories: %s\n%s", strings.Join(cmdResults.GetTargetsPaths(), ","), generalScaScanError.Error()), auditParams.AllowPartialResults())
}
go func() {
auditParallelRunner.ScaScansWg.Wait()
Expand Down Expand Up @@ -234,7 +280,19 @@ func RunJasScans(auditParallelRunner *utils.SecurityParallelRunner, auditParams
return
}
auditParallelRunner.ResultsMu.Lock()
jasScanner, err = jas.CreateJasScanner(serverDetails, scanResults.SecretValidation, auditParams.minSeverityFilter, jas.GetAnalyzerManagerXscEnvVars(auditParams.GetMultiScanId(), scanResults.GetTechnologies()...), auditParams.Exclusions()...)
jasScanner, err = jas.CreateJasScanner(
serverDetails,
scanResults.SecretValidation,
auditParams.minSeverityFilter,
jas.GetAnalyzerManagerXscEnvVars(
auditParams.GetMultiScanId(),
jas.GetGitRepoUrlKey(auditParams.resultsContext.GitRepoHttpsCloneUrl),
auditParams.resultsContext.ProjectKey,
auditParams.resultsContext.Watches,
scanResults.GetTechnologies()...,
),
auditParams.Exclusions()...,
)
auditParallelRunner.ResultsMu.Unlock()
if err != nil {
generalError = fmt.Errorf("failed to create jas scanner: %s", err.Error())
Expand Down Expand Up @@ -276,7 +334,7 @@ func createJasScansTasks(auditParallelRunner *utils.SecurityParallelRunner, scan
Scanner: scanner,
Module: *module,
ConfigProfile: auditParams.configProfile,
ScansToPreform: auditParams.ScansToPerform(),
ScansToPerform: auditParams.ScansToPerform(),
SecretsScanType: secrets.SecretsScannerType,
DirectDependencies: auditParams.DirectDependencies(),
ThirdPartyApplicabilityScan: auditParams.thirdPartyApplicabilityScan,
Expand Down Expand Up @@ -310,11 +368,13 @@ func initAuditCmdResults(params *AuditParams) (cmdResults *results.SecurityComma
cmdResults.SetXscVersion(params.GetXscVersion())
cmdResults.SetMultiScanId(params.GetMultiScanId())
cmdResults.SetStartTime(params.StartTime())
// Send entitlement requests
cmdResults.SetResultsContext(params.resultsContext)

xrayManager, err := xrayutils.CreateXrayServiceManager(serverDetails)
if err != nil {
return cmdResults.AddGeneralError(err, false)
}
// Send entitlement requests
entitledForJas, err := isEntitledForJas(xrayManager, params)
if err != nil {
return cmdResults.AddGeneralError(err, false)
Expand All @@ -330,11 +390,11 @@ func initAuditCmdResults(params *AuditParams) (cmdResults *results.SecurityComma
// No SCA targets were detected, add the root directory as a target for JAS scans.
cmdResults.NewScanResults(results.ScanTarget{Target: params.workingDirs[0]})
}
scanInfo, err := coreutils.GetJsonIndent(cmdResults)
scanInfo, err := coreutils.GetJsonIndent(cmdResults.GetTargets())
if err != nil {
return
}
log.Info(fmt.Sprintf("Preforming scans on %d targets:\n%s", len(cmdResults.Targets), scanInfo))
log.Info(fmt.Sprintf("Performing scans on %d targets:\n%s", len(cmdResults.Targets), scanInfo))
return
}

Expand All @@ -350,14 +410,14 @@ func detectScanTargets(cmdResults *results.SecurityCommandResults, params *Audit
log.Warn("Couldn't detect technologies in", requestedDirectory, "directory.", err.Error())
continue
}
// Create scans to preform
// Create scans to perform
for tech, workingDirs := range techToWorkingDirs {
if tech == techutils.Dotnet {
// We detect Dotnet and Nuget the same way, if one detected so does the other.
// We don't need to scan for both and get duplicate results.
continue
}
// No technology was detected, add scan without descriptors. (so no sca scan will be preformed and set at target level)
// No technology was detected, add scan without descriptors. (so no sca scan will be performed and set at target level)
if len(workingDirs) == 0 {
// Requested technology (from params) descriptors/indicators were not found or recursive scan with NoTech value, add scan without descriptors.
cmdResults.NewScanResults(results.ScanTarget{Target: requestedDirectory, Technology: tech})
Expand Down
Loading
Loading