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

chore: add provenance file handling into run_macaron.sh #698

Conversation

tromai
Copy link
Member

@tromai tromai commented Apr 10, 2024

Closes #697

@tromai tromai self-assigned this Apr 10, 2024
@tromai tromai requested a review from behnazh-w as a code owner April 10, 2024 03:53
@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Apr 10, 2024
@tromai tromai requested a review from nathanwn April 10, 2024 03:53
Copy link
Member

@nathanwn nathanwn left a comment

Choose a reason for hiding this comment

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

Thanks. LGTM.

@behnazh-w
Copy link
Member

@tromai Now that #685 is merged, can you please add a test to ingest the witness provenance and check the results in both integration_tests_docker.sh and integration_tests.sh?

@@ -439,6 +443,16 @@ if [[ -n "${arg_prov_exp:-}" ]]; then
fi
fi

# Determine the provenance expectation path to be mounted into ${MACARON_WORKSPACE}/prov_files/${pf_name} where pf_name is a file name.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# Determine the provenance expectation path to be mounted into ${MACARON_WORKSPACE}/prov_files/${pf_name} where pf_name is a file name.
# Mount the provenance file into ${MACARON_WORKSPACE}/prov_files/${pf_name} where pf_name is a file name.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in bf2f407

@nathanwn
Copy link
Member

Not a comment for this PR in particular, but a general comment: We should probably rethink where the expected result files should be stored. To me, it makes more sense to store all expected files for a particular test case in the same directory instead of scattering it through multiple different directories, making it hard to understand which expected file belongs to which test.

@tromai
Copy link
Member Author

tromai commented Apr 16, 2024

I will remove the --digest CLI input from the added integration test after #708 is merged.

@tromai tromai force-pushed the 697-update-run_macaronsh-to-mount-the-provenance-file-into-the-docker-container-file-system branch from 08ed216 to fc998db Compare April 18, 2024 23:42
@tromai
Copy link
Member Author

tromai commented Apr 19, 2024

@behnazh-w @nathanwn I have updated the integration test case:

  1. Remove the provided digest as input through --digest. With this move, we are hoping for the digest to be obtained from the provided witness provenance, combined with the repository path provided as input to form the main analysis target. (see 60d0cab).
  2. Update the policy file to enforce more check results in the test case (see b1bc20c)

For the 1. change, however, just removing the --digest from the run command of the integration test won't make Macaron behave as we expected. This is because for this test case scenario, these values are provided as input:

  • The witness provenance that only contains the commit hash
  • The path to the repository on local file system.
  • The PURL of the main target analysis.

This combination will be handled inside this block

case (_, _):
# If both the PURL and the repository are provided, we will use the user-provided repository path to
# create the ``Repository`` instance later on. This ``Repository`` instance is attached to the
# software component initialized from the user-provided PURL.
return Analyzer.AnalysisTarget(
parsed_purl=parsed_purl, repo_path=repo_path_input, branch=input_branch, digest=input_digest
)

However, its logic doesn't extract the commit hash from provenance, which leave Analyzer.AnalysisTarget.digest as empty. Therefore, when preparing the repository for the analysis, Macaron will try to find the commit from the given PURL here

if not digest and purl and purl.version:
found_digest = find_commit(git_obj, purl)
if not found_digest:
logger.error(
"Could not map the input purl string to a specific commit in the corresponding repository."
)
return None

which will fail because the target repository doesn't have any release on GitHub (see https://github.com/behnazh-w/example-maven-app/releases).
I have proposed a fix (see 82e241b) which make the test case work again. However, I am not sure that this fix is the best solution, and whether it's out of scope of this PR. There are other solutions:

  • Create releases on the example-maven-project repository so that the commit finder can work.
  • Still using --digest to provide digest for the integration test case and we don't need to fix anything in this PR. The fix for this issue can happen in a separated PR, together with the work on validating consistency of repo url and commit from multiple input sources.

Please let me know what you think.

@nicallen
Copy link
Member

@behnazh-w @nathanwn I have updated the integration test case:
... I have proposed a fix (see 82e241b) which make the test case work again. However, I am not sure that this fix is the best solution, and whether it's out of scope of this PR. ...

I think the proposed fix is the correct behaviour, but I think that commit should be separated into its own PR and merged prior to finishing this one (since it isn't really related to this change, more a continuation of #708 that happens to be a prerequisite for this one).

@nathanwn
Copy link
Member

nathanwn commented Apr 19, 2024

I have proposed a fix (see 82e241b) which make the test case work again.

In your fix, if I understand it right, the user-provided digest takes precedence over the commit in the provenance.
If this is as expected, then the fix looks OK to me.
One thing I realized from the fix: this final case branch here is not necessary and should be removed (duplicating the first case branch)

case _:
raise InvalidAnalysisTargetError(
"Cannot determine the analysis target: PURL and repository path are missing."
)

I agree with Nick that this should be in another PR. Do open it and I can approve it for you.

@tromai
Copy link
Member Author

tromai commented Apr 19, 2024

Thanks everyone! I will bring the fix commit to a difference Pull request shortly.

In your fix, if I understand it right, the user-provided digest takes precedence over the commit in the provenance.
If this is as expected, then the fix looks OK to me.

This is True, the digest provided from the user takes precedence.

One thing I realized from the fix: this final case branch here is not necessary and should be removed (duplicating the first case branch)

Yes this is True. I meant to put it there originally as a "default" case because mypy doesn't recognize that we have covered all possible cases.

@nathanwn
Copy link
Member

I now remember why the last case branch is necessary. It is related to the issue of mypy cannot type-narrow tuples correctly (seems to be recently fixed but not yet released).
We can keep it around I guess.

@tromai
Copy link
Member Author

tromai commented Apr 19, 2024

@nicallen @nathanwn Thanks for your feedback. I have created a Pull Request for fixing the issue here - #711. After that PR is merged, I will rebase and fix any conflicts here.

@tromai tromai force-pushed the 697-update-run_macaronsh-to-mount-the-provenance-file-into-the-docker-container-file-system branch from 82e241b to f3449a1 Compare April 21, 2024 23:38
@tromai tromai merged commit c9ed679 into staging Apr 22, 2024
9 checks passed
@tromai tromai deleted the 697-update-run_macaronsh-to-mount-the-provenance-file-into-the-docker-container-file-system branch April 22, 2024 00:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants