traceroute53 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d14ec1cd7f7bd6d16e0a1cf3e68680ce364852269e3e26cee6148af18cdde960
4
+ data.tar.gz: 6d75e452eb15b4bc1936aaa7086e1bd51ec2bc9dc7c25f4c37f064686eea0ced
5
+ SHA512:
6
+ metadata.gz: ed37b10833cd4e6cb866dcfe2bb20b3e9dd5a1225104df91920519e0ac9ba5f021e8cb218812eafcc02ee9bb8650e26c75ebe07156c6657e4b06e87bdeed0943
7
+ data.tar.gz: 575dcae80e93269651904cba2e5c78ab63c5f2967376edc8d5ba570178b34dab7bc66deb776784e6fe54faa21d6a1a7a0bbeed8aea027f2d8173180c8e635441
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.3
7
+ before_install: gem install bundler -v 1.17.3
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in traceroute53.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 NARUSE, Yui
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Traceroute53
2
+
3
+ A tool to investigate Route53, ELB, EC2 and Security Groups
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'traceroute53'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install traceroute53
20
+
21
+ ## Usage
22
+
23
+ ```
24
+ traceroute53 <domain>
25
+ ```
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/nurse/traceroute53.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "traceroute53"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/traceroute53 ADDED
@@ -0,0 +1,231 @@
1
+ #!/usr/bin/env ruby
2
+ # Trace route53 and Load Balancers related to the given domain
3
+ require 'aws-sdk'
4
+ require 'optparse'
5
+
6
+ def list_hosted_zones(client)
7
+ hosted_zones = []
8
+ marker = nil
9
+ loop do
10
+ resp = client.list_hosted_zones({
11
+ marker: marker,
12
+ })
13
+ hosted_zones.concat resp.hosted_zones
14
+ break unless resp.is_truncated
15
+ marker = resp.next_marker
16
+ end
17
+ # p hosted_zones.map(&:name)
18
+ hosted_zones
19
+ end
20
+
21
+ def list_resource_record_sets(client, hosted_zone)
22
+ records = []
23
+ start_record_name = nil
24
+ start_record_type = nil
25
+ start_record_identifier = nil
26
+ loop do
27
+ resp = client.list_resource_record_sets({
28
+ start_record_name: start_record_name,
29
+ start_record_type: start_record_type,
30
+ start_record_identifier: start_record_identifier,
31
+ hosted_zone_id: hosted_zone.id
32
+ })
33
+ records.concat resp.resource_record_sets
34
+ break unless resp.is_truncated
35
+ start_record_name = resp.next_record_name
36
+ start_record_type = resp.next_record_type
37
+ start_record_identifier = resp.next_record_identifier
38
+ end
39
+ # p records
40
+ # p records.map(&:name)
41
+ records
42
+ end
43
+
44
+ def describe_load_balancers(client)
45
+ marker = nil
46
+ load_balancers = []
47
+ loop do
48
+ resp = client.describe_load_balancers({
49
+ marker: marker,
50
+ })
51
+ load_balancers.concat resp.load_balancers
52
+ marker = resp.next_marker
53
+ break unless marker
54
+ end
55
+ load_balancers
56
+ end
57
+
58
+ def describe_listeners(client, load_balancer)
59
+ marker = nil
60
+ listeners = []
61
+ loop do
62
+ resp = client.describe_listeners({
63
+ load_balancer_arn: load_balancer.load_balancer_arn,
64
+ marker: marker,
65
+ })
66
+ listeners.concat resp.listeners
67
+ marker = resp.next_marker
68
+ break unless marker
69
+ end
70
+ listeners
71
+ end
72
+
73
+ def describe_target_groups(client, target_group_arns)
74
+ marker = nil
75
+ target_groups = []
76
+ loop do
77
+ resp = client.describe_target_groups({
78
+ target_group_arns: target_group_arns,
79
+ marker: marker,
80
+ })
81
+ target_groups.concat resp.target_groups
82
+ marker = resp.next_marker
83
+ break unless marker
84
+ end
85
+ target_groups
86
+ end
87
+
88
+ def describe_instances(client, instance_ids)
89
+ marker = nil
90
+ instances = []
91
+ loop do
92
+ resp = client.describe_instances({
93
+ instance_ids: instance_ids,
94
+ next_token: marker,
95
+ })
96
+ resp.reservations.each do |reservation|
97
+ instances.concat reservation.instances
98
+ end
99
+ marker = resp.next_token
100
+ break unless marker
101
+ end
102
+ instances
103
+ end
104
+
105
+ def describe_security_groups(client, group_ids)
106
+ resp = client.describe_security_groups({
107
+ group_ids: group_ids,
108
+ })
109
+ resp.security_groups
110
+ end
111
+
112
+ def describe_target_health(client, target_group_arn)
113
+ resp = client.describe_target_health({
114
+ target_group_arn: target_group_arn,
115
+ })
116
+ resp.target_health_descriptions
117
+ end
118
+
119
+ def main
120
+ opt = OptionParser.new("usage: traceroute53 <domain>")
121
+
122
+ profile = nil
123
+ opt.on('--profile PROFILE', "use given profile") {|v| profile = v }
124
+
125
+ opt.parse!(ARGV)
126
+ domain = ARGV.shift
127
+ unless domain
128
+ puts opt.help
129
+ exit
130
+ end
131
+
132
+ client = Aws::Route53::Client.new(
133
+ region: 'us-east-1',
134
+ profile: profile,
135
+ )
136
+
137
+ hosted_zones = list_hosted_zones(client)
138
+ domain_dot = domain + '.'
139
+ zones = hosted_zones.select{|zone| domain_dot.end_with?(zone.name)}
140
+ if zones.empty?
141
+ STDERR.puts "hosted zone not found for #{domain}"
142
+ exit 1
143
+ end
144
+ # p zones
145
+ hosted_zone = zones.sort_by{|zone| zone.name.size}.last
146
+ # p hosted_zone
147
+ puts "hosted zone: #{hosted_zone.name}"
148
+
149
+ records = list_resource_record_sets(client, hosted_zone)
150
+ records.select!{|record| record.name == domain_dot}
151
+ if records.empty?
152
+ STDERR.puts "resource record set not found in #{hosted_zone} for #{domain}"
153
+ exit 1
154
+ end
155
+ if records.size != 1
156
+ STDERR.puts records.inspect
157
+ STDERR.puts "more than one resource record set in #{hosted_zone} for #{domain}"
158
+ exit 1
159
+ end
160
+ dns_name = records[0].alias_target.dns_name
161
+ puts "dns name: #{dns_name}"
162
+ dns_name.sub!(/\Adualstack\./, '')
163
+ dns_name.chomp!('.')
164
+
165
+ region = dns_name[/([a-z0-9\-]+)\.elb\.amazonaws.com\z/, 1]
166
+ client = Aws::ElasticLoadBalancingV2::Client.new(
167
+ region: region,
168
+ profile: profile,
169
+ )
170
+ load_balancers = describe_load_balancers(client)
171
+ if load_balancers.empty?
172
+ STDERR.puts "load balancers not found in #{region} for #{dns_name}"
173
+ exit 1
174
+ end
175
+ load_balancer = load_balancers.find{|lb| lb.dns_name == dns_name}
176
+ unless load_balancer
177
+ load_balancers.each_with_index do |lb, i|
178
+ STDERR.puts "load balancer[#{i}]: #{lb.dns_name}"
179
+ end
180
+ STDERR.puts "load balancers not found in #{region} for #{dns_name}"
181
+ exit 1
182
+ end
183
+ puts "load balancer: #{load_balancer.load_balancer_name} #{load_balancer.security_groups}"
184
+
185
+ listeners = describe_listeners(client, load_balancer)
186
+ if listeners.empty?
187
+ STDERR.puts "listeners not found in #{region} for #{load_balancer}"
188
+ exit 1
189
+ end
190
+
191
+ instance_ids = []
192
+ listeners.each_with_index do |listener, i|
193
+ # p listener
194
+ puts "listener[#{i}]: port:#{listener.port} #{listener.listener_arn}"
195
+ listener.default_actions.each_with_index do |action, j|
196
+ puts "listener[#{i}]action[#{j}]: #{action.type} #{action.target_group_arn}"
197
+ target_healths = describe_target_health(client, action.target_group_arn)
198
+ target_healths.each_with_index do |health, k|
199
+ puts "listener[#{i}]action[#{j}]target[#{k}]: #{health.target.id}:#{health.target.port} #{health.target_health.state}"
200
+ instance_ids << health.target.id
201
+ end
202
+ end
203
+ end
204
+
205
+ # p target_group_arns
206
+ # target_groups = describe_target_groups(client, target_group_arns)
207
+ # if target_groups.empty?
208
+ # STDERR.puts "target groups not found in #{region} for #{listeners}"
209
+ # exit 1
210
+ # end
211
+ # p target_groups
212
+
213
+ client = Aws::EC2::Client.new(
214
+ region: region,
215
+ profile: profile,
216
+ )
217
+ instances = describe_instances(client, instance_ids)
218
+ group_ids_ary = instances.map{|instance| instance.security_groups.map(&:group_id)}.uniq
219
+
220
+ group_ids_ary.each_with_index do |group_ids, i|
221
+ puts "group_ids[#{i}]: #{group_ids}"
222
+ security_groups = describe_security_groups(client, group_ids)
223
+ security_groups.each_with_index do |sg, j|
224
+ puts "group_ids[#{i}]sg[#{j}]: #{sg.group_id}"
225
+ sg.ip_permissions.each_with_index do |ip, k|
226
+ puts "group_ids[#{i}]sg[#{j}]ip[#{k}]: port:#{ip.from_port.inspect} #{ip.user_id_group_pairs.map(&:group_id)}"
227
+ end
228
+ end
229
+ end
230
+ end
231
+ main
@@ -0,0 +1,6 @@
1
+ require "traceroute53/version"
2
+
3
+ module Traceroute53
4
+ class Error < StandardError; end
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,3 @@
1
+ module Traceroute53
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,42 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "traceroute53/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "traceroute53"
8
+ spec.version = Traceroute53::VERSION
9
+ spec.authors = ["NARUSE, Yui"]
10
+ spec.email = ["naruse@airemix.jp"]
11
+
12
+ spec.summary = %q{A tool to investigate Route53, ELB, EC2 and Security Groups}
13
+ spec.description = %q{An tool to investigate Route53, ELB, EC2 and Security Groups}
14
+ spec.homepage = "https://github.com/nurse/traceroute53"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
21
+
22
+ spec.metadata["homepage_uri"] = spec.homepage
23
+ spec.metadata["source_code_uri"] = "https://github.com/nurse/traceroute53"
24
+ #spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
25
+ else
26
+ raise "RubyGems 2.0 or newer is required to protect against " \
27
+ "public gem pushes."
28
+ end
29
+
30
+ # Specify which files should be added to the gem when it is released.
31
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
33
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
+ end
35
+ spec.bindir = "exe"
36
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
+ spec.require_paths = ["lib"]
38
+
39
+ spec.add_development_dependency "bundler", "~> 1.17"
40
+ spec.add_development_dependency "rake", "~> 10.0"
41
+ spec.add_development_dependency "rspec", "~> 3.0"
42
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: traceroute53
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - NARUSE, Yui
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-03-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: An tool to investigate Route53, ELB, EC2 and Security Groups
56
+ email:
57
+ - naruse@airemix.jp
58
+ executables:
59
+ - traceroute53
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - exe/traceroute53
73
+ - lib/traceroute53.rb
74
+ - lib/traceroute53/version.rb
75
+ - traceroute53.gemspec
76
+ homepage: https://github.com/nurse/traceroute53
77
+ licenses:
78
+ - MIT
79
+ metadata:
80
+ homepage_uri: https://github.com/nurse/traceroute53
81
+ source_code_uri: https://github.com/nurse/traceroute53
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.7.6
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: A tool to investigate Route53, ELB, EC2 and Security Groups
102
+ test_files: []