Compute Engine instance has an external IP

Confirm whether the VM needs an external IP, and restrict firewall access, administration paths, and service authentication.

Description

A VM with an external IPv4 address can receive internet connections on ports allowed by its network path, firewall and listening services.

Potential impact

Exposed management ports and applications can receive unwanted connections. Stolen credentials or vulnerable services can put data and availability at risk.

Remediation

Before removing an internal VM’s external IP, set up administration through IAP or a VPN. Provide outbound access such as Cloud NAT if needed. google.cloud 1.14.0 does not update network_interfaces on an existing VM, so use the console, gcloud or the API to remove its external IP. Check firewall scope and service authentication, then test management and application connectivity.

Examples

These excerpts create a VM. Supply the actual project, credentials, machine type, boot disk and network.

Before

yaml
- name: 인스턴스 생성
  google.cloud.gcp_compute_instance:
    name: test-object
    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
    state: present

After

yaml
- name: 인스턴스 생성
  google.cloud.gcp_compute_instance:
    name: test-object
    network_interfaces:
      - network: "{{ network }}"
    zone: us-central1-a
    project: "{{ project_id }}"
    auth_kind: serviceaccount
    state: present

The first excerpt requests an external IPv4 address with access_configs. The second requests none for this interface.

References