Skip to content

Commit 3435cfe

Browse files
committed
Rename firewall assertion plugins to check names
1 parent 797dbae commit 3435cfe

11 files changed

Lines changed: 69 additions & 69 deletions

File tree

docs/plugins/firewall.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ firewalld backend extras manage source bindings, ICMP blocks, masquerading and
5555
forward-port rules through explicit plugins: `network.firewall.firewalld.source`,
5656
`network.firewall.firewalld.icmp_block`, `network.firewall.firewalld.masquerade` and `network.firewall.firewalld.forward_port`.
5757

58-
nftables extras provide readback assertion and rollback: `network.firewall.nftables.ruleset_assert`
58+
nftables extras provide readback assertion and rollback: `network.firewall.nftables.ruleset_check`
5959
and `network.firewall.nftables.rollback_file`. Rollback requires `confirm: true`.
6060

6161
iptables extras provide deletion, rule existence assertion and counter assertion:
62-
`network.firewall.iptables.delete`, `network.firewall.iptables.exists_assert` and `network.firewall.iptables.counter_assert`.
62+
`network.firewall.iptables.delete`, `network.firewall.iptables.rule_check` and `network.firewall.iptables.counter_check`.
6363
Deletion requires `confirm: true`.
6464

6565
UFW extras provide `network.firewall.ufw.delete` and `network.firewall.ufw.reset`. Both require `confirm: true`

docs/plugins/generated.md

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4117,7 +4117,7 @@ with:
41174117
chain: value
41184118
```
41194119

4120-
### `network.firewall.iptables.counter_assert`
4120+
### `network.firewall.iptables.counter_check`
41214121

41224122
Assert iptables chain packet counters are above a threshold.
41234123

@@ -4145,7 +4145,7 @@ Result fields:
41454145
Example:
41464146

41474147
```yaml
4148-
use: network.firewall.iptables.counter_assert
4148+
use: network.firewall.iptables.counter_check
41494149
with:
41504150
chain: value
41514151
```
@@ -4185,40 +4185,6 @@ with:
41854185
rule: allow
41864186
```
41874187

4188-
### `network.firewall.iptables.exists_assert`
4189-
4190-
Assert an iptables rule exists.
4191-
4192-
- Remote session: `true`
4193-
- Dry-run support: `true`
4194-
- Check mode support: `true`
4195-
4196-
| Parameter | Required | Type | Default | Description |
4197-
|---|---:|---|---|---|
4198-
| `chain` | yes | `string` | | Firewall chain name. |
4199-
| `rule` | yes | `string` | | Firewall action such as allow, deny, reject or limit. |
4200-
| `table` | no | `string` | | Routing table name or number. |
4201-
| `ipv6` | no | `boolean` | `False` | Use IPv6 command variant when supported. |
4202-
| `sudo` | no | `boolean` | `False` | Run the remote operation through sudo -n when supported. |
4203-
4204-
Result fields:
4205-
4206-
- `changed`: Whether the plugin changed the target or controller state.
4207-
- `message`: Human-readable result message.
4208-
- `rc`: Process or command return code when applicable.
4209-
- `stdout`: Captured standard output when applicable.
4210-
- `stderr`: Captured standard error when applicable.
4211-
- `data`: Plugin-specific structured result data.
4212-
4213-
Example:
4214-
4215-
```yaml
4216-
use: network.firewall.iptables.exists_assert
4217-
with:
4218-
chain: value
4219-
rule: allow
4220-
```
4221-
42224188
### `network.firewall.iptables.list`
42234189

42244190
List iptables or ip6tables rules for a table or chain.
@@ -4360,6 +4326,40 @@ with:
43604326
rule: allow
43614327
```
43624328

4329+
### `network.firewall.iptables.rule_check`
4330+
4331+
Assert an iptables rule exists.
4332+
4333+
- Remote session: `true`
4334+
- Dry-run support: `true`
4335+
- Check mode support: `true`
4336+
4337+
| Parameter | Required | Type | Default | Description |
4338+
|---|---:|---|---|---|
4339+
| `chain` | yes | `string` | | Firewall chain name. |
4340+
| `rule` | yes | `string` | | Firewall action such as allow, deny, reject or limit. |
4341+
| `table` | no | `string` | | Routing table name or number. |
4342+
| `ipv6` | no | `boolean` | `False` | Use IPv6 command variant when supported. |
4343+
| `sudo` | no | `boolean` | `False` | Run the remote operation through sudo -n when supported. |
4344+
4345+
Result fields:
4346+
4347+
- `changed`: Whether the plugin changed the target or controller state.
4348+
- `message`: Human-readable result message.
4349+
- `rc`: Process or command return code when applicable.
4350+
- `stdout`: Captured standard output when applicable.
4351+
- `stderr`: Captured standard error when applicable.
4352+
- `data`: Plugin-specific structured result data.
4353+
4354+
Example:
4355+
4356+
```yaml
4357+
use: network.firewall.iptables.rule_check
4358+
with:
4359+
chain: value
4360+
rule: allow
4361+
```
4362+
43634363
### `network.firewall.iptables.save`
43644364

43654365
Save current iptables or ip6tables rules to a persistent file.
@@ -4527,7 +4527,7 @@ with:
45274527
file: /etc/sysctl.d/99-automax.conf
45284528
```
45294529

4530-
### `network.firewall.nftables.ruleset_assert`
4530+
### `network.firewall.nftables.ruleset_check`
45314531

45324532
Assert the active nftables ruleset contains a fragment.
45334533

@@ -4552,7 +4552,7 @@ Result fields:
45524552
Example:
45534553

45544554
```yaml
4555-
use: network.firewall.nftables.ruleset_assert
4555+
use: network.firewall.nftables.ruleset_check
45564556
with:
45574557
fragment: value
45584558
```

docs/plugins/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ network.firewall.firewalld.source
136136
network.firewall.firewalld.status
137137
network.firewall.firewalld.zone
138138
network.firewall.iptables.chain
139-
network.firewall.iptables.counter_assert
139+
network.firewall.iptables.counter_check
140140
network.firewall.iptables.delete
141-
network.firewall.iptables.exists_assert
141+
network.firewall.iptables.rule_check
142142
network.firewall.iptables.list
143143
network.firewall.iptables.policy
144144
network.firewall.iptables.restore
@@ -148,7 +148,7 @@ network.firewall.nftables.apply
148148
network.firewall.nftables.export
149149
network.firewall.nftables.list
150150
network.firewall.nftables.rollback_file
151-
network.firewall.nftables.ruleset_assert
151+
network.firewall.nftables.ruleset_check
152152
network.firewall.nftables.validate
153153
network.firewall.ufw.delete
154154
network.firewall.ufw.disable

examples/runbooks/runbooks/27-iptables.check.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ tasks:
1818
use: network.firewall.iptables.chain
1919
with:
2020
chain: INPUT
21-
- id: network_firewall_iptables_counter_assert
22-
use: network.firewall.iptables.counter_assert
21+
- id: network_firewall_iptables_counter_check
22+
use: network.firewall.iptables.counter_check
2323
with:
2424
chain: INPUT
2525
- id: network_firewall_iptables_delete
@@ -28,8 +28,8 @@ tasks:
2828
chain: INPUT
2929
rule: -p tcp --dport 18080 -j ACCEPT
3030
confirm: true
31-
- id: network_firewall_iptables_exists_assert
32-
use: network.firewall.iptables.exists_assert
31+
- id: network_firewall_iptables_rule_check
32+
use: network.firewall.iptables.rule_check
3333
with:
3434
chain: INPUT
3535
rule: -p tcp --dport 18080 -j ACCEPT

examples/runbooks/runbooks/39-nftables.check.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ tasks:
3434
with:
3535
file: /etc/sysctl.d/99-automax.conf
3636
confirm: true
37-
- id: network_firewall_nftables_ruleset_assert
38-
use: network.firewall.nftables.ruleset_assert
37+
- id: network_firewall_nftables_ruleset_check
38+
use: network.firewall.nftables.ruleset_check
3939
with:
4040
fragment: table inet
4141
- id: network_firewall_nftables_validate

