CLOUD-NETWORK practice question 23 of 30

In your project my-project, you have two subnets in a Virtual Private Cloud (VPC): subnet-a with IP range 10.128.0.0/20 and subnet-b with IP range…

Full set: 233 questions
In your project my-project, you have two subnets in a Virtual Private Cloud (VPC): subnet-a with IP range 10.128.0.0/20 and subnet-b with IP range 172.16.0.0/24. You need to deploy database servers in subnet-a. You will also deploy the application servers and web servers in subnet-b. You want to configure firewall rules that only allow database traffic from the application servers to the database servers. What should you do?
Answer options
A: Create network tag app-server and service account [email protected]. Add the tag to the application servers, and associate the service account with the database servers. Run the following command: gcloud compute firewall-rules create app-db-firewall-rule \ --action allow \ --direction ingress \ --rules top:3306 \ --source-tags app-server \ --target-service-accounts sa-db@my- project.iam.gserviceaccount.com
B: Create service accounts [email protected] and sa-db@my- project.iam.gserviceaccount.com. Associate service account sa-app with the application servers, and associate the service account sa-db with the database servers. Run the following command: gcloud compute firewall-rules create app-db-firewall-ru --allow TCP:3306 \ --source-service-accounts sa-app@democloud-idp- demo.iam.gserviceaccount.com \ --target-service-accounts sa-db@my- project.iam.gserviceaccount.com Correct answer
C: Create service accounts [email protected] and sa-db@my- project.iam.gserviceaccount.com. Associate the service account sa-app with the application servers, and associate the service account sa-db with the database servers. Run the following command: gcloud compute firewall-rules create app-db-firewall-ru --allow TCP:3306 \ --source-ranges 10.128.0.0/20 \ --source-service-accounts sa-app@my- project.iam.gserviceaccount.com \ --target-service-accounts sa-db@my- project.iam.gserviceaccount.com
D: Create network tags app-server and db-server. Add the app-server tag to the application servers, and add the db-server tag to the database servers. Run the following command: gcloud compute firewall-rules create app-db-firewall-rule \ --action allow \ --direction ingress \ --rules tcp:3306 \ --source-ranges 10.128.0.0/20 \ --source-tags app-server \ --target-tags db-server
Correct Answer:
B. Create service accounts [email protected] and sa-db@my- project.iam.gserviceaccount.com. Associate service account sa-app with the application servers, and associate the service account sa-db with the database servers. Run the following command: gcloud compute firewall-rules create app-db-firewall-ru --allow TCP:3306 \ --source-service-accounts sa-app@democloud-idp- demo.iam.gserviceaccount.com \ --target-service-accounts sa-db@my- project.iam.gserviceaccount.com
Explanation

The most secure and precise method to control traffic between specific groups of VMs is to use service accounts for both the source and target in a firewall rule. This approach ties the rule to the cryptographic identity of the VMs, not to mutable network tags or less specific IP ranges. Option B correctly creates an ingress firewall rule on the database servers (identified by sa-db) that allows traffic on the standard MySQL port (TCP 3306) only from application servers (identified by sa-app). This directly implements the principle of least privilege.

Why Incorrect

A. Using a network tag for the source is less secure than using a service account, as tags are simple metadata and not a verifiable identity.
C. This rule is overly restrictive and uses the wrong source IP range (10.128.0.0/20 is the database subnet, not the application subnet).
D. This rule is incorrect because it uses the wrong source IP range (10.128.0.0/20). Traffic from the application servers (in 172.16.0.0/24) would never match.

References

1. Google Cloud Documentation, "VPC firewall rules," in Virtual Private Cloud. This document states, "You can configure firewall rules based on service accounts... Using service accounts for the target and the source... is a more secure method than using tags for the target and source."

2. Google Cloud Documentation, "Firewall rules details," section "Source and target filtering by service account." This section confirms that you can specify both --source-service-accounts and --target-service-accounts to create identity-based rules.

3. Google Cloud Documentation, "gcloud compute firewall-rules create." The command reference shows the usage of --source-service-accounts and --target-service-accounts flags.

Scroll to Top