Question

Difficulty: MediumDeploying Serverless Applications with Cloud Run and Cloud Functions

A Cloud Engineer needs to deploy a custom microservice from local source code to Google Cloud Run and secure it so that only a specific client service account can invoke it. Arrange the steps in the correct sequential order from initial image creation to post-deployment verification.

  1. 1Build the container image from local source code and push it to Artifact Registry using `gcloud builds submit`.
  2. 2Deploy the container image to Cloud Run using `gcloud run deploy` with `--no-allow-unauthenticated`.
  3. 3Grant the client service account access by running `gcloud run services add-iam-policy-binding` with `--role=roles/run.invoker`.
  4. 4Test access to the service URL by passing an HTTP Authorization bearer header containing a token generated via `gcloud auth print-identity-token`.

Answer

The correct sequence is: 1. Build and push the container image to Artifact Registry using gcloud builds submit. 2. Deploy the container image to Cloud Run with unauthenticated access disabled. 3. Bind the Cloud Run Invoker role (roles/run.invoker) to the client service account. 4. Verify access by invoking the service endpoint with an identity token.
Deployment workflow follows a strict chronological order: First, the container image must be built from source code and pushed to Artifact Registry so that Cloud Run can access the container bits. Second, the Cloud Run service is created from this container image with unauthenticated invocations disabled. Third, once the service resource exists, an IAM policy binding is attached to grant the specific client service account the `roles/run.invoker` role. Fourth, the deployment is validated by sending an authenticated request using an identity token.

Step-by-Step Solution

1
Package and register the deployment artifact
A container image stored in Artifact Registry
Cloud Run requires a pre-built container image in a reachable container registry before deployment can commence.
2
Instantiate the Cloud Run service resource
A running, private Cloud Run service with a designated HTTPS URL
Deploying the service creates the target resource needed to attach service-specific IAM access policies.
3
Apply IAM invoker permissions
The client service account is explicitly authorized to invoke the endpoint
Adding the `roles/run.invoker` role via `gcloud run services add-iam-policy-binding` restricts invocation to the authorized identity.
4
Perform end-to-end verification
HTTP 200 OK response from the Cloud Run service endpoint
Sending an HTTP request with an identity token generated for the authorized service account confirms that authentication and authorization function properly.

Key Concept

Deploying containerized microservices to Cloud Run and managing service-level IAM authentication and invoker roles.
Rate this question