EugenMayer / chef-shorewall_ng

Maintained shorewall 5 for chef, focused on debian / ubuntu support

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

shorewall_ng Cookbook

Description

This cookbook enables you to configure a shorewall5 on a debian/ubunto based os a transparent, easy and encapsulated way

Shorewall is a rather comprehensive and easy-to-use abstraction layer on top of iptables.

This cookbook installs, configures and manages Shorewall.

Release

chef exec bundle install --binstubs --without='development vagrant docker dokken integration'
chef exec login --username <user>--key ~/.ssh/key.pem
# edit metadata.rb and release
chef exec stove

Tests

Run the test by using kitchen chef exec kitchen test

Requirements

Chef

Tested on 12 and 15 but newer and older version should work just fine.

Platform

The following platforms have been tested with this cookbook, meaning that the recipes run on these platforms without error:

  • Ubuntu
  • Debian(8/9/10)

Capabilities

It supports shorewall5, please see the recipes below.

Creates pretty Shorewall configuration files intended to be aesthetically comparable to hand-written ones.

Recipes

shorewall_ng::default

This cookbook installs and configures shorewall on the your node.

Attributes

shorewall_ng::default

Key Type Description Default
['shorewall']['enabled'] Boolean Enable o disable Shorewall false
['shorewall']['default']['options'] String Global start/restart/stop options
['shorewall']['default']['wait_interface'] String If your Shorewall configuration requires detection of the ip address of a ppp interface, you must list such interfaces in this attribute to get Shorewall to wait until the interface is configured false
['shorewall']['default']['startoptions'] String Start options
['shorewall']['default']['restartoptions'] String Restart options
['shorewall']['default']['initlog'] String Init Log. If it is /dev/null, will be used the STARTUP_LOG value defined in shorewall.conf /dev/null
['shorewall']['default']['safestop'] Numeric Set this to 1 to cause '/etc/init.d/shorewall stop' to place the firewall in a safe state rather than to open it 0
['shorewall']['zones'] Array This is an array of hashes that contain the zones settings. Each item could have the following keys: zone, type, options, in_options, out_options []
['shorewall']['policy'] Array This is an array of hashes that contain the polices settings. Each item could have the following keys: source, dest, policy, log_level, limit []
['shorewall']['interfaces'] Array This is an array of hashes that contain the interfaces settings. Each item could have the following keys: zone, interface, broadcast, options []
['shorewall']['hosts'] Array This is an array of hashes that contain the hosts settings. Each item could have the following keys: zone, hosts, options []
['shorewall']['rules'] Array This is an array of hashes that contain the rules settings. Each item could have the following keys: action, source, dest, proto, dest_port, source_port, original_dest, rate_limit, user, fwmark []
['shorewall']['tunnels'] Array This is an array of hashes that contain the tunnels settings. Each item could have the following keys: type, zone, gateway, gateway_zones []
['shorewall']['snat'] Array This is an array of hashes that contain the masq/SNAT settings. Each item could have the following keys: interface, source, address, proto, ports, ipsec, mark, user, switch []

For more details, see the attributes/default.rb file.

Usage

Just include shorewall_ng in your node's run_list:

{
  "name": "my_node",
  "run_list": ["recipe[shorewall_ng]"]
}

You need to set the zones, policies, rules, zones, interfaces in order to manage Shorewall by using this cookbook.

Examples:

  • Setting zones:
"shorewall": {
  "zones": [
    { "zone": "fw", "type": "firewall" },
    { "zone": "lan", "type": "ipv4" },
    { "zone": "net", "type": "ipv4" }
  ]
}
  • Setting policies:
"shorewall": {
  "policy": [
    { "source": "fw", "dest": "all", "policy": "ACCEPT" },
    { "source": "lan", "dest": "fw", "policy": "REJECT", "log": "DEBUG" },
    { "source": "all", "dest": "all", "policy": "REJECT" }
  ]
}
  • Setting interfaces
"shorewall": {
  "interfaces": [
    { "zone": "net", "interface": "eth0", "broadcast": "detect", "options": "tcpflags,nosmurfs,routefilter,logmartians" },
    { "zone": "lan", "interface": "eth1", "broadcast": "detect", "options": "tcpflags,nosmurfs,routefilter,logmartians" }
  ]
}
  • Setting rules
"shorewall": {
  "rules": [
    {
      "description": "Don't allow connection pickup from the net",
      "action": "Invalid(DROP)", "source": "net", "dest": "all"
    },
    {
      "description": "Accept DNS connections from the firewall to the network",
      "action": "DNS(ACCEPT)", "source": "fw", "dest": "net"
    },
    {
      "description": "Accept NTP connections from the firewall to the network",
      "action": "NTP(ACCEPT)", "source": "fw", "dest": "net"
    },
    {
      "description": "Incoming SSH to firewall",
      "source": "all", "dest": "fw", "proto": "tcp", "dest_port": 22, "action": "ACCEPT"
    },
    {
      "description": "Accept HTTP/HTTPS connections to internet",
      "action": "Web(ACCEPT)", "source": "fw", "dest": "net"
    },
    {
      "description": "Allow Ping from the local network",
      "action": "Ping(ACCEPT)", "source": "loc", "dest": "fw"
    },
    {
      "description": "Drop Ping from the \"bad\" net zone.. and prevent your log from being flooded..",
      "action": "Ping(DROP)", "source": "net", "dest": "fw"
    },
    {
      "description": "Drop Ping from the \"bad\" net zone.. and prevent your log from being flooded..",
      "action": "ACCEPT", "source": "fw", "dest": "loc", "proto": "icmp"
    },
    {
      "description": "Drop Ping from the \"bad\" net zone.. and prevent your log from being flooded..",
      "action": "ACCEPT", "source": "fw", "dest": "net", "proto": "icmp"
    }
  ]
}
  • Setting tunnels:
"shorewall": {
  "tunnels": [
    { "type": "ipsec", "zone": "net", "gateway": "0.0.0.0/0", "gateway_zones": "vpn" }
  ]
}
  • Setting SNAT/Masquerade
"shorewall": {
  "snat": [
      { "action": "MASQUERADE","dest": "eth0", "source": "192.168.0.0/24" }
  ]
}

Configuration

The following is a typical example of output (in this case, for a rules file):

#
# Shorewall version 5 - Rules File
#
# For information on the settings in this file, type "man shorewall-rules"
#
# The manpage is also online at
# http://www.shorewall.net/manpages/shorewall-rules.html
#
############################################################################################################################
#ACTION         SOURCE          DEST            PROTO   DEST    SOURCE          ORIGINAL        RATE            USER/   MARK
#                                                       PORT    PORT(S)         DEST            LIMIT           GROUP
#SECTION ESTABLISHED
#SECTION RELATED
SECTION NEW

# Allow all from VM host
ACCEPT          net:10.0.2.2    fw              -       -       -               -               -               -       -

# Incoming SSH to firewall
ACCEPT          all             fw              tcp     22      -               -               -               -       -

# Allow database load-balancer db1.vguest access to repmgr monitor
ACCEPT          lan:192.168.123.10 \
                                fw              tcp     5480    -               -               -               -       -

Note how line continuations are added as necessary to keep column alignment in place.

Contributing

I am very happy to accept this PRs or work on issues to extend the usage of this cookbook.

Just use the issue queue or even better, create pull requests for what you like to improve.

Testing

You can run the test using kitchen

chef exec kitchen converge

There are to test suites, default for testing shorewall5 to ensure we can install shorewall5 e.g. for docker support.

Credits

This cookbook is heavily based on the nowdays no longer maintained cookbook https://github.com/demonccc/chef-shorewall_reloaded - thank you for you hard work Claudio!

License and Authors

Author:: Eugen Mayer (eugenmayer on github)

Old Author:: Claudio Cesar Sanchez Tejeda demonccc@gmail.com

Copyright:: 2017, Eugen Mayer

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.

About

Maintained shorewall 5 for chef, focused on debian / ubuntu support


Languages

Language:HTML 55.8%Language:Ruby 44.2%