Control: VPC security groups should be associated with at least one ENI
Description
This rule ensures the security groups are attached to an AWS Elastic Compute Cloud (AWS EC2) instance or to an ENI. This rule helps monitoring unused security groups in the inventory and the management of your environment.
Usage
Run the control in your terminal:
powerpipe control run aws_compliance.control.vpc_security_group_associated_to_eni
Snapshot and share results via Turbot Pipes:
powerpipe loginpowerpipe control run aws_compliance.control.vpc_security_group_associated_to_eni --share
SQL
This control uses a named query:
with associated_sg as ( select count(sg ->> 'GroupId'), sg ->> 'GroupId' as secgrp_id from aws_ec2_network_interface, jsonb_array_elements(groups) as sg group by sg ->> 'GroupId')select distinct s.arn as resource, case when a.secgrp_id = s.group_id then 'ok' else 'alarm' end as status, case when a.secgrp_id = s.group_id then s.title || ' is associated with ' || a.count || ' ENI(s).' else s.title || ' not associated to any ENI.' end as reason , region, account_idfrom aws_vpc_security_group as s left join associated_sg as a on s.group_id = a.secgrp_id;