Bird
Raised Fist0
GCPcloud~5 mins

Cloud Armor for DDoS and WAF in GCP - Commands & Configuration

Choose your learning style10 modes available
Introduction
Cloud Armor helps protect your websites and apps from bad internet traffic like attacks that try to overload your servers or sneak in harmful requests. It acts like a security guard that blocks unwanted visitors before they reach your services.
When you want to stop large attacks that try to crash your website by sending too many requests at once.
When you need to block traffic from certain countries or IP addresses that cause trouble.
When you want to filter out harmful web requests that try to exploit your app's weaknesses.
When you want to create rules that allow only safe traffic to reach your backend services.
When you want to monitor and log suspicious traffic to understand attack patterns.
Config File - cloudarmor-policy.yaml
cloudarmor-policy.yaml
apiVersion: compute.googleapis.com/v1
kind: SecurityPolicy
name: example-cloudarmor-policy
rules:
- action: deny(403)
  description: "Block traffic from specific IP"
  priority: 1000
  match:
    versionedExpr: SRC_IPS_V1
    config:
      srcIpRanges:
      - 203.0.113.0/24
- action: allow
  description: "Allow all other traffic"
  priority: 2147483647
  match:
    versionedExpr: ""
    config: {}

This file defines a Cloud Armor security policy named example-cloudarmor-policy.

The first rule blocks all traffic coming from the IP range 203.0.113.0/24 by denying with HTTP 403.

The second rule allows all other traffic by default.

Rules are checked in order of priority, with lower numbers checked first.

