Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
166e0eb3e0 | ||
|
|
592b779ad8 | ||
|
|
7cb99de32d | ||
|
|
6a35c7407e | ||
|
|
ddfb1c6d0a | ||
|
|
b2d29df657 | ||
|
|
2f2d980ef7 | ||
|
|
fbdee5f778 |
No files matched your search
@@ -42,6 +42,7 @@ when its own prerequisites (tests, a safe cutover wherever the role already runs
|
||||
Still to come:
|
||||
|
||||
- Wave 3: `rke2`, `proxmox_host`.
|
||||
- Not yet in a wave: `openbao`.
|
||||
|
||||
Will not be extracted (they serve one lab or install that lab's own tool pins):
|
||||
`k8s_manage`, `k8s_localhost`, `k8s_lint_tools`, `minecraft_server`, `dragonwilds_server`,
|
||||
|
||||
+10
@@ -126,3 +126,13 @@ reduction. A later decision that accepts a risk adds an entry here.
|
||||
- **Trigger:** the pull request that moves `molecule.yml` to a new `molecule-controller` image
|
||||
fails Molecule because of a changed image input.
|
||||
- **Planned reduction:** none for now.
|
||||
|
||||
### Unseal keys in vaulted inventory
|
||||
|
||||
- **Risk:** the planned `openbao` role can unseal a Shamir-sealed OpenBao from unseal keys the
|
||||
consumer keeps in vaulted inventory (`openbao_unseal_keys`), so whoever holds the Ansible
|
||||
vault password can unseal alone. This weakens the split knowledge Shamir's scheme gives.
|
||||
- **Why accepted:** it keeps restarts and updates unattended, and the Collection already keeps
|
||||
secrets in vaulted inventory. The keys are optional: without them the role leaves the node
|
||||
sealed and warns.
|
||||
- **Trigger and planned reduction:** auto-unseal, tracked in #529.
|
||||
@@ -0,0 +1,6 @@
|
||||
---
|
||||
bugfixes:
|
||||
- >-
|
||||
ufw - A single quote in the ``comment`` of a ``ufw_rules`` entry is now refused before any rule is applied.
|
||||
The ufw module cannot pass it to ufw, so the play failed while applying the rules, after earlier rules of the
|
||||
list had been changed. The comment of an entry with ``delete: true`` is not checked, as it is never sent.
|
||||
@@ -68,6 +68,11 @@ names a check that does not exist yet and its backlog issue.
|
||||
- **Secrets.** Never in plaintext in the repository, a role's defaults, task output or a file on
|
||||
the controller; `no_log: true` on every task that carries one; a secret is a required input
|
||||
with no default; a role generates one only straight into a secret store the consumer names.
|
||||
A secret returned as a `no_log`, non-cacheable output fact from an opt-in entry point, for the
|
||||
calling play to persist (for example vault-encrypted into inventory), counts as handed straight
|
||||
to the consumer's store, as the gitea and cloudflared `mint` entry points do. Such an entry point
|
||||
has a confirm flag, refuses under CI environment variables, sets `no_log` on every task, blanks
|
||||
its intermediates, skips under `--check` and does nothing when the secret already exists.
|
||||
Keys a host generates for itself and keeps (SSH host keys) are not covered. The README line
|
||||
"`no_log` is not used: the role handles no secrets" stays only where true. *Why:* nothing leaks
|
||||
today and a role writing to a secret store stays possible. *Held:* review.
|
||||
|
||||
+5
-5
@@ -26,13 +26,13 @@ Main entry point:
|
||||
| Variable | Default | Required | Description |
|
||||
|---|---|---|---|
|
||||
| `ufw_enabled` | `true` | no | Skip all UFW configuration when false (the package is still installed). |
|
||||
| `ufw_manage_rules` | `true` | no | Skip the `ufw_rules` schema check, the lock-out guard and rule application when false. Before-rules validation and `before.rules`, defaults and enable still run (gated on `ufw_enabled`). |
|
||||
| `ufw_manage_rules` | `true` | no | Skip the `ufw_rules` schema and comment checks, the lock-out guard and rule application when false. Before-rules validation and `before.rules`, defaults and enable still run (gated on `ufw_enabled`). |
|
||||
| `ufw_defaults` | `incoming: deny`, `outgoing: allow`, `routed: deny` | no | Default policies. All three keys are read, so override all of them. |
|
||||
| `ufw_logging` | `"on"` | no | UFW logging level. |
|
||||
| `ufw_mask_nftables` | `true` | no | Mask `nftables.service` without stopping it, so a package upgrade cannot flush the rules ufw loaded (see Notes). Set false on a host that loads its own ruleset through that unit. Gated on `ufw_enabled`. |
|
||||
| `ufw_require_ssh_allow` | `true` | no | Enable the SSH lock-out guard. |
|
||||
| `ufw_ssh_port` | `ansible_port` or 22 | no | TCP port the guard looks for. |
|
||||
| `ufw_rules` | `[]` | no | Base rule list: `rule` (allow, deny, reject, limit), `port`, `proto`, `from`, `to`, `interface`, `direction`, `comment`, `delete` (see Notes). |
|
||||
| `ufw_rules` | `[]` | no | Base rule list: `rule` (allow, deny, reject, limit), `port`, `proto`, `from`, `to`, `interface`, `direction`, `comment`, `delete` (see Notes). A comment may not contain a single quote: the ufw module cannot pass one. |
|
||||
| `ufw_before_rules` | `[]` | no | Entries added as ACCEPT lines to `before.rules`: `interface`, `proto`, `port`, `from`, `comment`. |
|
||||
| `ufw_sysctl_overrides` | `[]` | no | `{name, value}` pairs written to `/etc/ufw/sysctl.conf`. |
|
||||
|
||||
@@ -141,7 +141,7 @@ The scenario `molecule/default/` runs in CI only, on two platforms: `${MOLECULE_
|
||||
|
||||
- Prepare installs ufw and stores rules the role must handle: an untagged manual rule, a manual rule the base list deletes, and tagged rules of service owners that are stale, removed or orphaned, some of them looking like an SSH path (port 22 with a source, no port, a range, an application profile named like SSH).
|
||||
- Converge applies the base `ufw_rules` (one entry with `delete: true`), then calls `service_rules` for several owners (purge on, purge off, `absent`), and `orphan_rules` with no list, an empty list, report only and purge.
|
||||
- Verify first checks that each refusal stops the run with its message and changes nothing: default deny without an SSH rule (also when the SSH rule is only deleted, or added and deleted), a stray `*_ufw_rules` or `*_ufw_before_rules` variable, the invalid `service_rules` inputs (owner name, reserved `base`, a quote in a comment, a rule another owner holds, a rule that would retag the SSH rule, an unknown key, an interface without a direction, a purge with an empty list), and an invalid managed owner for `orphan_rules`.
|
||||
- Verify first checks that each refusal stops the run with its message and changes nothing: default deny without an SSH rule (also when the SSH rule is only deleted, or added and deleted), a single quote in a base rule comment, a stray `*_ufw_rules` or `*_ufw_before_rules` variable, the invalid `service_rules` inputs (owner name, reserved `base`, a quote in a comment, a rule another owner holds, a rule that would retag the SSH rule, an unknown key, an interface without a direction, a purge with an empty list), and an invalid managed owner for `orphan_rules`.
|
||||
- Verify then reads `ufw status verbose` and `ufw show added`: ufw is active with default deny incoming, the base rules are loaded, the deleted rule is gone, the manual and SSH rules are untouched, the service rules carry their owner tag, stale and orphan rules are deleted only where purging was on and only when they cannot carry SSH.
|
||||
- Verify checks `before.rules`: the loopback accept, the INVALID-state drop behind its logging rule and in its place among the input rules.
|
||||
- Verify runs `service_rules` under the `check_mode` keyword and checks that the rule list did not change.
|
||||
@@ -155,9 +155,9 @@ Not covered: `ufw_mask_nftables: false` is never set, `ufw_before_rules` entries
|
||||
|
||||
- Idempotent: yes.
|
||||
- Lock-out guard: `defaults.yml` sets the deny policy before `rules.yml` adds any rule. When `ufw_enabled`, `ufw_manage_rules` and `ufw_require_ssh_allow` are true and the incoming default is deny or reject, the play fails unless `ufw_rules` holds an allow or limit rule for `ufw_ssh_port` that is TCP (or has no `proto`) and has `direction: in` or no `direction`. `direction: incoming`, which the module accepts, is not counted, so write `in`. Any `from`, `to` or `interface` restriction still counts; the guard cannot know the control host's address. An entry with `delete: true` never counts.
|
||||
- Replacing a base rule: list the new rule and the old one with `delete: true` (a boolean). Deletes are applied after every other rule, whatever their place in the list, so the replacement exists before the old rule goes, which matters when narrowing the SSH rule. The comment of a delete entry is not sent, so the rule matches whatever its comment, and a delete of a rule that is already gone changes nothing. An entry that deletes a rule the same list adds (same `rule`, `port`, `proto`, `from`, `to`, `interface` and `direction`, where no `direction` is `in` and no `from` or `to` is `any`) fails the play. A delete without an address removes the IPv4 and the IPv6 rule; a replacement with an IPv4 `from` allows IPv4 only, so check that the hosts you connect from are covered before narrowing SSH. `delete` is for `ufw_rules` only; `service_rules` removes its own stale rules.
|
||||
- Replacing a base rule: list the new rule and the old one with `delete: true` (a boolean). Deletes are applied after every other rule, whatever their place in the list, so the replacement exists before the old rule goes, which matters when narrowing the SSH rule. The comment of a delete entry is neither sent nor checked, so the rule matches whatever its comment, and a delete of a rule that is already gone changes nothing. An entry that deletes a rule the same list adds (same `rule`, `port`, `proto`, `from`, `to`, `interface` and `direction`, where no `direction` is `in` and no `from` or `to` is `any`) fails the play. A delete without an address removes the IPv4 and the IPv6 rule; a replacement with an IPv4 `from` allows IPv4 only, so check that the hosts you connect from are covered before narrowing SSH. `delete` is for `ufw_rules` only; `service_rules` removes its own stale rules.
|
||||
- `before.rules` is a template derived from UFW's own `before.rules` (GPL-3.0-only, see `NOTICE`) that fully replaces the stock file, including a loopback accept, conntrack (established accept and INVALID-state drop), ICMP and mDNS/UPnP entries. It is deployed whenever `ufw_enabled` is true, even with no before-rules.
|
||||
- Rule schema is asserted before anything changes: `rule` must be allow, deny, reject or limit, `port` a positive integer, `proto` tcp or udp, and each rule needs `port`, `from`, `to` or `interface`.
|
||||
- Rule schema is asserted before anything changes: `rule` must be allow, deny, reject or limit, `port` a positive integer, `proto` tcp or udp, each rule needs `port`, `from`, `to` or `interface`, and a `comment` must not contain a single quote.
|
||||
- UFW is only re-enabled when `ufw status verbose` shows it inactive or the logging line differs, because the module rewrites rules and re-applies sysctl on every call.
|
||||
- The `Reload UFW` handler runs `ufw reload`.
|
||||
- nftables: when `nftables.service` is enabled (a preset can do that), the `nftables` package's postinst restarts it on upgrade (`dh_installsystemd --no-enable --no-start --restart-after-upgrade` emits `deb-systemd-invoke try-restart`), and both the restart and the unit's `ExecStop=/usr/sbin/nft flush ruleset` delete every rule ufw (and Docker) loaded, since the stock `/etc/nftables.conf` begins with `flush ruleset`. The role masks the unit and does not stop it, so nothing is flushed during the run. systemd refuses every job but a stop on a masked unit, so the postinst's restart fails before anything runs and the postinst ignores the failure (`|| true`); at boot the unit is not started either. The mask also applies when the unit or the package is absent, so a later install cannot enable it; the package's postinst removes only a mask its own helper created. The role never unmasks: with `ufw_mask_nftables: false` or `ufw_enabled: false` an existing mask stays. `--check` reports the mask without applying it. When `/etc/systemd/system/nftables.service` is a unit file of its own rather than a link, `systemctl mask` refuses with "already exists" and the play fails; set `ufw_mask_nftables: false` on such a host.
|
||||
|
||||
@@ -22,7 +22,7 @@ argument_specs:
|
||||
default: true
|
||||
description:
|
||||
- >-
|
||||
When false the C(ufw_rules) schema check, the SSH lock-out guard and rule
|
||||
When false the C(ufw_rules) schema and comment checks, the SSH lock-out guard and rule
|
||||
application are skipped. Before-rules validation, C(before.rules), default policies and
|
||||
enabling still run, gated on C(ufw_enabled).
|
||||
ufw_defaults:
|
||||
@@ -77,12 +77,13 @@ argument_specs:
|
||||
- >-
|
||||
Each item is a mapping with C(rule) (allow, deny, reject or limit) and at least one of C(port), C(from), C(to)
|
||||
or C(interface). Optional keys are C(proto) (tcp or udp), C(direction), C(comment) and C(delete).
|
||||
- A comment may not contain a single quote, because the ufw module cannot pass one.
|
||||
- C(port) must be a positive integer value.
|
||||
- >-
|
||||
C(delete=true) (a boolean) removes the rule the other keys describe instead of adding it. Its comment is not
|
||||
sent, so the rule matches whatever its comment. Deletes are applied after every other rule of the list, so a replacement exists before the old
|
||||
rule goes; a rule that is both added and deleted in the list fails the play, and a delete entry never counts as
|
||||
the SSH allow rule of the lock-out guard.
|
||||
C(delete=true) (a boolean) removes the rule the other keys describe instead of adding it. Its comment is neither
|
||||
sent nor checked, so the rule matches whatever its comment. Deletes are applied after every other rule of the
|
||||
list, so a replacement exists before the old rule goes; a rule that is both added and deleted in the list fails
|
||||
the play, and a delete entry never counts as the SSH allow rule of the lock-out guard.
|
||||
ufw_before_rules:
|
||||
type: raw
|
||||
description:
|
||||
|
||||
@@ -7,6 +7,12 @@
|
||||
- name: Refuse default-deny without an SSH allow rule
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
vars:
|
||||
# A failed looped task reports "One or more items failed" in msg and the item
|
||||
# messages in results; an unlooped one has the message in msg.
|
||||
ufw_verify_failure: >-
|
||||
{{ ansible_failed_result.msg | default('') }}
|
||||
{{ ansible_failed_result.results | default([]) | map(attribute='msg', default='') | join(' ') }}
|
||||
tasks:
|
||||
- name: Run the role with only a non-SSH rule
|
||||
block:
|
||||
@@ -65,6 +71,25 @@
|
||||
that: "'both added and deleted' in ansible_failed_result.msg | default('')"
|
||||
quiet: true
|
||||
|
||||
# ufw's parser refuses a quote in a comment; the check must stop the play before any rule is applied.
|
||||
- name: A single quote in a base rule comment
|
||||
block:
|
||||
- name: Include ufw
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.ufw
|
||||
vars:
|
||||
ufw_rules:
|
||||
- {rule: allow, port: 22, proto: tcp, comment: ssh}
|
||||
- {rule: allow, port: 8080, proto: tcp, comment: "it's"}
|
||||
- name: Unreachable when base rule comments are checked
|
||||
ansible.builtin.fail:
|
||||
msg: a quote in a base rule comment was accepted
|
||||
rescue:
|
||||
- name: The comment check stopped the play
|
||||
ansible.builtin.assert:
|
||||
that: "'single quote' in ufw_verify_failure"
|
||||
quiet: true
|
||||
|
||||
# Stray variable guard: variables named like <role>_ufw_rules must fail the play
|
||||
# before anything changes, naming the variable. The vars sit on the include only, so they
|
||||
# do not reach the plays below (the base ufw_rules and ufw_before_rules never match).
|
||||
|
||||
@@ -16,6 +16,22 @@
|
||||
- ufw_manage_rules
|
||||
- ufw_aggregated_rules | length > 0
|
||||
|
||||
# The module wraps the comment in unescaped single quotes, which ufw's parser refuses, so the rules
|
||||
# loop would fail part-way. Delete entries are skipped: rules.yml never sends their comment.
|
||||
- name: Validate the ufw_rules comments
|
||||
ansible.builtin.assert:
|
||||
that: "\"'\" not in (ufw_rule.comment | default('', true) | string)"
|
||||
fail_msg: >-
|
||||
UFW rule comment contains a single quote, which the ufw module cannot pass to ufw: {{ ufw_rule }}
|
||||
quiet: true
|
||||
loop: "{{ ufw_aggregated_rules | default([]) }}"
|
||||
loop_control:
|
||||
loop_var: ufw_rule
|
||||
when:
|
||||
- ufw_manage_rules
|
||||
- ufw_aggregated_rules | length > 0
|
||||
- not ufw_rule.delete | default(false)
|
||||
|
||||
# A rule both added and deleted would be added, then deleted (deletes run last), and the
|
||||
# lock-out guard below would still count the added one. Fields are normalised the way ufw
|
||||
# stores them before comparing: no direction is in (incoming/outgoing are in/out), no from
|
||||
|
||||
Reference in new issue
Block a user