An infrastructure engineer needs to restrict outbound network traffic for Compute Engine instances located within a custom Virtual Private Cloud (VPC) subnet. The engineer creates a custom egress firewall rule that denies all egress traffic to destination with a priority of . A specific set of virtual machines tagged with `api-client` requires HTTPS access to an external partner service hosted at IP address . How should the engineer configure the firewall rules to allow this specific outbound connection while maintaining the blanket block?
- Create an egress firewall rule with priority 900, target tag `api-client`, action ALLOW, destination CIDR range `198.51.100.25/32`, and protocol/port `tcp:443`.Answer
- BCreate an egress firewall rule with priority 1100, target tag `api-client`, action ALLOW, destination CIDR range `198.51.100.25/32`, and protocol/port `tcp:443`.
- CCreate an ingress firewall rule with priority 900, target tag `api-client`, action ALLOW, source CIDR range `198.51.100.25/32`, and protocol/port `tcp:443`.
- DAssign the Compute Network Admin IAM role to the service account attached to the `api-client` instances to allow them to override VPC network firewall restrictions.
Answer
Create an egress firewall rule with priority 900, target tag `api-client`, action ALLOW, destination CIDR range `198.51.100.25/32`, and protocol/port `tcp:443`.
Google Cloud Virtual Private Cloud (VPC) firewall rules are evaluated based on rule priority, where lower numerical values indicate higher precedence. When creating a specific exception to a broad deny rule (such as a blanket egress block at priority 1000), the allowed rule must have a priority number lower than 1000 (such as 900) so that it is processed first. Furthermore, because the virtual machine initiates outbound traffic to an external endpoint, an egress firewall rule targeting the destination IP address and port is required.
Step-by-Step Solution
Key Concept
GCP VPC Firewall Priority and Egress Traffic Direction