Comment on page
rules.yml
The
rules.yml
configuration file contains expressions used by the lstn policy engine. When used in a CI workflow, it allows you to block or ignore certain behaviours in your dependency tree based on their priority levels or activity.Each rule in
rules.yml
is defined by a name
, a query
, and an optional behavior
. - The
name
field specifies a name for the rule. - The
query
field specifies a jq expression applied the output of lstn command for which the rule is applied. - The
behavior
field specifies the action to take when the rule is triggered. Ifbehavior
is not specified, the default action is to block.
The
name
attribute is used to uniquely identify each rule. It is a string value.The
query
attribute is a jq
expression that specifies the criteria for filtering verdicts. You can filter verdicts based on attributes such as priority level, message content, and metadata.The
behavior
attribute determines the action to take for verdicts that match the rule. The possible values are:- "block": Block the verdict (default behavior if not specified).
- "ignore": Ignore the verdict and take no action.
- Priority-based rules can be triggered depending on the output in the
priority
field of lstn verdicts. This can be eitherlow
,medium
orcritical
. For example, the providedblock_priority_critical
rule applies to verdicts with a priority level of "critical", and blocks CI in case it is detected. - Activity-based rules can be triggered depending on the output in the
message
field of lstn verdicts. An example of a message isnpm install spawned a process
. For example, the providedblock_network_connection
rule applies to verdicts with a message of "unexpected outbound connection destination", and blocks CI in case it is detected.
To use these rules in the
lstn
CI workflow:- 1.Make sure you have added the policy step in your
.yml
workflow file in GitHub: - 2.Create a YAML configuration file called
rules.yml
in your repository's root - 3.Add the code block provided below depending on the rules you want to include.
rules:
- name: block_priority_medium
query: .[] | select(.verdicts[]?.priority == "medium")
- name: ignore_priority_medium
query: .[] | select(.verdicts[]?.priority == "medium")
behavior: ignore
- name: block_priority_critical
query: .[] | select(.verdicts[]?.priority == "critical")
- name: block_network_connection
query: .[] | .verdicts[]? | select(.message == "unexpected outbound connection destination")
- name: ignore_network_connection
query: .[] | .verdicts[] | select(.message == "unexpected outbound connection destination")
behavior: ignore
- name: block_process_spawn
query: .[] | .verdicts[]? | select(.message == "npm install spawned a process")
- name: ignore_process_spawn
query: .[] | .verdicts[]? | select(.message == "npm install spawned a process")
behavior: ignore
Last modified 8mo ago