{
  "id": "artifact-registry/pull",
  "description": "Allows pulling container images and reading repository metadata",
  "platforms": {
    "aws": [
      {
        "grant": {
          "actions": [
            "ecr:BatchCheckLayerAvailability",
            "ecr:GetDownloadUrlForLayer",
            "ecr:BatchGetImage",
            "ecr:GetAuthorizationToken",
            "ecr:DescribeRepositories",
            "ecr:DescribeImages",
            "ecr:ListImages"
          ]
        },
        "binding": {
          "stack": {
            "resources": ["arn:aws:ecr:${awsRegion}:${awsAccountId}:repository/${stackPrefix}-*"]
          },
          "resource": {
            "resources": ["arn:aws:ecr:${awsRegion}:${awsAccountId}:repository/${resourceName}-*"]
          }
        }
      },
      {
        "grant": {
          "actions": ["sts:AssumeRole"]
        },
        "binding": {
          "stack": {
            "resources": ["arn:aws:iam::${awsAccountId}:role/${stackPrefix}-*-pull"]
          },
          "resource": {
            "resources": ["arn:aws:iam::${awsAccountId}:role/${stackPrefix}-${resourceName}-pull"]
          }
        }
      }
    ],
    "gcp": [
      {
        "grant": {
          "permissions": [
            "artifactregistry.repositories.get",
            "artifactregistry.repositories.list",
            "artifactregistry.tags.get",
            "artifactregistry.tags.list",
            "artifactregistry.versions.get",
            "artifactregistry.versions.list",
            "artifactregistry.repositories.downloadArtifacts"
          ]
        },
        "binding": {
          "stack": {
            "scope": "projects/${projectName}/locations/${region}",
            "condition": {
              "title": "Stack prefixed artifact registry pull",
              "expression": "resource.type == 'artifactregistry.googleapis.com/Repository' && resource.name.startsWith('projects/${projectName}/locations/${region}/repositories/${stackPrefix}-')"
            }
          },
          "resource": {
            "scope": "projects/${projectName}/locations/${region}",
            "condition": {
              "title": "Resource specific artifact registry pull",
              "expression": "resource.type == 'artifactregistry.googleapis.com/Repository' && resource.name.startsWith('projects/${projectName}/locations/${region}/repositories/${resourceName}-')"
            }
          }
        }
      },
      {
        "grant": {
          "permissions": ["iam.serviceAccounts.actAs", "iam.serviceAccounts.getAccessToken"]
        },
        "binding": {
          "stack": {
            "scope": "projects/${projectName}",
            "condition": {
              "title": "Artifact registry service accounts",
              "expression": "resource.type == 'iam.googleapis.com/ServiceAccount' && resource.name.startsWith('projects/${projectName}/serviceAccounts/${stackPrefix}')"
            }
          },
          "resource": {
            "scope": "projects/${projectName}",
            "condition": {
              "title": "Resource specific artifact registry service account",
              "expression": "resource.type == 'iam.googleapis.com/ServiceAccount' && resource.name.startsWith('projects/${projectName}/serviceAccounts/${stackPrefix}-${resourceName}-pull@')"
            }
          }
        }
      }
    ],
    "azure": [
      {
        "grant": {
          "actions": [
            "Microsoft.ContainerRegistry/registries/read",
            "Microsoft.ContainerRegistry/registries/metadata/read"
          ],
          "dataActions": ["Microsoft.ContainerRegistry/registries/pull/read"]
        },
        "binding": {
          "stack": {
            "scope": "/subscriptions/${subscriptionId}/resourceGroups/${resourceGroup}"
          },
          "resource": {
            "scope": "/subscriptions/${subscriptionId}/resourceGroups/${resourceGroup}/providers/Microsoft.ContainerRegistry/registries/${resourceName}"
          }
        }
      }
    ]
  }
}
