9f5d59748d | ||
---|---|---|
.. | ||
README.md | ||
main.tf | ||
outputs.tf | ||
variables.tf |
README.md
HTTP Load Balancer with Cloud Armor
Google Cloud HTTP(S) load balancing is implemented at the edge of Google's network in Google's points of presence (POP) around the world. User traffic directed to an HTTP(S) load balancer enters the POP closest to the user and is then load balanced over Google's global network to the closest backend that has sufficient capacity available.
Cloud Armor IP allowlist/denylist enable you to restrict or allow access to your HTTP(S) load balancer at the edge of the Google Cloud, as close as possible to the user and to malicious traffic. This prevents malicious users or traffic from consuming resources or entering your virtual private cloud (VPC) networks.
In this lab, you configure an HTTP Load Balancer with global backends, as shown in the diagram below. Then, you stress test the Load Balancer and denylist the stress test IP with Cloud Armor.
Running the example
Clone this repository or open it in cloud shell, then go through the following steps to create resources:
terraform init
terraform apply -var project_id=my-project-id
The following outputs will be available once everything is deployed:
glb_ip_address
, containing the IPv4 address of the HTTP Load Balancervm_siege_external_ip
, containing the external IPv4 address of the siege VM.
Once done testing, you can clean up resources by running terraform destroy
.
Testing the example
-
Connect to the siege VM and run the following command
siege -c 250 -t150s http://$LB_IP`ß
-
In the Cloud Console, on the Navigation menu, click Network Services > Load balancing.
-
Click Backends.
-
Click http-backend.
-
Navigate to http-lb.
-
Click on the Monitoring tab.
-
Monitor the Frontend Location (Total inbound traffic) between North America and the two backends for 2 to 3 minutes. At first, traffic should just be directed to us-east1-mig but as the RPS increases, traffic is also directed to europe-west1-mig. This demonstrates that by default traffic is forwarded to the closest backend but if the load is very high, traffic can be distributed across the backends.
-
Re-run terraform as follows:
terraform apply -var project_id=my-project-id -var enforce_security_policy=true
Like this we have applied a security policy to denylist the IP address of the siege VM
-
From the siege VM run the following command and verify that you get a 403 Forbidden error code back.
curl http://$LB_IP
Variables
name | description | type | required | default |
---|---|---|---|---|
project_id | Identifier of the project. | string |
✓ | |
enforce_security_policy | Enforce security policy. | bool |
true |
|
prefix | Prefix used for created resources. | string |
null |
|
project_create | Parameters for the creation of the new project. | object({…}) |
null |
Outputs
name | description | sensitive |
---|---|---|
glb_ip_address | Load balancer IP address. | |
vm_siege_external_ip | Siege VM external IP address. |