For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/iac_security/iac_rules/ansible/gcp/google_compute_network_using_firewall_rule_allows_all_ports.md.
A documentation index is available at /llms.txt.
Allowing ingress on all ports (0-65535) greatly increases attack surface by exposing every service port to network scanning and exploitation. This can lead to unauthorized access, lateral movement, and easier compromise of instances.
This rule flags Ansible tasks using the google.cloud.gcp_compute_firewall or gcp_compute_firewall module where the rule is ingress and the allowed entry contains ports: ["0-65535"] for a firewall associated with a compute network referenced by a preceding google.cloud.gcp_compute_network/gcp_compute_network task.
The allowed.ports property must not include "0-65535". Instead, specify explicit ports or narrow ranges (for example "80", "443", or "1024-2048") and restrict access with appropriate sourceRanges or other selectors.
Secure example (allow only HTTP/HTTPS from a limited source range):
- name:Allow HTTP and HTTPS from internal rangegoogle.cloud.gcp_compute_firewall:name:allow-webnetwork:"{{ my_network }}"direction:INGRESSallowed:- IPProtocol:tcpports:["80","443"]sourceRanges:["10.0.0.0/8"]
Compliant Code Examples
- name:create a firewallgoogle.cloud.gcp_compute_firewall:name:test_objectallowed:- ip_protocol:tcpports:- '22'target_tags:- test-ssh-server- staging-ssh-serversource_tags:- test-ssh-clientsproject:test_projectauth_kind:serviceaccountservice_account_file:"/tmp/auth.pem"state:presentnetwork:"{{ my_network }}"- name:create a networkgoogle.cloud.gcp_compute_network:name:test_objectauto_create_subnetworks:'true'project:test_projectauth_kind:serviceaccountservice_account_file:"/tmp/auth.pem"state:presentregister:my_network
Non-Compliant Code Examples
- name:create a firewall2google.cloud.gcp_compute_firewall:name:test_objectallowed:- ip_protocol:tcpports:- '0-65535'target_tags:- test-ssh-server- staging-ssh-serversource_tags:- test-ssh-clientsproject:test_projectauth_kind:serviceaccountservice_account_file:"/tmp/auth.pem"state:presentnetwork:"{{ my_network2 }}"- name:create a network2google.cloud.gcp_compute_network:name:test_objectauto_create_subnetworks:'true'project:test_projectauth_kind:serviceaccountservice_account_file:"/tmp/auth.pem"state:presentregister:my_network2
1
2
rulesets:- Ansible / GCP # Rules to enforce / GCP.
Request a personalized demo
Get Started with Datadog
Ask AI
AI-generated responses may be inaccurate. Verify important info.