Skip to content

Commit cd02e4e

Browse files
authored
Merge pull request #13825 from alanmcanonical/var_log_user
[Ubuntu] Allow sys uid and empty user group
2 parents 31c4204 + 6c0255c commit cd02e4e

File tree

11 files changed

+103
-17
lines changed

11 files changed

+103
-17
lines changed

linux_os/guide/system/permissions/files/permissions_var_log_dir/file_groupownerships_var_log/oval/shared.xml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
<unix:object object_ref="object_group_ownership_var_log" />
2222
<unix:state state_ref="state_group_ownership_adm_var_log_auth_log"/>
2323
<unix:state state_ref="state_group_ownership_root_var_log_auth_log"/>
24+
{{%- if product == "ubuntu2204" %}}
25+
<unix:state state_ref="{{{ rule_id }}}_group_only_has_sys_uids"/>
26+
{{%- endif %}}
2427
</unix:file_test>
2528
<unix:file_object comment="/var/log/*" id="object_group_ownership_var_log" version="1">
2629
<unix:behaviors recurse="directories" recurse_direction="down" max_depth="-1" recurse_file_system="all" />
@@ -93,4 +96,47 @@
9396
<unix:file_state id="{{{ rule_id }}}_exclude_files_waagent" version="1">
9497
<unix:filename operation="pattern match">^waagent\.log.*$</unix:filename>
9598
</unix:file_state>
99+
{{%- if product == "ubuntu2204" %}}
100+
<unix:file_state id="{{{ rule_id }}}_group_only_has_sys_uids" version="1">
101+
<unix:group_id datatype="int" var_ref="empty_group_ids" var_check="at least one"/>
102+
</unix:file_state>
103+
104+
<local_variable id="empty_group_ids" comment="Group IDs with no members" datatype="int" version="1">
105+
<object_component item_field="subexpression" object_ref="empty_members_in_etc_group"/>
106+
</local_variable>
107+
108+
<ind:textfilecontent54_object comment="Groups with no members" id="empty_members_in_etc_group" version="1">
109+
<ind:filepath>/etc/group</ind:filepath>
110+
<ind:pattern operation="pattern match" var_ref="variable_{{{ rule_id }}}_group_regex" var_check="at least one"/>
111+
<ind:instance datatype="int" operation="greater than or equal">1</ind:instance>
112+
</ind:textfilecontent54_object>
113+
114+
<local_variable id="variable_{{{ rule_id }}}_group_regex" datatype="string" version="1" comment="gid rows retrieved from /etc/passwd">
115+
<concat>
116+
<literal_component>^[^:]+:[^:]*:(</literal_component>
117+
<object_component item_field="subexpression" object_ref="obj_{{{ rule_id }}}_gids_with_only_sys_uids" />
118+
<literal_component>):$</literal_component>
119+
</concat>
120+
</local_variable>
121+
122+
<ind:textfilecontent54_object id="obj_{{{ rule_id }}}_gids_with_only_sys_uids" version="1">
123+
<ind:filepath>/etc/passwd</ind:filepath>
124+
<ind:pattern operation="pattern match" var_ref="variable_{{{ rule_id }}}_regex" var_check="at least one"/>
125+
<ind:instance datatype="int" operation="greater than or equal">1</ind:instance>
126+
</ind:textfilecontent54_object>
127+
128+
<local_variable id="variable_{{{ rule_id }}}_regex" datatype="string" version="1" comment="uid rows retrieved from /etc/passwd">
129+
<concat>
130+
<literal_component>^[^:]*:[^:]*:</literal_component>
131+
<object_component item_field="subexpression" object_ref="obj_{{{ rule_id }}}_sys_uid" />
132+
<literal_component>:(\d+):.*$</literal_component>
133+
</concat>
134+
</local_variable>
135+
136+
<ind:textfilecontent54_object id="obj_{{{ rule_id }}}_sys_uid" version="1">
137+
<ind:filepath>/etc/passwd</ind:filepath>
138+
<ind:pattern operation="pattern match">^[^:]+:[^:]*:(\d\d?\d?):.*$</ind:pattern>
139+
<ind:instance datatype="int" operation="greater than or equal">1</ind:instance>
140+
</ind:textfilecontent54_object>
141+
{{%- endif %}}
96142
</def-group>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
# platform = Ubuntu 22.04
3+
# packages = rsyslog
4+
5+
chown root -R /var/log/*
6+
7+
groupadd testgroup
8+
useradd testUser
9+
usermod -g testgroup testUser
10+
11+
touch /var/log/test.log
12+
chgrp testgroup /var/log/test.log
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
# platform = Ubuntu 22.04
3+
# packages = rsyslog
4+
5+
chown root -R /var/log/*
6+
7+
groupadd testgroup
8+
useradd -r testUser
9+
usermod -g testgroup testUser
10+
11+
touch /var/log/test.log
12+
chgrp testgroup /var/log/test.log

linux_os/guide/system/permissions/files/permissions_var_log_dir/file_ownerships_var_log/bash/shared.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# platform = Ubuntu 24.04
1+
# platform = multi_platform_ubuntu
22
# reboot = false
33
# strategy = configure
44
# complexity = low

linux_os/guide/system/permissions/files/permissions_var_log_dir/file_ownerships_var_log/oval/shared.xml

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,23 @@
66
</criteria>
77
</definition>
88

9-
<unix:password_object id="object_syslog_uid" version="1">
10-
{{% if 'debian' in product %}}
11-
<unix:username operation="pattern match">root</unix:username>
12-
{{% else %}}
13-
<unix:username operation="pattern match">syslog</unix:username>
14-
{{% endif %}}
15-
</unix:password_object>
16-
<local_variable id="var_syslog_uid" comment="Retrieve the uid of syslog" datatype="int" version="1">
17-
<object_component item_field="user_id" object_ref="object_syslog_uid" />
9+
<ind:textfilecontent54_object id="{{{ rule_id }}}_object_syslog_uid" version="1" comment="uid of the dedicated syslog group">
10+
<ind:filepath>/etc/passwd</ind:filepath>
11+
<ind:pattern operation="pattern match">^syslog:[^:]+:([0-9]+):</ind:pattern>
12+
<ind:instance datatype="int" operation="equals">1</ind:instance>
13+
</ind:textfilecontent54_object>
14+
<local_variable id="{{{ rule_id }}}_var_syslog_uid" comment="Retrieve the uid of syslog" datatype="int" version="1">
15+
<object_component item_field="subexpression" object_ref="{{{ rule_id }}}_object_syslog_uid" />
1816
</local_variable>
1917

20-
<unix:file_test check="all" comment="/var/log/* owner is root|syslog"
18+
<unix:file_test check_existence="any_exist" check="all" comment="/var/log/* owner is root|syslog"
2119
id="test_file_ownership_var_log" state_operator="OR" version="1">
2220
<unix:object object_ref="object_file_ownership_var_log" />
2321
<unix:state state_ref="state_file_ownership_syslog_var_log_auth_log"/>
2422
<unix:state state_ref="state_file_ownership_root_var_log_auth_log"/>
23+
{{%- if product == "ubuntu2204" %}}
24+
<unix:state state_ref="{{{ rule_id }}}_system_files_with_empty_group"/>
25+
{{%- endif %}}
2526
</unix:file_test>
2627
<unix:file_object comment="/var/log/*" id="object_file_ownership_var_log" version="1">
2728
<unix:behaviors recurse="directories" recurse_direction="down" max_depth="-1" recurse_file_system="all" />
@@ -52,7 +53,7 @@
5253
<unix:type operation="equals">symbolic link</unix:type>
5354
</unix:file_state>
5455
<unix:file_state id="state_file_ownership_syslog_var_log_auth_log" version="1">
55-
<unix:user_id datatype="int" operation="equals" var_ref="var_syslog_uid"/>
56+
<unix:user_id datatype="int" operation="equals" var_ref="{{{ rule_id }}}_var_syslog_uid"/>
5657
</unix:file_state>
5758
<unix:file_state id="state_file_ownership_root_var_log_auth_log" version="1">
5859
<unix:user_id datatype="int" operation="equals">0</unix:user_id>
@@ -107,4 +108,9 @@
107108
<unix:filepath operation="pattern match">^/var/log/exim4/.*$</unix:filepath>
108109
</unix:file_state>
109110
{{% endif %}}
111+
{{%- if product == "ubuntu2204" %}}
112+
<unix:file_state id="{{{ rule_id }}}_system_files_with_empty_group" version="3">
113+
<unix:user_id datatype="int" operation="less than">{{{ uid_min }}}</unix:user_id>
114+
</unix:file_state>
115+
{{%- endif %}}
110116
</def-group>

linux_os/guide/system/permissions/files/permissions_var_log_dir/file_ownerships_var_log/tests/excluded_files.pass.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# platform = Ubuntu 24.04
2+
# platform = multi_platform_ubuntu
33
# packages = rsyslog
44

55
chown root -R /var/log/*

linux_os/guide/system/permissions/files/permissions_var_log_dir/file_ownerships_var_log/tests/owned_by_nobody.fail.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# platform = Ubuntu 24.04
2+
# platform = multi_platform_ubuntu
33
# packages = rsyslog
44

55
chown root -R /var/log/*

linux_os/guide/system/permissions/files/permissions_var_log_dir/file_ownerships_var_log/tests/owned_by_root.pass.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# platform = Ubuntu 24.04
2+
# platform = multi_platform_ubuntu
33
# packages = rsyslog
44

55
chown root -R /var/log/*
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
# platform = Ubuntu 22.04
3+
# packages = rsyslog
4+
5+
chown root -R /var/log/*
6+
7+
useradd -r testUser
8+
9+
touch /var/log/test.log
10+
chown testUser /var/log/test.log

linux_os/guide/system/permissions/files/permissions_var_log_dir/file_ownerships_var_log/tests/owned_by_syslog.pass.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# platform = Ubuntu 24.04
2+
# platform = multi_platform_ubuntu
33
# packages = rsyslog
44

55
chown root -R /var/log/*

0 commit comments

Comments
 (0)