Configuring Pub/Sub notifications

When changes are made to your Container Registry repository, such as whenimages are pushed, tagged, or deleted, you can receive notifications usingPub/Sub.

Pub/Sub publishes messages about your repository to namedresources calledtopics. These messages are received by applicationssubscribed to Pub/Sub topics. Subscriber applications sendnotifications when your repository's state changes.

Additionally, you can configure roles and permissions for yourPub/Sub topics to control how users interact with your repository.

To support the transition from Container Registry toArtifact Registry, Artifact Registry publishes messagesto the same topic as Container Registry.

For information about configuring Artifact Analysis notifications foractivity such as new vulnerability scan results, see theArtifact Analysis documentation.

Create a Pub/Sub topic

When you activate the Container Registry API in a Google Cloud project,Container Registry automatically creates a Pub/Subtopic with the topic IDgcr.

If thegcr topic was accidentally deleted or is missing, you can add ityourself. For example, the topic might be missing if your Google Cloudorganization has anorganization policy constraint that requiresencryption with customer-managed encryption keys (CMEK). When thePub/Sub API is in the deny list of this constraint,services cannot automatically create topics with Google-owned and Google-managed encryption keys.

To create thegcr topic with Google-owned and Google-managed encryption keys:

Console

  1. Go to the Pub/Sub topics page in the Google Cloud console.

    Go to the Pub/Sub topics page

  2. ClickCreate Topic.

  3. Enter the topic IDgcr.

  4. ClickCreate Topic.

gcloud

Run the following command:

gcloud pubsub topics create gcr --project=PROJECT-ID

ReplacePROJECT-ID with your Google Cloudproject ID. If you omit the--project flag, the commanduses the current project.

Note: If this command returns a "Resource already exists in the project"error, the topicgcr already exists in the project.

To learn more about thegcloud pubsub topics command, see thetopics documentation.

To create thegcr topic with CMEK encryption, see the Pub/Subinstructions for encrypting topics.

After you have have created thegcr topic or verified that it exists, you cancreate asubscription to the topic.

Create a Pub/Sub subscription

Every Pub/Sub topic should have a subscription.

Asubscriber applicationreceives messages from your repository's topic. Subscribers fulfill tasks likeevent notifications, system logging, and communication betweenapplications.

Subscriptions can be configured to use apush modelor apull model.

To create a subscription:

Console

  1. Go to the Pub/Sub topics page in the Google Cloud console.

    Go to the Pub/Sub topics page

  2. Click your project's topic.

  3. ClickCreate Subscription.

  4. Enter a subscription name:

    projects/[PROJECT-ID]/subscriptions/[SUBSCRIPTION-NAME]

    Leave Delivery Type set to Pull.

  5. ClickCreate.

gcloud

From the system where Docker images are pushed or tagged run the followingcommand:

gcloud pubsub subscriptions create [SUBSCRIPTION-NAME] --topic=gcr
Note: Use the optional flag--ack-deadline to configure how many secondsthe system will wait for acknowledgement from the subscriber beforere-attempting delivery. Without this flag, the default deadline is 10seconds.

To learn more about thegcloud pubsub subscriptions command, see thesubscriptions documentation.

Configuring Pub/Sub permissions

UsePub/Sub access controlto configure permissions for your project and resources. Access controls keepyour repository secure and allow you to manage user permissions using role-basedaccess.

You can configure Pub/Sub access controls in the Google Cloud console's IAM pageor via theIAM API.

  • To configure permissions for publishing, use any of thefollowing roles: owner, editor, pubsub.admin, pubsub.editor, pubsub.publisher.Principals that push images or delete images from the registry must havethepubsub.topics.publish permission to publish a message toPub/Sub.

  • To configure permissions for subscribing, use any of the followingroles: owner, editor, pubsub.admin, pubsub.editor, pubsub.subscriber.

Notification examples

Notifications are sent as JSON-formatted strings. Below are examples of what toexpect when receiving Container Registry notifications fromPub/Sub.

When an image is pushed to Container Registry, the notificationpayload might look like this:

{"action":"INSERT","digest":"gcr.io/my-project/hello-world@sha256:6ec128e26cd5..."}

When a new tag is pushed to Container Registry, the notification payloadmight look like this:

{"action":"INSERT","digest":"gcr.io/my-project/hello-world@sha256:6ec128e26cd5...","tag":"gcr.io/my-project/hello-world:1.1"}

The message identifies the relevant image using either adigest ortag key.

When a tag is deleted from Container Registry, the notification payloadmight look like this:

{  "action":"DELETE",  "tag":"gcr.io/my-project/hello-world:1.1"}

The message might contain eitherDELETE orINSERT as values for theactionkey.

What's next

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-19 UTC.