awsec 0.0.1
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.
- data/bin/awsec +116 -0
- data/lib/aw_sec.rb +5 -0
- data/lib/providers/ip_echo.rb +18 -0
- data/lib/providers/my_ip.rb +24 -0
- data/lib/version.rb +52 -0
- metadata +83 -0
data/bin/awsec
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'aw_sec'))
|
4
|
+
require 'json'
|
5
|
+
require 'highline/import'
|
6
|
+
require 'optparse'
|
7
|
+
|
8
|
+
config_path = File.join(Dir.home, '.awsec', 'awsec.json')
|
9
|
+
|
10
|
+
defaults = {}
|
11
|
+
defaults[:whitelist] = []
|
12
|
+
|
13
|
+
if File.exists? config_path
|
14
|
+
defaults = JSON.load(File.read(config_path))
|
15
|
+
else
|
16
|
+
FileUtils.mkdir_p File.join(Dir.home, '.awsec')
|
17
|
+
|
18
|
+
defaults[:aws_key] = ask('AWS Key?')
|
19
|
+
defaults[:aws_secret] = ask('AWS Secret?') { |q| q.echo = "*" }
|
20
|
+
defaults[:aws_region] = ask('Default AWS Region?') { |q| q.default = 'us-east-1' }
|
21
|
+
defaults[:group_names] = ask('Default Security Groups? []')
|
22
|
+
defaults[:port] = ask('Default port?', Integer) { |q| q.default = 22 }
|
23
|
+
|
24
|
+
choose do |menu|
|
25
|
+
menu.prompt = "Please choose your public IP provider?"
|
26
|
+
|
27
|
+
AwSec::Providers::Register.list.each do |provider|
|
28
|
+
menu.choice(provider[:name]) do
|
29
|
+
defaults[:ip_provider] = provider[:class].class.name
|
30
|
+
provider[:class].configure
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
defaults[:whilelist] = ask('Default comma separated IP whitelist? []')
|
36
|
+
|
37
|
+
File.write(config_path, JSON.dump(defaults))
|
38
|
+
say('Configuration saved')
|
39
|
+
end
|
40
|
+
|
41
|
+
defaults = defaults.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
|
42
|
+
options = defaults
|
43
|
+
optparse = OptionParser.new do |opts|
|
44
|
+
opts.banner = "Usage: awsec [options]"
|
45
|
+
|
46
|
+
opts.on('--clear', 'Clears the configuration') do
|
47
|
+
File.delete(config_path) if File.exists? config_path
|
48
|
+
say('Configuration deleted')
|
49
|
+
exit
|
50
|
+
end
|
51
|
+
|
52
|
+
opts.on('-w', '--whitelist WHITELIST', 'Whitelist IP address (comma separated). You can use subnet masks like /32' ) do |lst|
|
53
|
+
options[:whitelist] = lst.split(',')
|
54
|
+
end
|
55
|
+
|
56
|
+
options[:revoke_all] = true
|
57
|
+
opts.on( '-r', '--[no-]revoke', 'Revoke all access before adding new ones (except the whitelist)' ) do |v|
|
58
|
+
options[:revoke_all] = v
|
59
|
+
end
|
60
|
+
|
61
|
+
opts.on('--groups GROUPS', 'AWS Security Group names to action (comma separated)') do |v|
|
62
|
+
options[:group_names] = v.split(',')
|
63
|
+
end
|
64
|
+
|
65
|
+
opts.on( '--aws-region REGION', 'AWS Region.' ) do |v|
|
66
|
+
options[:aws_region] = v
|
67
|
+
end
|
68
|
+
|
69
|
+
opts.on( '-p', '--port PORT', 'Port to open.' ) do |v|
|
70
|
+
say "I'm here with #{v}"
|
71
|
+
options[:port] = v
|
72
|
+
end
|
73
|
+
|
74
|
+
opts.on( '--ip IP', 'IP to open to. You can use subnet masks like /32' ) do |v|
|
75
|
+
options[:ip] = v
|
76
|
+
end
|
77
|
+
|
78
|
+
opts.on( '--provider PROVIDER', 'Public IP provider' ) do |v|
|
79
|
+
options[:ip_provider] = v
|
80
|
+
end
|
81
|
+
|
82
|
+
opts.on('-v', '--version', 'AwSec version') do
|
83
|
+
say("AwSec v#{VERSION}")
|
84
|
+
exit
|
85
|
+
end
|
86
|
+
|
87
|
+
opts.on( '-h', '--help', 'Display this screen' ) do
|
88
|
+
puts opts
|
89
|
+
exit
|
90
|
+
end
|
91
|
+
|
92
|
+
opts.on('--show', 'Shows the configuration') do
|
93
|
+
puts options
|
94
|
+
exit
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
optparse.parse(ARGV)
|
100
|
+
|
101
|
+
# validate
|
102
|
+
if !options.has_key?(:group_names) || options[:group_names] == ''
|
103
|
+
say('No Security Group names found')
|
104
|
+
exit
|
105
|
+
end
|
106
|
+
|
107
|
+
if !options.has_key?(:ip) || options[:ip] == nil || options[:ip] == ''
|
108
|
+
provider = eval("#{options[:ip_provider]}.new")
|
109
|
+
public_ip = provider.get_public_ip(options)
|
110
|
+
say "Your IP address is #{public_ip}"
|
111
|
+
else
|
112
|
+
public_ip = options[:ip]
|
113
|
+
end
|
114
|
+
|
115
|
+
AwSec::Core.secure(options[:group_names], public_ip, options)
|
116
|
+
|
data/lib/aw_sec.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module AwSec
|
4
|
+
module Providers
|
5
|
+
class EchoIp
|
6
|
+
|
7
|
+
Register.register('Echo IP', AwSec::Providers::EchoIp.new())
|
8
|
+
|
9
|
+
def get_public_ip(options)
|
10
|
+
Net::HTTP.get(URI "http://ipecho.net/plain")
|
11
|
+
end
|
12
|
+
|
13
|
+
def configure
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'highline/import'
|
3
|
+
|
4
|
+
module AwSec
|
5
|
+
module Providers
|
6
|
+
class MyIp
|
7
|
+
|
8
|
+
Register.register('My IP', AwSec::Providers::MyIp.new())
|
9
|
+
|
10
|
+
def get_public_ip(options)
|
11
|
+
Net::HTTP.get(URI "http://auto.whatismyip.com/ip.php?user=#{options[:my_ip_username]}&password=#{options[:my_ip_password]}")
|
12
|
+
end
|
13
|
+
|
14
|
+
def configure
|
15
|
+
result = {}
|
16
|
+
result[:my_ip_username] = ask('My IP username')
|
17
|
+
result[:my_ip_password] = ask('My IP password') { |q| q.echo = "*" }
|
18
|
+
|
19
|
+
result
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/version.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module AwSec
|
4
|
+
class Version
|
5
|
+
|
6
|
+
##
|
7
|
+
# Change the MAJOR, MINOR and PATCH constants below
|
8
|
+
# to adjust the version of the Cloud66 Agent gem
|
9
|
+
#
|
10
|
+
# MAJOR:
|
11
|
+
# Defines the major version
|
12
|
+
# MINOR:
|
13
|
+
# Defines the minor version
|
14
|
+
# PATCH:
|
15
|
+
# Defines the patch version
|
16
|
+
MAJOR, MINOR, PATCH = 0, 0, 1
|
17
|
+
|
18
|
+
#ie. PRERELEASE_MODIFIER = 'beta1'
|
19
|
+
PRERELEASE_MODIFIER = nil
|
20
|
+
|
21
|
+
##
|
22
|
+
# Returns the major version ( big release based off of multiple minor releases )
|
23
|
+
def self.major
|
24
|
+
MAJOR
|
25
|
+
end
|
26
|
+
|
27
|
+
##
|
28
|
+
# Returns the minor version ( small release based off of multiple patches )
|
29
|
+
def self.minor
|
30
|
+
MINOR
|
31
|
+
end
|
32
|
+
|
33
|
+
##
|
34
|
+
# Returns the patch version ( updates, features and (crucial) bug fixes )
|
35
|
+
def self.patch
|
36
|
+
PATCH
|
37
|
+
end
|
38
|
+
|
39
|
+
##
|
40
|
+
# Returns the prerelease modifier ( not quite ready for public consumption )
|
41
|
+
def self.prerelease_modifier
|
42
|
+
PRERELEASE_MODIFIER
|
43
|
+
end
|
44
|
+
|
45
|
+
##
|
46
|
+
# Returns the current version of the Backup gem ( qualified for the gemspec )
|
47
|
+
def self.current
|
48
|
+
prerelease_modifier.nil? ? "#{major}.#{minor}.#{patch}" : "#{major}.#{minor}.#{patch}.#{prerelease_modifier}"
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: awsec
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Cloud 66
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-25 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: json
|
16
|
+
requirement: &70315292689740 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.6.3
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70315292689740
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: fog
|
27
|
+
requirement: &70315292688100 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.4.0
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70315292688100
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: highline
|
38
|
+
requirement: &70315292686980 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.6.11
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70315292686980
|
47
|
+
description: Open and close AWS Security Group from the terminal for more secure operations
|
48
|
+
email: khash@cloud66.com
|
49
|
+
executables:
|
50
|
+
- awsec
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- lib/version.rb
|
55
|
+
- lib/aw_sec.rb
|
56
|
+
- lib/providers/ip_echo.rb
|
57
|
+
- lib/providers/my_ip.rb
|
58
|
+
- bin/awsec
|
59
|
+
homepage: https://github.com/cloud66/awsec
|
60
|
+
licenses: []
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 1.8.15
|
80
|
+
signing_key:
|
81
|
+
specification_version: 3
|
82
|
+
summary: AWS Security Toolbelt
|
83
|
+
test_files: []
|