Allow Artifact Registry
Duration: 5 min | Persona: Org Admin
In this section, you will enable and grant the appropriate APIs in the Tenant project and the IAM role for the Tenant project’s service account. This will allow later this service account to provision the Artifact Registry to have your private container images. You will also the containers analysis and scanning features of Artifact Registry.
Initialize variables:
WORK_DIR=~/
source ${WORK_DIR}acm-workshop-variables.sh
Define role
Define the artifactregistry.admin
role with an IAMPolicyMember
for the Tenant project’s service account:
cat <<EOF > ${WORK_DIR}$HOST_PROJECT_DIR_NAME/projects/$TENANT_PROJECT_ID/artifactregistry-admin.yaml
apiVersion: iam.cnrm.cloud.google.com/v1beta1
kind: IAMPolicyMember
metadata:
name: artifactregistry-admin-${TENANT_PROJECT_ID}
namespace: config-control
annotations:
config.kubernetes.io/depends-on: iam.cnrm.cloud.google.com/namespaces/config-control/IAMServiceAccount/${TENANT_PROJECT_ID},resourcemanager.cnrm.cloud.google.com/namespaces/config-control/Project/${TENANT_PROJECT_ID}
spec:
memberFrom:
serviceAccountRef:
name: ${TENANT_PROJECT_ID}
role: roles/artifactregistry.admin
resourceRef:
kind: Project
external: projects/${TENANT_PROJECT_ID}
EOF
Define APIs
Define the Artifact Registry API Service
resource for the Tenant project:
cat <<EOF > ${WORK_DIR}$HOST_PROJECT_DIR_NAME/projects/$TENANT_PROJECT_ID/artifactregistry-service.yaml
apiVersion: serviceusage.cnrm.cloud.google.com/v1beta1
kind: Service
metadata:
annotations:
cnrm.cloud.google.com/deletion-policy: "abandon"
cnrm.cloud.google.com/disable-dependent-services: "false"
config.kubernetes.io/depends-on: resourcemanager.cnrm.cloud.google.com/namespaces/config-control/Project/${TENANT_PROJECT_ID}
name: ${TENANT_PROJECT_ID}-artifactregistry
namespace: config-control
spec:
projectRef:
name: ${TENANT_PROJECT_ID}
resourceID: artifactregistry.googleapis.com
EOF
We are enabling the GCP services APIs from the Org Admin, it allows more control and governance over which GCP services APIs the Platform Admin could use or not. If you want to give more autonomy to the Platform Admin, you could grant the serviceusage.serviceUsageAdmin
role to the associated service account.
Define the Container scanning APIs Service
resource for the Tenant project:
cat <<EOF > ${WORK_DIR}$HOST_PROJECT_DIR_NAME/projects/$TENANT_PROJECT_ID/containeranalysis-service.yaml
apiVersion: serviceusage.cnrm.cloud.google.com/v1beta1
kind: Service
metadata:
annotations:
cnrm.cloud.google.com/deletion-policy: "abandon"
cnrm.cloud.google.com/disable-dependent-services: "false"
config.kubernetes.io/depends-on: resourcemanager.cnrm.cloud.google.com/namespaces/config-control/Project/${TENANT_PROJECT_ID}
name: ${TENANT_PROJECT_ID}-containeranalysis
namespace: config-control
spec:
projectRef:
name: ${TENANT_PROJECT_ID}
resourceID: containeranalysis.googleapis.com
EOF
cat <<EOF > ${WORK_DIR}$HOST_PROJECT_DIR_NAME/projects/$TENANT_PROJECT_ID/containerscanning-service.yaml
apiVersion: serviceusage.cnrm.cloud.google.com/v1beta1
kind: Service
metadata:
annotations:
cnrm.cloud.google.com/deletion-policy: "abandon"
cnrm.cloud.google.com/disable-dependent-services: "false"
config.kubernetes.io/depends-on: resourcemanager.cnrm.cloud.google.com/namespaces/config-control/Project/${TENANT_PROJECT_ID}
name: ${TENANT_PROJECT_ID}-containerscanning
namespace: config-control
spec:
projectRef:
name: ${TENANT_PROJECT_ID}
resourceID: containerscanning.googleapis.com
EOF
Container Analysis performs vulnerability scans on container images in Artifact Registry and Container Registry, and it monitors the vulnerability information to keep it up to date. This process comprises two main tasks: scanning and continuous analysis.
Define the On-demand scanning APIs Service
resource for the Tenant project:
cat <<EOF > ${WORK_DIR}$HOST_PROJECT_DIR_NAME/projects/$TENANT_PROJECT_ID/ondemandscanning-service.yaml
apiVersion: serviceusage.cnrm.cloud.google.com/v1beta1
kind: Service
metadata:
annotations:
cnrm.cloud.google.com/deletion-policy: "abandon"
cnrm.cloud.google.com/disable-dependent-services: "false"
config.kubernetes.io/depends-on: resourcemanager.cnrm.cloud.google.com/namespaces/config-control/Project/${TENANT_PROJECT_ID}
name: ${TENANT_PROJECT_ID}-ondemandscanning
namespace: config-control
spec:
projectRef:
name: ${TENANT_PROJECT_ID}
resourceID: ondemandscanning.googleapis.com
EOF
On-demand scanning lets you scan container images locally on your computer or in your registry, using the gcloud CLI. This gives you the flexibility to customize your CI/CD pipeline, depending on when you need to access the vulnerability results. In this workshop, you will try out this feature with its associated gcloud
command.
Deploy Kubernetes manifests
cd ${WORK_DIR}$HOST_PROJECT_DIR_NAME/
git add . && git commit -m "Allow Artifact Registry for Tenant project" && git push origin main
Check deployments
graph TD; IAMPolicyMember-.->IAMServiceAccount IAMPolicyMember-.->Project Service-.->Project Service-.->Project Service-.->Project Service-.->Project
List the Kubernetes resources managed by Config Sync in Config Controller for the Host project configs repository:
Run this command and click on this link:
echo -e "https://console.cloud.google.com/kubernetes/config_management/packages?project=${HOST_PROJECT_ID}"
Wait until you see the Sync status
column as Synced
and the Reconcile status
column as Current
.
Run this command:
gcloud alpha anthos config sync repo describe \
--project $HOST_PROJECT_ID \
--managed-resources all \
--sync-name root-sync \
--sync-namespace config-management-system
Wait and re-run this command above until you see "status": "SYNCED"
. All the managed_resources
listed should have STATUS: Current
too.
List the GitHub runs for the Host project configs repository:
cd ${WORK_DIR}$HOST_PROJECT_DIR_NAME && gh run list
List the Google Cloud resources created:
gcloud services list \
--enabled \
--project ${TENANT_PROJECT_ID} \
| grep -E 'containerscanning|containeranalysis|artifactregistry|ondemandscanning'
gcloud projects get-iam-policy $TENANT_PROJECT_ID \
--filter="bindings.members:${TENANT_PROJECT_SA_EMAIL}" \
--flatten="bindings[].members" \
--format="table(bindings.role)" \
| grep artifactregistry
Wait and re-run this command above until you see the resources created.