Skip to content

Commit c19064b

Browse files
author
Trong Nhan Mai
authored
docs: add exclude include check feature tutorial (#667)
Signed-off-by: Trong Nhan Mai <[email protected]>
1 parent 44dbf0a commit c19064b

File tree

5 files changed

+179
-0
lines changed

5 files changed

+179
-0
lines changed
343 KB
Loading

docs/source/pages/developers_guide/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
.. Copyright (c) 2023 - 2024, Oracle and/or its affiliates. All rights reserved.
22
.. Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/.
33
4+
.. _macaron-developer-guide:
5+
46
=========================
57
Macaron Developer's Guide
68
=========================

docs/source/pages/tutorials/detect_malicious_java_dep.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
.. Copyright (c) 2024 - 2024, Oracle and/or its affiliates. All rights reserved.
22
.. Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/.
33
4+
.. _detect-malicious-java-dep:
5+
46
------------------------------------------------------------------------
57
Detecting a malicious Java dependency uploaded manually to Maven Central
68
------------------------------------------------------------------------
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
.. Copyright (c) 2024 - 2024, Oracle and/or its affiliates. All rights reserved.
2+
.. Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/.
3+
4+
=====================================
5+
Exclude and include checks in Macaron
6+
=====================================
7+
8+
.. note::
9+
10+
This feature is only available from Macaron 0.8.0
11+
12+
This tutorial will show how you can configure Macaron to:
13+
14+
* exclude checks that you don't want to run.
15+
* include only checks that you want to run.
16+
17+
.. note::
18+
19+
By default, Macaron will run all of its checks.
20+
21+
-------------
22+
Prerequisites
23+
-------------
24+
25+
* You are expected to have gone through :ref:`this tutorial <detect-malicious-java-dep>`.
26+
* 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.
27+
28+
------------------
29+
Motivating example
30+
------------------
31+
32+
Let's say you want to run the analysis on Maven artifact ``io.micronaut/micronaut-core`` version ``4.3.10``.
33+
34+
Normally, this is how you would run Macaron:
35+
36+
.. code-block:: shell
37+
38+
./run_macaron.sh analyze --package-url pkg:maven/io.micronaut/[email protected] --skip-deps
39+
40+
However, there can be checks in Macaron that are not relevant for the ``io.micronaut/micronaut-core`` artifact.
41+
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.
42+
43+
1. In your current directory, create a ``defaults.ini`` configuration file with the following content.
44+
45+
.. code-block:: ini
46+
47+
[analysis.checks]
48+
exclude = mcn_provenance_witness_level_one_1
49+
include = *
50+
51+
In the ini configuration above:
52+
53+
* The ``exclude`` option contains the check ID ``mcn_provenance_witness_level_one_1``. The check with this ID will be excluded.
54+
* 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.
55+
56+
With these two configuration options, all checks except for the excluded ``mcn_provenance_witness_level_one_1`` will run.
57+
58+
2. Run Macaron analyze by providing the path to the custom ``defaults.ini`` configuration.
59+
60+
.. code-block:: shell
61+
62+
./run_macaron.sh --defaults-path ./defaults.ini analyze --package-url pkg:maven/io.micronaut/[email protected] --skip-deps
63+
64+
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).
65+
66+
.. code-block:: shell
67+
68+
open output/reports/maven/io_micronaut/micronaut-core/micronaut-core.html
69+
70+
.. _fig_exclude_provenance_withness_level_one:
71+
72+
73+
.. figure:: ../../_static/images/exclude_provenance_withness_level_one.png
74+
:alt: Check results for ``io.micronaut/micronaut-core`` version ``4.3.10`` with witness provenance check excluded
75+
:align: center
76+
77+
78+
------------------------------------------------
79+
Configuring exclude/include checks in ini config
80+
------------------------------------------------
81+
82+
You can configure the exclusion and inclusion of checks through the ``[analysis.checks]`` section in the ``defaults.ini`` file. These are the defaults values:
83+
84+
.. code-block:: ini
85+
86+
[analysis.checks]
87+
# By default, we don't exclude any checks.
88+
exclude =
89+
# By default, we run all checks available.
90+
include = *
91+
92+
The ``exclude`` and ``include`` options accept a list of strings (terminated by new lines). Each element in that list can either be:
93+
94+
* An ID of a check
95+
* 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.
96+
97+
The two lists of ``exclude`` and ``include`` check IDs obtained from your configuration can be defined as:
98+
99+
* ``EXPLICIT_EXCLUDE`` = checks excluded from the user configuration.
100+
* ``EXPLICIT_INCLUDE`` = checks included from the user configuration.
101+
102+
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:
103+
104+
* If a check is excluded, all of the children which can be transitively reached from it will be excluded.
105+
* If a check is included, all of the parents which can be transitively reached from it will be included.
106+
107+
We define the list of check IDs after extending to transitive parents/children as:
108+
109+
* ``EFFECTIVE_INCLUDED`` = ``EXPLICIT_INCLUDE`` set plus transitive parents
110+
* ``EFFECTIVE_EXCLUDED`` = ``EXPLICIT_EXCLUDE`` set plus transitive children
111+
112+
The final list of checks that will run can be defined as:
113+
114+
* ``FINAL_INCLUDED`` = ``EFFECTIVE_INCLUDED`` minus ``EFFECTIVE_EXCLUDED``
115+
116+
-------------
117+
More examples
118+
-------------
119+
120+
^^^^^^^^^^^^^^^^^^^^^
121+
Not running any check
122+
^^^^^^^^^^^^^^^^^^^^^
123+
The following configurations will result in no check running and Macaron will return on error.
124+
125+
.. code-block:: ini
126+
127+
[analysis.checks]
128+
exclude = *
129+
include = *
130+
131+
.. code-block:: ini
132+
133+
[analysis.checks]
134+
exclude =
135+
include =
136+
137+
^^^^^^^^^^^^^^^^^^^^^^
138+
Run a subset of checks
139+
^^^^^^^^^^^^^^^^^^^^^^
140+
141+
.. code-block:: ini
142+
143+
[analysis.checks]
144+
exclude =
145+
include =
146+
mcn_provenance_witness_level_one_1
147+
mcn_trusted_builder_level_three_1
148+
149+
This will result in ``mcn_provenance_witness_level_one_1``, ``mcn_trusted_builder_level_three_1``, and their transitive parents running.
150+
151+
^^^^^^^^^^^^^^^^^^^^^^^^^^
152+
Disable a subset of checks
153+
^^^^^^^^^^^^^^^^^^^^^^^^^^
154+
155+
.. code-block:: ini
156+
157+
[analysis.checks]
158+
exclude =
159+
mcn_provenance_witness_level_one_1
160+
mcn_trusted_builder_level_three_1
161+
include = *
162+
163+
This will result in ``mcn_provenance_witness_level_one_1``, ``mcn_trusted_builder_level_three_1``, and their transitive children not running.
164+
165+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
166+
Only run checks whose ID starts with ``mcn_build_*``
167+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
168+
169+
.. code-block:: ini
170+
171+
[analysis.checks]
172+
exclude =
173+
include =
174+
mcn_build_*

docs/source/pages/tutorials/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ For the full list of supported technologies, such as CI services, registries, an
1919

2020
detect_malicious_java_dep
2121
commit_finder
22+
exclude_include_checks

0 commit comments

Comments
 (0)