Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use specific name in private key groups instead of gid #10622

Merged
merged 1 commit into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ documentation_complete: true
title: 'Verify Group Ownership on SSH Server Private *_key Key Files'

{{% set dedicated_ssh_groupname = groups.get("dedicated_ssh_keyowner", {}).get("name") %}}
{{% set dedicated_ssh_groupid = groups.get("dedicated_ssh_keyowner", {}).get("id") %}}

description: |-
SSH server private keys, files that match the <code>/etc/ssh/*_key</code> glob, must be
Expand Down Expand Up @@ -36,4 +35,4 @@ template:
- /etc/ssh/
file_regex:
- ^.*_key$
filegid: '{{{ dedicated_ssh_groupid if dedicated_ssh_groupid else '0' }}}'
filegid: '{{{ dedicated_ssh_groupname if dedicated_ssh_groupname else '0' }}}'
1 change: 0 additions & 1 deletion products/rhel7/product.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ audisp_conf_path: "/etc/audisp"
groups:
dedicated_ssh_keyowner:
name: ssh_keys
id: "997"

cpes_root: "../../shared/applicability"
cpes:
Expand Down
1 change: 0 additions & 1 deletion products/rhel8/product.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ grub2_uefi_boot_path: "/boot/efi/EFI/redhat"
groups:
dedicated_ssh_keyowner:
name: ssh_keys
id: "995"

faillock_path: "/var/log/faillock"

Expand Down
1 change: 0 additions & 1 deletion products/rhel9/product.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ grub2_uefi_boot_path: "/boot/grub2"
groups:
dedicated_ssh_keyowner:
name: ssh_keys
id: "996"

sshd_distributed_config: "true"

Expand Down
23 changes: 23 additions & 0 deletions shared/templates/file_groupowner/oval.template
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,34 @@
</unix:file_object>

<unix:file_state id="state_file_groupowner{{{ FILEID }}}_gid_{{{ FILEGID }}}_{{{ loop.index0 }}}" version="1">
{{%- if FILEGID == '0' %}}
<unix:group_id datatype="int">{{{ FILEGID }}}</unix:group_id>
{{%- else %}}
<unix:group_id datatype="int" var_ref="var_dedicated_groupowner{{{ FILEID }}}_uid_{{{ FILEGID }}}"></unix:group_id>
{{%- endif %}}
</unix:file_state>
{{% endfor %}}

<unix:file_state id="symlink_file_groupowner{{{ FILEID }}}_uid_{{{ FILEGID }}}" version="1">
<unix:type operation="equals">symbolic link</unix:type>
</unix:file_state>

{{%- if FILEGID != '0' %}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A explanatory variable gid_is_name would fit perfectly here, and probably should be more robust - numbers are probably IDs, not numbers are definitely names. Moreover, I believe that the template code could propagate a boolean with the template.

<ind:textfilecontent54_object id="obj_dedicated_groupowner{{{ FILEID }}}_uid_{{{ FILEGID }}}" version="1" comment="gid of the dedicated {{{ FILEGID }}} group">
{{%- if product != 'rhcos4' -%}}
<ind:filepath>/etc/group</ind:filepath>
{{%- else %}}
{{# CoreOS doesn't list all groups in /etc/group - that's probably related to the FS immutability #}}
<ind:filepath>/usr/lib/group</ind:filepath>
{{%- endif %}}
<ind:pattern operation="pattern match">^{{{ FILEGID }}}:\w+:(\w+):.*</ind:pattern>
<ind:instance datatype="int" operation="equals">1</ind:instance>
</ind:textfilecontent54_object>

<!-- variable storing count of all group names - including duplicates -->
<local_variable id="var_dedicated_groupowner{{{ FILEID }}}_uid_{{{ FILEGID }}}" datatype="int" version="1"
comment="Count of all group names (including duplicates if any)">
<object_component item_field="subexpression" object_ref="obj_dedicated_groupowner{{{ FILEID }}}_uid_{{{ FILEGID }}}"/>
</local_variable>
{{%- endif %}}
</def-group>
Loading