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

fix: container sarif replace colon within location uri #4670

Merged

Conversation

rmutuleanu
Copy link
Contributor

When using sarif as output and the Dockerfile is not specified, the path is used as the sarif results location uri (added with PR: #4649).

But the path can contain colon characters (e.g. between repo and tag) and GitHub Code Scanning seems to return an error in that case.

What does this PR do?

Replaces the colon characters from the sarif results location uri with underscore characters.

Issue: LUM-257

@rmutuleanu rmutuleanu force-pushed the fix/container-sarif-replace-colon-within-location-uri branch 2 times, most recently from e364a81 to 716ea88 Compare June 19, 2023 13:37
@rmutuleanu rmutuleanu marked this pull request as ready for review June 20, 2023 09:36
@rmutuleanu rmutuleanu requested review from a team as code owners June 20, 2023 09:36
@@ -5,7 +5,7 @@ describe('Retrieving sarif result', () => {
it('should use the test results path as the location uri when target file is not present', () => {
let result = getResults(
getTestResult({
path: 'alpine:3.18.0',
path: 'alpine',
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a bit confused, isn't this the input to the fix, and shouldn't that include the tag? doesn't it need to include the tag to get the below results? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, you are right, I've added 3 runs inside that test with different inputs each. I will split the test into 3 individual tests.

uri: testResult.displayTargetFile || testResult.path,
uri:
testResult.displayTargetFile ||
getArtifactLocationUriFromPath(testResult.path),
Copy link
Contributor

Choose a reason for hiding this comment

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

This path variable is weirdly named, I would think that an image name would rather be in displayTargetFile than in path....can we add a comment to explain that? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The displayTargetFile is what we are passing to the --file flag (i.e. Dockerfile in our case)

The test result path seem to be the image reference used and with an optional project name appended in some cases (e.g. alpine, alpine:3.18.0, alpine/kubernetes-monitor, last one has the project name appended)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can add a comment to explain this

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I think that would be nice 😅

@rmutuleanu rmutuleanu force-pushed the fix/container-sarif-replace-colon-within-location-uri branch 2 times, most recently from 351c74a to bb8c36c Compare June 20, 2023 14:30
Copy link
Contributor

@tommyknows tommyknows left a comment

Choose a reason for hiding this comment

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

Very nice! :)

@@ -42,3 +42,15 @@ export function getLevel(vuln: AnnotatedIssue) {
return 'note';
}
}

function getArtifactLocationUri(targetFile: string, path: string): string {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice solution, thanks!

@rmutuleanu rmutuleanu force-pushed the fix/container-sarif-replace-colon-within-location-uri branch from bb8c36c to a0c29cf Compare June 20, 2023 14:38
@rmutuleanu rmutuleanu force-pushed the fix/container-sarif-replace-colon-within-location-uri branch from a0c29cf to 20e6b97 Compare June 22, 2023 12:52
When using sarif output and the Dockerfile is not specified, the path is used as the sarif results location uri. But the path can contain colon characters (e.g. between repo and tag) and GitHub Code Scanning seems to return an error in this case. This fix replaces the colon characters from the sarif results location uri with underscore characters.

Issue: LUM-257
@rmutuleanu rmutuleanu force-pushed the fix/container-sarif-replace-colon-within-location-uri branch from 20e6b97 to 6b3e046 Compare June 23, 2023 06:25
@rmutuleanu rmutuleanu merged commit 7e422c0 into master Jun 23, 2023
11 checks passed
@rmutuleanu rmutuleanu deleted the fix/container-sarif-replace-colon-within-location-uri branch June 23, 2023 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants