Control: Network Security Groups RDP Services are restricted from the Internet
Description
Disable Internet exposed RDP ports on network security groups.
Usage
Run the control in your terminal:
powerpipe control run terraform_azure_compliance.control.network_security_group_rdp_access_restricted
Snapshot and share results via Turbot Pipes:
powerpipe loginpowerpipe control run terraform_azure_compliance.control.network_security_group_rdp_access_restricted --share
SQL
This control uses a named query:
with nsg_group as ( select distinct address as name from terraform_resource, jsonb_array_elements( case jsonb_typeof(attributes_std -> 'security_rule') when 'array' then (attributes_std -> 'security_rule') when 'object' then jsonb_build_array(attributes_std -> 'security_rule') else null end ) sg, jsonb_array_elements_text( case when ((sg -> 'destination_port_ranges') != 'null') and jsonb_array_length(sg -> 'destination_port_ranges') > 0 then (sg -> 'destination_port_ranges') else jsonb_build_array(sg -> 'destination_port_range') end ) as dport, jsonb_array_elements_text( case when ((sg -> 'source_address_prefixes') != 'null') and jsonb_array_length(sg -> 'source_address_prefixes') > 0 then (sg -> 'source_address_prefixes') else jsonb_build_array(sg -> 'source_address_prefix') end) as sip where type = 'azurerm_network_security_group' and lower(sg ->> 'access') = 'allow' and lower(sg ->> 'direction') = 'inbound' and (lower(sg ->> 'protocol') ilike 'TCP' or lower(sg ->> 'protocol') = '*') and lower(sip) in ('*', '0.0.0.0', '0.0.0.0/0', 'internet', 'any', '<nw>/0', '/0') and ( dport in ('3389', '*') or ( dport like '%-%' and split_part(dport, '-', 1) :: integer <= 3389 and split_part(dport, '-', 2) :: integer >= 3389 ) ))select r.address as resource, case when g.name is null then 'ok' else 'alarm' end as status, split_part(r.address, '.', 2) || case when g.name is null then ' restricts RDP access from internet' else ' allows RDP access from internet' end || '.' reason , path || ':' || start_linefrom terraform_resource as r left join nsg_group as g on g.name = r.namewhere type = 'azurerm_network_security_group';