aws_recon 0.2.2 → 0.2.7

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: 233f4b10a4360186449d4046d61bb0ae0e78511483e4dac27ae0dfee89a8ff04
4
- data.tar.gz: 1cde6970d7f06cdfa0d52cefd9d931794c832cceeb98c7b8fe5e2f7aa5a447ab
3
+ metadata.gz: 5378dc5f65acecaf982ff59b6d4330561a03d3ed68b8ec56051126e64dff9b09
4
+ data.tar.gz: d4c1c151b7a96c66e0bf541fc198f479622d06ced30f1197dd912afd965122fd
5
5
  SHA512:
6
- metadata.gz: 38ee33272bf5980f4c4e5a764790e29222febaf435bab4c7a7b478a688b07211432a281b762ec94565d052be2f7496a45b028b501f1c741446b06a87da75611f
7
- data.tar.gz: 5691d204c31c2423e92c86bcb05b27406c95285ef5777d1f5225496750aae35a6642c52f3b4b92ac36859c05692bced6c0968f11d41ee12a43ed628a98f74afc
6
+ metadata.gz: 65bfec760bd658d331a505d9faa37c3bf5c27b6e36d6b963c962ae963fa7da738e7ba4b2d48f584c94b70fba6d1ce441de3c4e23a594fb0d81e0cb59066c8b07
7
+ data.tar.gz: cf33e89b9faf71b70dbf555e14d2bbf8190fbc81aa8c2504f43e5773dc614fc3a5a2b086360d02491ffdf626abf8a91e3bcdf019e6f54637aafe36ec9f0caf83
@@ -0,0 +1,17 @@
1
+ # Number of days of inactivity before an issue becomes stale
2
+ daysUntilStale: 30
3
+ # Number of days of inactivity before a stale issue is closed
4
+ daysUntilClose: 5
5
+ # Issues with these labels will never be considered stale
6
+ exemptLabels:
7
+ - pinned
8
+ - security
9
+ # Label to use when marking an issue as stale
10
+ staleLabel: wontfix
11
+ # Comment to post when marking an issue as stale. Set to `false` to disable
12
+ markComment: >
13
+ This issue has been automatically marked as stale because it has not had
14
+ recent activity. It will be closed if no further activity occurs. Thank you
15
+ for your contributions.
16
+ # Comment to post when closing a stale issue. Set to `false` to disable
17
+ closeComment: false
data/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  .DS_Store
2
2
  *.json
3
+ Gemfile.lock
3
4
  .rvmrc
4
5
  .ruby-gemset
5
6
  .ruby-version
@@ -7,10 +7,10 @@ require 'aws_recon/version'
7
7
  Gem::Specification.new do |spec|
8
8
  spec.name = 'aws_recon'
9
9
  spec.version = AwsRecon::VERSION
10
- spec.authors = ['Josh Larsen']
10
+ spec.authors = ['Josh Larsen', 'Darkbit']
11
11
  spec.required_ruby_version = '>= 2.5.0'
12
- spec.summary = 'A multi-threaded AWS inventory collection tool.'
13
- spec.description = spec.summary
12
+ spec.summary = 'A multi-threaded AWS inventory collection cli tool.'
13
+ spec.description = 'AWS Recon is a command line tool to collect resources from an Amazon Web Services (AWS) account. The tool outputs JSON suitable for processing with other tools.'
14
14
  spec.homepage = 'https://github.com/darkbitio/aws-recon'
15
15
  spec.license = 'MIT'
16
16
 
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
28
28
 
29
29
  spec.add_development_dependency 'bundler', '~> 1.17'
30
30
  spec.add_development_dependency 'gem-release', '~> 2.1'
31
- spec.add_development_dependency 'rake', '~> 10.0'
31
+ spec.add_development_dependency 'rake', '~> 12.3'
32
32
  spec.add_development_dependency 'minitest', '~> 5.0'
33
33
  spec.add_development_dependency 'solargraph', '~> 0.39.11'
34
34
  spec.add_development_dependency 'rubocop', '~> 0.87.1'
@@ -1,5 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ # for local testing
4
+ $LOAD_PATH.unshift(File.expand_path(File.join('..', '..', 'lib'), __FILE__))
5
+
3
6
  require 'aws_recon'
4
7
 
5
8
  AwsRecon::CLI.new.start(ARGV)
@@ -12,7 +12,7 @@ require 'aws-sdk'
12
12
  require 'aws_recon/options.rb'
13
13
  require 'aws_recon/lib/mapper.rb'
