Table: aws_vpc_security_group - Query AWS VPC Security Groups using SQL
An AWS VPC Security Group acts as a virtual firewall for your instance to control inbound and outbound traffic. When you launch an instance in a VPC, you can assign up to five security groups to the instance. Security groups act at the instance level, not the subnet level, therefore each instance in a subnet in your VPC can be assigned to a different set of security groups.
Table Usage Guide
The aws_vpc_security_group
table in Steampipe provides you with information about Security Groups within AWS Virtual Private Cloud (VPC). This table enables you, as a DevOps engineer, to query security group-specific details, including configurations, associated policies, and related metadata. You can utilize this table to gather insights on security groups, such as understanding the security rules applied, verifying the security policies, and more. The schema outlines for you the various attributes of the security group, including the group ID, name, description, owner ID, and associated VPC ID.
Examples
Basic ingress rule info
Review the configuration of your network's security settings to understand which ports are open and the protocols being used. This can help in identifying potential security vulnerabilities and ensuring that the network is adequately protected.
select group_name, vpc_id, perm ->> 'FromPort' as from_port, perm ->> 'ToPort' as to_port, perm ->> 'IpProtocol' as ip_protocol, perm ->> 'IpRanges' as ip_ranges, perm ->> 'Ipv6Ranges' as ipv6_ranges, perm ->> 'UserIdGroupPairs' as user_id_group_pairs, perm ->> 'PrefixListIds' as prefix_list_idsfrom aws_vpc_security_group as sg cross join jsonb_array_elements(ip_permissions) as perm;
select group_name, vpc_id, json_extract(perm.value, '$.FromPort') as from_port, json_extract(perm.value, '$.ToPort') as to_port, json_extract(perm.value, '$.IpProtocol') as ip_protocol, json_extract(perm.value, '$.IpRanges') as ip_ranges, json_extract(perm.value, '$.Ipv6Ranges') as ipv6_ranges, json_extract(perm.value, '$.UserIdGroupPairs') as user_id_group_pairs, json_extract(perm.value, '$.PrefixListIds') as prefix_list_idsfrom aws_vpc_security_group as sg, json_each(ip_permissions) as perm;
List of security groups whose SSH and RDP access is not restricted from the internet
Explore which security groups have unrestricted SSH and RDP access from the internet, allowing you to identify potential security risks and tighten access controls. This is crucial for maintaining security standards and preventing unauthorized access.
select sg.group_name, sg.group_id, sgr.type, sgr.ip_protocol, sgr.from_port, sgr.to_port, cidr_ipfrom aws_vpc_security_group as sg join aws_vpc_security_group_rule as sgr on sg.group_name = sgr.group_namewhere sgr.type = 'ingress' and sgr.cidr_ip = '0.0.0.0/0' and ( ( sgr.ip_protocol = '-1' -- all traffic and sgr.from_port is null ) or ( sgr.from_port <= 22 and sgr.to_port >= 22 ) or ( sgr.from_port <= 3389 and sgr.to_port >= 3389 ) );
select sg.group_name, sg.group_id, sgr.type, sgr.ip_protocol, sgr.from_port, sgr.to_port, cidr_ipfrom aws_vpc_security_group as sg join aws_vpc_security_group_rule as sgr on sg.group_name = sgr.group_namewhere sgr.type = 'ingress' and sgr.cidr_ip = '0.0.0.0/0' and ( ( sgr.ip_protocol = '-1' -- all traffic and sgr.from_port is null ) or ( sgr.from_port <= 22 and sgr.to_port >= 22 ) or ( sgr.from_port <= 3389 and sgr.to_port >= 3389 ) );
Count of security groups by VPC ID
Gain insights into the distribution of security groups across your Virtual Private Clouds (VPCs) to manage resources and improve security measures effectively.
select vpc_id, count(vpc_id) as countfrom aws_vpc_security_groupgroup by vpc_id;
select vpc_id, count(vpc_id) as countfrom aws_vpc_security_groupgroup by vpc_id;
List of security groups whose name is prefixed with 'launch wizard'
Identify instances where security groups have names prefixed with 'launch wizard'. This can help in managing and organizing your security groups effectively, particularly in large-scale AWS environments.
select group_name, group_idfrom aws_vpc_security_groupwhere group_name like '%launch-wizard%';
select group_name, group_idfrom aws_vpc_security_groupwhere group_name like '%launch-wizard%';
Query examples
- vpc_security_group_by_acount
- vpc_security_group_by_region
- vpc_security_group_by_vpc
- vpc_security_group_count
- vpc_security_group_details_for_vpc
- vpc_security_group_egress_rule_sankey
- vpc_security_group_ingress_rule_sankey
- vpc_security_group_input
- vpc_security_group_overview
- vpc_security_group_tags
- vpc_security_group_unassociated_count
- vpc_security_groups_for_codebuild_project
- vpc_security_groups_for_ec2_application_load_balancer
- vpc_security_groups_for_ec2_classic_load_balancer
- vpc_security_groups_for_ec2_gateway_load_balancer
- vpc_security_groups_for_ec2_network_load_balancer
- vpc_security_groups_for_ecs_service
- vpc_security_groups_for_elasticache_cluster_node
- vpc_security_groups_for_vpc
- vpc_security_unrestricted_egress_count
- vpc_security_unrestricted_ingress_count
- vpc_vpcs_for_vpc_security_group
Control examples
- All Controls > VPC > Ensure no security groups allow ingress from ::/0 to remote server administration ports
- All Controls > VPC > Ensure no security groups allow ingress from 0.0.0.0/0 to port 3389
- All Controls > VPC > Ensure no security groups allow ingress from 0.0.0.0/0 to remote server administration ports
- All Controls > VPC > Ensure no security groups allow ingress from 0.0.0.0/0 to remote server administration ports
- All Controls > VPC > Security groups should not allow unrestricted access to ports with high risk
- All Controls > VPC > Unused EC2 security groups should be removed
- All Controls > VPC > VPC security groups should restrict ingress from 0.0.0.0/0 or ::/0 to cassandra ports 7199 or 9160 or 8888
- All Controls > VPC > VPC security groups should restrict ingress from 0.0.0.0/0 or ::/0 to memcached port 11211
- All Controls > VPC > VPC security groups should restrict ingress from 0.0.0.0/0 or ::/0 to mongoDB ports 27017 and 27018
- All Controls > VPC > VPC security groups should restrict ingress from 0.0.0.0/0 or ::/0 to oracle ports 1521 or 2483
- All Controls > VPC > VPC security groups should restrict ingress Kafka port access from 0.0.0.0/0
- All Controls > VPC > VPC security groups should restrict ingress kibana port access from 0.0.0.0/0
- All Controls > VPC > VPC security groups should restrict ingress redis access from 0.0.0.0/0
- All Controls > VPC > VPC security groups should restrict uses of 'launch-wizard' security groups.
- AWS Foundational Security Best Practices > EC2 > 18 Security groups should only allow unrestricted incoming traffic for authorized ports
- AWS Foundational Security Best Practices > EC2 > 19 Security groups should not allow unrestricted access to ports with high risk
- AWS Foundational Security Best Practices > EC2 > 2 VPC default security groups should not allow inbound or outbound traffic
- CIS AWS Compute Services Benchmark v1.0.0 > 2 Elastic Cloud Compute (EC2) > 2.7 Ensure Default EC2 Security groups are not being used
- CIS v1.2.0 > 4 Networking > 4.1 Ensure no security groups allow ingress from 0.0.0.0/0 to port 22
- CIS v1.2.0 > 4 Networking > 4.2 Ensure no security groups allow ingress from 0.0.0.0/0 to port 3389
- CIS v1.2.0 > 4 Networking > 4.3 Ensure the default security group of every VPC restricts all traffic
- CIS v1.3.0 > 5 Networking > 5.2 Ensure no security groups allow ingress from 0.0.0.0/0 to remote server administration ports
- CIS v1.3.0 > 5 Networking > 5.3 Ensure the default security group of every VPC restricts all traffic
- CIS v1.4.0 > 5 Networking > 5.2 Ensure no security groups allow ingress from 0.0.0.0/0 to remote server administration ports
- CIS v1.4.0 > 5 Networking > 5.3 Ensure the default security group of every VPC restricts all traffic
- CIS v1.5.0 > 5 Networking > 5.2 Ensure no security groups allow ingress from 0.0.0.0/0 to remote server administration ports
- CIS v1.5.0 > 5 Networking > 5.3 Ensure no security groups allow ingress from ::/0 to remote server administration ports
- CIS v1.5.0 > 5 Networking > 5.4 Ensure the default security group of every VPC restricts all traffic
- CIS v2.0.0 > 5 Networking > 5.2 Ensure no security groups allow ingress from 0.0.0.0/0 to remote server administration ports
- CIS v2.0.0 > 5 Networking > 5.3 Ensure no security groups allow ingress from ::/0 to remote server administration ports
- CIS v2.0.0 > 5 Networking > 5.4 Ensure the default security group of every VPC restricts all traffic
- CIS v3.0.0 > 5 Networking > 5.2 Ensure no security groups allow ingress from 0.0.0.0/0 to remote server administration ports
- CIS v3.0.0 > 5 Networking > 5.3 Ensure no security groups allow ingress from ::/0 to remote server administration ports
- CIS v3.0.0 > 5 Networking > 5.4 Ensure the default security group of every VPC restricts all traffic
- VPC default security group should not allow inbound and outbound traffic
- VPC security groups should be associated with at least one ENI
- VPC Security groups should only allow unrestricted incoming traffic for authorized ports
- VPC security groups should restrict ingress access on ports 20, 21, 22, 3306, 3389, 4333 from 0.0.0.0/0
- VPC security groups should restrict ingress SSH access from 0.0.0.0/0
- VPC security groups should restrict ingress TCP and UDP access from 0.0.0.0/0
Schema for aws_vpc_security_group
Name | Type | Operators | Description |
---|---|---|---|
_ctx | jsonb | Steampipe context in JSON form. | |
account_id | text | =, !=, ~~, ~~*, !~~, !~~* | The AWS Account ID in which the resource is located. |
akas | jsonb | Array of globally unique identifier strings (also known as) for the resource. | |
arn | text | The Amazon Resource Name (ARN) specifying the security group. | |
description | text | = | A description of the security group. |
group_id | text | = | Contains the unique ID to identify a security group. |
group_name | text | = | The friendly name that identifies the security group. |
ip_permissions | jsonb | A list of inbound rules associated with the security group | |
ip_permissions_egress | jsonb | A list of outbound rules associated with the security group | |
owner_id | text | = | Contains the AWS account ID of the owner of the security group. |
partition | text | The AWS partition in which the resource is located (aws, aws-cn, or aws-us-gov). | |
region | text | The AWS Region in which the resource is located. | |
sp_connection_name | text | =, !=, ~~, ~~*, !~~, !~~* | Steampipe connection name. |
sp_ctx | jsonb | Steampipe context in JSON form. | |
tags | jsonb | A map of tags for the resource. | |
tags_src | jsonb | A list of tags that are attached to the security group | |
title | text | Title of the resource. | |
vpc_id | text | = | The ID of the VPC for the security group. |
Export
This table is available as a standalone Exporter CLI. Steampipe exporters are stand-alone binaries that allow you to extract data using Steampipe plugins without a database.
You can download the tarball for your platform from the Releases page, but it is simplest to install them with the steampipe_export_installer.sh
script:
/bin/sh -c "$(curl -fsSL https://steampipe.io/install/export.sh)" -- aws
You can pass the configuration to the command with the --config
argument:
steampipe_export_aws --config '<your_config>' aws_vpc_security_group