aws_recon 0.2.25 → 0.2.26

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8786af60d08967c2203b1f4417480b135ae32b9a40ec05810afc9c2ae126f49d
4
- data.tar.gz: fbd4741002a54dc15f2b2716dee6e1b6efcec48edfdf3e101d9c7bcb19105a4e
3
+ metadata.gz: e94ce0b14c283d62b106df80e56dc8340c4acc37970381cf95294d337d55ceda
4
+ data.tar.gz: 8e4fb54d9907493f94dfe4a3d73afcb396d8c101c309e8acacac6b527076be81
5
5
  SHA512:
6
- metadata.gz: 2c11e60d61cf9fcf894b8e38cb136e934b03fd7e9ef1bd349ce27c41c9943e75cb146893d14374167d7f2eb73b40d97a901fbaebd6e6aee5ac93ef8095b1d0b4
7
- data.tar.gz: 9510a49029fbc382fefc50ad8ae0de0351b6f8648a1044abbebdf695459ef5a4845014057618387549546876c10ea1eb09cba55f4692a0405f41b96810c0dce5
6
+ metadata.gz: '0283ab12e7885d2462f24038648b5a326978a88465a92869fb8dcd617dde52789383d48a343c017050fc1c321ce72c40466a116b8d2bf3adc861fea2c4307e35'
7
+ data.tar.gz: e325e70dee2f236d77c0bb72e257a80b14900d26ed3347aa316e9b0e89fec7dbfa82e3fca010ae95959692114ccd58a0b7a8addc93fc573eac193ca5ea0c4ccc
@@ -8,24 +8,24 @@ class ECS < Mapper
8
8
  resources = []
9
9
 
10
10
  #
11
- # describe_clusters
11
+ # list_clusters
12
12
  #
13
- @client.describe_clusters.each_with_index do |response, page|
13
+ @client.list_clusters.each_with_index do |response, page|
14
14
  log(response.context.operation_name, page)
15
15
 
16
- response.clusters.each do |cluster|
17
- struct = OpenStruct.new(cluster.to_h)
16
+ response.cluster_arns.each do |cluster|
17
+ struct = OpenStruct.new(@client.describe_clusters({ clusters: [cluster] }).clusters.first.to_h)
18
18
  struct.type = 'cluster'
19
- struct.arn = cluster.cluster_arn
19
+ struct.arn = cluster
20
20
  struct.tasks = []
21
21
 
22
22
  # list_tasks
23
- @client.list_tasks({ cluster: cluster.cluster_arn }).each_with_index do |response, page|
23
+ @client.list_tasks({ cluster: cluster }).each_with_index do |response, page|
24
24
  log(response.context.operation_name, 'list_tasks', page)
25
25
 
26
26
  # describe_tasks
27
27
  response.task_arns.each do |task_arn|
28
- @client.describe_tasks({ cluster: cluster.cluster_arn, tasks: [task_arn] }).tasks.each do |task|
28
+ @client.describe_tasks({ cluster: cluster, tasks: [task_arn] }).tasks.each do |task|
29
29
  struct.tasks.push(task)
30
30
  end
31
31
  end
@@ -18,7 +18,7 @@ class SQS < Mapper
18
18
  struct = OpenStruct.new(@client.get_queue_attributes({ queue_url: queue, attribute_names: ['All'] }).attributes.to_h)
19
19
  struct.type = 'queue'
20
20
  struct.arn = struct.QueueArn
21
- struct.policy = struct.delete_field('Policy').parse_policy
21
+ struct.policy = struct.Policy ? struct.delete_field('Policy').parse_policy : nil
22
22
 
23
23
  resources.push(struct.to_h)
24
24
  end
@@ -1,3 +1,3 @@
1
1
  module AwsRecon
2
- VERSION = "0.2.25"
2
+ VERSION = "0.2.26"
3
3
  end
data/readme.md CHANGED
@@ -7,9 +7,9 @@ A multi-threaded AWS inventory collection tool.
7
7
 