14
14
  require 'aws_recon/lib/formatter.rb'
15
- require 'aws_recon/collectors/collectors.rb'
15
+ require 'aws_recon/collectors.rb'
16
16
 
17
17
  require 'aws_recon/version'
18
18
  require 'aws_recon/aws_recon'
@@ -88,7 +88,7 @@ module AwsRecon
88
88
  @regions.filter { |x| x != 'global' }.each do |region|
89
89
  Parallel.map(@aws_services.map { |x| OpenStruct.new(x) }.filter { |s| !s.global }.each, in_threads: @options.threads) do |service|
90
90
  # some services aren't available in some regions
91
- skip_region = @service&.excluded_regions&.include?(region)
91
+ skip_region = service&.excluded_regions&.include?(region)
92
92
 
93
93
  # user included this region in the args
94
94
  next unless @regions.include?(region) && !skip_region
@@ -0,0 +1,2 @@
1
+ # require all collectors
2
+ Dir[File.join(__dir__, 'collectors', '*.rb')].each { |file| require file }
@@ -48,6 +48,23 @@ class EC2 < Mapper
48
48
  struct.arn = instance.instance_id # no true ARN
49
49
  struct.reservation_id = reservation.reservation_id
50
50
 
51
+ # collect instance user_data
52
+ if @options.collect_user_data
53
+ user_data_raw = @client.describe_instance_attribute({
54
+ attribute: 'userData',
55
+ instance_id: instance.instance_id
56
+ }).user_data.to_h[:value]
57
+
58
+ # don't save non-string user_data
59
+ if user_data_raw
60
+ user_data = Base64.decode64(user_data_raw)
61
+
62
+ if user_data.force_encoding('UTF-8').ascii_only?
63
+ struct.user_data = user_data
64
+ end
65
+ end
66
+ end
67
+
51
68
  resources.push(struct.to_h)
52
69
  end
53
70
  end
@@ -0,0 +1,22 @@
1
+ class ElastiCache < Mapper
2
+ def collect
3
+ resources = []
4
+
5
+ #
6
+ # describe_cache_clusters
7
+ #
8
+ @client.describe_cache_clusters.each_with_index do |response, page|
9
+ log(response.context.operation_name, page)
10
+
11
+ response.cache_clusters.each do |cluster|
12
+ struct = OpenStruct.new(cluster.to_h)
13
+ struct.type = 'cluster'
14
+ struct.arn = cluster.arn
15
+
16
+ resources.push(struct.to_h)
17
+ end
18
+ end
19
+
20
+ resources
21
+ end
22
+ end
@@ -1,6 +1,5 @@
1
1
  class Lambda < Mapper
2
2
  def collect
3
- service = self.class.to_s.downcase
4
3
  resources = []
5
4
 
6
5
  #
@@ -15,8 +15,6 @@ class S3 < Mapper
15
15
  log(response.context.operation_name, page)
16
16
 
17
17
  Parallel.map(response.buckets.each, in_threads: @options.threads) do |bucket|
18
- # use shared client instance
19
- client = @client
20
18
  @thread = Parallel.worker_number
21
19
  log(response.context.operation_name, bucket.name)
22
20
 
@@ -27,10 +25,14 @@ class S3 < Mapper
27
25
  # check bucket region constraint
28
26
  location = @client.get_bucket_location({ bucket: bucket.name }).location_constraint
29
27
 
30
- # reset client if needed
31
- unless location.empty?
32
- client = Aws::S3::Client.new({ region: location })
33
- end
28
+ # if you use a region other than the us-east-1 endpoint
29
+ # to create a bucket, you must set the location_constraint
30
+ # bucket parameter to the same region. (https://docs.aws.amazon.com/general/latest/gr/s3.html)
31
+ client = if location.empty?
32
+ @client
33
+ else
34
+ Aws::S3::Client.new({ region: location })
35
+ end
34
36
 
