Google Cloud | Enforcing Restrictions on External IP Addresses in VPCs

Enforcing Restrictions on External IP Addresses in VPCs

Question

Your organization has decided to restrict the use of external IP addresses on instances to only approved instances.

You want to enforce this requirement across all of your Virtual Private Clouds (VPCs)

What should you do?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

D.

https://cloud.google.com/compute/docs/ip-addresses/reserve-static-external-ip-address

The correct answer to the question is D: Set an Organization Policy with a constraint on constraints/compute.vmExternalIpAccess. List the approved instances in the allowedValues list.

Here's a detailed explanation:

When you create a Google Cloud Platform (GCP) instance, it's automatically assigned an external IP address. However, for security reasons, you may want to restrict the use of external IP addresses on instances to only approved instances. There are several ways to do this, but the best approach is to use an Organization Policy constraint.

An Organization Policy is a centralized way to manage and enforce policies across all projects in your organization. A constraint is a rule that defines a policy. In this case, you'll use the compute.vmExternalIpAccess constraint to restrict the use of external IP addresses on instances.

Here's how you can do it:

  1. Open the Cloud Console and go to the Organization Policies page.
  2. Create a new policy or edit an existing policy.
  3. Click Add Constraint and select compute.vmExternalIpAccess from the list of constraints.
  4. Set the Constraint mode to "Enforced."
  5. In the allowedValues field, list the approved instances. For example, you can use the instance name or a label.
  6. Click Save.

With this policy in place, any new instance that tries to use an external IP address will be denied unless it's on the approved list. If an instance is already running and has an external IP address, it will continue to use it unless you stop and restart the instance.

Note that this policy will only apply to instances created in projects that are under the organization's control. If someone creates a project outside of the organization's control and creates an instance there, this policy won't apply.

Options A, B, and C are incorrect because they don't address the requirement to restrict the use of external IP addresses on instances to only approved instances across all VPCs. Removing the default route on all VPCs (Option A) or creating a new VPC with a default route to the internet gateway (Option B) won't prevent instances from using external IP addresses. Implementing a Cloud NAT solution (Option C) will remove the need for external IP addresses, but it won't restrict their use on approved instances.