Description
Enable can_ip_forward only on VMs that must forward packets for other addresses, such as routers or NAT appliances. Guest settings, routes and firewall rules must also permit forwarding.
Potential impact
A compromised VM with a forwarding path can relay traffic to other networks. Turning off forwarding on an active router can interrupt that traffic.
Remediation
Use can_ip_forward: no when creating an ordinary VM. In google.cloud 1.14.0, gcp_compute_instance cannot change this property on an existing VM. Update its canIpForward property in Compute Engine. On routing appliances, keep only the necessary guest forwarding, routes and firewall rules. Verify the applied setting and required connections.
Examples
These excerpts are for a new VM. Supply the actual project, network, address, boot disk and service account JSON file. Verify the startup script’s location and contents.
Before
- name: Create a VM
google.cloud.gcp_compute_instance:
name: test-object
machine_type: n1-standard-1
metadata:
startup-script-url: gs://graphite-playground/bootstrap.sh
cost-center: "12345"
labels:
environment: production
network_interfaces:
- network: "{{ network }}"
access_configs:
- name: External NAT
nat_ip: "{{ address }}"
type: ONE_TO_ONE_NAT
zone: us-central1-a
project: "{{ project_id }}"
auth_kind: serviceaccount
service_account_file: "/tmp/auth.pem"
state: present
can_ip_forward: yes
After
- name: Create a VM
google.cloud.gcp_compute_instance:
name: test-object
machine_type: n1-standard-1
metadata:
startup-script-url: gs://graphite-playground/bootstrap.sh
cost-center: "12345"
labels:
environment: production
network_interfaces:
- network: "{{ network }}"
access_configs:
- name: External NAT
nat_ip: "{{ address }}"
type: ONE_TO_ONE_NAT
zone: us-central1-a
project: "{{ project_id }}"
auth_kind: serviceaccount
service_account_file: /tmp/auth.pem
state: present
can_ip_forward: no
The second task still assigns an external IPv4 address. Manage external access and application-level proxying separately.