turbot/gcp_compliance

Query: compute_firewall_rule_ingress_access_restricted_to_http_port_80

Usage

powerpipe query gcp_compliance.query.compute_firewall_rule_ingress_access_restricted_to_http_port_80

Steampipe Tables

SQL

with ip_protocol_all as (
select
name
from
gcp_compute_firewall
where
direction = 'INGRESS'
and action = 'Allow'
and (
source_ranges ?& array['0.0.0.0/0']
or source_ranges ?& array['::0']
or source_ranges ?& array['0.0.0.0']
or source_ranges ?& array['::/0']
or source_ranges ?& array['::']
)
and (
allowed @> '[{"IPProtocol":"all"}]'
or (allowed @> '[{"IPProtocol":"tcp"}]' and allowed -> 0 -> 'ports' is null)
or (allowed @> '[{"IPProtocol":"udp"}]' and allowed -> 0 -> 'ports' is null)
)
),
ip_protocol_tcp_udp as (
select
name
from
gcp_compute_firewall,
jsonb_array_elements(allowed) as p,
jsonb_array_elements_text(p -> 'ports') as port
where
direction = 'INGRESS'
and action = 'Allow'
and (
source_ranges ?& array['0.0.0.0/0']
or source_ranges ?& array['::0']
or source_ranges ?& array['0.0.0.0']
or source_ranges ?& array['::/0']
or source_ranges ?& array['::']
)
and (p ->> 'IPProtocol' = 'tcp' or p ->> 'IPProtocol' = 'udp')
and (
port = '80'
or (
port like '%-%'
and split_part(port, '-', 1) :: integer <= 80
and split_part(port, '-', 2) :: integer >= 80
)
)
)
select
self_link resource,
case
when name in (select name from ip_protocol_tcp_udp) then 'alarm'
when name in (select name from ip_protocol_all) then 'alarm'
else 'ok'
end as status,
case
when name in (select name from ip_protocol_tcp_udp) or name in (select name from ip_protocol_all)
then title || ' allows access from internet to HTTP port 80.'
else title || ' restricts access from internet to HTTP port 80.'
end as reason
, location as location, project as project
from
gcp_compute_firewall;

Controls

The query is being used by the following controls: