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

sast-snyk-check: increased version to 0.3 #1359

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jperezdealgaba
Copy link

@jperezdealgaba jperezdealgaba commented Aug 30, 2024

Resolves: https://issues.redhat.com/browse/OSH-737

In this version, the severity-threshold argument is introduced and enabled by default to high and the results are parsed with csgrep to be uploaded with the fingerprint. This MR needs to be merged after this one: konflux-ci/konflux-test#292

All changes have been discussed in the provided Jira tracker.

@konflux-team , we created this as a draft PR in order to gather feedback from you. Would this be acceptable? Is something else needed? ...

Before you complete this pull request ...

Look for any open pull requests in the repository with the title "e2e-tests update" and
see if there are recent e2e-tests updates that will be applicable to your change.

@jperezdealgaba
Copy link
Author

@jsztuka Would you mind giving a review for this?

@jperezdealgaba
Copy link
Author

@jsztuka Does the 👍🏻 mean that it looks good and nothind needs to be modified?

Copy link
Contributor

@jsztuka jsztuka left a comment

Choose a reason for hiding this comment

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

lgtm

@kdudka
Copy link

kdudka commented Sep 5, 2024

@jsztuka Could you please approve the 6 workflows that are awaiting approval?

@jperezdealgaba
Copy link
Author

Will update lint problems in following commit adding false positives filtering...

@jperezdealgaba jperezdealgaba force-pushed the snyk-enhanced-version branch 2 times, most recently from a5f8188 to 7d3c6e5 Compare September 9, 2024 14:54
task/sast-snyk-check/0.3/sast-snyk-check.yaml Outdated Show resolved Hide resolved
task/sast-snyk-check/0.3/sast-snyk-check.yaml Outdated Show resolved Hide resolved
@jperezdealgaba jperezdealgaba force-pushed the snyk-enhanced-version branch 3 times, most recently from f3a637d to 2907e70 Compare September 11, 2024 16:26
@jperezdealgaba
Copy link
Author

Although the MR is finished, I will look for ProdSec feedback before taking this out from draft.

Copy link

@kdudka kdudka left a comment

Choose a reason for hiding this comment

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

@jperezdealgaba I can see that we still print the full SARIF file into the CI log, which is not much user-friendly and it will cause problems on tasks that produce too much results. I would suggest to invoke csgrep --mode=evtstat instead to provide a useful summary for end users. In case we are filtering false positives we can run the command twice to record the number of findings that were excluded from the results.

task/sast-snyk-check/0.3/MIGRATION.md Outdated Show resolved Hide resolved
@jperezdealgaba
Copy link
Author

jperezdealgaba commented Sep 13, 2024

@jperezdealgaba I can see that we still print the full SARIF file into the CI log, which is not much user-friendly and it will cause problems on tasks that produce too much results. I would suggest to invoke csgrep --mode=evtstat instead to provide a useful summary for end users. In case we are filtering false positives we can run the command twice to record the number of findings that were excluded from the results.

@kdudka The SARIF output is no longer shown and the results are shown in evtstat mode. Before and after filtering. Example pipeline is here: https://konflux.apps.stone-prod-p02.hjvn.p1.openshiftapps.com/application-pipeline/workspaces/jperezde/applications/test-coverity/pipelineruns/osh-cli-container-konflux-test-2-on-pull-request-7l7nj (Note: Installation of packages is only for testing until the image contains csdiff)

@jperezdealgaba jperezdealgaba force-pushed the snyk-enhanced-version branch 2 times, most recently from 7801607 to 227c4ed Compare September 19, 2024 14:41
@jperezdealgaba jperezdealgaba force-pushed the snyk-enhanced-version branch 2 times, most recently from e85b7e6 to 436e45f Compare September 19, 2024 15:16
@jperezdealgaba
Copy link
Author

@kdudka I updated the container image, I added the PROJECT_NVR and RECORD_EXCLUDED and updated the upload task

task/sast-snyk-check/0.3/sast-snyk-check.yaml Outdated Show resolved Hide resolved
task/sast-snyk-check/0.3/sast-snyk-check.yaml Outdated Show resolved Hide resolved
task/sast-snyk-check/0.3/sast-snyk-check.yaml Outdated Show resolved Hide resolved
task/sast-snyk-check/0.3/sast-snyk-check.yaml Outdated Show resolved Hide resolved
task/sast-snyk-check/0.3/README.md Outdated Show resolved Hide resolved
task/sast-snyk-check/0.3/MIGRATION.md Outdated Show resolved Hide resolved
task/sast-snyk-check/0.3/MIGRATION.md Outdated Show resolved Hide resolved
task/sast-snyk-check/0.3/MIGRATION.md Outdated Show resolved Hide resolved
task/sast-snyk-check/0.3/MIGRATION.md Outdated Show resolved Hide resolved
task/sast-snyk-check/0.3/sast-snyk-check.yaml Outdated Show resolved Hide resolved
task/sast-snyk-check/0.3/sast-snyk-check.yaml Show resolved Hide resolved
task/sast-snyk-check/0.3/sast-snyk-check.yaml Outdated Show resolved Hide resolved
grep -q "$SKIP_MSG" stdout.txt || test_not_skipped=$?

# In order to generate csdiff/v1, we need to add the whole path of the source code as Snyk only provides an URI to embed the context
csgrep --mode=json --prepend-path-prefix="$SOURCE_CODE_DIR"/ sast_snyk_check_out.json \
Copy link

Choose a reason for hiding this comment

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

I think the extra step with csgrep --prepend-path-prefix=... is unnecessary. It should be sufficient to run csgrep --embed-context=... in the correct directory:

(cd "$SOURCE_CODE_DIR" && csgrep --mode=json --embed-context=3 sast_snyk_check_out.json) \
    csgrep --mode=json --strip-path-prefix="source/"  \
    > sast_snyk_check_out_all_findings.json

Copy link
Author

Choose a reason for hiding this comment

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

Modified

Copy link
Author

Choose a reason for hiding this comment

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

Just in case, the path of the sast_snyk_check_out.json file was modified as it couldn't be found after we executed the commands on the SOURCE_CODE_DIR

Copy link

Choose a reason for hiding this comment

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

Right. I should have used an absolute path to the input file in my example.

task/sast-snyk-check/0.3/sast-snyk-check.yaml Outdated Show resolved Hide resolved
task/sast-snyk-check/0.3/sast-snyk-check.yaml Show resolved Hide resolved
@jperezdealgaba jperezdealgaba force-pushed the snyk-enhanced-version branch 4 times, most recently from 794512c to 8474024 Compare September 26, 2024 19:54
Solves: https://issues.redhat.com/browse/OSH-737

In this version, the severity-threshold argument is introduced and enabled by default to high and the results are parsed with csgrep to be uploaded with the fingerprint. Also, results are filtered using the newly introduced csfilter-kfp and KFP_GIT_URL variable and known false positives won't be shown.
| IMP_FINDINGS_ONLY | Report only important findings. Default is true. To report all findings, specify "false" | true | yes |
| KFP_GIT_URL | Link to the known-false-positives repository. If left blank, results won't be filtered | "" | no |
| PROJECT_NVR | Name-Version-Release (NVR) of the scanned project, used to find path exclusions (it is optional) | "" | no |
| RECORD_EXCLUDED | Write excluded records in file. Useful for debugging (it is optional). Default is "false" | false | no |
Copy link
Author

Choose a reason for hiding this comment

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

This doesn't match the description from the task parameter. I will update it in a bit...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants