Skip to content

Commit

Permalink
fix: ls_laZ handling "?" as rhel8 selinux context (#3956)
Browse files Browse the repository at this point in the history
Signed-off-by: Xiaoxue Wang <xiaoxwan@redhat.com>
(cherry picked from commit cf8602e)
  • Loading branch information
JoySnow authored and xiangce committed Nov 16, 2023
1 parent e7405ca commit a1e0de9
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
4 changes: 3 additions & 1 deletion insights/core/ls_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ def __init__(self, name, total, body):
# We have to split the line again to see if this is a RHEL8
# selinux stanza. This assumes that the context section will
# always have at least two pieces separated by ':'.
if ":" in line.split()[4]:
# '?' as the whole RHEL8 security context is also acceptable.
rhel8_selinux_ctx = line.split()[4].strip()
if ":" in rhel8_selinux_ctx or '?' == rhel8_selinux_ctx:
rest = parse_rhel8_selinux(parts[1:])
else:
rest = parse_non_selinux(parts[1:])
Expand Down
46 changes: 46 additions & 0 deletions insights/tests/parsers/test_ls.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,36 @@
lrwxrwxrwx. root root system_u:object_r:device_t:s0 systty -> tty0
"""

LS_LAZ_CONTENT3_RHEL8_SELINUX = """
/etc:
total 1352
drwxr-xr-x. 133 root root system_u:object_r:etc_t:s0 12288 Nov 12 23:55 .
dr-xr-xr-x. 21 root root system_u:object_r:root_t:s0 4096 Jul 5 2022 ..
-rw-r--r-- 1 root root ? 1529 Apr 15 2020 aliases
-rw-r--r-- 1 root root ? 12288 Jul 5 2022 aliases.db
-rw-r--r--. 1 root root system_u:object_r:etc_t:s0 1 Aug 12 2018 at.deny
drwxr-x---. 4 root root system_u:object_r:auditd_etc_t:s0 150 Nov 12 23:55 audit
drwxr-xr-x. 2 root root system_u:object_r:etc_t:s0 160 Sep 15 12:32 bash_completion.d
-rw-r--r-- 1 root root ? 3019 Apr 15 2020 bashrc
-rw-r--r-- 1 root root ? 881 Jul 5 2022 chrony.conf
-rw-r-----. 1 root chrony system_u:object_r:chronyd_keys_t:s0 540 May 10 2019 chrony.keys
drwxr-xr-x. 2 root root system_u:object_r:etc_t:s0 26 Jul 28 2021 cifs-utils
/var/log:
total 114496
drwxr-xr-x. 17 root root system_u:object_r:var_log_t:s0 8192 Nov 12 03:47 .
drwxr-xr-x. 23 root root system_u:object_r:var_t:s0 4096 Jul 5 2022 ..
drwxr-xr-x 3 root root ? 122 Jul 5 2022 Automation
drwxr-xr-x. 2 root root system_u:object_r:var_log_t:s0 280 Mar 11 2020 anaconda
drwx------. 2 root root system_u:object_r:auditd_log_t:s0 99 Nov 12 19:00 audit
-rw-------. 1 root root system_u:object_r:plymouthd_var_log_t:s0 0 Jul 5 2022 boot.log
-rw------- 1 root root ? 79952 Sep 30 2020 boot.log-20200930
-rw------- 1 root root ? 22027 Jul 5 2022 boot.log-20220705
-rw------- 1 root utmp ? 0 Nov 1 03:15 btmp
drwxr-xr-x. 2 chrony chrony system_u:object_r:chronyd_var_log_t:s0 6 Mar 1 2021 chrony
""".strip()


LS_LARZ_DEV_CONTENT1 = """
/dev:
total 0
Expand Down Expand Up @@ -508,6 +538,22 @@ def test_ls_laZ():
assert 'stderr' in dev_listings
assert dev_listings["stderr"]['link'] == '/proc/self/fd/2'

ls = LSlaZ(context_wrap(LS_LAZ_CONTENT3_RHEL8_SELINUX))
assert '/etc' in ls

dev_listings = ls.listing_of('/etc')
assert "bashrc" in dev_listings
assert dev_listings["bashrc"]['se_user'] == '?'
assert dev_listings["bashrc"]['se_role'] is None
assert dev_listings["bashrc"]['se_type'] is None
assert "chrony.conf" in dev_listings
assert 'se_type' in dev_listings["chrony.conf"]
assert dev_listings["chrony.keys"]['se_type'] == 'chronyd_keys_t'

dev_listings = ls.listing_of('/var/log')
assert 'boot.log-20220705' in dev_listings
assert dev_listings["boot.log-20220705"]['size'] == 22027


def test_ls_laZ_on_dev():
ls = LSlaRZ(context_wrap(LS_LARZ_DEV_CONTENT1))
Expand Down

0 comments on commit a1e0de9

Please sign in to comment.