Skip to content

Commit 500791f

Browse files
committed
Refactor firewall backends into dedicated resources
1 parent 5ad6dac commit 500791f

27 files changed

Lines changed: 1138 additions & 674 deletions

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ name: ci
77

88
jobs:
99
lint-unit:
10-
uses: sous-chefs/.github/.github/workflows/lint-unit.yml@6.0.0
10+
uses: sous-chefs/.github/.github/workflows/lint-unit.yml@8.0.0
1111
permissions:
1212
checks: write
1313
pull-requests: write
@@ -192,7 +192,7 @@ jobs:
192192
- name: Checkout code
193193
uses: actions/checkout@v6
194194
- name: Install Cinc Workstation
195-
uses: sous-chefs/.github/.github/actions/install-workstation@6.0.0
195+
uses: sous-chefs/.github/.github/actions/install-workstation@8.0.0
196196
- name: Dokken
197197
uses: actionshub/test-kitchen@3.0.0
198198
env:

.github/workflows/conventional-commits.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ name: conventional-commits
1111

1212
jobs:
1313
conventional-commits:
14-
uses: sous-chefs/.github/.github/workflows/conventional-commits.yml@6.0.0
14+
uses: sous-chefs/.github/.github/workflows/conventional-commits.yml@8.0.0
1515
permissions:
1616
pull-requests: read

.github/workflows/prevent-file-change.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ name: prevent-file-change
1111

1212
jobs:
1313
prevent-file-change:
14-
uses: sous-chefs/.github/.github/workflows/prevent-file-change.yml@6.0.0
14+
uses: sous-chefs/.github/.github/workflows/prevent-file-change.yml@8.0.0
1515
permissions:
1616
pull-requests: write
1717
secrets:

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ permissions:
1616

1717
jobs:
1818
release:
19-
uses: sous-chefs/.github/.github/workflows/release-cookbook.yml@6.0.0
19+
uses: sous-chefs/.github/.github/workflows/release-cookbook.yml@8.0.0
2020
secrets:
2121
token: ${{ secrets.PORTER_GITHUB_TOKEN }}
2222
supermarket_user: ${{ secrets.CHEF_SUPERMARKET_USER }}

README.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,12 @@ The most basic use involves two resources, `firewall` and `firewall_rule`. The
101101
typical usage scenario is as follows:
102102

