2017-12-14 03:36:23 +00:00
---
2018-02-08 04:23:05 +00:00
title: About the aws_security_groups Resource
2018-02-14 01:42:39 +00:00
platform: aws
2017-12-14 03:36:23 +00:00
---
2018-02-15 02:23:29 +00:00
# aws\_security\_groups
2017-12-14 03:36:23 +00:00
2019-04-26 18:24:29 +00:00
Use the `aws_security_groups` Chef InSpec audit resource to test properties of some or all security groups.
2017-12-14 03:36:23 +00:00
2018-02-14 01:42:39 +00:00
Security groups are a networking construct that contain ingress and egress rules for network communications. Security groups may be attached to EC2 instances, as well as certain other AWS resources. Along with Network Access Control Lists, Security Groups are one of the two main mechanisms of enforcing network-level security.
2017-12-14 03:36:23 +00:00
<br>
2018-08-09 12:34:49 +00:00
## Availability
### Installation
2019-04-26 18:24:29 +00:00
This resource is distributed along with Chef InSpec itself. You can use it automatically.
2018-08-09 12:34:49 +00:00
### Version
This resource first became available in v2.0.16 of InSpec.
2017-12-14 03:36:23 +00:00
## Syntax
2018-02-08 04:23:05 +00:00
An `aws_security_groups` resource block uses an optional filter to select a group of security groups and then tests that group.
2017-12-14 03:36:23 +00:00
# Verify you have more than the default security group
2018-02-08 04:23:05 +00:00
describe aws_security_groups do
2017-12-20 17:20:09 +00:00
its('entries.count') { should be > 1 }
2017-12-14 03:36:23 +00:00
end
<br>
## Examples
2019-04-26 18:24:29 +00:00
The following examples show how to use this Chef InSpec audit resource.
2017-12-14 03:36:23 +00:00
2018-02-08 04:23:05 +00:00
As this is the initial release of `aws_security_groups`, its limited functionality precludes examples.
2017-12-14 03:36:23 +00:00
<br>
## Filter Criteria
2018-02-15 02:23:29 +00:00
### vpc\_id
2017-12-14 03:36:23 +00:00
A string identifying the VPC which contains the security group.
# Look for a particular security group in just one VPC
2018-02-08 04:23:05 +00:00
describe aws_security_groups.where( vpc_id: 'vpc-12345678') do
2017-12-14 03:36:23 +00:00
its('group_ids') { should include('sg-abcdef12')}
end
2018-02-15 02:23:29 +00:00
### group\_name
2017-12-14 03:36:23 +00:00
2018-02-14 01:42:39 +00:00
A string identifying a group. Since groups are contained in VPCs, group names are unique within the AWS account, but not across VPCs.
2017-12-14 03:36:23 +00:00
# Examine the default security group in all VPCs
2018-02-08 04:23:05 +00:00
describe aws_security_groups.where( group_name: 'default') do
2017-12-14 03:36:23 +00:00
it { should exist }
end
2018-02-15 04:31:56 +00:00
<br>
2017-12-14 03:36:23 +00:00
## Properties
2018-02-26 16:11:06 +00:00
* `entries`, `group_ids`
2018-02-14 01:42:39 +00:00
2018-02-15 04:31:56 +00:00
<br>
## Property Examples
2018-02-14 01:42:39 +00:00
### entries
Provides access to the raw results of the query. This can be useful for checking counts and other advanced operations.
# Allow at most 100 security groups on the account
describe aws_security_groups do
its('entries.count') { should be <= 100}
end
2018-02-15 02:23:29 +00:00
### group\_ids
2017-12-14 03:36:23 +00:00
Provides a list of all security group IDs matched.
2018-02-08 04:23:05 +00:00
describe aws_security_groups do
2017-12-14 03:36:23 +00:00
its('group_ids') { should include('sg-12345678') }
end
2018-02-14 01:42:39 +00:00
## Matchers
2017-12-14 03:36:23 +00:00
2019-04-26 18:24:29 +00:00
This Chef InSpec audit resource has the following special matchers. For a full list of available matchers, please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
2018-02-14 01:42:39 +00:00
### exists
The control will pass if the filter returns at least one result. Use `should_not` if you expect zero matches.
# You will always have at least one SG, the VPC default SG
describe aws_security_groups
it { should exist }
2018-02-26 16:11:06 +00:00
end
2018-05-10 18:57:53 +00:00
## AWS Permissions
Your [Principal](https://docs.aws.amazon.com/IAM/latest/UserGuide/intro-structure.html#intro-structure-principal) will need the `ec2:DescribeSecurityGroups` action with Effect set to Allow.
You can find detailed documentation at [Actions, Resources, and Condition Keys for Amazon EC2](https://docs.aws.amazon.com/IAM/latest/UserGuide/list_amazonec2.html).