fog-bouncer 0.0.6

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.
@@ -0,0 +1,5 @@
1
+ module Fog
2
+ module Bouncer
3
+ VERSION = "0.0.6"
4
+ end
5
+ end
@@ -0,0 +1,61 @@
1
+ require "helper"
2
+
3
+ describe Fog::Bouncer do
4
+ before do
5
+ Fog::Bouncer.reset
6
+ Fog::Mock.reset if Fog.mocking?
7
+
8
+ load_security(:private)
9
+
10
+ @doorlist = Fog::Bouncer.doorlists[:private]
11
+ @doorlist.import_remote_groups
12
+ @fog = Fog::Bouncer.fog
13
+ @doorlist.sync
14
+ end
15
+
16
+
17
+ describe Fog::Bouncer::Group do
18
+ before do
19
+ @group = @doorlist.groups.find { |g| g.name == 'douchebag' }
20
+ end
21
+
22
+ describe "use" do
23
+ it "should include any source definition specified" do
24
+ @group.sources.find { |s| s.source == "0.0.0.0/0" && s.protocols.find { |p| p.type == "icmp" && p.from == 8 && p.to == 0 } }.wont_be_nil
25
+ end
26
+
27
+ it "should not create duplicate sources" do
28
+ @group.sources.select { |s| s.source == "0.0.0.0/0" }.size.must_equal 1
29
+ end
30
+ end
31
+
32
+ describe "#extras" do
33
+ before do
34
+ Fog::Bouncer::IPPermissions.to(@group, [{ "ipProtocol" => "tcp", "fromPort" => 20, "toPort" => 20, "ipRanges" => [{ "cidrIp" => "2.2.2.2/2" }], "groups" => [] }])
35
+
36
+ @doorlist.clear_remote
37
+ end
38
+
39
+ it "detects the extra sources" do
40
+ @group.extra_remote_sources.must_equal @group.sources.select { |s| s.source == "2.2.2.2/2" }
41
+
42
+ @doorlist.clear_remote
43
+ end
44
+ end
45
+
46
+ describe "#missing" do
47
+ before do
48
+ @source = Fog::Bouncer::Sources.for("2.2.2.2/2", @group)
49
+ @source.protocols << Fog::Bouncer::Protocols::TCP.new(90, @source)
50
+ @source.local = true
51
+ @group.sources << @source
52
+ end
53
+
54
+ it "detects the missing sources" do
55
+ @group.missing_remote_sources.must_equal [@source]
56
+
57
+ @doorlist.clear_remote
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,25 @@
1
+ require "helper"
2
+
3
+ describe Fog::Bouncer::Protocols::ICMP do
4
+ subject { Fog::Bouncer::Protocols::ICMP }
5
+
6
+ it "only supports valid AWS ICMP types" do
7
+ lambda { subject.new(256, nil) }.must_raise(Fog::Bouncer::Protocols::InvalidICMPType)
8
+ end
9
+ end
10
+
11
+ describe Fog::Bouncer::Protocols::TCP do
12
+ subject { Fog::Bouncer::Protocols::TCP }
13
+
14
+ it "only supports valid port ranges" do
15
+ lambda { subject.new(65536, nil) }.must_raise(Fog::Bouncer::Protocols::InvalidPort)
16
+ end
17
+ end
18
+
19
+ describe Fog::Bouncer::Protocols::UDP do
20
+ subject { Fog::Bouncer::Protocols::UDP }
21
+
22
+ it "only supports valid port ranges" do
23
+ lambda { subject.new(65536, nil) }.must_raise(Fog::Bouncer::Protocols::InvalidPort)
24
+ end
25
+ end
@@ -0,0 +1,85 @@
1
+ require "helper"
2
+
3
+ describe Fog::Bouncer::Security do
4
+ before do
5
+ Fog::Bouncer.reset
6
+ Fog::Mock.reset if Fog.mocking?
7
+
8
+ load_security(:private)
9
+
10
+ @doorlist = Fog::Bouncer.doorlists[:private]
11
+ @doorlist.import_remote_groups
12
+ @fog = Fog::Bouncer.fog
13
+ end
14
+
15
+ describe "pretending" do
16
+ before do
17
+ Fog::Bouncer.pretend!
18
+ @groups = @fog.security_groups.all
19
+ @fog.security_groups.get('default').connection.authorize_security_group_ingress('default', "IpPermissions" => [{"Groups" => [], "IpRanges" => [{"CidrIp" => "0.0.0.0/0"}], "IpProtocol" => "icmp", "FromPort" => "-1", "ToPort" => "-1"}])
20
+ @doorlist.sync
21
+ end
22
+
23
+ it "should not sync anything" do
24
+ assert !@doorlist.groups.first.remote?
25
+ @fog.security_groups.get('default').ip_permissions.wont_be_empty
26
+ @fog.security_groups.size.must_equal @groups.size
27
+ end
28
+ end
29
+
30
+ describe "use" do
31
+ it "should include any source definition specified in all groups" do
32
+ @doorlist.groups.each do |group|
33
+ next unless group.local?
34
+ group.sources.find { |s| s.source == "0.0.0.0/0" && s.protocols.find { |p| p.type == "tcp" && p.from == 22 && p.to == 22 } }.wont_be_nil
35
+ end
36
+ end
37
+ end
38
+
39
+ describe "#sync" do
40
+ before do
41
+ @doorlist.sync
42
+ end
43
+
44
+ it "synchronises against AWS" do
45
+ @fog.security_groups.size.must_equal 4
46
+
47
+ fog_douchebag = @fog.security_groups.get('douchebag')
48
+ douchebag = @doorlist.groups.find { |g| g.name == 'douchebag' }
49
+ douchebag.remote.group_id.must_equal fog_douchebag.group_id
50
+
51
+ source = @doorlist.groups.find { |g| g.name == 'guido' }.sources.first
52
+ assert source.remote # not sure of the minitest/spec equivalent
53
+ source.user_alias.must_equal "jersey_shore"
54
+ source.user_id.must_equal ENV['AWS_ACCOUNT_ID']
55
+
56
+ default = @fog.security_groups.get('default')
57
+ default.ip_permissions.must_be_empty
58
+
59
+ @doorlist.clear_remote
60
+ end
61
+ end
62
+
63
+ describe "#extra_remote_groups" do
64
+ it "detects the extra groups" do
65
+ @doorlist.extra_remote_groups.must_equal [@doorlist.groups.find { |g| g.name == "default"}]
66
+
67
+ @doorlist.clear_remote
68
+ end
69
+ end
70
+
71
+ describe "#missing_remote_groups" do
72
+ before do
73
+ @doorlist.sync
74
+ @new = Fog::Bouncer::Group.new('new', 'new', self)
75
+ @new.local = true
76
+ @doorlist.groups << @new
77
+ end
78
+
79
+ it "detects the missing groups" do
80
+ @doorlist.missing_remote_groups.must_equal [@new]
81
+
82
+ @doorlist.clear_remote
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,49 @@
1
+ require "helper"
2
+
3
+ describe Fog::Bouncer do
4
+ before do
5
+ Fog::Bouncer.reset
6
+ Fog::Mock.reset if Fog.mocking?
7
+
8
+ load_security(:private)
9
+
10
+ @doorlist = Fog::Bouncer.doorlists[:private]
11
+ @doorlist.import_remote_groups
12
+ @fog = Fog::Bouncer.fog
13
+ end
14
+
15
+ describe Fog::Bouncer::Source do
16
+ describe "#extras" do
17
+ before do
18
+ @group = @doorlist.groups.first
19
+ @group.sync
20
+ @source = @group.sources.first
21
+ @protocol = @source.protocols.first
22
+ @protocol.local = false
23
+ @protocol.remote = true
24
+ @extras = @source.extras
25
+ end
26
+
27
+ it "detects the extra protocols" do
28
+ @extras.must_equal [@protocol]
29
+ end
30
+ end
31
+
32
+ describe "#missing" do
33
+ before do
34
+ @group = @doorlist.groups.first
35
+ @group.sync
36
+ @source = Fog::Bouncer::Sources.for("1.1.1.1/1", @group)
37
+ @source.protocols << (@protocol = Fog::Bouncer::Protocols::TCP.new(90, @source))
38
+ @protocol.local = true
39
+ @protocol.remote = false
40
+ @group.sources << @source
41
+ @missing = @source.missing
42
+ end
43
+
44
+ it "detects the missing protocols" do
45
+ @missing.must_equal [@protocol]
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,9 @@
1
+ require "helper"
2
+
3
+ describe Fog::Bouncer::Sources::CIDR do
4
+ subject { Fog::Bouncer::Sources::CIDR }
5
+
6
+ it "only supports valid CIDR ranges" do
7
+ lambda { subject.new("1234.5678.9012.3456/999999", nil) }.must_raise(ArgumentError)
8
+ end
9
+ end
@@ -0,0 +1,45 @@
1
+ require "helper"
2
+
3
+ describe Fog::Bouncer do
4
+ before do
5
+ Fog::Bouncer.reset
6
+ Fog::Mock.reset if Fog.mocking?
7
+
8
+ load_security(:private)
9
+
10
+ @doorlist = Fog::Bouncer.doorlists[:private]
11
+ @doorlist.import_remote_groups
12
+ @fog = Fog::Bouncer.fog
13
+ end
14
+
15
+ it "bounces" do
16
+ true.must_equal true
17
+ end
18
+
19
+ describe ".security" do
20
+ it "has a douchebag group" do
21
+ douchebag = @doorlist.groups.find { |g| g.name == 'douchebag' }
22
+ douchebag.name.must_equal "douchebag"
23
+ douchebag.description.must_equal "Don't let them in!"
24
+
25
+ source = douchebag.sources.first
26
+ source.must_be_kind_of Fog::Bouncer::Sources::CIDR
27
+ source.range.must_equal "1.1.1.1/1"
28
+
29
+ protocol = source.protocols.first
30
+ protocol.must_be_kind_of Fog::Bouncer::Protocols::TCP
31
+ protocol.from.must_equal 7070
32
+ protocol.to.must_equal 8080
33
+ end
34
+
35
+ it "has a guido group" do
36
+ guido = @doorlist.groups.find { |g| g.name == "guido" }
37
+
38
+ source = guido.sources.first
39
+ source.must_be_kind_of Fog::Bouncer::Sources::Group
40
+ source.user_alias.must_equal "jersey_shore"
41
+ source.user_id.must_equal ENV['AWS_ACCOUNT_ID']
42
+ source.name.must_equal "douchebag"
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,28 @@
1
+ require "simplecov"
2
+ require 'minitest/autorun'
3
+
4
+ ENV['AWS_ACCESS_KEY_ID'] ||= "abcde1234"
5
+ ENV['AWS_SECRET_ACCESS_KEY'] ||= "abcde1234"
6
+ ENV['AWS_ACCOUNT_ID'] ||= "1234567890"
7
+
8
+ require "fog/bouncer"
9
+
10
+ Fog::Bouncer.logger = File.open(File.dirname(__FILE__) + '/../logs/test.log', 'w')
11
+
12
+ def load_security(security)
13
+ Fog::Bouncer.load File.dirname(__FILE__) + "/support/security/#{security}.rb"
14
+ end
15
+
16
+ Fog.mock! unless ENV['FOG_REAL']
17
+
18
+ MiniTest::Unit.after_tests do
19
+ Fog::Bouncer.doorlists.each do |name, doorlist|
20
+ doorlist.groups.each do |group|
21
+ group.revoke
22
+ end
23
+
24
+ doorlist.groups.each do |group|
25
+ group.destroy
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,46 @@
1
+ Fog::Bouncer.security :private do
2
+ account "jersey_shore", Fog::Bouncer.aws_account_id
3
+
4
+ define :ping, "0.0.0.0/0" do
5
+ icmp :ping
6
+ end
7
+
8
+ define :ssh, "0.0.0.0/0" do
9
+ tcp 22
10
+ end
11
+
12
+ use :ssh
13
+
14
+ group "douchebag", "Don't let them in!" do
15
+ use :ping
16
+
17
+ source "1.1.1.1/1" do
18
+ tcp 7070..8080, 80
19
+ end
20
+
21
+ source "0.0.0.0/0" do
22
+ icmp :ping
23
+ end
24
+ end
25
+
26
+ group "guido", "Definitely don't let them in!" do
27
+ source "douchebag@jersey_shore" do
28
+ tcp 7070..8080
29
+ udp 8081
30
+ end
31
+
32
+ source "other@#{Fog::Bouncer.aws_account_id}" do
33
+ icmp :all
34
+ end
35
+ end
36
+
37
+ group "other", "Some other randomness" do
38
+ source "douchebag" do
39
+ tcp 80
40
+ end
41
+
42
+ source "douchebag" do
43
+ udp 8080
44
+ end
45
+ end
46
+ end
metadata ADDED
@@ -0,0 +1,179 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fog-bouncer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dylan Egan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: clamp
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.3.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.3.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: fog
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 1.2.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.2.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: ipaddress
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.8.0
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.8.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: scrolls
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 0.0.5
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 0.0.5
94
+ - !ruby/object:Gem::Dependency
95
+ name: minitest
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: A simple way to define and manage security groups for AWS with the backing
111
+ support of fog.
112
+ email:
113
+ - dylanegan@gmail.com
114
+ executables:
115
+ - fog-bouncer
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - .gitignore
120
+ - .simplecov
121
+ - Gemfile
122
+ - README.md
123
+ - Rakefile
124
+ - bin/fog-bouncer
125
+ - bouncer.jpg
126
+ - fog-bouncer.gemspec
127
+ - lib/fog/bouncer.rb
128
+ - lib/fog/bouncer/cli.rb
129
+ - lib/fog/bouncer/group.rb
130
+ - lib/fog/bouncer/group_manager.rb
131
+ - lib/fog/bouncer/ip_permissions.rb
132
+ - lib/fog/bouncer/protocols.rb
133
+ - lib/fog/bouncer/security.rb
134
+ - lib/fog/bouncer/source.rb
135
+ - lib/fog/bouncer/source_manager.rb
136
+ - lib/fog/bouncer/sources.rb
137
+ - lib/fog/bouncer/version.rb
138
+ - logs/.gitignore
139
+ - spec/fog/bouncer/group_spec.rb
140
+ - spec/fog/bouncer/protocols_spec.rb
141
+ - spec/fog/bouncer/security_spec.rb
142
+ - spec/fog/bouncer/source_spec.rb
143
+ - spec/fog/bouncer/sources/cidr_spec.rb
144
+ - spec/fog/bouncer_spec.rb
145
+ - spec/helper.rb
146
+ - spec/support/security/private.rb
147
+ homepage: ''
148
+ licenses: []
149
+ post_install_message:
150
+ rdoc_options: []
151
+ require_paths:
152
+ - lib
153
+ required_ruby_version: !ruby/object:Gem::Requirement
154
+ none: false
155
+ requirements:
156
+ - - ! '>='
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ none: false
161
+ requirements:
162
+ - - ! '>='
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ requirements: []
166
+ rubyforge_project:
167
+ rubygems_version: 1.8.21
168
+ signing_key:
169
+ specification_version: 3
170
+ summary: A manage security.
171
+ test_files:
172
+ - spec/fog/bouncer/group_spec.rb
173
+ - spec/fog/bouncer/protocols_spec.rb
174
+ - spec/fog/bouncer/security_spec.rb
175
+ - spec/fog/bouncer/source_spec.rb
176
+ - spec/fog/bouncer/sources/cidr_spec.rb
177
+ - spec/fog/bouncer_spec.rb
178
+ - spec/helper.rb
179
+ - spec/support/security/private.rb