Skip to content

Commit 09c07a4

Browse files
authored
operations.selinux.port: fix a bug where the op would not find existing labels if sepolicy command was missing from the host (#1654)
1 parent 185f7db commit 09c07a4

13 files changed

Lines changed: 86 additions & 102 deletions

src/pyinfra/operations/selinux.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def port(protocol: Protocol | str, port_num: int, se_type: str | None = None, pr
173173
current = host.get_fact(SEPort, protocol=protocol, port=port_num)
174174
else:
175175
port_info = host.get_fact(SEPorts)
176-
current = port_info.get(protocol, {}).get(str(port_num), "")
176+
current = port_info.get(protocol, {}).get(port_num, "")
177177

178178
if present:
179179
option = "-a" if current == "" else ("-m" if current != se_type else "")
@@ -191,4 +191,4 @@ def port(protocol: Protocol | str, port_num: int, se_type: str | None = None, pr
191191
if not direct_get:
192192
if protocol not in port_info:
193193
port_info[protocol] = {}
194-
port_info[protocol][str(port_num)] = new_type
194+
port_info[protocol][port_num] = new_type

tests/operations/selinux.port/add_different.json

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
args:
2+
- tcp
3+
- 22
4+
- ssh_port_t
5+
kwargs:
6+
present: true
7+
facts:
8+
selinux.SEPorts:
9+
tcp:
10+
22: xray_port_t
11+
server.Which:
12+
command=sepolicy: null
13+
commands:
14+
- semanage port -m -t ssh_port_t -p tcp 22

tests/operations/selinux.port/add_not_existing.json

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
args:
2+
- tcp
3+
- 22
4+
- ssh_port_t
5+
kwargs:
6+
present: true
7+
facts:
8+
selinux.SEPorts:
9+
tcp:
10+
22: ""
11+
server.Which:
12+
command=sepolicy: null
13+
commands:
14+
- semanage port -a -t ssh_port_t -p tcp 22

tests/operations/selinux.port/add_not_existing_protocol.json

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
args:
2+
- tcp
3+
- 22
4+
- ssh_port_t
5+
kwargs:
6+
present: true
7+
facts:
8+
selinux.SEPorts:
9+
udp:
10+
53: dns_port_t
11+
server.Which:
12+
command=sepolicy: null
13+
commands:
14+
- semanage port -a -t ssh_port_t -p tcp 22

tests/operations/selinux.port/add_same.json

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
args:
2+
- tcp
3+
- 22
4+
- ssh_port_t
5+
kwargs:
6+
present: true
7+
facts:
8+
selinux.SEPorts:
9+
tcp:
10+
22: ssh_port_t
11+
server.Which:
12+
command=sepolicy: null
13+
commands: []
14+
noop_description: "setype for 'tcp/22' is already 'ssh_port_t'"

tests/operations/selinux.port/remove_existing.json

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)