Skip to content

Commit 4836da1

Browse files
authored
added the single_bucket input and updated the README
Signed-off-by: GitHub <noreply@github.com>
1 parent 90f5c1d commit 4836da1

File tree

4 files changed

+88
-40
lines changed

4 files changed

+88
-40
lines changed

README.md

Lines changed: 69 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1-
# aws-s3-baseline
1+
# aws-s3-baseline
22

33
A micro-baseline to check for insecure or public S3 buckets and bucket objects in your AWS Environment. This [InSpec](https://github.com/chef/inspec) compliance profile verifies that you do not have any insure or open to public S3 Bucket or Bucket Objects in your AWS Environment in an automated way.
44

5-
NOTE: Small Word of Warning
5+
#### Warning: Large amounts of Bucket Objects
66

7-
In this InSpec profile implementation, the `s3-objects-no-public-access` control iterates through and verifies every objects in each bucket in your AWS Environment, thus its runtime will depend on the number of objects in your S3 Buckets.
7+
The `s3-objects-no-public-access` control iterates through and verifies every objects in each bucket in your AWS Environment, thus its runtime will depend on the number of objects in your S3 Buckets.
8+
9+
If you have buckets with large numbers of objects, we suggest you script a loop and use the `single_bucket` input to parallelize the workload.
10+
11+
Then you can load all your HDF JSON results into [Heimdall Lite](https://heimdall-lite.mitre.org) to easily review all your scan results.
812

913
## Getting Started
10-
It is intended and recommended that InSpec and this profile be run from a __"runner"__ host (such as a DevOps orchestration server, an administrative management system, or a developer's workstation/laptop) against the target remotely over __AWS CLI__.
1114

12-
__For the best security of the runner, always install on the runner the _latest version_ of InSpec and supporting Ruby language components.__
15+
It is intended and recommended that InSpec and this profile be run from a **"runner"** host (such as a DevOps orchestration server, an administrative management system, or a developer's workstation/laptop) against the target remotely over **AWS CLI**.
16+
17+
**For the best security of the runner, always install on the runner the _latest version_ of InSpec and supporting Ruby language components.**
1318

1419
The latest versions and installation options are available at the [InSpec](http://inspec.io/) site.
1520

@@ -26,27 +31,38 @@ You will need to ensure your AWS CLI environment has the right system environmen
2631

2732
### Notes on MFA
2833

29-
In any AWS MFA enabled environment - you need to use `derived credentials` to use the CLI. Your default `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` will not satisfy the MFA Policies in AWS environments.
34+
In any AWS MFA enabled environment - you need to use `derived credentials` to use the CLI. Your default `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` will not satisfy the MFA Policies in AWS environments.
3035

31-
- The AWS documentation is here: https://docs.aws.amazon.com/cli/latest/reference/sts/get-session-token.html
32-
- The AWS profile documentation is here: https://docs.aws.amazon.com/cli/latest/userguide/cli-multiple-profiles.html
33-
- A useful bash script for automating this is here: https://gist.github.com/dinvlad/d1bc0a45419abc277eb86f2d1ce70625
36+
- The AWS documentation is here: <https://docs.aws.amazon.com/cli/latest/reference/sts/get-session-token.html>
37+
- The AWS profile documentation is here: <https://docs.aws.amazon.com/cli/latest/userguide/cli-multiple-profiles.html>
38+
- A useful bash script for automating this is here: <https://gist.github.com/dinvlad/d1bc0a45419abc277eb86f2d1ce70625>
3439

3540
To generate credentials using an AWS Profile you will need to use the following AWS CLI commands.
3641

37-
a. `aws sts get-session-token --serial-number arn:aws:iam::<$YOUR-MFA-SERIAL> --token-code <$YOUR-CURRENT-MFA-TOKEN> --profile=<$YOUR-AWS-PROFILE>`
42+
a. `aws sts get-session-token --serial-number arn:aws:iam::<$YOUR-MFA-SERIAL> --token-code <$YOUR-CURRENT-MFA-TOKEN> --profile=<$YOUR-AWS-PROFILE>`
3843

39-
b. Then export the `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` and `AWS_SESSION_TOKEN` that was generated by the above command.
44+
b. Then export the `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` and `AWS_SESSION_TOKEN` that was generated by the above command.
4045

4146
## Tailoring to Your Environment
47+
4248
The following inputs must be configured in an inputs ".yml" file for the profile to run correctly for your specific environment. More information about InSpec inputs can be found in the [InSpec Profile Documentation](https://www.inspec.io/docs/reference/profiles/).
43-
44-
```
45-
# Description: List of buckets exempted from inspection.
46-
exception_bucket_list: []
49+
50+
```yaml
51+
# List of buckets exempted from inspection.
52+
exception_bucket_list:
53+
- bucket1
54+
- bucket2
55+
...
56+
57+
# Test only one bucket
58+
single_bucket: 'my-bucket'
4759
```
4860
49-
## Usage
61+
## Note
62+
63+
When you use the `single_bucket` input, the profile will _***ONLY scan***_ that bucket.
64+
65+
# Usage
5066

5167
```
5268
# Set required ENV variables
@@ -55,72 +71,86 @@ $ export AWS_SECRET_ACCESS_KEY=access-key
5571
$ export AWS_SESSION_TOKEN=session-token # if MFA is enabled
5672
```
5773
58-
# Running This Baseline Directly from Github
74+
## Running This Baseline Directly from Github
5975
60-
```
61-
# How to run
62-
inspec exec https://github.com/mitre/aws-s3-baseline/archive/master.tar.gz --target aws:// --input-file=<path_to_your_inputs_file/name_of_your_inputs_file.yml> --reporter=cli json:<path_to_your_output_file/name_of_your_output_file.json>
63-
```
76+
### Testing all your buckets except those defined in your `excluded buckets`
77+
78+
`inspec exec https://github.com/mitre/aws-s3-baseline/archive/master.tar.gz --target aws:// --input-file=your_inputs_file.yml --reporter=cli json:your_output_file.json`
79+
80+
### Testing a single bucket
81+
82+
`inspec exec https://github.com/mitre/aws-s3-baseline/archive/master.tar.gz --target aws:// --input single_bucket=your_bucket --reporter=cli json:your_output_file.json`
6483
6584
### Different Run Options
6685
67-
[Full exec options](https://docs.chef.io/inspec/cli/#options-3)
86+
[Full exec options](https://docs.chef.io/inspec/cli/#options-3)
6887
69-
## Running This Baseline from a local Archive copy
88+
## Running This Baseline from a local Archive copy
7089
7190
If your runner is not always expected to have direct access to GitHub, use the following steps to create an archive bundle of this baseline and all of its dependent tests:
7291
7392
(Git is required to clone the InSpec profile using the instructions below. Git can be downloaded from the [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) site.)
7493
75-
When the __"runner"__ host uses this profile baseline for the first time, follow these steps:
94+
When the **"runner"** host uses this profile baseline for the first time, follow these steps:
7695
77-
```
96+
### Create your Archieve of the Profile
97+
98+
```bash
7899
mkdir profiles
79100
cd profiles
80101
git clone https://github.com/mitre/aws-s3-baseline
81102
inspec archive aws-s3-baseline
82-
inspec exec <name of generated archive> --target aws:// --input-file=<path_to_your_inputs_file/name_of_your_inputs_file.yml> --reporter=cli json:<path_to_your_output_file/name_of_your_output_file.json>
83103
```
104+
105+
### Run your scan using the Archieved Copy
106+
107+
`inspec exec <name of generated archive> --target aws:// --input-file=<path_to_your_inputs_file/name_of_your_inputs_file.yml> --reporter=cli json:<path_to_your_output_file/name_of_your_output_file.json>`
108+
109+
### Updating your Archieved Copy
110+
84111
For every successive run, follow these steps to always have the latest version of this baseline:
85112

86-
```
113+
```bash
87114
cd aws-s3-baseline
88115
git pull
89116
cd ..
90117
inspec archive aws-s3-baseline --overwrite
91-
inspec exec <name of generated archive> --target aws:// --input-file=<path_to_your_inputs_file/name_of_your_inputs_file.yml> --reporter=cli json:<path_to_your_output_file/name_of_your_output_file.json>
92118
```
93119

120+
### Run your updated Archieved Copy
121+
122+
`inspec exec <name of generated archive> --target aws:// --input-file=<path_to_your_inputs_file/name_of_your_inputs_file.yml> --reporter=cli json:<path_to_your_output_file/name_of_your_output_file.json>`
123+
94124
## Using Heimdall for Viewing the JSON Results
95125

96-
The JSON results output file can be loaded into __[heimdall-lite](https://heimdall-lite.mitre.org/)__ for a user-interactive, graphical view of the InSpec results.
126+
The JSON results output file can be loaded into **[heimdall-lite](https://heimdall-lite.mitre.org/)** for a user-interactive, graphical view of the InSpec results.
97127

98-
The JSON InSpec results file may also be loaded into a __[full heimdall server](https://github.com/mitre/heimdall)__, allowing for additional functionality such as to store and compare multiple profile runs.
128+
The JSON InSpec results file may also be loaded into a **[full heimdall server](https://github.com/mitre/heimdall)**, allowing for additional functionality such as to store and compare multiple profile runs.
99129

100130
## Authors
101131

102-
* Rony Xavier - [rx294](https://github.com/rx294)
103-
* Aaron Lippold - [aaronlippold](https://github.com/aaronlippold)
104-
* Matthew Dromazos - [dromazmj](https://github.com/dromazmj)
132+
- Rony Xavier - [rx294](https://github.com/rx294)
133+
- Aaron Lippold - [aaronlippold](https://github.com/aaronlippold)
134+
- Matthew Dromazos - [dromazmj](https://github.com/dromazmj)
105135

106136
### Special Thanks
107137

108-
* Shivani Karikar - [karikarshivani](https://github.com/karikarshivani)
138+
- Shivani Karikar - [karikarshivani](https://github.com/karikarshivani)
109139

110140
### NOTICE
111141

112-
© 2018-2020 The MITRE Corporation.
142+
© 2018-2021 The MITRE Corporation.
113143

114144
Approved for Public Release; Distribution Unlimited. Case Number 18-3678.
115145

116-
### NOTICE
146+
### NOTICE
117147

118148
MITRE hereby grants express written permission to use, reproduce, distribute, modify, and otherwise leverage this software to the extent permitted by the licensed terms provided in the LICENSE.md file included with this project.
119149

120-
### NOTICE
150+
### NOTICE
121151

122-
This software was produced for the U. S. Government under Contract Number HHSM-500-2012-00008I, and is subject to Federal Acquisition Regulation Clause 52.227-14, Rights in Data-General.
152+
This software was produced for the U. S. Government under Contract Number HHSM-500-2012-00008I, and is subject to Federal Acquisition Regulation Clause 52.227-14, Rights in Data-General.
123153

124154
No other use other than that granted to the U. S. Government, or to those acting on behalf of the U. S. Government under that Clause is authorized without the express written permission of The MITRE Corporation.
125155

126-
For further information, please contact The MITRE Corporation, Contracts Management Office, 7515 Colshire Drive, McLean, VA 22102-7539, (703) 983-6000.
156+
For further information, please contact The MITRE Corporation, Contracts Management Office, 7515 Colshire Drive, McLean, VA 22102-7539, (703) 983-6000.

controls/aws_s3_bucket.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
describe 'This control is Non Applicable since no S3 buckets were found.' do
2424
skip 'This control is Non Applicable since no S3 buckets were found.'
2525
end
26+
elsif !input('single_bucket').to_s.empty?
27+
describe aws_s3_bucket(input('single_bucket').to_s) do
28+
it { should_not be_public }
29+
end
2630
else
2731
aws_s3_buckets.bucket_names.each do |bucket|
2832
next if exception_bucket_list.include?(bucket)

controls/aws_s3_bucket_objects.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@
2323
describe 'This control is Non Applicable since no S3 buckets were found.' do
2424
skip 'This control is Non Applicable since no S3 buckets were found.'
2525
end
26+
elsif !input('single_bucket').to_s.empty?
27+
my_items = aws_s3_bucket_objects(bucket_name: input('single_bucket')).contents_keys
28+
describe "#{input('single_bucket')} object" do
29+
my_items.each do |key|
30+
describe key.to_s do
31+
subject { aws_s3_bucket_object(bucket_name: input('single_bucket'), key: key) }
32+
it { should_not be_public }
33+
end
34+
end
35+
end
2636
else
2737
aws_s3_buckets.bucket_names.each do |bucket|
2838
next if exception_bucket_list.include?(bucket)

inspec.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ copyright: MITRE, 2022
55
copyright_email: inspec@mitre.org
66
license: Apache-2.0
77
summary: "InSpec validation example baseline profile for AWS S3 - to test if you have public buckets"
8-
version: 1.2.0
8+
version: 1.3.0
99

1010
inspec_version: ">= 4.0"
1111

@@ -22,3 +22,7 @@ inputs:
2222
type: array
2323
value:
2424
- ""
25+
- name: single_bucket
26+
description: "The name of the single bucket you wish to scan"
27+
type: string
28+
value: ""

0 commit comments

Comments
 (0)