Other Articles

VPC Firewall – Restrict Public SSH and RDP Access

Secure Configuration Checks > GCP

This check ensures that no VPC firewall rule allows SSH (port 22) or RDP (port 3389) from the entire internet. Open remote access ports are scanned and attacked within minutes.

Check Details

  • Resource: VPC Network (firewall rules)
  • Check: Restrict public SSH and RDP access
  • Risk: Attackers can try brute force attacks and exploit remote access flaws. A successful attack gives them control of the instance.

Remediation via Google Cloud Console

  1. Log in to the Google Cloud Console and navigate to VPC network > Firewall. VPC Firewall Rules
  2. Find each ingress rule that allows tcp:22 or tcp:3389 from the source 0.0.0.0/0 or ::/0.
  3. Click the rule name, then click Edit. VPC Firewall Rule Edit
  4. Under Source IPv4 ranges, replace 0.0.0.0/0 with a trusted IP range. To use Identity-Aware Proxy, enter 35.235.240.0/20. VPC Firewall Source Ranges
  5. Click Save to apply the changes.
  6. If the rule is not needed, select it and click Delete instead.
  7. Repeat steps 2 to 6 for every affected rule.

Remediation via Google Cloud CLI

  1. Open the Google Cloud Console and launch Cloud Shell. GCP Cloud Shell
  2. List the enabled ingress rules that are open to the internet:

    gcloud compute firewall-rules list \
    --filter='direction=INGRESS AND disabled=false AND (sourceRanges:"0.0.0.0/0" OR sourceRanges:"::/0")' \
    --format="table(name,network.basename(),sourceRanges.list(),allowed[].map().firewall_rule().list())"
    

    A rule is non-compliant if it allows tcp:22, tcp:3389, a port range that includes them, or all protocols.

  3. Limit the source of the rule to a trusted range:

    gcloud compute firewall-rules update <RULE_NAME> --source-ranges=<TRUSTED_CIDR>
    

    Replace <RULE_NAME> with the rule name and <TRUSTED_CIDR> with your range, for example 203.0.113.10/32. To use Identity-Aware Proxy, use 35.235.240.0/20. If the rule also allows other ports, create a separate rule for them first.

  4. Or delete the rule if it is not needed:

    gcloud compute firewall-rules delete <RULE_NAME>
    
  5. Verify the rule:

    gcloud compute firewall-rules describe <RULE_NAME> \
    --format="yaml(name,sourceRanges,allowed)"
    
    Verify VPC firewall rule

Default Value

The default network has the rules default-allow-ssh and default-allow-rdp. Both allow access from 0.0.0.0/0. Custom networks have no such rules, because ingress traffic is denied by default.

Updated on 09 November, 2026