8
8
  The [creators](https://darkbit.io) of this tool have a recurring need to be able to efficiently collect a large amount of AWS resource attributes and metadata to help clients understand their cloud security posture.
9
9
 
10
- There are a handful of tools (e.g. [AWS Config](https://aws.amazon.com/config), [CloudMapper](https://github.com/duo-labs/cloudmapper), [CloudSploit](https://github.com/cloudsploit/scans), [Prowler](https://github.com/toniblyx/prowler)) that do some form of resource collection to support other functions. But we found we needed broader coverage and more details at a per-service level. We also needed a consistent and structured format that allowed for integration with our other systems and tooling.
10
+ Existing tools (e.g. [AWS Config](https://aws.amazon.com/config)) that do some form of resource collection lack the coverage and specificity we needed. We also needed a tool that produced consistent output that was easily consumed by other tools/systems.
11
11
 
12
- Enter AWS Recon, multi-threaded AWS inventory collection tool written in plain Ruby. Though most AWS tooling tends to be dominated by Python, the [Ruby SDK](https://aws.amazon.com/sdk-for-ruby/) is quite mature and capable. The maintainers of the Ruby SDK have done a fantastic job making it easy to handle automatic retries, paging of large responses, and threading huge numbers of requests.
12
+ Enter AWS Recon, multi-threaded AWS inventory collection tool written in plain Ruby. Though Python tends to dominate the AWS tooling landscape, the [Ruby SDK](https://aws.amazon.com/sdk-for-ruby/) has a few convenient advantages over the [other](https://aws.amazon.com/sdk-for-node-js/) [AWS](https://aws.amazon.com/sdk-for-python/) [SDKs](https://aws.amazon.com/sdk-for-go/) we tested. Specifically, easy handling of automatic retries, paging of large responses, and - with some help - threading huge numbers of requests.
13
13
 
14
14
  ## Project Goals
15
15
 
@@ -23,24 +23,44 @@ Enter AWS Recon, multi-threaded AWS inventory collection tool written in plain R
23
23
 
24
24
  ### Requirements
25
25
 
26
- Ruby 2.5.x or 2.6.x (developed and tested with 2.6.5)
26
+ AWS Recon needs AWS account role or credentials with `ReadOnlyAccess`. Full `AdministratorAccess` is over-privileged, but will work as well. The `SecurityAudit` policy is **not** sufficient as it omits access to many services.
27
+
28
+ #### Running via Docker
29
+
30
+ Use Docker version 19.x or above to run the pre-built image without having to install anything.
31
+
32
+ #### Running locally via Ruby
33
+
34
+ If you already have Ruby installed (2.5.x or 2.6.x), you may want to install the Ruby gem.
27
35
 
28
36
  ### Installation
29
37
 
30
- AWS Recon can be run locally by installing the Ruby gem, or via a Docker container.
38
+ AWS Recon can be run locally via a Docker container or by installing the Ruby gem.
39
+
40
+ To run via a Docker a container, pass the necessary AWS credentials into the Docker `run` command. For example:
41
+
42
+ ```
43
+ $ docker run -t --rm \
44
+ -e AWS_REGION \
45
+ -e AWS_ACCESS_KEY_ID \
46
+ -e AWS_SECRET_ACCESS_KEY \
47
+ -e AWS_SESSION_TOKEN \
48
+ -v $(pwd)/output.json:/recon/output.json \
49
+ darkbitio/aws_recon:latest \
50
+ aws_recon -v -s EC2 -r global,us-east-1,us-east-2
51
+ ```
31
52
 
32
53
  To run locally, first install the gem:
33
54
 
34
55
  ```
35
56
  $ gem install aws_recon
36
- Fetching aws_recon-0.2.8.gem
37
- Fetching aws-sdk-resources-3.76.0.gem
57
+ Fetching aws_recon-0.2.26.gem
38
58
  Fetching aws-sdk-3.0.1.gem
39
- Fetching parallel-1.19.2.gem
59
+ Fetching parallel-1.20.1.gem
40
60
  ...
41
61
  Successfully installed aws-sdk-3.0.1
42
- Successfully installed parallel-1.19.2
43
- Successfully installed aws_recon-0.2.8
62
+ Successfully installed parallel-1.20.1
63
+ Successfully installed aws_recon-0.2.26
44
64
  ```
45
65
 
46
66
  Or add it to your Gemfile using `bundle`:
@@ -51,27 +71,13 @@ Fetching gem metadata from https://rubygems.org/
51
71
  Resolving dependencies...
52
72
  ...
53
73
  Using aws-sdk 3.0.1
54
- Using parallel 1.19.2
55
- Using aws_recon 0.2.8
74
+ Using parallel-1.20.1
75
+ Using aws_recon 0.2.26
56
76
  ```
57
77
 
58
- To run via a Docker a container, pass the necessary AWS credentials into the Docker `run` command. For example:
59
-
60
- ```
61
- $ docker run -t --rm \
62
- -e AWS_REGION \
63
- -e AWS_ACCESS_KEY_ID \
64
- -e AWS_SECRET_ACCESS_KEY \
65
- -e AWS_SESSION_TOKEN \
66
- -v $(pwd)/output.json:/recon/output.json \
67
- darkbitio/aws_recon:latest \
68
- aws_recon -v -s EC2 -r global,us-east-1,us-east-2
69
- ```
70
-
71
-
72
78
  ## Usage
73
79
 
74
- AWS Recon will leverage any AWS credentials currently available to the environment it runs in. If you are collecting from multiple accounts, you may want to leverage something like [aws-vault](https://github.com/99designs/aws-vault) to manage different credentials.
80
+ AWS Recon will leverage any AWS credentials (see [requirements](#requirements)) currently available to the environment it runs in. If you are collecting from multiple accounts, you may want to leverage something like [aws-vault](https://github.com/99designs/aws-vault) to manage different credentials.
75
81
 
76
82
  ```
77
83
  $ aws-vault exec profile -- aws_recon
@@ -95,7 +101,7 @@ $ aws-vault exec <vault_profile> -- docker run -t --rm \
95
101
  aws_recon -j -s EC2 -r global,us-east-1,us-east-2
96
102
  ```
97
103
 
98
- To run from a Docker container using `aws-vault` managed credentials and output to a file, you will need to satisfy a couple of requirements. First, Docker needs access to bind mount the path you specify (or a parent path above). Second, you need to create an empty file to save the output into (e.g. `output.json`). This is because we are only mounting that one file into the Docker container at run time. For example:
104
+ To run from a Docker container using `aws-vault` managed credentials and output to a file, you will need to satisfy a couple of requirements. First, Docker needs access to bind mount the path you specify (or a parent path above). Second, you need to create an empty file to save the output into (e.g. `output.json`). This is because only that one file is mounted into the Docker container at run time. For example:
99
105
 
100
106
  Create an empty file.
101
107
 
@@ -167,14 +173,33 @@ $ AWS_PROFILE=<profile> aws_recon -s S3,EC2 -r global,us-east-1,us-east-2 -f cus
167
173
 
168
174
  #### Errors
169
175
 
170
- An exception will be raised on `AccessDeniedException` errors. This typically means your user/role doesn't have the necessary permissions to get/list/describe for that service. These exceptions are raised so troubleshooting access issues is easier.
176
+ API exceptions related to permissions are silently ignored in most cases. These errors are usually due to one of these cases:
177
+
178
+ - using a role without sufficient permissions
179
+ - querying an account with SCPs in place that prevent usage of certain services
180
+ - trying to query a service that isn't enabled/available in your region/account
181
+
182
+ In `verbose` mode, you will see exception logs in the output:
183
+
184
+ ```
185
+ t2.us-east-1.EC2.describe_subnets.0
186
+ t4.us-east-1.SSM.describe_instance_information.0
187
+ t6.us-east-1.SecurityHub.InvalidAccessException <-----
188
+ t2.us-east-1.EC2.describe_addresses.0
189
+ t4.us-east-1.SSM.describe_parameters.0
190
+ t1.us-east-1.GuardDuty.list_detectors.0
191
+ ```
192
+
193
+ Use the `-q` command line option to re-raise these exceptions so troubleshooting access issues is easier.
171
194
 
172
195
  ```
173
196
  Traceback (most recent call last):
174
- arn:aws:sts::1234567890:assumed-role/role/9876543210 is not authorized to perform: codepipeline:GetPipeline on resource: arn:aws:codepipeline:us-west-2:876543210123:pipeline (Aws::CodePipeline::Errors::AccessDeniedException)
197
+ arn:aws:sts::1234567890:assumed-role/role/my-audit-role is not authorized to perform:
198
+ codepipeline:GetPipeline on resource: arn:aws:codepipeline:us-west-2:1234567890:pipeline
199
+ (Aws::CodePipeline::Errors::AccessDeniedException)
175
200
  ```
176
201
 
177
- The exact API operation that triggered the exception is indicated on the last line of the stack trace. If you can't resolve the necessary access, you should exclude those services with `-x` or `--not-services` so the collection can continue.
202
+ The exact API operation that triggered the exception is indicated on the last line of the stack trace. If you can't resolve the necessary access, you should exclude those services with `-x` or `--not-services`, or leave off the `-q` option so the collection can continue.
178
203
 
179
204
  ### Threads
180
205
 
@@ -184,14 +209,20 @@ For global services like IAM, Shield, and Support, requests are not multi-thread
184
209
 
185
210
  For regional services, a thread (up to the thread limit) is spawned for each service in a region. By default, up to 8 threads will be used. If your account has resources spread across many regions, you may see a speed improvement by increasing threads with `-t X`, where `X` is the number of threads.
186
211
 
212
+ ### Performance
213
+
214
+ AWS Recon will make a minimum of ~2,000 API calls in a new/empty account, just to query the supported services in all 20 standard (non-GovCloud, non-China) regions. It is very likely to encounter API rate-limiting (throttling) on large accounts if you enable more threads than the default (8).
215
+
216
+ Recon will automatically backoff and respect the retry limits in the API response. If you observe long pauses during collection, this is likely what is happening. Retry collection with the `-d` or `--debug` option to observe the wire trace and see if you're being throttled. Consider using fewer threads or requesting higher rate limits from AWS if you are regularly getting rate-limited.
217
+
187
218
  ### Options
188
219
 
189
- Most users will want to limit collection to relevant services and regions. Running without any options will attempt to collect all resources from all 16 regular regions.
220
+ Most users will want to limit collection to relevant services and regions. Running without any exclusions will attempt to collect all resources from all regions enabled for the account.
190
221
 
191
222
  ```
192
223
  $ aws_recon -h
193
224
 
194
- AWS Recon - AWS Inventory Collector (0.2.8)
225
+ AWS Recon - AWS Inventory Collector (0.2.26)
195
226
 
196
227
  Usage: aws_recon [options]
197
228
  -r, --regions [REGIONS] Regions to scan, separated by comma (default: all)
@@ -204,8 +235,10 @@ Usage: aws_recon [options]
204
235
  -t, --threads [THREADS] Specify max threads (default: 8, max: 128)
205
236
  -u, --user-data Collect EC2 instance user data (default: false)
206
237
  -z, --skip-slow Skip slow operations (default: false)
238
+ -g, --skip-credential-report Skip generating IAM credential report (default: false)
207
239
  -j, --stream-output Stream JSON lines to stdout (default: false)
208
240
  -v, --verbose Output client progress and current operation
241
+ -q, --quit-on-exception Stop collection if an API error is encountered (default: false)
209
242
  -d, --debug Output debug with wire trace info
210
243
  -h, --help Print this help information
211
244
 
@@ -217,7 +250,7 @@ Output is always some form of JSON - either JSON lines or plain JSON. The output
217
250
 
218
251
  ## Support for Manually Enabled Regions
219
252
 
220
- If you have enabled manually enabled regions:
253
+ If you have enabled **manually enabled regions**:
221
254
 
222
255
  - me-south-1 - Middle East (Bahrain)
223
256
  - af-south-1 - Africa (Cape Town)
@@ -228,7 +261,7 @@ and you are using STS to assume a role into an account, you will need to [enable
228
261
 
229
262
  > Version 1 tokens are valid only in AWS Regions that are available by default. These tokens do not work in manually enabled Regions, such as Asia Pacific (Hong Kong). Version 2 tokens are valid in all Regions. However, version 2 tokens are longer and might affect systems where you temporarily store tokens.
230
263
 
231
- If you are using a static access key/secret, you can collect from these regions with either `v1` or `v2` STS tokens.
264
+ If you are using a static access key/secret, you can collect from these regions regardless of STS token version.
232
265
 
233
266
  ## Supported Services & Resources
234
267
 
@@ -324,11 +357,8 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
324
357
 
325
358
  ### TODO
326
359
 
327
- - [ ] Optionally suppress AWS API errors instead of re-raising them
328
- - [x] Package as a gem
329
360
  - [ ] Test coverage with AWS SDK stubbed resources
330
361
 
331
-
332
362
  ## Kudos
333
363
 
334
364
  AWS Recon was inspired by the excellent work of the people and teams behind these tools:
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws_recon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.25
4
+ version: 0.2.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Larsen
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-12-06 00:00:00.000000000 Z
12
+ date: 2020-12-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk