Question

Difficulty: MediumDeploying Serverless Applications with Cloud Run and Cloud Functions

A DevOps engineer needs to deploy a Cloud Functions (2nd gen) service from local source code to handle background file processing triggered by a Cloud Storage bucket event. The deployment must adhere to the principle of least privilege using a custom service account. What is the correct sequence of steps to perform this deployment?

  1. 1Create a dedicated custom IAM service account for the function.
  2. 2Grant the required IAM roles to the custom service account.
  3. 3Run `gcloud functions deploy` specifying the Cloud Storage trigger and the `--service-account` flag.
  4. 4Upload a test file to the Cloud Storage bucket to verify event delivery and function execution.

Answer

The correct sequence of steps is: 1) Create a dedicated custom IAM service account for the function. 2) Grant the required IAM roles to the custom service account. 3) Run `gcloud functions deploy` specifying the Cloud Storage trigger and the `--service-account` flag. 4) Upload a test file to the Cloud Storage bucket to verify event delivery and function execution.
Deploying an event-driven Cloud Function following GCP security best practices requires creating the custom service account first. Next, IAM roles must be granted to that service account so it possesses the appropriate execution permissions. Third, executing `gcloud functions deploy` attaches the configured service account and sets up the Cloud Storage trigger. Finally, uploading a file to the bucket tests and verifies that the live function executes as expected.

Step-by-Step Solution

1
Create the custom service account
A unique service account identity is created within the Google Cloud project.
An identity must exist before IAM roles can be granted to it or attached to a Cloud Function.
2
Bind required IAM roles to the service account
The service account gains necessary authorization for runtime resources.
Least privilege access control requires configuring resource access permissions prior to runtime usage.
3
Deploy the function using the gcloud CLI
The serverless function is built, deployed, and linked to the Eventarc trigger and custom service account.
Cloud Functions deployment attaches the pre-configured service account identity.
4
Trigger the event by uploading a file
Eventarc delivers the event notification to the function, invoking the code.
Verification can only occur once the service is active and listening for storage events.

Key Concept

Order of operations for deploying event-driven Cloud Functions with custom service account identities
Rate this question