> [!NOTE]
> **Note:** This document or section includes references to one or more terms that Google considers disrespectful or offensive. The terms are used because they are keywords in the software that's described in the document. The terms: `whitelist`

This page contains reference information for Binary Authorization
[policies](https://docs.cloud.google.com/binary-authorization/docs/key-concepts.md.txt#policies) as specified in
[YAML](http://yaml.org) format. When you
configure a policy using the [command-line interface](https://docs.cloud.google.com/binary-authorization/docs/configuring-policy-cli.md.txt),
you edit a YAML-formatted file that complies with this specification. For
examples of policies in YAML format, see [Example Policies](https://docs.cloud.google.com/binary-authorization/docs/example-policies.md.txt).

Policy YAML files have the following format:

```yaml
name: projects/<PROJECT_ID>/policy
admissionWhitelistPatterns:
- namePattern: <MATCHING_PATTERN>
- ...
globalPolicyEvaluationMode: <GLOBAL_EVAL_MODE>
defaultAdmissionRule:
  <ADMISSION_RULE>
clusterAdmissionRules:
  <CLUSTER_SPECIFIER>:
    <ADMISSION_RULE>
  ...
```

## Nodes

The YAML format has the following top-level nodes:

| Node | Description | Required |
|---|---|---|
| `name` | Name of the policy. | Yes |
| `admissionWhitelistPatterns` | Specifies container images that are always allowed to be deployed. | No |
| `globalPolicyEvaluationMode` | Specifies whether to apply a system policy that exempts Google-owned system images. | No |
| `defaultAdmissionRule` | The rule to use when no specific rule applies. | Yes |
| `clusterAdmissionRules` | Specifies rules that apply to specific clusters. | No |

### `name`

The `name` node contains the name of the policy in the following format:

```
name: projects/PROJECT_ID/policy
```

where <var translate="no">PROJECT_ID</var> is the name of your Google Cloud
project where your policy is defined.

For example:

```yaml
name: projects/example-project/policy
```

### `admissionWhitelistPatterns`

> [!NOTE]
> **Note:** We don't recommend using `admissionWhitelistPatterns` to allowlist Google-managed system images. Google-managed system images are allowed if `globalPolicyEvaluationMode` is set to `ENABLE` (the default setting). See [`globalPolicyEvaluationMode`](https://docs.cloud.google.com/binary-authorization/docs/policy-yaml-reference.md.txt#globalpolicyevaluationmode) for details.

`admissionWhitelistPatterns` specifies an allowlist of container images that are
[exempt from policy enforcement](https://docs.cloud.google.com/binary-authorization/docs/key-concepts.md.txt#exempt_images). You specify the
path to the images in Artifact Registry, another registry, or a local reference in
the `namePattern` subnode:

```
admissionWhitelistPatterns:
  - namePattern: MATCHING_PATTERN
  - ...
```

Replace <var translate="no">MATCHING_PATTERN</var> with either a path to a single image or
a matching pattern containing one of the wildcard symbols (`*`, `**`).

- Wildcards are valid only at the end of the pattern. For example, `us-west1.docker.pkg.dev/my-project/my-repo/nginx*` is a valid pattern, but `us-west1.docker.pkg.dev/my-project/my-repo/n*x` isn't.
- The `*` wildcard doesn't include nested directories below the wildcard. For example,`gcr.io/my-project/nginx*` matches `gcr.io/my-project/nginx:latest`, but not `gcr.io/my-project/nginx-images/nginx`
- The `**` wildcard matches all paths that start with the same string. For example, the path `gcr.io/my-project/nginx**` matches `gcr.io/my-project/nginx-1.14.2/image:latest`

> [!CAUTION]
> **Caution:** Be careful when using the `**` wildcard with project IDs as doing so also matches images in different projects. For example, the path `us-west1.docker.pkg.dev/my-project**`, allows image versions in both `us-west1.docker.pkg.dev/my-project/my-repo/nginx` and `us-west1.docker.pkg.dev/my-project-exploit/exploit-repo/nginx-exploit` to be deployed.

The following example adds image versions located at
`us-west1.docker.pkg.dev/example-project/my-repo/helloworld` and a local
image reference to the list of exempt images for the policy:

```
admissionWhitelistPatterns:
  - namePattern: us-west1.docker.pkg.dev/example-project/my-repo/helloworld*
  - namePattern: loc-ref
```

> [!IMPORTANT]
> **Important:** If `globalPolicyEvaluationMode` is disabled, you must include images required by GKE in `admissionWhitelistPatterns` and keep the list up-to-date.

#### Allowlist patterns

> [!NOTE]
> **Note:** The same rules apply for local references to images.

To allowlist all container images whose registry location matches the specified
path:

```
admissionWhitelistPatterns:
  ...
  - namePattern: gcr.io/example-project/*
```

To allowlist a specific image:

```
admissionWhitelistPatterns:
  ...
  - namePattern: gcr.io/example-project/helloworld
```

To allowlist a currently-tagged version:

```
admissionWhitelistPatterns:
  ...
  - namePattern: gcr.io/example-project/helloworld:latest
  - namePattern: gcr.io/example-project/helloworld:my-tag
  - namePattern: gcr.io/example-project/helloworld:v1.*
```

To allowlist a specific version of an image by its digest:

```
admissionWhitelistPatterns:
  ...
  - namePattern: gcr.io/example-project/helloworld@sha256:77b0b75136b9bd0fd36fb50f4c92ae0dbdbbe164ab67885e736fa4374e0cbb8c
```

To allowlist images in subdirectories of a given path:

```
admissionWhitelistPatterns:
  ...
  - namePattern: gcr.io/example-project/**
```

### `globalPolicyEvaluationMode`

[System policy evaluation mode](https://docs.cloud.google.com/binary-authorization/docs/key-concepts.md.txt#google-maintained_system_images)
is a policy setting that causes Binary Authorization to evaluate a system policy
before evaluating the policy that you configure. The system policy is provided
by Google and exempts a list of Google-maintained system images from further
policy evaluation. When you have this setting enabled, images that are required
by GKE are not blocked by policy enforcement. The system
policy is evaluated prior to and in addition to user policy evaluation,
including `admissionWhitelistPatterns`.

To allow all Google-maintained system images, set the
`globalPolicyEvaluationMode` property to `ENABLE`:

```
globalPolicyEvaluationMode: ENABLE
```

To disable system policy evaluation mode:

```
globalPolicyEvaluationMode: DISABLE
```

It is recommended that you leave `globalPolicyEvaluationMode` on its
default setting, `ENABLE`. For GKE to work properly, it needs to
run a number of system images in your cluster. When you enable
`globalPolicyEvaluationMode`, the Google-maintained allowlist of system images
is automatically updated with every GKE release. While you can
manage system images yourself by listing them in `admissionWhitelistPatterns`,
updated system images might not be allowed to run if the allowlist is not kept
up to date.

If you *disable* `globalPolicyEvaluationMode`, you must include paths to images
that are required to successfully start GKE clusters in the
`admissionWhitelistPatterns` allowlist. To view the full list of system image
paths, run the following command:

```bash
gcloud alpha container binauthz policy export-system-policy
```

### `defaultAdmissionRule`

`defaultAdmissionRule` specifies the [default rule](https://docs.cloud.google.com/binary-authorization/docs/key-concepts.md.txt#default-rules)
for the policy. The default rule defines the constraints that apply to all
non-exempt container images with the exception of those that have their own
cluster-specific rule. You specify the default rule using the
<var translate="no">[ADMISSION_RULE](https://docs.cloud.google.com/binary-authorization/docs/policy-yaml-reference.md.txt#admission_rule)</var> collection:

```
defaultAdmissionRule:
  ADMISSION_RULE
```

The following example shows a default rule that allows only those container
images to be deployed which have been authorized by the specified
[attestor](https://docs.cloud.google.com/binary-authorization/docs/key-concepts.md.txt#attestors). In the case that all required attestors have
not authorized the image, Binary Authorization blocks the deployment and writes
to the audit log.

```
defaultAdmissionRule:
  evaluationMode: REQUIRE_ATTESTATION
  enforcementMode: ENFORCED_BLOCK_AND_AUDIT_LOG
  requireAttestationsBy:
  - projects/example-project/attestors/secure-build
```

### `clusterAdmissionRules`

`clusterAdmissionRules` declare
[cluster-specific rules](https://docs.cloud.google.com/binary-authorization/docs/key-concepts.md.txt#cluster-specific_rules) for the policy.
The constraints in these rules apply only to the specified cluster. If
Binary Authorization applies a cluster-specific rule to a deployment, the default
rule is not considered. As with default rules, you specify cluster-specific
rules using the
<var translate="no">[ADMISSION_RULE](https://docs.cloud.google.com/binary-authorization/docs/policy-yaml-reference.md.txt#admission_rule)</var> collection:

```
clusterAdmissionRules:
  CLUSTER_SPECIFIER:
    ADMISSION_RULE
```

where <var translate="no">CLUSTER_SPECIFIER</var> is the resource ID of the cluster to which
the rule applies in the format `location.name` (for example,
`us-east1-a.prod-cluster`).

The following examples shows a cluster-specific rule that only allows those
container images to be deployed which have been authorized by the specified
attestors:

```
clusterAdmissionRules:
  us-east1-a.prod-cluster:
    evaluationMode: REQUIRE_ATTESTATION
    enforcementMode: ENFORCED_BLOCK_AND_AUDIT_LOG
    requireAttestationsBy:
    - projects/example-project/attestors/secure-build
    - projects/example-project/attestors/prod-qualified
```

## Node collections

### `ADMISSION_RULE`

`ADMISSION_RULE` is a collection of nodes that specify the constraints for the
rule in the following format:

```
evaluationMode: EVAL_MODE
enforcementMode: ENFORCEMENT_MODE
requireAttestationsBy:
- ATTESTOR
- ...
```

Both `defaultAdmissionRule` and `clusterAdmissionRule` reference this
collection.

#### `evaluationMode`

`evaluationMode` specifies the operation that Binary Authorization performs in
order to evaluate whether to deploy a container image. The possible values are:

- `ALWAYS_ALLOW`: Always allow deployment of images evaluated by this rule
- `ALWAYS_DENY`: Always deny deployment of images evaluated by this rule
- `REQUIRE_ATTESTATION`: Require one or more attestors to authorize the release before deployment

If the `evaluationMode` is `REQUIRE_ATTESTATION`, you must provide a reference
to the required attestors in
`requireAttestationsBy`.

#### `enforcementMode`

`enforcementMode` specifies the action that Binary Authorization takes if a
container image does not conform to the constraints defined in the rule. The
possible values are:

- `ENFORCED_BLOCK_AND_AUDIT_LOG`: Blocks deployment and writes to the audit log.
- `DRYRUN_AUDIT_LOG_ONLY`: Allows deployment of non-conformant images and writes details about the violation to the audit log.

Most production rules use the `ENFORCED_BLOCK_AND_AUDIT_LOG` enforcement mode.
`DRYRUN_AUDIT_LOG_ONLY` is primarily used for testing a policy in your
environment before it goes into effect.

#### `requireAttestationsBy`

`requireAttestationsBy` specifies one or more attestors who must authorize the
release before a container image can be deployed. This is required for
`REQUIRE_ATTESTATION` rules only. The format for this node is:

```
requireAttestationsBy:
  - projects/PROJECT_ID/attestors/ATTESTOR_NAME
  - ...
```

where <var translate="no">PROJECT_ID</var> is the name of the project where your attestors
are defined and <var translate="no">ATTESTOR_NAME</var> is the name of an attestor who
is required to sign the release.

The following example shows how to specify attestors:

```
requireAttestationsBy:
- projects/example-project/attestors/secure-build
- projects/example-project/attestors/prod-qualified
```