generated from oracle/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 30
feat!: allow specifying the dependency depth resolution through CLI and make dependency resolution off by default #840
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
Merged
tromai
merged 16 commits into
staging
from
838-make-dependency-resolution-and-analysis-optional
Sep 25, 2024
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
7d99b17
chore: remove recursive option for deps resolution from ini config an…
5b1d50b
chore: add --deps-depth and make --skip-deps do nothing and turn off …
0052c45
chore: remove --skip-deps from existing integration test cases
558dd54
chore: modify case django_with_dep_resolution_virtual_env_as_input
2df09ac
chore: update integration test cases where direct dependencies are an…
89804e2
chore: add new integration test cases on invalid usage of --deps-depth
bbd7b58
chore: update Sphinx documentation
feab84f
chore: add a missing space
97f76ce
chore: fix inconsistent capitalisation
6f81633
chore: update all SBOM examples in using.rst to use --deps-depth=inf
eaf2275
chore: make the deprecated message for skip-deps in CLI consistent wi…
187a03c
chore: update the doc string for resolve_dependencies and collect_dep…
a49c3fc
chore: update doc string of get_deps_from_sbom and get_dep_components
190dc63
chore: disabling dependency analysis when provide venv or sbom is not…
8b6ceac
chore: remove remaining --skip-deps in tutorials and docs
87e7bb9
chore: add Python dep analysis to supported technologies page
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,7 +50,7 @@ To perform an analysis on Arrow, Macaron can be run with the following command: | |
|
|
||
| .. code-block:: shell | ||
|
|
||
| ./run_macaron.sh analyze -rp https://github.com/arrow-py/arrow --skip-deps | ||
| ./run_macaron.sh analyze -rp https://github.com/arrow-py/arrow | ||
|
|
||
| However, this will return results based only on the current state of the repository, which as described above, is not what we want to achieve in this tutorial. To perform analyses on other repository states, we need to provide Macaron with the target artifact versions in the form of `PURLs <https://github.com/package-url/purl-spec>`_, or Package URLs, which is a convenient way to encode packages from different ecosystems into the same format. | ||
|
|
||
|
|
@@ -67,7 +67,7 @@ We will start by running the analysis on the latest version, ``1.3.0``, with the | |
|
|
||
| .. code-block:: shell | ||
|
|
||
| ./run_macaron.sh analyze -purl pkg:pypi/[email protected] --skip-deps | ||
| ./run_macaron.sh analyze -purl pkg:pypi/[email protected] | ||
|
|
||
| The analysis involves Macaron downloading the contents of the target repository to the configured, or default, ``output`` folder. Results from the analysis, including checks, are stored in the database found at ``output/macaron.db`` (See :ref:`Output Files Guide <output_files_guide>`). Once the analysis is complete, Macaron will also produce a report in the form of a HTML file. | ||
|
|
||
|
|
@@ -101,7 +101,7 @@ Now we should run the next analysis, and then open the new report. | |
|
|
||
| .. code-block:: shell | ||
|
|
||
| ./run_macaron.sh analyze -purl pkg:pypi/[email protected] --skip-deps | ||
| ./run_macaron.sh analyze -purl pkg:pypi/[email protected] | ||
| open output/reports/pypi/arrow/arrow.html | ||
|
|
||
| .. _fig_arrow_0.15.0_top: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,7 +65,7 @@ First, we need to run the ``analyze`` command of Macaron to run a number of :ref | |
|
|
||
| .. code-block:: shell | ||
|
|
||
| ./run_macaron.sh analyze -purl pkg:pypi/[email protected] --skip-deps | ||
| ./run_macaron.sh analyze -purl pkg:pypi/[email protected] | ||
|
|
||
| .. note:: By default, Macaron clones the repositories and creates output files under the ``output`` directory. To understand the structure of this directory please see :ref:`Output Files Guide <output_files_guide>`. | ||
|
|
||
|
|
@@ -172,27 +172,17 @@ Let's assume ``/tmp/.django_venv`` is the virtual environment where ``[email protected] | |
|
|
||
| .. note:: If you want Macaron to analyze the virtual environment directly to identify the dependencies, we require Python 3.11 to be used to install the package. Alternatively, you can generate the SBOM as instructed :ref:`here <python-sbom>` and pass it to Macaron as input. | ||
|
|
||
| Run Macaron as follows to analyze ``django`` and its dependencies. | ||
| Run Macaron as follows to analyze ``django`` and its direct dependencies. | ||
|
|
||
| .. code-block:: shell | ||
|
|
||
| ./run_macaron.sh analyze -purl pkg:pypi/[email protected] --python-venv "/tmp/.django_venv" | ||
| ./run_macaron.sh analyze -purl pkg:pypi/[email protected] --python-venv "/tmp/.django_venv" --deps-depth=1 | ||
|
|
||
|
|
||
| By default Macaron only checks the direct dependencies. To turn on recursive dependency analysis, add the following to the ``configurations.ini`` file: | ||
|
|
||
| .. code-block:: ini | ||
|
|
||
| [dependency.resolver] | ||
| recursive = True | ||
|
|
||
| And pass that to the ``analyze`` command: | ||
| Or alternatively, run Macaron as follows to analyze ``django`` and all its transitive dependencies. | ||
|
|
||
| .. code-block:: shell | ||
|
|
||
| ./run_macaron.sh --defaults-path configurations.ini analyze -purl pkg:pypi/[email protected] --python-venv "/tmp/.django_venv" | ||
|
|
||
| To learn more about changing configurations see :ref:`here <change-config>`. | ||
| ./run_macaron.sh analyze -purl pkg:pypi/[email protected] --python-venv "/tmp/.django_venv" --deps-depth=inf | ||
|
|
||
| Now we can enforce the policy below to ensure that the ``mcn_detect_malicious_metadata_1`` check always passes on ``django`` and its dependencies, indicating that none of the dependencies have malicious behavior. | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,7 +37,7 @@ Normally, this is how you would run Macaron: | |
|
|
||
| .. code-block:: shell | ||
|
|
||
| ./run_macaron.sh analyze --package-url pkg:maven/io.micronaut/[email protected] --skip-deps | ||
| ./run_macaron.sh analyze --package-url pkg:maven/io.micronaut/[email protected] | ||
|
|
||
| However, there can be checks in Macaron that are not relevant for the ``io.micronaut/micronaut-core`` artifact. | ||
| For example, the ``mcn_provenance_witness_level_one_1`` check (defined in :class:`ProvenanceWitnessL1Check <macaron.slsa_analyzer.checks.provenance_witness_l1_check.ProvenanceWitnessL1Check>`) is not relevant because ``micronaut-projects/micronaut-core`` generates and publishes :term:`SLSA` provenances and no :term:`Witness` provenances. Therefore, we could exclude this check from running by performing the following steps. | ||
|
|
@@ -61,7 +61,7 @@ With these two configuration options, all checks except for the excluded ``mcn_p | |
|
|
||
| .. code-block:: shell | ||
|
|
||
| ./run_macaron.sh --defaults-path ./defaults.ini analyze --package-url pkg:maven/io.micronaut/[email protected] --skip-deps | ||
| ./run_macaron.sh --defaults-path ./defaults.ini analyze --package-url pkg:maven/io.micronaut/[email protected] | ||
|
|
||
| This time, the check ``mcn_provenance_witness_level_one_1`` doesn't run. After the ``analyze`` command finishes, we can view the data that Macaron has gathered about the ``micronaut-projects/micronaut-core`` repository at ``v4.3.10`` in an HTML report. Note that the result of the excluded check is not recorded in the Macaron HTML reports, JSON reports, or the database). | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,8 +47,7 @@ In order to verify the artifact with Macaron, you can follow the following steps | |
| ./run_macaron.sh analyze \ | ||
| --package-url pkg:maven/io.micronaut.openapi/[email protected]?type=jar \ | ||
| --provenance-file multiple.intoto.jsonl \ | ||
| --provenance-expectation expectation.cue \ | ||
| --skip-deps | ||
| --provenance-expectation expectation.cue | ||
|
|
||
| .. note:: | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,7 +42,7 @@ To perform an analysis on the latest version of semver (when this tutorial was w | |
|
|
||
| .. code-block:: shell | ||
|
|
||
| ./run_macaron.sh analyze -purl pkg:npm/[email protected] --skip-deps | ||
| ./run_macaron.sh analyze -purl pkg:npm/[email protected] | ||
|
|
||
| The analysis involves Macaron downloading the contents of the target repository to the configured, or default, ``output`` folder. Results from the analysis, including checks, are stored in the database found at ``output/macaron.db`` (See :ref:`Output Files Guide <output_files_guide>`). Once the analysis is complete, Macaron will also produce a report in the form of a HTML file. | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ Using Macaron | |
| Analyzing an artifact with a PURL string | ||
| ---------------------------------------- | ||
|
|
||
| Macaron can analyze an artifact (and its dependencies) to determine its supply chain security posture. To analyze an artifact, you need to provide the PURL identifier of the artifact: | ||
| Macaron can analyze an artifact to determine its supply chain security posture. To analyze an artifact, you need to provide the PURL identifier of the artifact: | ||
|
|
||
| .. code-block:: | ||
|
|
||
|
|
@@ -51,6 +51,7 @@ To run Macaron on an artifact, we use the following command: | |
|
|
||
| ./run_macaron.sh analyze -purl <artifact-purl> | ||
|
|
||
| Macaron can also analyze the package's dependencies. Please see :ref:`automate-deps-resolution`. | ||
|
|
||
| '''''''''''''''''''''''''''''''''''''' | ||
| Automated repository and commit finder | ||
|
|
@@ -79,6 +80,7 @@ Within the configuration file under the ``repofinder.java`` header, three option | |
| - ``repo_pom_paths`` (Values: List of POM tags) - Determines where to search for repository information in the POM files. E.g. scm.url. | ||
| - ``find_parents`` (Values: True or False) - When enabled, the Repository Finding feature will also search for repository URLs in parents POM files of the current dependency. | ||
|
|
||
| .. note:: Dependency related configurations like ``artifact_repositories`` or ``find_parents`` can affect :ref:`Macaron automatic dependency resolution <automate-deps-resolution>`. | ||
|
|
||
| .. note:: Finding repositories requires at least one remote call, adding some additional overhead to an analysis run. | ||
|
|
||
|
|
@@ -113,7 +115,7 @@ Analyzing a source code repository | |
| Analyzing a public GitHub repository | ||
| '''''''''''''''''''''''''''''''''''' | ||
|
|
||
| Macaron can also analyze a public GitHub repository (and potentially the repositories of its dependencies). | ||
| Macaron can also analyze a public GitHub repository. | ||
|
|
||
| To run Macaron on a GitHub public repository, we use the following command: | ||
|
|
||
|
|
@@ -135,14 +137,6 @@ For example, to analyze the SLSA posture of `micronaut-core <https://github.com/ | |
|
|
||
| ./run_macaron.sh analyze -rp https://github.com/micronaut-projects/micronaut-core -b 4.0.x -d 82d115b4901d10226552ac67b0a10978cd5bc603 | ||
|
|
||
| .. note:: Macaron automatically detects and analyzes **direct** dependencies for Java Maven and Gradle projects. This process might take a while and can be skipped by using the ``--skip-deps`` option. | ||
|
|
||
| Take the same example as above, to disable analyzing `micronaut-core <https://github.com/micronaut-projects/micronaut-core>`_ direct dependencies, we could use the following command: | ||
|
|
||
| .. code-block:: shell | ||
|
|
||
| ./run_macaron.sh analyze -rp https://github.com/micronaut-projects/micronaut-core -b 4.0.x -d 82d115b4901d10226552ac67b0a10978cd5bc603 --skip-deps | ||
|
|
||
| .. note:: By default, Macaron would generate report files into the ``output`` directory in the current working directory. To understand the structure of this directory please see :ref:`Output Files Guide <output_files_guide>`. | ||
|
|
||
| With the example above, the generated output reports can be seen here: | ||
|
|
@@ -242,7 +236,7 @@ workflows. | |
|
|
||
| .. code-block:: shell | ||
|
|
||
| ./run_macaron.sh analyze -pe micronaut-core.cue -rp https://github.com/micronaut-projects/micronaut-core -b 4.0.x -d 82d115b4901d10226552ac67b0a10978cd5bc603 --skip-deps | ||
| ./run_macaron.sh analyze -pe micronaut-core.cue -rp https://github.com/micronaut-projects/micronaut-core -b 4.0.x -d 82d115b4901d10226552ac67b0a10978cd5bc603 | ||
|
|
||
| where ``micronaut-core.cue`` file can contain: | ||
|
|
||
|
|
@@ -263,6 +257,32 @@ where ``micronaut-core.cue`` file can contain: | |
| .. note:: | ||
| The provenance expectation is verified via the ``provenance_expectation`` check in Macaron. You can see the result of this check in the HTML or JSON report and see if the provenance found by Macaron meets the expectation CUE file. | ||
|
|
||
| .. _automate-deps-resolution: | ||
|
|
||
| ------------------------------------ | ||
| Analyzing dependencies automatically | ||
| ------------------------------------ | ||
|
|
||
| Macaron supports automatically detecting and analyzing dependencies for certain types of projects (:ref:`supported_automatic_deps_resolution`). This feature is disabled by default and can be enabled with the CLI flag ``--deps-depth``. | ||
|
|
||
| The ``--deps-depth`` flag currently accepts these values: | ||
|
|
||
| * ``0``: Disable dependency resolution (Default). | ||
| * ``1``: Resolve and analyze direct dependencies. | ||
| * ``inf``: Resolve and analyze all transitive dependencies. | ||
|
|
||
| For example, to analyze `micronaut-core <https://github.com/micronaut-projects/micronaut-core>`_ and its **direct** dependencies, we could use the following command: | ||
|
|
||
| .. code-block:: shell | ||
|
|
||
| ./run_macaron.sh analyze \ | ||
| -rp https://github.com/micronaut-projects/micronaut-core \ | ||
| -b 4.0.x \ | ||
| -d 82d115b4901d10226552ac67b0a10978cd5bc603 \ | ||
| --deps-depth=1 | ||
|
|
||
| .. note:: This process might take a while. Alternatively, you can help Macaron by providing the dependencies information through : :ref:`an sbom <with-sbom>` or :ref:`a Python virtual environment <python-venv-deps>` (for Python packages only). | ||
|
|
||
| .. _with-sbom: | ||
|
|
||
| ---------------------- | ||
|
|
@@ -283,10 +303,12 @@ To run the analysis against that SBOM, run this command: | |
|
|
||
| .. code-block:: shell | ||
|
|
||
| ./run_macaron.sh analyze -purl pkg:maven/org.apache.maven/[email protected]?type=pom -sbom <path_to_sbom> | ||
| ./run_macaron.sh analyze -purl pkg:maven/org.apache.maven/[email protected]?type=pom -sbom <path_to_sbom> --deps-depth=inf | ||
|
|
||
| Where ``path_to_sbom`` is the path to the SBOM you want to use. | ||
|
|
||
| .. note:: Make sure to enable dependency resolution with ``--deps-depth``. | ||
|
|
||
| .. _python-sbom: | ||
|
|
||
| '''''''''''''''''''''''' | ||
|
|
@@ -305,7 +327,7 @@ Then run Macaron and pass the SBOM file as input: | |
|
|
||
| .. code-block:: shell | ||
|
|
||
| ./run_macaron.sh analyze -purl pkg:pypi/[email protected] -sbom <path_to_django_sbom.json> | ||
| ./run_macaron.sh analyze -purl pkg:pypi/[email protected] -sbom <path_to_django_sbom.json> --deps-depth=inf | ||
|
|
||
| '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' | ||
| Analyzing dependencies in the SBOM without the main software component | ||
|
|
@@ -320,7 +342,7 @@ Then the analysis can be run as follows: | |
|
|
||
| .. code-block:: shell | ||
|
|
||
| ./run_macaron.sh analyze -purl pkg:maven/private.apache.maven/[email protected]?type=pom -sbom <path_to_sbom> | ||
| ./run_macaron.sh analyze -purl pkg:maven/private.apache.maven/[email protected]?type=pom -sbom <path_to_sbom> --deps-depth=inf | ||
|
|
||
| Where ``path_to_sbom`` is the path to the SBOM you want to use. | ||
|
|
||
|
|
@@ -344,10 +366,12 @@ Then run Macaron as follows: | |
|
|
||
| .. code-block:: shell | ||
|
|
||
| ./run_macaron.sh analyze -purl pkg:pypi/[email protected] --python-venv "/tmp/.django_venv" | ||
| ./run_macaron.sh analyze -purl pkg:pypi/[email protected] --python-venv "/tmp/.django_venv" --deps-depth=1 | ||
|
|
||
| Where ``--python-venv`` is the path to virtual environment. | ||
|
|
||
| .. note:: Make sure to enable dependency resolution with ``--deps-depth``. | ||
|
|
||
| Alternatively, you can create an SBOM for the python package and provide it to Macaron as input as explained :ref:`here <with-sbom>`. | ||
|
|
||
| .. note:: We only support Python 3.11 for this feature of Macaron. Please make sure to install the package using this version of Python. | ||
|
|
@@ -396,7 +420,7 @@ We can run Macaron against the local repository at ``target`` by using this comm | |
|
|
||
| ./run_macaron.sh --local-repos-path ./boo/foo --defaults-path ./defaults.ini analyze --repo-path target <rest_of_args> | ||
|
|
||
| With ``rest_of_args`` being the arguments to the ``analyze`` command (e.g. ``--branch/-b``, ``--digest/-d`` or ``--skip-deps`` similar to two previous examples). | ||
| With ``rest_of_args`` being the arguments to the ``analyze`` command (e.g. ``--branch/-b``, ``--digest/-d`` similar to two previous examples). | ||
|
|
||
| The ``--local-repos-path/-lr`` flag tells Macaron to look into ``./boo/foo`` for local repositories. For more information, please see :ref:`Command Line Usage <cli-usage>`. | ||
|
|
||
|
|
@@ -422,7 +446,7 @@ We can run Macaron against the local repository at ``target`` by using this comm | |
|
|
||
| ./run_macaron.sh --local-repos-path ./boo/foo analyze --repo-path target <rest_of_args> | ||
|
|
||
| With ``rest_of_args`` being the arguments to the ``analyze`` command (e.g. ``--branch/-b``, ``--digest/-d`` or ``--skip-deps`` similar to two previous examples). | ||
| With ``rest_of_args`` being the arguments to the ``analyze`` command (e.g. ``--branch/-b``, ``--digest/-d`` similar to two previous examples). | ||
|
|
||
| The ``--local-repos-path/-lr`` flag tells Macaron to look into ``./boo/foo`` for local repositories. For more information, please see :ref:`Command Line Usage <cli-usage>`. | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.