103103
* declare the `firewall` resource named `'default'`, which installs appropriate packages and configures services to start on boot and starts them.
104-
* run the `:create` action on every `firewall_rule` resource, which routes to the selected backend resource. How the rules are implemented depends on the firewall backend:
105-
* **firewalld**: `firewall_rule` creates firewalld [rich rules](https://firewalld.org/documentation/man-pages/firewalld.richlanguage.html) in the system's default zone.
104+
* run the `:create` action on every `firewall_rule` resource, which routes to the selected backend rule resource. How the rules are implemented depends on the firewall backend:
105+
* **firewalld**: `firewall_rule` routes to `firewalld_rule`, which creates firewalld [rich rules](https://firewalld.org/documentation/man-pages/firewalld.richlanguage.html) in the system's default zone.
106106
* **nftables**: `firewall_rule` routes to `nftables_rule`.
107-
* **iptables, ufw, windows**: `firewall_rule` routes to the matching backend rule resource, which automatically sends a delayed notification to the `firewall['default']` resource to run the `:restart` action.
108-
* when the delayed `:restart` notification on the `firewall` resource fires, if any rules are different than the last run, the provider will update the current state of the firewall rules to match the expected rules.
107+
* **iptables, ufw, windows**: `firewall_rule` routes to the matching backend rule resource.
108+
* backend rule resources notify their matching backend resource, such as `iptables['default']`, `ufw['default']`, `nftables['default']`, or `windows_firewall['default']`, to rebuild delayed.
109+
* when the delayed backend rebuild fires, if any rules are different than the last run, the backend resource updates the current firewall rules to match the expected rules.
109110

110111
There is a fundamental mismatch between the idea of a Chef action and the action that should be taken on a firewall
111112
rule. For this reason, the Chef action for a `firewall_rule` may be `:create` (the rule should be present in the
@@ -159,9 +160,10 @@ Please read the documentation for the
159160
## firewalld
160161

161162
For most rules it's sufficient to simply use the `firewall_rule` resource which is a platform-agnostic way to add
162-
firewall rules. On firewalld systems it adds rules to the default zone as firewalld [rich
163-
rules](https://firewalld.org/documentation/man-pages/firewalld.richlanguage.html). See the
164-
[`firewall_rule`](#firewall_rule) section for examples.
163+
firewall rules. On firewalld systems it routes to `firewalld_rule`, which adds rules to the default zone as firewalld
164+
[rich rules](https://firewalld.org/documentation/man-pages/firewalld.richlanguage.html). Use `firewalld_rule`
165+
directly when you want the portable firewalld rule interface, and use `firewalld_rich_rule` when you want to pass
166+
native rich-rule properties.
165167

166168
See the [`firewalld` resources](documentation/README.md) documentation for advanced firewalld configuration.
167169

@@ -178,7 +180,7 @@ recipe and attribute API.
178180
Declare this resource before adding your desired `firewall_rule` resources. See
179181
the [`firewall_rule`](#firewall_rule) section for examples.
180182

181-
***NB***: The name 'default' of this resource is important as it is used for firewall_rule providers to locate the firewall resource. If you change it, you must also supply the same value to any firewall_rule resources using the `firewall_name` parameter.
183+
***NB***: The name 'default' of this resource is important as it is used for `firewall_rule` to locate the matching backend resource. If you change it, you must also supply the same value to any `firewall_rule` resources using the `firewall_name` parameter.
182184

183185
#### Actions
184186

@@ -220,7 +222,7 @@ end
220222

221223
#### Actions
222224

223-
* `:create`: Create the firewall rule and notify the firewall to reload after the rule has been saved. On firewalld systems, the rules are added to the default zone as firewalld [rich rules](https://firewalld.org/documentation/man-pages/firewalld.richlanguage.html).
225+
* `:create`: Create the firewall rule through the selected backend rule resource. On firewalld systems, rules are routed through `firewalld_rule` and added to the default zone as firewalld [rich rules](https://firewalld.org/documentation/man-pages/firewalld.richlanguage.html).
224226

225227
#### Properties
226228

@@ -247,15 +249,15 @@ firewall_rule 'name' do
247249
stateful Symbol, Array # Firewall: iptables, nftables, ufw
248250
raw String # Firewall: iptables, nftables, ufw
249251
direction Symbol # Firewall: iptables, nftables, ufw, windows. Default: :in
250-
notify_firewall true, false # Firewall: iptables, nftables, ufw, windows. Default: true
252+
notify_firewall true, false # Notify selected backend to apply rules. Default: true
251253
program String # Firewall: windows
252254
service String # Firewall: windows
253255
end
254256
```
255257

256258
Firewall-agnostic properties that can be used with `firewall_rule` on any firewall system:
257259

258-
* `firewall_name`: the matching firewall resource that this rule applies to. Default value: `default`
260+
* `firewall_name`: the matching `firewall` facade and backend resource name that this rule applies to. Default value: `default`
259261
* `description` (*default: same as rule name*): Used to provide a comment that will be included when adding the firewall rule.
260262
* `command`: What action to take on a particular packet
261263
* `:allow` (*default action*): the rule should allow matching packets
@@ -287,8 +289,8 @@ Additional properties for advanced firewall rules that are tied to specific fire
287289
* `raw` (*iptables, nftables, ufw*): Used to pass an entire rule as a string, omitting all other parameters. This line will be directly loaded by `iptables-restore`, included in the nftables ruleset, or fed directly into `ufw` on the command line.
288290
* `direction` (*iptables, nftables, ufw, windows*): Direction of the rule. Valid values are: `:in` (*default*), `:out`, `:pre`,
289291
`:post`.
290-
* `notify_firewall` (*iptables, nftables, ufw, windows*): Notify the firewall to recalculate (and potentially reapply) the
291-
`firewall_rule`(s) it finds. Default: `true`
292+
* `notify_firewall` (*iptables, nftables, ufw, windows*): Notify the selected backend resource to recalculate (and
293+
potentially reapply) the `firewall_rule`(s) it finds. Default: `true`
292294

293295
#### Examples
294296

documentation/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* [firewalld_icmptype](resources/firewalld_icmptype.md)
1111
* [firewalld_ipset](resources/firewalld_ipset.md)
1212
* [firewalld_policy](resources/firewalld_policy.md)
13+
* [firewalld_rule](resources/firewalld_rule.md)
1314
* [firewalld_rich_rule](resources/firewalld_rich_rule.md)
1415
* [firewalld_service](resources/firewalld_service.md)
1516
* [firewalld_zone](resources/firewalld_zone.md)

documentation/firewall_firewall.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# firewall
22

3-
The `firewall` resource installs, enables, disables, and rebuilds a platform
4-
firewall backend.
3+
The `firewall` resource is a compatibility facade that delegates install,
4+
reload, disable, flush, and rebuild actions to the selected backend resource.
55

66
## Actions
77

88
| Action | Description |
99
| ---------- | ----------------------------------------------------------------- |
1010
| `:install` | Install and enable the selected firewall backend. |
11-
| `:restart` | Rebuild and apply rules collected from `firewall_rule` resources. |
11+
| `:restart` | Rebuild and apply rules through the selected backend resource. |
1212
| `:reload` | Reload firewalld, or rebuild non-firewalld backends. |
1313
| `:disable` | Disable the selected firewall backend. |
1414
| `:flush` | Flush runtime rules where the selected backend supports it. |

documentation/firewall_firewall_rule.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# firewall_rule
22

33
The `firewall_rule` resource creates backend-agnostic firewall rules and
4-
notifies the named `firewall` resource to apply them.
4+
routes them to the backend rule resource selected by the named `firewall`
5+
resource.
56

67
## Actions
78

@@ -13,7 +14,7 @@ notifies the named `firewall` resource to apply them.
1314

1415
| Property | Type | Default | Description |
1516
| ----------------- | --------------------- | ------------- | --------------------------------------------------------------------------- |
16-
| `firewall_name` | String | `default` | Name of the `firewall` resource to notify. |
17+
| `firewall_name` | String | `default` | Name shared by the `firewall` facade and selected backend resource. |
1718
| `command` | Symbol | `:allow` | One of `:reject`, `:allow`, `:deny`, `:masquerade`, `:redirect`, or `:log`. |
1819
| `protocol` | Integer, Symbol | `:tcp` | Protocol for the rule. |
1920
| `source` | String | | Source address. |
@@ -34,7 +35,7 @@ notifies the named `firewall` resource to apply them.
3435
| `program` | String | | Windows program match. |
3536
| `service` | String | | Windows service match. |
3637
| `raw` | String | | Raw backend rule. |
37-
| `notify_firewall` | true, false | `true` | Notify the firewall resource to apply rules. |
38+
| `notify_firewall` | true, false | `true` | Notify the backend resource to apply rules. |
3839

3940
## Examples
4041

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# firewalld_rule
2+
3+
The `firewalld_rule` resource is the firewalld backend implementation for the
4+
portable `firewall_rule` API. It translates common firewall rule properties into
5+
`firewalld_rich_rule` declarations.
6+
7+
Use `firewalld_rule` directly when you want the portable rule shape on a
8+
firewalld-only cookbook. Use `firewalld_rich_rule` when you want to model native
9+
firewalld rich-rule properties directly.
10+
11+
## Actions
12+
13+
| Action | Description |
14+
| --------- | ------------------------------------ |
15+
| `:create` | Create the matching firewalld rule. |
16+
17+
## Examples
18+
19+
```ruby
20+
firewalld_rule 'ssh' do
21+
port 22
22+
command :allow
23+
end
24+
```
25+
26+
```ruby
27+
firewalld_rule 'redirect ssh' do
28+
command :redirect
29+
source_port 2222
30+
redirect_port 22
31+
end
32+
```

0 commit comments

Comments
 (0)