generated from oracle/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 30
docs: add exclude include check feature tutorial #667
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 12 commits into
staging
from
661-add-a-tutorial-to-showcase-the-new-check-include-exclude-feature
Mar 15, 2024
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8e593b6
docs: add exclude include check feature tutorial
7da9505
chore: remove unecessary installation guide from presequisite
2d78fc7
chore: use a fixed path for the defaults.ini the example commands; ch…
b578153
chore: add eventual effect of the exclude/include configuration in th…
44541c9
chore: bring the note of default Macaron running all checks to the to…
f72fc8e
chore: fix grammar errors
3eed119
chore: update malformed PURL in the example
d7273be
chore: add an example for disabling a subset of checks
75cf547
chore: minor fix
2389ea3
chore: more minor fixes
dc0940b
chore: change not applicable to not relevant in the example
fab4153
chore: change repo PURL to Maven PURL in the example and upate the HT…
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| .. Copyright (c) 2024 - 2024, Oracle and/or its affiliates. All rights reserved. | ||
| .. Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/. | ||
|
|
||
| ===================================== | ||
| Exclude and include checks in Macaron | ||
| ===================================== | ||
|
|
||
| .. note:: | ||
|
|
||
| This feature is only available from Macaron 0.8.0 | ||
|
|
||
| This tutorial will show how you can configure Macaron to: | ||
|
|
||
| * exclude checks that you don't want to run. | ||
| * include only checks that you want to run. | ||
|
|
||
| .. note:: | ||
|
|
||
| By default, Macaron will run all of its checks. | ||
|
|
||
| ------------- | ||
| Prerequisites | ||
| ------------- | ||
|
|
||
| * You are expected to have gone through :ref:`this tutorial <detect-malicious-java-dep>`. | ||
| * This tutorial requires a high-level understanding of checks in Macaron and how they depend on each other. Please see this :ref:`page <macaron-developer-guide>` for more information. | ||
|
|
||
| ------------------ | ||
| Motivating example | ||
| ------------------ | ||
|
|
||
| Let's say you want to run the analysis on Maven artifact ``io.micronaut/micronaut-core`` version ``4.3.10``. | ||
|
|
||
| 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 | ||
|
|
||
| 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. | ||
|
|
||
| 1. In your current directory, create a ``defaults.ini`` configuration file with the following content. | ||
|
|
||
| .. code-block:: ini | ||
|
|
||
| [analysis.checks] | ||
| exclude = mcn_provenance_witness_level_one_1 | ||
| include = * | ||
|
|
||
| In the ini configuration above: | ||
|
|
||
| * The ``exclude`` option contains the check ID ``mcn_provenance_witness_level_one_1``. The check with this ID will be excluded. | ||
| * The ``include`` option contains the `glob <https://docs.python.org/3/library/glob.html>`_ pattern ``*``. Checks with IDs matching this glob pattern will be included in the analysis. In this case, ``*`` matches all check IDs. | ||
|
|
||
| With these two configuration options, all checks except for the excluded ``mcn_provenance_witness_level_one_1`` will run. | ||
|
|
||
| 2. Run Macaron analyze by providing the path to the custom ``defaults.ini`` configuration. | ||
|
|
||
| .. code-block:: shell | ||
|
|
||
| ./run_macaron.sh --defaults-path ./defaults.ini analyze --package-url pkg:maven/io.micronaut/[email protected] --skip-deps | ||
|
|
||
| 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). | ||
|
|
||
| .. code-block:: shell | ||
|
|
||
| open output/reports/maven/io_micronaut/micronaut-core/micronaut-core.html | ||
|
|
||
| .. _fig_exclude_provenance_withness_level_one: | ||
|
|
||
|
|
||
| .. figure:: ../../_static/images/exclude_provenance_withness_level_one.png | ||
| :alt: Check results for ``io.micronaut/micronaut-core`` version ``4.3.10`` with witness provenance check excluded | ||
| :align: center | ||
|
|
||
|
|
||
| ------------------------------------------------ | ||
| Configuring exclude/include checks in ini config | ||
| ------------------------------------------------ | ||
|
|
||
| You can configure the exclusion and inclusion of checks through the ``[analysis.checks]`` section in the ``defaults.ini`` file. These are the defaults values: | ||
|
|
||
| .. code-block:: ini | ||
|
|
||
| [analysis.checks] | ||
| # By default, we don't exclude any checks. | ||
| exclude = | ||
| # By default, we run all checks available. | ||
| include = * | ||
|
|
||
| The ``exclude`` and ``include`` options accept a list of strings (terminated by new lines). Each element in that list can either be: | ||
|
|
||
| * An ID of a check | ||
| * A glob pattern (similar to patterns used in `glob <https://docs.python.org/3/library/glob.html>`_). When a glob pattern is given, all check IDs that match it will be included in the corresponding ``exclude`` or ``include`` list. | ||
|
|
||
| The two lists of ``exclude`` and ``include`` check IDs obtained from your configuration can be defined as: | ||
|
|
||
| * ``EXPLICIT_EXCLUDE`` = checks excluded from the user configuration. | ||
| * ``EXPLICIT_INCLUDE`` = checks included from the user configuration. | ||
|
|
||
| Checks in Macaron depend on each other. Therefore, when you want to exclude/include a check, you must be aware of how that will affect its transitive children/parents: | ||
|
|
||
| * If a check is excluded, all of the children which can be transitively reached from it will be excluded. | ||
| * If a check is included, all of the parents which can be transitively reached from it will be included. | ||
|
|
||
| We define the list of check IDs after extending to transitive parents/children as: | ||
|
|
||
| * ``EFFECTIVE_INCLUDED`` = ``EXPLICIT_INCLUDE`` set plus transitive parents | ||
| * ``EFFECTIVE_EXCLUDED`` = ``EXPLICIT_EXCLUDE`` set plus transitive children | ||
|
|
||
| The final list of checks that will run can be defined as: | ||
|
|
||
| * ``FINAL_INCLUDED`` = ``EFFECTIVE_INCLUDED`` minus ``EFFECTIVE_EXCLUDED`` | ||
|
|
||
| ------------- | ||
| More examples | ||
| ------------- | ||
|
|
||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
| Not running any check | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
| The following configurations will result in no check running and Macaron will return on error. | ||
|
|
||
| .. code-block:: ini | ||
|
|
||
| [analysis.checks] | ||
| exclude = * | ||
| include = * | ||
|
|
||
| .. code-block:: ini | ||
|
|
||
| [analysis.checks] | ||
| exclude = | ||
| include = | ||
|
|
||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
| Run a subset of checks | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| .. code-block:: ini | ||
|
|
||
| [analysis.checks] | ||
| exclude = | ||
| include = | ||
| mcn_provenance_witness_level_one_1 | ||
| mcn_trusted_builder_level_three_1 | ||
|
|
||
| This will result in ``mcn_provenance_witness_level_one_1``, ``mcn_trusted_builder_level_three_1``, and their transitive parents running. | ||
|
|
||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| Disable a subset of checks | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| .. code-block:: ini | ||
|
|
||
| [analysis.checks] | ||
| exclude = | ||
| mcn_provenance_witness_level_one_1 | ||
| mcn_trusted_builder_level_three_1 | ||
| include = * | ||
|
|
||
| This will result in ``mcn_provenance_witness_level_one_1``, ``mcn_trusted_builder_level_three_1``, and their transitive children not running. | ||
|
|
||
nathanwn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| Only run checks whose ID starts with ``mcn_build_*`` | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| .. code-block:: ini | ||
|
|
||
| [analysis.checks] | ||
| exclude = | ||
| include = | ||
| mcn_build_* | ||
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
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.