src/automax/core/capabilities.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ class CapabilityRequirement:
7373
"fs.attr.check": ("lsattr",),
7474
"fs.attr.set": ("chattr",),
7575
"network.firewall.iptables.chain": ("iptables",),
76-
"network.firewall.iptables.counter_assert": ("iptables",),
76+
"network.firewall.iptables.counter_check": ("iptables",),
7777
"network.firewall.iptables.delete": ("iptables",),
78-
"network.firewall.iptables.exists_assert": ("iptables",),
78+
"network.firewall.iptables.rule_check": ("iptables",),
7979
"network.firewall.iptables.list": ("iptables",),
8080
"network.firewall.iptables.policy": ("iptables",),
8181
"network.firewall.iptables.restore": ("iptables-restore",),
@@ -125,7 +125,7 @@ class CapabilityRequirement:
125125
"network.firewall.nftables.export": ("nft",),
126126
"network.firewall.nftables.list": ("nft",),
127127
"network.firewall.nftables.rollback_file": ("nft",),
128-
"network.firewall.nftables.ruleset_assert": ("nft",),
128+
"network.firewall.nftables.ruleset_check": ("nft",),
129129
"network.firewall.nftables.validate": ("nft",),
130130
"security.pam.validate": ("awk",),
131131
"os.package.repo.priority.set": ("install",),

src/automax/plugins/audit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def sample_params(plugin: Any) -> dict[str, Any]:
181181
params["max_stratum"] = 16
182182
if plugin.name == "os.package.check":
183183
params["state"] = "installed"
184-
if plugin.name == "network.firewall.iptables.counter_assert":
184+
if plugin.name == "network.firewall.iptables.counter_check":
185185
params["min_packets"] = 1
186186
if plugin.name == "fs.file.replace":
187187
params["count"] = 0

src/automax/plugins/ops_completeness.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,8 @@ def _spec(self, params: Dict[str, Any])->str:
550550
def manual_commands(self, params: Dict[str, Any], context: ExecutionContext)->list[str]:
551551
state=_state(params); zone=f"--zone={quote(params['zone'])} " if params.get("zone") else ""; permanent="--permanent " if bool(params.get("permanent", True)) else ""; action="add-forward-port" if state=="present" else "remove-forward-port"; spec=self._spec(params); query_cmd=f"{sudo_prefix(params, default=True)}firewall-cmd {zone}{permanent}--query-forward-port={quote(spec)}"; expected="0" if state=="present" else "1"; cmd=f"if {query_cmd} >/dev/null 2>&1; then present=0; else present=1; fi; if [ \"$present\" = {expected} ]; then true; else {sudo_prefix(params, default=True)}firewall-cmd {zone}{permanent}--{action}={quote(spec)} && echo {CHANGE_MARKER}; fi"; return [cmd + (f"; {sudo_prefix(params, default=True)}firewall-cmd --reload" if bool(params.get("reload", False)) else "")]
552552

553-
class NftablesRulesetAssertPlugin(ReadOnlyCommandPlugin):
554-
name="network.firewall.nftables.ruleset_assert"; description="Assert the active nftables ruleset contains a fragment."; required_params=("fragment",); optional_params=("sudo",)
553+
class NftablesRulesetCheckPlugin(ReadOnlyCommandPlugin):
554+
name="network.firewall.nftables.ruleset_check"; description="Assert the active nftables ruleset contains a fragment."; required_params=("fragment",); optional_params=("sudo",)
555555
def manual_commands(self, params: Dict[str, Any], context: ExecutionContext)->list[str]: return [f"{sudo_prefix(params, default=True)}nft list ruleset | grep -F -- {quote(params['fragment'])}"]
556556

557557
class NftablesRollbackFilePlugin(BasePlugin):
@@ -573,13 +573,13 @@ def manual_commands(self, params: Dict[str, Any], context: ExecutionContext)->li
573573
def execute(self, params: Dict[str, Any], context: ExecutionContext)->PluginResult:
574574
rc,out,err=exec_remote(context,self.manual_commands(params,context)[0]+f" && echo {CHANGE_MARKER}"); return result_from_remote(rc=rc, stdout=out, stderr=err, message="network.firewall.iptables.delete failed")
575575

576-
class IptablesExistsAssertPlugin(ReadOnlyCommandPlugin):
577-
name="network.firewall.iptables.exists_assert"; description="Assert an iptables rule exists."; required_params=("chain","rule"); optional_params=("table","ipv6","sudo")
576+
class IptablesRuleCheckPlugin(ReadOnlyCommandPlugin):
577+
name="network.firewall.iptables.rule_check"; description="Assert an iptables rule exists."; required_params=("chain","rule"); optional_params=("table","ipv6","sudo")
578578
def manual_commands(self, params: Dict[str, Any], context: ExecutionContext)->list[str]:
579579
binary="ip6tables" if bool(params.get("ipv6",False)) else "iptables"; table=str(params.get("table","filter")); return [f"{sudo_prefix(params, default=True)}{binary} -t {quote(table)} -C {quote(params['chain'])} {params['rule']}"]
580580