35
37
  operations = [
36
38
  { func: 'get_bucket_acl', key: 'acl', field: nil },
@@ -15,6 +15,13 @@
15
15
  # to add 5 seconds delay on each retry for a total max of 55 seconds.
16
16
  #
17
17
  class Mapper
18
+ # Services that use us-east-1 endpoint only:
19
+ # Organizations
20
+ # Route53Domains
21
+ # Shield
22
+ # S3 (unless the bucket was created in another region)
23
+ SINGLE_REGION_SERVICES = %w[route53domains s3 shield support organizations].freeze
24
+
18
25
  def initialize(service, region, options)
19
26
  @service = service
20
27
  @region = region
@@ -39,8 +46,8 @@ class Mapper
39
46
  # regional service
40
47
  client_options.merge!({ region: region }) unless region == 'global'
41
48
 
42
- # organizations only uses us-east-1 in non cn/gov regions
43
- client_options.merge!({ region: 'us-east-1' }) if service.downcase == 'organizations' # rubocop:disable Layout/LineLength
49
+ # single region services
50
+ client_options.merge!({ region: 'us-east-1' }) if SINGLE_REGION_SERVICES.include?(service.downcase) # rubocop:disable Layout/LineLength
44
51
 
45
52
  # debug with wire trace
46
53
  client_options.merge!({ http_wire_trace: true }) if @options.debug
@@ -15,6 +15,7 @@ class Parser
15
15
  :output_file,
16
16
  :output_format,
17
17
  :threads,
18
+ :collect_user_data,
18
19
  :skip_slow,
19
20
  :stream_output,
20
21
  :verbose,
@@ -43,11 +44,12 @@ class Parser
43
44
  false,
44
45
  false,
45
46
  false,
47
+ false,
46
48
  false
47
49
  )
48
50
 
49
51
  opt_parser = OptionParser.new do |opts|
50
- opts.banner = "\n\x1b[32mAWS Recon\x1b[0m - AWS Inventory Collector\n\nUsage: aws_recon [options]"
52
+ opts.banner = "\n\x1b[32mAWS Recon\x1b[0m - AWS Inventory Collector (#{AwsRecon::VERSION})\n\nUsage: aws_recon [options]"
51
53
 
52
54
  # regions
53
55
  opts.on('-r', '--regions [REGIONS]', 'Regions to scan, separated by comma (default: all)') do |regions|
@@ -103,6 +105,11 @@ class Parser
103
105
  end
104
106
  end
105
107
 
108
+ # collect EC2 instance user data
109
+ opts.on('-u', '--user-data', 'Collect EC2 instance user data (default: false)') do
110
+ args.collect_user_data = true
111
+ end
112
+
106
113
  # skip slow operations
107
114
  opts.on('-z', '--skip-slow', 'Skip slow operations (default: false)') do
108
115
  args.skip_slow = true
@@ -21,8 +21,6 @@
21
21
  alias: ec2
22
22
  - name: EKS
23
23
  alias: eks
24
- excluded_regions:
25
- - us-west-1
26
24
  - name: ECS
27
25
  alias: ecs
28
26
  - name: ElasticLoadBalancing
@@ -33,6 +31,8 @@
33
31
  alias: elbv2
34
32
  excluded_regions:
35
33
  - ap-southeast-1
34
+ - name: ElastiCache
35
+ alias: elasticache
36
36
  - name: IAM
37
37
  global: true
38
38
  alias: iam
@@ -1,3 +1,3 @@
1
1
  module AwsRecon
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.7"
3
3
  end
