Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iptables #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Ignore .swp files
*.swp
*~

# Ignore Vagrant temp files
.vagrant
Expand Down
4 changes: 4 additions & 0 deletions Berksfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@

metadata

cookbook "iptables",
git: "git://github.com/RSEmail/iptables.git",
branch: "master"

# vim:et:fdm=marker:sts=4:sw=4:ts=4:
2 changes: 2 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@
}
}

default["cassandra"]["open_ports"] = [22, 7000, 7001, 8081]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be opening port 22? Some people might not want it open. Maybe we should just do the ports that make cassandra work? I don't know.


# vim:et:fdm=marker:sts=4:sw=4:ts=4:
1 change: 1 addition & 0 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
depends "yum", "= 2.0.2"
depends "apt", "= 1.5.0"
depends "java", "= 1.6.4"
depends "iptables", "= 0.11.0"

supports "ubuntu", ">= 10.04"
#supports "debian", ">= 6.0"
Expand Down
2 changes: 2 additions & 0 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#

include_recipe "java"
include_recipe "iptables"
include_recipe "#{@cookbook_name}::iptables"
include_recipe "#{@cookbook_name}::repos"
include_recipe "#{@cookbook_name}::packages"
include_recipe "#{@cookbook_name}::configs"
Expand Down
27 changes: 27 additions & 0 deletions recipes/iptables.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Cookbook Name:: casserole
# Recipe:: firewall
#
# Copyright 2012, Arif Khokar, Joshua Rush, and Kyle Morgan
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#Open ports
iptables_rule "open_cassandra_ports" do
source "iptables/open_cassandra_ports.erb"
variables(
:iptables_chain => "FWR",
:ports => node["cassandra"]["open_ports"]
)
end

# vim:et:fdm=marker:sts=4:sw=4:ts=4:
3 changes: 2 additions & 1 deletion spec/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

before(:each) do
chef_run.node.automatic_attrs["platform_family"] = "rhel"
%w{java casserole::repos casserole::packages}.each do |r|
%w{java iptables casserole::repos casserole::packages}.each do |r|
chef_run.node.run_state.seen_recipes[r] = true
end
Chef::Recipe.any_instance.stub(:iptables_rule) {}
end

it "should install Oracle Java" do
Expand Down
1 change: 1 addition & 0 deletions templates/default/iptables/open_cassandra_ports.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-A <%= @iptables_chain %> -p tcp -m multiport --dports <%= @ports.join(',') %> -m state --state NEW -j ACCEPT
6 changes: 6 additions & 0 deletions test/kitchen/Kitchenfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ cookbook "casserole" do
configuration "repos"
configuration "packages"
configuration "configs"
configuration "iptables"

# Fail immediately on a Foodcritic check and call ChefSpec before
# spending the time to spawn test servers
preflight_command <<-END.gsub(/^\s+/, "")
pushd test/kitchen &&
librarian-chef clean &&
librarian-chef install &&
popd &&
knife cookbook metadata -o .. casserole &&
knife cookbook test -o .. casserole &&
foodcritic -f any . &&
rspec
Expand Down