> ## Documentation Index
> Fetch the complete documentation index at: https://docs.plerion.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Custom checks

> Write your own detection rules in Rego, preview their findings, and run them across your cloud integrations alongside Plerion's built-in checks

With **[Custom checks](https://app.plerion.com/settings/custom-checks)**, you can turn your own security rules into findings. You write a rule as a policy in [Rego](https://www.openpolicyagent.org/docs/latest/policy-language/), the policy language of Open Policy Agent (OPA). Plerion runs it against the assets it collects from your cloud integrations. Use custom checks for rules only your organization has, such as required tags, approved accounts, or naming standards.

***

## How custom checks work

A custom check has three parts:

* **Primary asset type**: The kind of asset the check judges, such as `AWS::S3::Bucket` or `GCP::Storage::Bucket`. Each finding belongs to one asset of this type.
* **Additional asset types** *(optional)*: Other asset types the policy can read, for rules that look across assets. For example, a check on Lambda functions can also read IAM roles.
* **Policy**: Rego code that receives the assets and returns a verdict for each one it judges: `FAILED` or `PASSED`.

Every verdict becomes a finding. Custom check findings appear in the [Findings dashboard](https://docs.plerion.com/guides/platform/findings-overview.md) next to Plerion's own findings, with a **Custom** badge and the check's slug as their name.

Plerion runs a check:

* As soon as you publish it, and again each time you change it.
* After every scan of each integration from the matching cloud provider.
* Within minutes of a change to a target asset, when [continuous scanning](https://docs.plerion.com/guides/integrations/aws/additional-aws-configurations/continuous-scanning.md) is on.

A check sees the assets of one integration at a time, so a rule never compares assets across two cloud accounts.

To see the custom checks page, your role needs the `CustomCheck:Read` permission. To create, change, preview, or delete checks, it needs `CustomCheck:Modify`.

***

## Steps to create a custom check

This walkthrough builds a check that fails every S3 bucket without all four [S3 Block Public Access](https://docs.aws.amazon.com/AmazonS3/latest/userguide/access-control-block-public-access.html) settings. Buckets tagged `PublicAccess=approved` are left out.

**1. Go to Settings > Custom checks**

The page lists every custom check in the tenant with its asset type, default severity, run status, and number of findings. Click `New check`.

![Custom checks page listing two checks with their asset type, severity, status, findings count, and author, and the New check button](https://mintcdn.com/pleriondocs/mO8NL1n6N85tC9Q5/images/product/custom-checks/01-list.jpg?fit=max\&auto=format\&n=mO8NL1n6N85tC9Q5\&q=85\&s=c306f2b8b815af5a0383d08197bd98f3)

**2. Start from an example (optional)**

To begin from a working policy, pick one under **Examples**. The example fills in the whole form, which you can then change. The examples are:

* **Match every asset (test)**: Fails every asset of the chosen type. Use it to see findings flow end to end before you write real logic.
* **OIDC trust constraint — GitHub Actions**: Fails IAM roles that trust GitHub Actions without limiting which repository can assume them.
* **S3 buckets must have versioning + KMS encryption**: Fails buckets missing either control.
* **EBS volumes must be encrypted**: Fails unencrypted EBS volumes.

![Examples section with the Start from an example dropdown](https://mintcdn.com/pleriondocs/mO8NL1n6N85tC9Q5/images/product/custom-checks/02-examples.jpg?fit=max\&auto=format\&n=mO8NL1n6N85tC9Q5\&q=85\&s=67bb2cbf4cc9d93c2dcc5aec60a8d9fb)

**3. Fill in the details**

* **Title**: What the check enforces, written as a rule. For example, `S3 buckets must block public access`.
* **Slug**: A short ID shown on findings and in exports. Plerion fills it in from the title. Use lowercase letters, numbers, and hyphens. The slug must be unique in the tenant.
* **Description** *(optional)*: More detail on what the check enforces and why.
* **Default severity**: The severity of each finding, unless the policy sets one: **Informational**, **Low**, **Medium**, **High**, or **Critical**.
* **Default remediation** *(optional)*: How to fix a failing asset. It's shown on the check's failed findings.

![Details section filled in with title, slug, description, S3 Bucket as the primary asset type, High default severity, and a default remediation](https://mintcdn.com/pleriondocs/mO8NL1n6N85tC9Q5/images/product/custom-checks/03-details.jpg?fit=max\&auto=format\&n=mO8NL1n6N85tC9Q5\&q=85\&s=91142d8e473a1583553a5c38c4fe0fc4)

**4. Choose the asset types**

In **Primary asset type**, search by name or type and pick the type the check judges. Here, it's **S3 Bucket** (`AWS::S3::Bucket`). The list covers every asset type Plerion collects across AWS, Azure, and GCP.

If the policy needs other assets, add their types in **Additional asset types**. Plerion collects these from the same cloud account.

![Asset type search showing S3 and GCP bucket types for the search term bucket](https://mintcdn.com/pleriondocs/mO8NL1n6N85tC9Q5/images/product/custom-checks/04-asset-type.jpg?fit=max\&auto=format\&n=mO8NL1n6N85tC9Q5\&q=85\&s=50a70a674476b30eecaf966ac6535ec8)

**5. Write the policy**

Enter the policy in the **Rego policy** editor. This one returns a failed verdict for each bucket with a Block Public Access setting turned off, and names the settings in the finding's message:

```rego theme={"system"}
package custom

settings := ["BlockPublicAcls", "IgnorePublicAcls", "BlockPublicPolicy", "RestrictPublicBuckets"]

default result := []

result := [{
	"id": bucket.id,
	"status": "FAILED",
	"message": sprintf("Public access block settings off: %s", [concat(", ", off)]),
} |
	bucket := input.assets[_]
	not approved_public(bucket)
	off := [name | name := settings[_]; not bucket.data.PublicAccessBlockConfiguration[name]]
	count(off) > 0
]

# Buckets tagged PublicAccess=approved are allowed to be public.
approved_public(bucket) if {
	some tag in bucket.meta.resource.providerTags
	tag.Key == "PublicAccess"
	tag.Value == "approved"
}
```

A bucket with no Block Public Access configuration at all fails on all four settings. That's because `not` is true when a field is missing.

![Rego policy editor showing the S3 Block Public Access policy](https://mintcdn.com/pleriondocs/mO8NL1n6N85tC9Q5/images/product/custom-checks/05-rego.jpg?fit=max\&auto=format\&n=mO8NL1n6N85tC9Q5\&q=85\&s=5073039a114600cb55882513f191fafd)

**6. Preview the findings**

Under **Preview**, pick an integration in **Run against integration** and click `Run preview`. Plerion runs the policy against the assets from that integration's latest scan and shows the findings it would create. Nothing is saved.

If the policy has an error, the preview shows the error and the line it's on. If it produces no findings, check the asset type, the field paths, and the conditions.

![Preview section showing 12 preview findings, each failed with High severity, the bucket name, and the message listing the settings that are off](https://mintcdn.com/pleriondocs/mO8NL1n6N85tC9Q5/images/product/custom-checks/06-preview.jpg?fit=max\&auto=format\&n=mO8NL1n6N85tC9Q5\&q=85\&s=ab4c7eef6de6b8ebb693885130b74271)

**7. Click Publish**

Plerion saves the check and runs it against every integration from the matching cloud provider. You go back to the list, where the check's **Status** shows the run's progress:

* **Running**: At least one integration is still being evaluated.
* **Completed**: The check has run on every integration.
* **Error**: The run failed on at least one integration.
* **Pending**: The check hasn't run yet, or no integration has assets of its type.

Until you publish, the form keeps your changes as an **Unsaved draft**, so you can leave the page and come back.

***

## See a check's results

On the custom checks page:

* Click a check's **Status** to see how its last run went on each integration, with the number of findings and the time of the run.
* Click the number in **Findings** to open the check's findings. To open them on the Findings page instead, open the link in a new tab.

![Run status by integration panel showing the sandbox integration completed with 12 findings](https://mintcdn.com/pleriondocs/mO8NL1n6N85tC9Q5/images/product/custom-checks/07-status.jpg?fit=max\&auto=format\&n=mO8NL1n6N85tC9Q5\&q=85\&s=187f2e577cc35f19537b170ff45d32ee)

![Findings panel for the check, each finding showing the check slug, a Custom badge, High severity, and the message](https://mintcdn.com/pleriondocs/mO8NL1n6N85tC9Q5/images/product/custom-checks/08-findings.jpg?fit=max\&auto=format\&n=mO8NL1n6N85tC9Q5\&q=85\&s=309cd4df11cb310d09aca16deae28dcb)

To change a check, click its edit icon. When you publish the change, Plerion runs the check again and updates its findings. To delete a check, click its delete icon. Plerion also removes the check's findings in the background, which can take a few minutes.

You can also map custom checks to the controls of your own compliance frameworks. In the [custom compliance builder](https://docs.plerion.com/guides/platform/compliance-frameworks.md#custom-compliance-builder), choose them under **Mapped Custom Checks** on a control with no child controls.

***

## What a policy receives and returns

A policy must declare `package custom` and define a rule named `result`. Plerion evaluates the rule and reads its value as a list of verdicts.

The policy receives:

| Field | Contents |
| - | - |
| `input.assets` | The assets of the primary asset type. |
| `input.additionalAssets` | Every asset of each additional asset type, keyed by type. For example, `input.additionalAssets["AWS::IAM::Role"]`. |
| `input.context` | The `tenantId`, `organizationId`, and `integrationId` the check is running for. |

Each asset has these fields:

| Field | Contents |
| - | - |
| `id` | The asset's Plerion ID. Return it in the verdict. |
| `type` | The asset type, for example `AWS::S3::Bucket`. |
| `data` | The configuration Plerion collected from the cloud provider, in the provider's own shape. For example, an IAM role has `Arn`, `RoleName`, `AssumeRolePolicyDocument`, and `AttachedManagedPolicies`. |
| `meta` | Details Plerion adds to every asset. `meta.region` is the asset's region. `meta.provider.awsAccountId` is its AWS account. `meta.resource.providerTags` is its tags as a list of `Key` and `Value` pairs, in the same shape for every asset type. |

Each verdict in `result` is an object:

| Field | Required | Description |
| - | - | - |
| `id` | Yes | The `id` of an asset in `input.assets` |
| `status` | Yes | `FAILED` or `PASSED` |
| `severityLevel` | No | `INFORMATIONAL`, `LOW`, `MEDIUM`, `HIGH`, or `CRITICAL`. Replaces the default severity for this finding. |
| `message` | No | Replaces the default message for this finding |
| `remediation` | No | Replaces the default remediation for this finding. Used on failed findings only. |
| `informational` | No | Replaces the default `informational` value for this finding |
| `meta` | No | An object merged over the default `meta` for this finding |
| `relatedAssetIds` | No | The `id` of each asset in `input.additionalAssets` that decided this verdict |

Some rules for verdicts:

* Every verdict becomes a finding. An asset left out of `result` has no finding, and leaving out an asset that had a finding removes that finding.
* Return one verdict per asset. Gather every reason an asset fails into one verdict, as the examples below do.
* A `PASSED` verdict without a `message` gets the check's default message, which reads as a violation. Set a message on passed verdicts, or return failed verdicts only.
* If any verdict has another `status`, names an asset that isn't in `input.assets`, or lists a `relatedAssetIds` entry that isn't in `input.additionalAssets`, Plerion rejects the whole evaluation.

With continuous scanning on, Plerion re-evaluates a check soon after an asset of its primary type changes. Set `relatedAssetIds` to also re-evaluate a verdict when one of the additional assets it names changes. Without it, a change to an additional asset updates the verdict at the next scheduled scan.

> [!TIP]
>
> To learn which fields an asset type has, preview a policy that lists them. Each finding's message shows the field names of one asset.
>
> ```rego theme={"system"}
> package custom
>
> default result := []
>
> result := [{"id": a.id, "status": "FAILED", "message": json.marshal(object.keys(a.data))} | a := input.assets[_]]
> ```

***

## Examples

Paste an example into a new check, set the asset types it names, and preview it.

### Require tags on Lambda functions

**Primary asset type:** `AWS::Lambda::Function`

Reports every function, passing those with all the required tags and failing the rest. The message names the missing tags. The check reads tags from `meta.resource.providerTags`, so it works on any asset type once you change the primary asset type.

```rego theme={"system"}
package custom

required_tags := {"Owner", "CostCenter"}

default result := []

result := [verdict(fn) | fn := input.assets[_]]

tag_keys(asset) := {tag.Key | tag := asset.meta.resource.providerTags[_]}

verdict(fn) := {"id": fn.id, "status": "PASSED", "message": "All required tags are set."} if {
	count(required_tags - tag_keys(fn)) == 0
}

verdict(fn) := {
	"id": fn.id,
	"status": "FAILED",
	"message": sprintf("Missing tags: %s", [concat(", ", sort(missing))]),
} if {
	missing := required_tags - tag_keys(fn)
	count(missing) > 0
}
```

### Flag IAM roles that trust unapproved accounts

**Primary asset type:** `AWS::IAM::Role`

Fails roles that another AWS account can assume when that account isn't on your allow list. A trust policy that lets in any AWS account, with the principal `"*"` or `{"AWS": "*"}`, shows as `*` in the message. The policy sets each finding's severity itself:

* **Critical** when a statement lets in an unapproved account without an `sts:ExternalId` condition, so anyone in that account can assume the role.
* **Medium** when every statement that lets in an unapproved account requires an external ID.

Replace the account IDs in `trusted_accounts` with your own.

```rego theme={"system"}
package custom

# Accounts that may assume roles in this account.
trusted_accounts := {"111122223333", "444455556666"}

default result := []

result := [verdict(role, untrusted) |
	role := input.assets[_]
	untrusted := {account |
		statement := allow_statements(role)[_]
		account := untrusted_accounts(role, statement)[_]
	}
	count(untrusted) > 0
]

verdict(role, untrusted) := {
	"id": role.id,
	"status": "FAILED",
	"severityLevel": severity(role),
	"message": sprintf("Trusts accounts not on the allow list: %s", [concat(", ", sort(untrusted))]),
}

allow_statements(role) := [s | s := role.data.AssumeRolePolicyDocument.Statement[_]; s.Effect == "Allow"]

# The accounts in one statement that are neither this account nor on the allow list.
untrusted_accounts(role, statement) := {account |
	account := account_of(aws_principals(statement)[_])
	account != role.meta.provider.awsAccountId
	not trusted_accounts[account]
}

# Principal.AWS can be a single string or a list. A bare "*" principal means any account.
aws_principals(statement) := [statement.Principal.AWS] if is_string(statement.Principal.AWS)

aws_principals(statement) := statement.Principal.AWS if is_array(statement.Principal.AWS)

aws_principals(statement) := ["*"] if statement.Principal == "*"

# A principal is an account ID, an ARN that contains one, or "*" for any account.
account_of(principal) := principal if regex.match(`^[0-9]{12}$`, principal)

account_of(principal) := split(principal, ":")[4] if startswith(principal, "arn:")

account_of("*") := "*"

# Critical when a statement lets an untrusted account in without an sts:ExternalId condition.
severity(role) := "CRITICAL" if {
	some statement in allow_statements(role)
	count(untrusted_accounts(role, statement)) > 0
	not statement.Condition.StringEquals["sts:ExternalId"]
} else := "MEDIUM"
```

### Find Lambda functions that run with administrator access

**Primary asset type:** `AWS::Lambda::Function`
**Additional asset types:** `AWS::IAM::Role`

Fails each function whose execution role has the AWS managed `AdministratorAccess` policy attached. The function only names its role by ARN, so the policy finds the role among the additional assets. It returns the role in `relatedAssetIds`, so a change to the role updates the finding too.

```rego theme={"system"}
package custom

admin_policy := "arn:aws:iam::aws:policy/AdministratorAccess"

default result := []

result := [{
	"id": fn.id,
	"status": "FAILED",
	"message": sprintf("Execution role %s has AdministratorAccess attached.", [role.data.RoleName]),
	"relatedAssetIds": [role.id],
} |
	fn := input.assets[_]
	role := input.additionalAssets["AWS::IAM::Role"][_]
	role.data.Arn == fn.data.Role
	role.data.AttachedManagedPolicies[_].PolicyArn == admin_policy
]
```

***

## Manage custom checks outside the app

* **Customer API**: create, list, change, and delete checks, and preview a check's findings with a dry run, from your own scripts and pipelines. See the [custom checks API reference](https://docs.plerion.com/api-reference/custom-checks/list.md).
* **Terraform**: keep checks in code, review policy changes in pull requests, and preview findings during `terraform plan`. See [Manage with Terraform](https://docs.plerion.com/guides/platform/custom-checks/terraform.md).
* **CLI**: run one-off tasks from a terminal with the [`plerion custom-checks`](https://docs.plerion.com/cli-reference/commands/custom-checks) commands.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.