Review access allowed by GCP default firewall rules

Review the sources, targets, and ports allowed by default firewall rules, and limit them to business needs.

Description

The default VPC’s predefined SSH and RDP rules allow all IPv4 sources. Check the rule’s sources, target VMs, protocols and ports to determine what it allows.

Potential impact

An overly broad rule can expose management services with an external route or allow unnecessary connections between VMs.

Remediation

Select the management clients, target VMs and required ports. Limit who can change the tags or service accounts used in firewall rules. Check priorities and test the approved connection before removing the broader rule.

Examples

Supply the actual project and network and set service_account_file to a service-account JSON file. With google.cloud 1.14.0, use source_ranges to restrict sources alongside target_tags.

Before

yaml
- name: create a firewall2
  google.cloud.gcp_compute_firewall:
    name: default
    allowed:
      - ip_protocol: tcp
        ports:
          - "22"
    state: present
    network: "{{ my_network2 }}"

The first rule allows TCP 22 from any IPv4 source to all VMs on its VPC. A connection still needs a network path.

After

yaml
- name: create a firewall
  google.cloud.gcp_compute_firewall:
    name: test-object
    allowed:
      - ip_protocol: tcp
        ports:
          - "22"
    target_tags:
      - test-ssh-server
      - staging-ssh-server
    source_ranges:
      - "192.0.2.10/32"
    project: "{{ project_id }}"
    auth_kind: serviceaccount
    service_account_file: "/tmp/auth.pem"
    state: present
    network: "{{ my_network }}"

Replace 192.0.2.10/32 with the internal /32 of an approved SSH client VM and apply one of the target tags to each intended server. The rules have different names. Adding the second leaves the first in place even if both network variables identify the same VPC.

References