Commands
This command creates a new Cloud Armor security policy named example-cloudarmor-policy with a description.
Terminal
gcloud compute security-policies create example-cloudarmor-policy --description="Block bad IPs and allow others"
Expected OutputExpected
Created [https://www.googleapis.com/compute/v1/projects/my-project/global/securityPolicies/example-cloudarmor-policy].
→
--description - Adds a human-readable description to the policy.
This command adds a rule to the policy to block traffic from the IP range 203.0.113.0/24 by returning HTTP 403.
Terminal
gcloud compute security-policies rules create 1000 --security-policy=example-cloudarmor-policy --action=deny-403 --src-ip-ranges=203.0.113.0/24 --description="Block traffic from specific IP range"
Expected OutputExpected
Created [https://www.googleapis.com/compute/v1/projects/my-project/global/securityPolicies/example-cloudarmor-policy/rules/1000].
→
--action - Specifies the action to take on matching traffic, here deny with HTTP 403.
→
--src-ip-ranges - Defines the source IP addresses to match.
This command adds a default rule to allow all other traffic not matched by previous rules.
Terminal
gcloud compute security-policies rules create 2147483647 --security-policy=example-cloudarmor-policy --action=allow --description="Allow all other traffic"
Expected OutputExpected
Created [https://www.googleapis.com/compute/v1/projects/my-project/global/securityPolicies/example-cloudarmor-policy/rules/2147483647].
→
--action - Allows traffic that does not match earlier rules.
This command lists all Cloud Armor security policies in the project to verify creation.
Terminal
gcloud compute security-policies list
Expected OutputExpected
NAME DESCRIPTION RULES example-cloudarmor-policy Block bad IPs and allow others 2
This command shows details of the example-cloudarmor-policy including its rules and actions.
Terminal
gcloud compute security-policies describe example-cloudarmor-policy
Expected OutputExpected
name: example-cloudarmor-policy description: Block bad IPs and allow others rules: - action: deny(403) description: Block traffic from specific IP range priority: 1000 match: config: srcIpRanges: - 203.0.113.0/24 versionedExpr: SRC_IPS_V1 - action: allow description: Allow all other traffic priority: 2147483647 match: config: {} versionedExpr: ""
Key Concept

If you remember nothing else from this pattern, remember: Cloud Armor lets you create rules that block or allow traffic based on IPs or request details to protect your apps from attacks.

Common Mistakes
Not setting a default allow rule after deny rules
Without a default allow rule, all traffic not matching deny rules is blocked by default, which can block legitimate users.
Always add a low priority rule that allows all other traffic to avoid accidental blocking.
Using overlapping IP ranges in multiple rules without clear priorities
Rules are evaluated by priority; overlapping ranges can cause unexpected blocking or allowing if priorities are not set correctly.
Assign clear priorities and avoid overlapping IP ranges or carefully order rules to ensure correct behavior.
Not verifying the policy after creation
Without verification, you might miss errors or misconfigurations that leave your app unprotected or inaccessible.
Use 'gcloud compute security-policies describe' and 'list' commands to check your policy and rules.
Summary
Create a Cloud Armor security policy to define traffic filtering rules.
Add rules with priorities to block bad IPs and allow safe traffic.
Verify the policy and rules to ensure correct protection is applied.

Practice

(1/5)
1. What is the main purpose of Google Cloud Armor in protecting your applications?
easy
A. To block bad traffic and protect against attacks like DDoS
B. To store application data securely
C. To manage user authentication and login
D. To monitor application performance metrics

Solution

  1. Step 1: Understand Cloud Armor's role

    Cloud Armor is designed to protect applications from harmful traffic and attacks such as Distributed Denial of Service (DDoS).
  2. Step 2: Compare options

    Options B, C, and D describe other services like storage, authentication, and monitoring, which are not Cloud Armor's main function.
  3. Final Answer:

    To block bad traffic and protect against attacks like DDoS -> Option A
  4. Quick Check:

    Cloud Armor protects apps from bad traffic = A [OK]
Hint: Cloud Armor blocks bad traffic and DDoS attacks [OK]
Common Mistakes:
  • Confusing Cloud Armor with storage or authentication services
  • Thinking Cloud Armor monitors performance instead of security
2. Which of the following is the correct way to create a Cloud Armor security policy using gcloud CLI?
easy
A. gcloud compute security-policies create my-policy --description="Protect app"
B. gcloud compute firewall-rules create my-policy --description="Protect app"
C. gcloud compute instances create my-policy --description="Protect app"
D. gcloud compute networks create my-policy --description="Protect app"

Solution

  1. Step 1: Identify correct gcloud command for Cloud Armor policy

    The command to create a Cloud Armor security policy is under 'compute security-policies create'.
  2. Step 2: Eliminate incorrect commands

    Firewall rules, instances, and networks are different resources and use different commands.
  3. Final Answer:

    gcloud compute security-policies create my-policy --description="Protect app" -> Option A
  4. Quick Check:

    Security policy creation uses 'compute security-policies create' = B [OK]
Hint: Cloud Armor policies use 'compute security-policies create' command [OK]
Common Mistakes:
  • Using firewall or instance commands instead of security-policies
  • Confusing network creation with security policy creation
3. Given this Cloud Armor rule snippet, what action will be taken for requests from IP 203.0.113.5?
{
  "expression": "origin.ip == '203.0.113.5'",
  "action": "deny(403)"
}
medium
A. Requests from 203.0.113.5 will be allowed
B. Requests from 203.0.113.5 will be denied with HTTP 403
C. Requests from all IPs except 203.0.113.5 will be denied
D. Requests from 203.0.113.5 will be redirected

Solution

  1. Step 1: Analyze the rule expression and action

    The rule matches requests where the IP is exactly '203.0.113.5' and denies them with HTTP status 403.
  2. Step 2: Understand the effect on matching IP

    Requests from 203.0.113.5 will be blocked and receive a 403 Forbidden response.
  3. Final Answer:

    Requests from 203.0.113.5 will be denied with HTTP 403 -> Option B
  4. Quick Check:

    IP match with deny(403) means block = D [OK]
Hint: deny(403) blocks matching IPs with forbidden response [OK]
Common Mistakes:
  • Thinking deny means allow
  • Confusing deny with redirect or allow
  • Assuming rule applies to all IPs
4. You created a Cloud Armor security policy but it is not blocking malicious traffic as expected. What is a common mistake to check?
medium
A. The Cloud Armor API is enabled in the project
B. The policy rules have correct IP addresses
C. The firewall rules allow all traffic
D. The security policy is not attached to the backend service or load balancer

Solution

  1. Step 1: Verify policy attachment

    Cloud Armor policies must be attached to backend services or load balancers to take effect.
  2. Step 2: Check other factors

    While correct IPs and API enablement matter, the main reason for no blocking is often missing attachment.
  3. Final Answer:

    The security policy is not attached to the backend service or load balancer -> Option D
  4. Quick Check:

    Policy must be attached to work = C [OK]
Hint: Attach policy to backend service or load balancer to activate [OK]
Common Mistakes:
  • Forgetting to attach policy to backend service
  • Assuming policy works without attachment
  • Ignoring API enablement or rule correctness
5. You want to protect your web app from both DDoS attacks and common web exploits. Which combination of Cloud Armor features should you use?
hard
A. Use Cloud Armor only for DDoS, and rely on firewall rules for web exploits
B. Only create IP-based allow/block rules without WAF
C. Create IP-based allow/block rules and enable the preconfigured WAF rules
D. Use Cloud Armor to monitor traffic but not block anything

Solution

  1. Step 1: Understand protection needs

    DDoS protection requires blocking bad IPs; web exploits need WAF rules to detect attacks like SQL injection.
  2. Step 2: Combine IP rules and WAF

    Cloud Armor supports both IP-based rules and preconfigured WAF rules to cover these threats together.
  3. Final Answer:

    Create IP-based allow/block rules and enable the preconfigured WAF rules -> Option C
  4. Quick Check:

    Use IP rules + WAF for full protection = A [OK]
Hint: Combine IP rules with WAF for best protection [OK]
Common Mistakes:
  • Using only IP rules without WAF for web exploits
  • Relying on firewall rules instead of Cloud Armor WAF
  • Not enabling blocking, only monitoring
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard