Adoptable Cookbooks List

Looking for a cookbook to adopt? You can now see a list of cookbooks available for adoption!
List of Adoptable Cookbooks

Supermarket Belongs to the Community

Supermarket belongs to the community. While Chef has the responsibility to keep it running and be stewards of its functionality, what it does and how it works is driven by the community. The chef/supermarket repository will continue to be where development of the Supermarket application takes place. Come be part of shaping the direction of Supermarket by opening issues and pull requests or by joining us on the Chef Mailing List.

Select Badges

Select Supported Platforms

Select Status

RSS

quick_firewall (8) Versions 0.1.6

Installs/Configures quick_firewall

Policyfile
Berkshelf
Knife
cookbook 'quick_firewall', '= 0.1.6', :supermarket
cookbook 'quick_firewall', '= 0.1.6'
knife supermarket install quick_firewall
knife supermarket download quick_firewall
README
Dependencies
Changelog

Quick Firewall Chef Cookbook

This cookbook is intended to configure basic firewall settings that are commonly used.

The modules make use of firewalld or ufw to set the rules.

This cookbook is not intended to provide complete OS Firewall wrapping via resources, but instead provides an easy way to add or remove simple rules. It is currently mainly used for host-based firewalls in Debian and RHEL Family.

Requirements

  • Chef Infra Client 16.0+
depends 'quick_firewall'

Supported firewalls and platforms

  • UFW - Ubuntu, Debian
  • FirewallD - Red Hat & CentOS >= 7.0

Tested on:

  • Ubuntu 22.04 with ufw
  • CentOS 7 with firewalld
  • CentOS 8 with firewalld
  • Oracle 9 with firewalld

Resources

This cookbook comes with five resources:
- firewall_install
- firewall_open_port
- firewall_open_service
- firewall_allow_protocol
- firewall_zone

Attributes

  • default['quick_firewall']['open_ssh'] = true, set true to open port 22 for SSH when the default recipe runs
  • default['quick_firewall']['open_http'] = false, set true to open port 80 for http when the default recipe runs
  • default['quick_firewall']['open_https'] = false, set true to open port 443 for https when the default recipe runs

Usage

Installation

To install and enable the firewall use the firewall_install resource.

firewall_install 'default' do
action :install
end

This would keep the ssh port 22 open as a default action.
To prevent this set
default['quick_firewall']['open_ssh'] = false

Opening a port

The most basic way to open port 80 would be

firewall_open_port '80' do
port 80
protocol 'tcp'
action :create
end

Resource Definition:

firewall_open_port 'name' do
port Integer
protocol String
source String
interface String
zone String
action Symbol
end

where
* port is the port that is required to be open
* protocol is the protocol that the port uses, generally, tcp or udp
* source An IP or a subnet from where the request will be allowed. Debian family only will be ignored in RHEL. Give a subnet by its network address (10.0.0.0/24, not 10.0.0.5/24): ufw rewrites it otherwise, and the rule is then re-applied on every Chef run.
* interface Only allow traffic arriving on this interface, e.g. docker_gwbridge. Debian family only; on RHEL the run fails rather than opening the port on every interface (put the interface in a zone and use zone there).
* zone The firewall zone to use. Note RHEL Family only, will be ignored in Debian

On ufw the resource is idempotent: it skips the rule when ufw status already lists the same port, protocol, interface and source.

Example: let containers on a Docker Swarm node reach a port published on the host's own IP (hairpin). Docker doesn't forward traffic coming from docker_gwbridge, so ufw's default deny drops it.

firewall_open_port 'gwbridge-hairpin-443' do
port 443
protocol 'tcp'
source '172.18.0.0/16'
interface 'docker_gwbridge'
end

Opening a service

Though we recommend to use the firewall_open_port resource, services can be opened by this resource.
Example to open https.

firewall_open_service 'https' do
service_name 'https'
ufw_port_track '443'
action :create
end

Resource Definition:

firewall_open_service 'name' do
service_name String
zone String
action Symbol
end

where
* service_name is the service that is required to be open. Examples ssh, https, ldap etc
* ufw_port_track (Debian ONLY) Ignored in RHEL, is the port of the corresponding service. 22 for SSH etc.
* zone The firewall zone to use. Note RHEL Family only, will be ignored in Debian

Allowing a protocol without ports

Some IP protocols have no ports, for example ESP (IPsec, used by Docker Swarm encrypted overlay networks), AH or GRE.
Example to allow ESP from one host.

firewall_allow_protocol 'esp' do
source '10.0.0.5'
comment 'docker swarm encrypted overlay'
end

Resource Definition:

firewall_allow_protocol 'name' do
protocol String # defaults to the name
source String
comment String
zone String
action Symbol
end

where
* protocol is the IP protocol to allow, e.g. esp, ah, gre
* source An IP or a subnet from where the protocol is allowed. Leave empty to allow from anywhere. On RHEL a source uses a firewalld rich rule.
* comment (Debian ONLY) Comment to add on UFW
* zone The firewall zone to use. Note RHEL Family only, will be ignored in Debian

Creating a firewalld zone

This resource will create a firewall zone in the RedHat Family.
Example 1

firewalld_zone 'xyz-private' do
source '10.10.10.0/24'
action :create
end

Example 2

firewalld_zone 'xyz-private' do
interface 'eth-2'
action :create
end

Resource Definition:

firewalld_zone 'name' do
name String
source String
interface String
action Symbol
end

where
* name is the name of the zone to create
* source is the source IP or network
* interface if required, create the zone for a specific interface.

Advanced Firewall

This cookbook takes the path where it relies more on the existing CLI firewall tools firewall-cmd and ufw so that it can be adapted rapidly with the latest OS releases though compromising on granular controls but useful enough for most basic scenarios.

For an advanced firewall configuration, please have a look at the firewall cookbook by sous-chef.

License

The cookbook comes as is without any warranty.

Dependent cookbooks

This cookbook has no specified dependencies.

Contingent cookbooks

There are no cookbooks that are contingent upon this one.

quick_firewall CHANGELOG

This file is used to list changes made in each version of the quick_firewall cookbook.

0.1.6

  • firewall_open_port: fix the ufw guard, which was missing a | before grep -w 'ALLOW' and so never matched. The rule was re-applied, and reported as updated, on every Chef run. The guard now matches the whole ufw status row (port/protocol, interface, source), so a rule for another port, source or interface no longer counts as this one.
  • firewall_open_port: new interface property (ufw only) that allows traffic arriving on one interface, e.g. docker_gwbridge. Setting it on firewalld fails the run instead of opening the port on every interface.
  • First ChefSpec specs (spec/unit/resources/firewall_open_port_spec.rb).

0.1.5

  • New resource firewall_allow_protocol to allow IP protocols that have no ports (esp, ah, gre), optionally from one source, on ufw and firewalld.

0.1.0

Initial release.

  • change 0
  • change 1
Copyright © 2026 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.

Progress and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries.
See Trademarksfor appropriate markings. All rights in any other trademarks contained herein are reserved by their respective owners and their inclusion does not imply an endorsement, affiliation, or sponsorship as between Progress and the respective owners.

Code of Conduct Terms and Conditions of Use Privacy Policy Cookie Policy Trademark Policy Status