This page shows you how to give Binary Authorization access to policies and container
images that exist in different Google Cloud projects than your current project.
For example, if you deploy images in your Google Kubernetes Engine (GKE) cluster
from an Artifact Registry repository that's owned by a different project, you'll need
to give the Binary Authorization service in your project access to the image
metadata in the source repository.

## Terminology

This document uses the following terms:

- **Service agent:**A Google Cloud-managed service account. Binary Authorization uses a service agent to interact with your Google Cloud resources, like GKE clusters.
- **Policy project:**The Google Cloud project that contains your Binary Authorization policy.
- **Cluster project:**The Google Cloud project that contains your GKE cluster.
- **Artifact project:**The Google Cloud project that contains your Artifact Registry repository.

## Scenarios that require cross-project access

You must grant cross-project permissions in situations like the following:

- Your policy project is different than your cluster project.
- Your cluster project is different than your artifact project.

## Before you begin

<br />

## Cluster project different than the policy project

Grant the Binary Authorization service agent in the cluster project the
[Binary Authorization Policy Evaluator](https://docs.cloud.google.com/iam/docs/roles-permissions/binaryauthorization.md.txt#binaryauthorization.policyEvaluator)
(`roles/binaryauthorization.policyEvaluator`)
role on the policy project.

```bash
gcloud projects add-iam-policy-binding POLICY_PROJECT_ID \
  --member="serviceAccount:service-$(gcloud projects describe CLUSTER_PROJECT_ID --format='value(projectNumber)')@gcp-sa-binaryauthorization.iam.gserviceaccount.com" \
  --role=roles/binaryauthorization.policyEvaluator
```

Replace the following:

- `POLICY_PROJECT_ID`: the ID of the project that contains your policy.
- `CLUSTER_PROJECT_ID`: the project ID of the cluster.

<br />

## Cluster project different than the artifact project

Grant the Binary Authorization service agent in the cluster project the
[Artifact Registry Reader](https://docs.cloud.google.com/iam/docs/roles-permissions/artifactregistry.md.txt#artifactregistry.reader)
(`roles/artifactregistry.reader`) role on the artifact project.

```bash
gcloud projects add-iam-policy-binding ARTIFACT_PROJECT_ID \
    --member="serviceAccount:service-$(gcloud projects describe CLUSTER_PROJECT_ID --format='value(projectNumber)')@gcp-sa-binaryauthorization.iam.gserviceaccount.com" \
    --role=roles/artifactregistry.reader
```

Replace the following:

- `ARTIFACT_PROJECT_ID`: the ID of the project that contains your Artifact Registry repository.
- `CLUSTER_PROJECT_ID`: the project ID that runs your GKE clusters.

<br />