Skip to content

Commit 7916aaf

Browse files
authored
docs(misconf): Add information about selectors (#3703)
Signed-off-by: Simar <[email protected]>
1 parent 1b1ed39 commit 7916aaf

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Input Selectors
2+
3+
## Overview
4+
Sometimes you might want to limit a certain policy to only be run on certain resources. This can be
5+
achieved with input selectors.
6+
7+
## Use case
8+
For instance, if you have a custom policy that you only want to be evaluated if a certain resource type is being scanned.
9+
In such a case you could utilize input selectors to limit its evaluation on only those resources.
10+
11+
!!! example
12+
```
13+
# METADATA
14+
# title: "RDS Publicly Accessible"
15+
# description: "Ensures RDS instances are not launched into the public cloud."
16+
# custom:
17+
# input:
18+
# selector:
19+
# - type: cloud
20+
# subtypes:
21+
# - provider: aws
22+
# service: rds
23+
package builtin.aws.rds.aws0999
24+
25+
deny[res] {
26+
instance := input.aws.rds.instances[_]
27+
instance.publicaccess.value
28+
res := result.new("Instance has Public Access enabled", instance.publicaccess)
29+
```
30+
31+
Observe the following `subtypes` defined:
32+
```yaml
33+
# subtypes:
34+
# - provider: aws
35+
# service: rds
36+
```
37+
38+
They will ensure that the policy is only run when the input to such a policy contains an `RDS` instance.
39+
40+
## Enabling selectors and subtypes
41+
Currently, the following are supported:
42+
43+
| Selector | Subtype fields required | Example |
44+
|--------------------------|-------------------------|---------------------------------|
45+
| Cloud (AWS, Azure, etc.) | `provider`, `service` | `provider: aws`, `service: rds` |
46+
| Kubernetes | | `type: kubernetes` |
47+
| Dockerfile | | `type: dockerfile` |
48+
49+
50+
## Default behaviour
51+
If no subtypes or selectors are specified, the policy will be evaluated regardless of input.

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ nav:
7171
- Overview: docs/misconfiguration/custom/index.md
7272
- Data: docs/misconfiguration/custom/data.md
7373
- Combine: docs/misconfiguration/custom/combine.md
74+
- Selectors: docs/misconfiguration/custom/selectors.md
7475
- Schemas: docs/misconfiguration/custom/schema.md
7576
- Testing: docs/misconfiguration/custom/testing.md
7677
- Debugging Policies: docs/misconfiguration/custom/debug.md

0 commit comments

Comments
 (0)