Skip to content

Commit 417fb2d

Browse files
committed
add docs on policy expression
Signed-off-by: Vivek Kumar Sahu <vivekkumarsahu650@gmail.com>
1 parent 9861b7c commit 417fb2d

2 files changed

Lines changed: 92 additions & 0 deletions

File tree

docs/commands/policy.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,71 @@ policy:
147147
- **Multiple values/patterns in a rule**: Combined with **OR** (any value passes)
148148
- **Multiple actual values**: For whitelist, ALL must match; for blacklist, NONE must match
149149
150+
### `values` vs `patterns`
151+
152+
Rules can use either (or both) `values` and `patterns`:
153+
154+
| Option | Matching Type | Use Case | Example |
155+
|--------|--------------|----------|---------|
156+
| `values` | **Exact string match** | Specific versions, exact license IDs | `MIT`, `Apache-2.0`, `log4j-core-2.17.1` |
157+
| `patterns` | **Regular expression** | License families, version ranges, naming conventions | `GPL-.*`, `.*-SNAPSHOT`, `log4j-1\..*` |
158+
159+
#### Using `values` (Exact Match)
160+
161+
Use for precise matching when you know the exact values:
162+
163+
```yaml
164+
rules:
165+
- field: license
166+
values:
167+
- MIT
168+
- Apache-2.0
169+
- BSD-3-Clause
170+
```
171+
172+
#### Using `patterns` (Regex Match)
173+
174+
Use for matching **groups** or **families** of values:
175+
176+
```yaml
177+
rules:
178+
- field: license
179+
patterns:
180+
- "^GPL-.*" # Any GPL variant (starts with "GPL-")
181+
- "^LGPL-.*" # Any LGPL variant
182+
- "^AGPL-.*" # Any AGPL variant
183+
```
184+
185+
**Common Regex Patterns:**
186+
187+
| Pattern | Matches | Example Values |
188+
|---------|---------|----------------|
189+
| `^GPL-.*` | GPL variants (start with "GPL-") | `GPL-2.0`, `GPL-3.0-only` |
190+
| `.*-SNAPSHOT` | Snapshot versions | `1.0.0-SNAPSHOT`, `2.1-SNAPSHOT` |
191+
| `log4j-1\..*` | Log4j 1.x versions | `log4j-1.2.17`, `log4j-1.2.19` |
192+
| `log4j-core-2\.1[0-6]\..*` | Log4j vulnerable (2.10-2.16) | `log4j-core-2.14.0` |
193+
| `^Apache-.*` | Apache licenses | `Apache-2.0`, `Apache-1.1` |
194+
195+
> **Note:** The `^` anchor ensures the match is at the **start** of the string. Without it, `GPL-.*` would also match `MIT OR GPL-2.0`.
196+
197+
#### Combining `values` and `patterns`
198+
199+
You can use both together (combined with OR):
200+
201+
```yaml
202+
rules:
203+
- field: license
204+
values:
205+
- SSPL-1.0
206+
- CC-BY-SA-4.0
207+
patterns:
208+
- "^GPL-.*"
209+
- "^LGPL-.*"
210+
- "^AGPL-.*"
211+
```
212+
213+
This blocks: All GPL/LGPL/AGPL variants, plus SSPL-1.0 and CC-BY-SA-4.0.
214+
150215
## Examples
151216

152217
### From Policy File

docs/guides/policy.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,33 @@ Each rule contains:
6868
- **Multiple rules in a policy** → combined with **AND** (all must pass)
6969
- **Multiple values/patterns in a rule** → combined with **OR** (any value passes)
7070

71+
### `values` vs `patterns`
72+
73+
Rules can match using either exact values or regex patterns:
74+
75+
| Option | Matching | Best For | Examples |
76+
|--------|----------|----------|----------|
77+
| `values` | Exact string match | Specific known values | `MIT`, `Apache-2.0`, `log4j-2.17.1` |
78+
| `patterns` | Regular expressions | Groups, families, ranges | `^GPL-.*`, `.*-SNAPSHOT` |
79+
80+
**Example - Using values (exact match):**
81+
```yaml
82+
rules:
83+
- field: license
84+
values: [MIT, Apache-2.0] # Only these exact values
85+
```
86+
87+
**Example - Using patterns (regex):**
88+
```yaml
89+
rules:
90+
- field: license
91+
patterns:
92+
- "^GPL-.*" # All GPL variants
93+
- "^LGPL-.*" # All LGPL variants
94+
```
95+
96+
> **Tip:** Use `^` at the start of patterns to match from the beginning. `^GPL-.*` matches `GPL-2.0` but NOT `MIT OR GPL-2.0`.
97+
7198
## Policy Types
7299

73100
The type defines **how rules are interpreted**:

0 commit comments

Comments
 (0)