581-
class IptablesCounterAssertPlugin(ReadOnlyCommandPlugin):
582-
name="network.firewall.iptables.counter_assert"; description="Assert iptables chain packet counters are above a threshold."; required_params=("chain",); optional_params=("table","min_packets","ipv6","sudo")
581+
class IptablesCounterCheckPlugin(ReadOnlyCommandPlugin):
582+
name="network.firewall.iptables.counter_check"; description="Assert iptables chain packet counters are above a threshold."; required_params=("chain",); optional_params=("table","min_packets","ipv6","sudo")
583583
def manual_commands(self, params: Dict[str, Any], context: ExecutionContext)->list[str]:
584584
binary="ip6tables" if bool(params.get("ipv6",False)) else "iptables"; table=str(params.get("table","filter")); minp=int(params.get("min_packets",1)); return [f"{sudo_prefix(params, default=True)}{binary} -t {quote(table)} -L {quote(params['chain'])} -v -n -x | awk 'NR>2 && $1+0>={minp} {{found=1}} END {{exit !found}}'"]
585585

src/automax/plugins/registry.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -326,15 +326,15 @@ def build_builtin_registry(extra_plugin_paths: Iterable[str] = ()) -> PluginRegi
326326
FstabAssertPlugin,
327327
GroupMemberAbsentPlugin,
328328
GroupMembersPlugin,
329-
IptablesCounterAssertPlugin,
329+
IptablesCounterCheckPlugin,
330330
IptablesDeletePlugin,
331-
IptablesExistsAssertPlugin,
331+
IptablesRuleCheckPlugin,
332332
KernelBootParamAbsentPlugin,
333333
KernelCmdlineAssertPlugin,
334334
KernelModuleBlacklistPlugin,
335335
KernelModuleStatusPlugin,
336336
NftablesRollbackFilePlugin,
337-
NftablesRulesetAssertPlugin,
337+
NftablesRulesetCheckPlugin,
338338
PamBackupPlugin,
339339
PamIncludeAssertPlugin,
340340
PamModuleAssertPlugin,
@@ -589,8 +589,8 @@ def build_builtin_registry(extra_plugin_paths: Iterable[str] = ()) -> PluginRegi
589589
IptablesRulePlugin(),
590590
IptablesSavePlugin(),
591591
IptablesDeletePlugin(),
592-
IptablesExistsAssertPlugin(),
593-
IptablesCounterAssertPlugin(),
592+
IptablesRuleCheckPlugin(),
593+
IptablesCounterCheckPlugin(),
594594
IptablesListPlugin(),
595595
IptablesPolicyPlugin(),
596596
IptablesChainPlugin(),
@@ -604,7 +604,7 @@ def build_builtin_registry(extra_plugin_paths: Iterable[str] = ()) -> PluginRegi
604604
NftablesApplyPlugin(),
605605
NftablesListPlugin(),
606606
NftablesExportPlugin(),
607-
NftablesRulesetAssertPlugin(),
607+
NftablesRulesetCheckPlugin(),
608608
NftablesRollbackFilePlugin(),
609609
SysctlGetPlugin(),
610610
SysctlSetPlugin(),

tests/test_documentation_and_regressions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,9 +1320,9 @@ def test_top_level_firewall_namespaces_are_not_public_plugin_surface():
13201320

13211321
old_names = [
13221322
"iptables.chain",
1323-
"iptables.counter_assert",
1323+
"iptables.counter_check",
13241324
"iptables.delete",
1325-
"iptables.exists_assert",
1325+
"iptables.rule_check",
13261326
"iptables.list",
13271327
"iptables.policy",
13281328
"iptables.restore",
@@ -1343,7 +1343,7 @@ def test_top_level_firewall_namespaces_are_not_public_plugin_surface():
13431343
"nftables.export",
13441344
"nftables.list",
13451345
"nftables.rollback_file",
1346-
"nftables.ruleset_assert",
1346+
"nftables.ruleset_check",
13471347
"nftables.validate",
13481348
"ufw.delete",
13491349
"ufw.disable",

0 commit comments

Comments
 (0)