data/readme.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Gem Version](https://badge.fury.io/rb/aws_recon.svg)](https://badge.fury.io/rb/aws_recon)
2
+
1
3
  # AWS Recon
2
4
 
3
5
  A multi-threaded AWS inventory collection tool.
@@ -24,17 +26,30 @@ Ruby 2.5.x or 2.6.x (developed and tested with 2.6.5)
24
26
 
25
27
  ### Installation
26
28
 
27
- Clone this repository, then install the required gems using `bundle`:
29
+ Install the gem:
28
30
 
29
31
  ```
30
- $ git clone git@github.com:darkbitio/aws-recon.git
31
- $ cd aws-recon
32
- $ bundle
32
+ $ gem install aws_recon
33
+ Fetching aws_recon-0.2.7.gem
34
+ Fetching aws-sdk-resources-3.76.0.gem
35
+ Fetching aws-sdk-3.0.1.gem
36
+ Fetching parallel-1.19.2.gem
33
37
  ...
34
- Using aws-sdk-core 3.103.0
38
+ Successfully installed aws-sdk-3.0.1
39
+ Successfully installed parallel-1.19.2
40
+ Successfully installed aws_recon-0.2.7
41
+ ```
42
+
43
+ Or add it to your Gemfile using `bundle`:
44
+
45
+ ```
46
+ $ bundle add aws_recon
47
+ Fetching gem metadata from https://rubygems.org/
48
+ Resolving dependencies...
35
49
  ...
36
- Bundle complete! 5 Gemfile dependencies, 259 gems now installed.
37
- Use `bundle info [gemname]` to see where a bundled gem is installed.
50
+ Using aws-sdk 3.0.1
51
+ Using parallel 1.19.2
52
+ Using aws_recon 0.2.2
38
53
  ```
39
54
 
40
55
  ## Usage
@@ -42,13 +57,13 @@ Use `bundle info [gemname]` to see where a bundled gem is installed.
42
57
  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.
43
58
 
44
59
  ```
45
- $ aws-vault exec profile -- ./recon.rb
60
+ $ aws-vault exec profile -- aws_recon
46
61
  ```
47
62
 
48
63
  Plain environment variables will work fine too.
49
64
 
50
65
  ```
51
- $ AWS_PROFILE=<profile> ./recon.rb
66
+ $ AWS_PROFILE=<profile> aws_recon
52
67
  ```
53
68
 
54
69
  You may want to use the `-v` or `--verbose` flag initially to see status and activity while collection is running.
@@ -62,7 +77,7 @@ In verbose mode, the console output will show:
62
77
  The `t` prefix indicates which thread a particular request is running under. Region, service, and operation indicate which request operation is currently in progress and where.
63
78
 
64
79
  ```
65
- $ ./recon.rb -v
80
+ $ aws_recon -v
66
81
 
67
82
  t0.global.EC2.describe_account_attributes
68
83
  t2.global.S3.list_buckets
@@ -87,11 +102,11 @@ Finished in 46 seconds. Saving resources to output.json.
87
102
  #### Example command line options
88
103
 
89
104
  ```
90
- $ AWS_PROFILE=<profile> ./recon.rb -s S3,EC2 -r global,us-east-1,us-east-2
105
+ $ AWS_PROFILE=<profile> aws_recon -s S3,EC2 -r global,us-east-1,us-east-2
91
106
  ```
92
107
 
93
108
  ```
94
- $ AWS_PROFILE=<profile> ./recon.rb --services S3,EC2 --regions global,us-east-1,us-east-2
109
+ $ AWS_PROFILE=<profile> aws_recon --services S3,EC2 --regions global,us-east-1,us-east-2
95
110
  ```
96
111
 
97
112
  #### Errors
@@ -118,11 +133,11 @@ For regional services, a thread (up to the thread limit) is spawned for each ser
118
133
  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.
119
134
 
120
135
  ```
121
- $ ./recon.rb -h
136
+ $ aws_recon -h
122
137
 
123
- AWS Recon - AWS Inventory Collector
138
+ AWS Recon - AWS Inventory Collector (0.2.7)
124
139
 
125
- Usage: ./recon.rb [options]
140
+ Usage: aws_recon [options]
126
141
  -r, --regions [REGIONS] Regions to scan, separated by comma (default: all)
127
142
  -n, --not-regions [REGIONS] Regions to skip, separated by comma (default: none)
128
143
  -s, --services [SERVICES] Services to scan, separated by comma (default: all)
@@ -131,6 +146,7 @@ Usage: ./recon.rb [options]
131
146
  -o, --output [OUTPUT] Specify output file (default: output.json)
132
147
  -f, --format [FORMAT] Specify output format (default: aws)
133
148
  -t, --threads [THREADS] Specify max threads (default: 8, max: 128)
149
+ -u, --user-data Collect EC2 instance user data (default: false)
134
150
  -z, --skip-slow Skip slow operations (default: false)
135
151
  -j, --stream-output Stream JSON lines to stdout (default: false)
136
152
  -v, --verbose Output client progress and current operation
@@ -178,6 +194,7 @@ AWS Recon aims to collect all resources and metadata that are relevant in determ
178
194
  - [x] ELB
179
195
  - [x] EKS
180
196
  - [x] Elasticsearch
197
+ - [x] ElastiCache
181
198
  - [x] Firehose
182
199
  - [ ] FMS
183
200
  - [ ] Glacier
@@ -210,10 +227,29 @@ AWS Recon aims to collect all resources and metadata that are relevant in determ
210
227
 
211
228
  One of the primary motivations for AWS Recon was to build a tool that is easy to maintain and extend. If you feel like coverage could be improved for a particular service, we would welcome PRs to that effect. Anyone with a moderate familiarity with Ruby will be able to mimic the pattern used by the existing collectors to query a specific service and add the results to the resource collection.
212
229
 
230
+ ### Development
231
+
232
+ Clone this repository:
233
+
234
+ ```
235
+ $ git clone git@github.com:darkbitio/aws-recon.git
236
+ $ cd aws-recon
237
+ ```
238
+
239
+ Create a sticky gemset if using RVM:
240
+
241
+ ```
242
+ $ rvm use 2.6.5@aws_recon_dev --create --ruby-version
243
+ ```
244
+
245
+ Run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
246
+
247
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
248
+
213
249
  ### TODO
214
250
 
215
251
  - [ ] Optionally suppress AWS API errors instead of re-raising them
216
- - [ ] Package as a gem
252
+ - [x] Package as a gem
217
253
  - [ ] Test coverage with AWS SDK stubbed resources
218
254
 
219
255
 
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws_recon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Larsen
8
+ - Darkbit
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2020-08-10 00:00:00.000000000 Z
12
+ date: 2020-09-21 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: aws-sdk
@@ -72,14 +73,14 @@ dependencies:
72
73
  requirements:
73
74
  - - "~>"
74
75
  - !ruby/object:Gem::Version
75
- version: '10.0'
76
+ version: '12.3'
76
77
  type: :development
77
78
  prerelease: false
78
79
  version_requirements: !ruby/object:Gem::Requirement
79
80
  requirements:
80
81
  - - "~>"
81
82
  - !ruby/object:Gem::Version
82
- version: '10.0'
83
+ version: '12.3'
83
84
  - !ruby/object:Gem::Dependency
84
85
  name: minitest
85
86
  requirement: !ruby/object:Gem::Requirement
@@ -136,7 +137,9 @@ dependencies:
136
137
  - - "~>"
137
138
  - !ruby/object:Gem::Version
138
139
  version: 0.13.1
139
- description: A multi-threaded AWS inventory collection tool.
140
+ description: AWS Recon is a command line tool to collect resources from an Amazon
141
+ Web Services (AWS) account. The tool outputs JSON suitable for processing with other
142
+ tools.
140
143
  email:
141
144
  executables:
142
145
  - aws_recon
@@ -145,13 +148,11 @@ executables:
145
148
  extensions: []
146
149
  extra_rdoc_files: []
147
150
  files:
151
+ - ".github/stale.yml"
148
152
  - ".gitignore"
149
153
  - ".rubocop.yml"
150
- - ".ruby-gemset"
151
- - ".ruby-version"
152
154
  - ".travis.yml"
153
155
  - Gemfile
154
- - Gemfile.lock
155
156
  - LICENSE.txt
156
157
  - Rakefile
157
158
  - aws_recon.gemspec
@@ -160,6 +161,7 @@ files:
160
161
  - bin/setup
161
162
  - lib/aws_recon.rb
162
163
  - lib/aws_recon/aws_recon.rb
164
+ - lib/aws_recon/collectors.rb
163
165
  - lib/aws_recon/collectors/acm.rb
164
166
  - lib/aws_recon/collectors/apigateway.rb
165
167
  - lib/aws_recon/collectors/apigatewayv2.rb
@@ -172,7 +174,6 @@ files:
172
174
  - lib/aws_recon/collectors/cloudwatchlogs.rb
173
175
  - lib/aws_recon/collectors/codebuild.rb
174
176
  - lib/aws_recon/collectors/codepipeline.rb
175
- - lib/aws_recon/collectors/collectors.rb
176
177
  - lib/aws_recon/collectors/configservice.rb
177
178
  - lib/aws_recon/collectors/directconnect.rb
178
179
  - lib/aws_recon/collectors/directyservice.rb
@@ -183,6 +184,7 @@ files:
183
184
  - lib/aws_recon/collectors/ecs.rb
184
185
  - lib/aws_recon/collectors/efs.rb
185
186
  - lib/aws_recon/collectors/eks.rb
187
+ - lib/aws_recon/collectors/elasticache.rb
186
188
  - lib/aws_recon/collectors/elasticloadbalancing.rb
187
189
  - lib/aws_recon/collectors/elasticloadbalancingv2.rb
188
190
  - lib/aws_recon/collectors/elasticsearch.rb
@@ -218,7 +220,6 @@ files:
218
220
  - lib/aws_recon/services.yaml
219
221
  - lib/aws_recon/version.rb
220
222
  - readme.md
221
- - readme_gem.md
222
223
  homepage: https://github.com/darkbitio/aws-recon
223
224
  licenses:
224
225
  - MIT
@@ -241,5 +242,5 @@ requirements: []
241
242
  rubygems_version: 3.0.8
242
243
  signing_key:
243
244
  specification_version: 4
244
- summary: A multi-threaded AWS inventory collection tool.
245
+ summary: A multi-threaded AWS inventory collection cli tool.
245
246
  test_files: []