[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2024-12-21 UTC。"],[[["\u003cp\u003eContainer Registry uses Pub/Sub to send notifications about repository changes, such as images being pushed, tagged, or deleted, to subscribed applications.\u003c/p\u003e\n"],["\u003cp\u003eWhen the Container Registry API is enabled, a Pub/Sub topic with the ID \u003ccode\u003egcr\u003c/code\u003e is automatically created, or it can be manually created if missing.\u003c/p\u003e\n"],["\u003cp\u003eEach Pub/Sub topic requires a subscription, enabling subscriber applications to receive messages regarding repository activity, using either a push or pull model.\u003c/p\u003e\n"],["\u003cp\u003ePub/Sub permissions can be configured to manage access to the repository, including defining roles for publishing and subscribing, ensuring controlled interaction.\u003c/p\u003e\n"],["\u003cp\u003eNotifications are delivered as JSON-formatted strings, indicating the action performed (INSERT or DELETE) along with a \u003ccode\u003edigest\u003c/code\u003e or \u003ccode\u003etag\u003c/code\u003e to identify the relevant image.\u003c/p\u003e\n"]]],[],null,["# Configuring Pub/Sub notifications\n\nWhen changes are made to your Container Registry repository, such as when\nimages are pushed, tagged, or deleted, you can receive notifications using\n[Pub/Sub](/pubsub).\n\nPub/Sub publishes messages about your repository to named\nresources called *topics* . These messages are received by applications\n*subscribed* to Pub/Sub topics. Subscriber applications send\nnotifications when your repository's state changes.\n\nAdditionally, you can configure roles and permissions for your\nPub/Sub topics to control how users interact with your repository.\n\nTo support the transition from Container Registry to\n[Artifact Registry](/artifact-registry), Artifact Registry publishes messages\nto the same topic as Container Registry.\n\nFor information about configuring Artifact Analysis notifications for\nactivity such as new vulnerability scan results, see the\n[Artifact Analysis documentation](/container-analysis/docs/pub-sub-notifications).\n\nCreate a Pub/Sub topic\n----------------------\n\nWhen you activate the Container Registry API in a Google Cloud project,\nContainer Registry automatically creates a Pub/Sub\ntopic with the topic ID `gcr`.\n\nIf the `gcr` topic was accidentally deleted or is missing, you can add it\nyourself. For example, the topic might be missing if your Google Cloud\norganization has an [organization policy constraint](/resource-manager/docs/organization-policy/org-policy-constraints) that requires\nencryption with customer-managed encryption keys (CMEK). When the\nPub/Sub API is in the deny list of this constraint,\nservices cannot automatically create topics with Google-owned and Google-managed encryption keys.\n\nTo create the `gcr` topic with Google-owned and Google-managed encryption keys: \n\n### Console\n\n1. Go to the Pub/Sub topics page in the Google Cloud console.\n\n [Go to the Pub/Sub topics page](https://console.cloud.google.com/cloudpubsub/topicList)\n2. Click **Create Topic**.\n\n3. Enter the topic ID `gcr`.\n\n4. Click **Create Topic**.\n\n### gcloud\n\nRun the following command: \n\n gcloud pubsub topics create gcr --project=\u003cvar translate=\"no\"\u003ePROJECT-ID\u003c/var\u003e\n\nReplace \u003cvar translate=\"no\"\u003ePROJECT-ID\u003c/var\u003e with your Google Cloud\n[project ID](/resource-manager/docs/creating-managing-projects#identifying_projects). If you omit the `--project` flag, the command\nuses the current project.\n| **Note:** If this command returns a \"Resource already exists in the project\" error, the topic `gcr` already exists in the project.\n\nTo learn more about the `gcloud pubsub topics` command, see the\n[`topics` documentation](/sdk/gcloud/reference/pubsub/topics).\n\nTo create the `gcr` topic with CMEK encryption, see the Pub/Sub\n[instructions for encrypting topics](/pubsub/docs/encryption#using-cmek).\n\nAfter you have have created the `gcr` topic or verified that it exists, you can\ncreate a [subscription](#subscription) to the topic.\n\nCreate a Pub/Sub subscription\n-----------------------------\n\nEvery Pub/Sub topic should have a subscription.\n\nA [subscriber application](/pubsub/docs/subscriber)\nreceives messages from your repository's topic. Subscribers fulfill tasks like\nevent notifications, system logging, and communication between\napplications.\n\nSubscriptions can be configured to use a [push model](/pubsub/docs/push)\nor a [pull model](/pubsub/docs/pull).\n\nTo create a subscription: \n\n### Console\n\n1. Go to the Pub/Sub topics page in the Google Cloud console.\n\n [Go to the Pub/Sub topics page](https://console.cloud.google.com/cloudpubsub/topicList)\n2. Click your project's topic.\n\n3. Click **Create Subscription**.\n\n4. Enter a subscription name:\n\n projects/[PROJECT-ID]/subscriptions/[SUBSCRIPTION-NAME]\n\n Leave Delivery Type set to Pull.\n5. Click **Create**.\n\n### gcloud\n\nFrom the system where Docker images are pushed or tagged run the following\ncommand: \n\n gcloud pubsub subscriptions create [SUBSCRIPTION-NAME] --topic=gcr\n\n| **Note:** Use the optional flag `--ack-deadline` to configure how many seconds the system will wait for acknowledgement from the subscriber before re-attempting delivery. Without this flag, the default deadline is 10 seconds.\n\nTo learn more about the `gcloud pubsub subscriptions` command, see the\n[`subscriptions` documentation](/sdk/gcloud/reference/pubsub/subscriptions).\n\nConfiguring Pub/Sub permissions\n-------------------------------\n\nUse [Pub/Sub access control](/pubsub/docs/access_control)\nto configure permissions for your project and resources. Access controls keep\nyour repository secure and allow you to manage user permissions using role-based\naccess.\n\nYou can configure Pub/Sub access controls in the\n[Google Cloud console's IAM page](/pubsub/docs/access_control#console)\nor via the [IAM API](/pubsub/docs/access_control#api).\n\n- To configure permissions for publishing, use any of the\n following roles: owner, editor, pubsub.admin, pubsub.editor, pubsub.publisher.\n Principals that push images or delete images from the registry must have\n the `pubsub.topics.publish` permission to publish a message to\n Pub/Sub.\n\n- To configure permissions for subscribing, use any of the following\n roles: owner, editor, pubsub.admin, pubsub.editor, pubsub.subscriber.\n\nNotification examples\n---------------------\n\nNotifications are sent as JSON-formatted strings. Below are examples of what to\nexpect when receiving Container Registry notifications from\nPub/Sub.\n\nWhen an image is pushed to Container Registry, the notification\npayload might look like this: \n\n {\n \"action\":\"INSERT\",\n \"digest\":\"gcr.io/my-project/hello-world@sha256:6ec128e26cd5...\"\n }\n\nWhen a new tag is pushed to Container Registry, the notification payload\nmight look like this: \n\n {\n \"action\":\"INSERT\",\n \"digest\":\"gcr.io/my-project/hello-world@sha256:6ec128e26cd5...\",\n \"tag\":\"gcr.io/my-project/hello-world:1.1\"\n }\n\nThe message identifies the relevant image using either a `digest` or `tag` key.\n\nWhen a tag is deleted from Container Registry, the notification payload\nmight look like this: \n\n {\n \"action\":\"DELETE\",\n \"tag\":\"gcr.io/my-project/hello-world:1.1\"\n }\n\nThe message might contain either `DELETE` or `INSERT` as values for the `action`\nkey.\n\nWhat's next\n-----------\n\n- Read the [Pub/Sub documentation](/pubsub/docs).\n- For an in-depth explanation of Pub/Sub, see [What is Pub/Sub?](/pubsub/docs/overview)\n- Learn more about [Pub/Sub access control roles](/pubsub/docs/access_control#tbl_roles)."]]