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

Logic to conditionally-create user.cfg files to support EFI-booted systems. #490

Merged
merged 30 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
77d092a
Ensure UEFI bootloader password is set
ferricoxide Mar 11, 2024
ec23390
Only run if system is not UEFI-enabled
ferricoxide Mar 11, 2024
bcd6282
Ensure new state executes
ferricoxide Mar 11, 2024
a138e8d
Prevent ID conflicts
ferricoxide Mar 11, 2024
871048c
Match requirements and get rid of mode-set attempt
ferricoxide Mar 11, 2024
a89087f
Match requirements labels
ferricoxide Mar 11, 2024
4959f44
Avoid any actions that will attempt to change mode
ferricoxide Mar 11, 2024
faf750a
Can't change SEL labels on VFAT-formatted filesystems
ferricoxide Mar 11, 2024
46be457
Make it conditional
ferricoxide Mar 11, 2024
e97e5ff
fixup
ferricoxide Mar 11, 2024
31bdbf3
Try to ensure that requisites are ANDed
ferricoxide Mar 11, 2024
417429a
Update ash-linux/el8/STIGbyID/cat1/RHEL-08-010140.sls
ferricoxide Mar 12, 2024
8e439ab
Update ash-linux/el8/STIGbyID/cat1/RHEL-08-010140.sls
ferricoxide Mar 12, 2024
46872ac
Only generate password-hash *once*
ferricoxide Mar 13, 2024
95a3cb5
Fix var-refs
ferricoxide Mar 13, 2024
13761c9
Fix dependency-logic
ferricoxide Mar 13, 2024
36066c2
Improve linking-logic
ferricoxide Mar 13, 2024
95d9745
Collapse SELinux label-changes into file-managed state
ferricoxide Mar 13, 2024
fefbc93
Fix selinux: struct
ferricoxide Mar 13, 2024
7b46b75
Fix dependency-logic
ferricoxide Mar 13, 2024
88e0120
Change to file.managed states
ferricoxide Mar 13, 2024
0b1cb8a
Try to ensure SEL labels persist across runs
ferricoxide Mar 13, 2024
cfbb2ef
Fix SEL labels
ferricoxide Mar 13, 2024
bf9a8d3
Collapse double-management of user.cfg file
ferricoxide Mar 13, 2024
6d1de77
Make notifiers stateful
ferricoxide Mar 13, 2024
f5d1e4a
Fix quoting
ferricoxide Mar 13, 2024
555b3a2
Fix ypto
ferricoxide Mar 13, 2024
cce5ae1
Change notifier-script to use test.show_notification module
ferricoxide Mar 13, 2024
3dd846c
Update ash-linux/el8/STIGbyID/cat1/RHEL-08-010150.sls
ferricoxide Mar 13, 2024
cf2c91c
Update ash-linux/el8/STIGbyID/cat1/RHEL-08-010140.sls
ferricoxide Mar 13, 2024
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
104 changes: 104 additions & 0 deletions ash-linux/el8/STIGbyID/cat1/RHEL-08-010140.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Ref Doc: STIG - RHEL 8 v1r7
# Finding ID: V-230235
# STIG ID: RHEL-08-010140
# Rule ID: SV-230235r743925_rule
# SRG ID(s): SRG-OS-000080-GPOS-00048
# Finding Level: high
#
# Rule Summary:
# RHEL 8 operating systems booted with EFI must
# require authentication upon booting into
# single-user and maintenance modes
#
# References:
# CCI:
# - CCI-000213
# NIST SP 800-53 :: AC-3
# NIST SP 800-53A :: AC-3.1
# NIST SP 800-53 Revision 4 :: AC-3
#
#################################################################
{%- set stig_id = 'RHEL-08-010140' %}
{%- set helperLoc = tpldir ~ '/files' %}
{%- from tpldir ~ '/grub2_info.jinja' import grubEncryptedPass with context %}
{%- from tpldir ~ '/grub2_info.jinja' import grubUser with context %}
{%- set skipIt = salt.pillar.get('ash-linux:lookup:skip-stigs', []) %}
{%- set mustSet = salt.pillar.get('ash-linux:lookup:grub-passwd', '') %}
{%- set grubUserFile = '/etc/grub.d/01_users' %}
{%- if salt.grains.get('os')|lower == 'centos stream' %}
{%- set grubPassFile = '/boot/efi/EFI/centos/user.cfg' %}
{%- else %}
{%- set grubPassFile = '/boot/efi/EFI/redhat/user.cfg' %}
{%- endif %}


{{ stig_id }}-description:
test.show_notification:
- text: |
--------------------------------------
STIG Finding ID: V-230234
RHEL 8 must require authenticated
user in order to access single-
user and maintenance modes
--------------------------------------

{%- if stig_id in skipIt %}
notify_{{ stig_id }}-skipSet:
cmd.run:
- name: 'printf "\nchanged=no comment=''Handler for {{ stig_id }} has been selected for skip.''\n"'
- stateful: True
- cwd: /root
ferricoxide marked this conversation as resolved.
Show resolved Hide resolved
{%- else %}
user_cfg_exists-{{ stig_id }}:
file.touch:
- name: '{{ grubPassFile }}'
- makedirs: True
- onlyif:
- test -d /sys/firmware/efi/
- unless: {{ grubPassFile }}

user_cfg_content-{{ stig_id }}:
file.managed:
- name: '{{ grubPassFile }}'
- contents: |-
GRUB2_PASSWORD={{ grubEncryptedPass }}
- onchanges:
- file: user_cfg_exists-{{ stig_id }}
- onchanges_in:
- regen_grubCfg-{{ stig_id }}

grubuser_superDef-{{ grubUserFile }}-{{ stig_id }}:
file.replace:
- name: '{{ grubUserFile }}'
- pattern: 'superusers=".*"'
- repl: 'superusers="{{ grubUser }}"'

grubuser_userSub-{{ grubUserFile }}-{{ stig_id }}:
file.replace:
- name: '{{ grubUserFile }}'
- pattern: 'password_pbkdf2 .* \\'
- repl: 'password_pbkdf2 {{ grubUser }} \\'

regen_grubCfg-{{ stig_id }}:
cmd.run:
- name: '/sbin/grub2-mkconfig -o /boot/grub2/grub.cfg'
- cwd: /root
- onchanges:
- file: grubuser_superDef-{{ grubUserFile }}-{{ stig_id }}
- file: grubuser_userSub-{{ grubUserFile }}-{{ stig_id }}
- onchanges_in:
- file: fix_perms_grubCfg-{{ stig_id }}

fix_perms_grubCfg-{{ stig_id }}:
file.managed:
- name: '/boot/grub2/grub.cfg'
- mode: '0600'
- owner: 'root'
- selinux:
serange: 's0'
serole: 'object_r'
setype: 'boot_t'
seuser: 'unconfined_u'
- user: 'root'

{%- endif %}
76 changes: 45 additions & 31 deletions ash-linux/el8/STIGbyID/cat1/RHEL-08-010150.sls
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,23 @@
#################################################################
{%- set stig_id = 'RHEL-08-010150' %}
{%- set helperLoc = tpldir ~ '/files' %}
{%- from tpldir ~ '/grub2_info.jinja' import grubEncryptedPass with context %}
{%- from tpldir ~ '/grub2_info.jinja' import grubUser with context %}
{%- set skipIt = salt.pillar.get('ash-linux:lookup:skip-stigs', []) %}
{%- set mustSet = salt.pillar.get('ash-linux:lookup:grub-passwd', '') %}
{%- set grubUser = salt.pillar.get('ash-linux:lookup:grub-user', 'grubuser') %}
{%- set grubPass = salt.pillar.get('ash-linux:lookup:grub-passwd', 'AR34llyB4dP4ssw*rd') %}
{%- set grubUserFile = '/etc/grub.d/01_users' %}
{%- set grubPassFile = '/boot/grub2/user.cfg' %}
{%- set grubUtil = '/bin/grub2-mkpasswd-pbkdf2' %}

script_{{ stig_id }}-describe:
cmd.script:
- source: salt://{{ helperLoc }}/{{ stig_id }}.sh
- cwd: /root
{{ stig_id }}-description:
test.show_notification:
- text: |
--------------------------------------
STIG Finding ID: V-230235
RHEL 8 must require authenticated
user in order to access single-
user and maintenance modes
--------------------------------------

{%- if stig_id in skipIt %}
notify_{{ stig_id }}-skipSet:
Expand All @@ -40,47 +45,56 @@ notify_{{ stig_id }}-skipSet:
- stateful: True
- cwd: /root
{%- else %}
user_cfg_permissions-{{ stig_id }}:
user_cfg_content-{{ stig_id }}:
file.managed:
- name: '{{ grubPassFile }}'
- user: 'root'
- owner: 'root'
- contents: |-
GRUB2_PASSWORD={{ grubEncryptedPass }}
- mode: '000600'
- onchanges_in:
- cmd: regen_grubCfg-{{ stig_id }}
- onlyif:
- [[ ! -d /sys/firmware/efi/ ]]
- owner: 'root'
- replace: false
- selinux:
serange: 's0'
serole: 'object_r'
setype: 'boot_t'
seuser: 'unconfined_u'
- user: 'root'

user_cfg_selLabels-{{ stig_id }}:
cmd.run:
- name: 'chcon -u system_u -r object_r -t boot_t {{ grubPassFile }}'
- cwd: /root
- require:
- file: user_cfg_permissions-{{ stig_id }}
- unless:
- '[[ $( ls -lZ /boot/grub2/user.cfg | awk "{ print $5 }" ) =~ "system_u:object_r:boot_t:"* ]]'

user_cfg_content-{{ stig_id }}:
cmd.run:
- name: 'printf "GRUB2_PASSWORD=%s\n" "$( printf "{{ grubPass }}\n{{ grubPass }}\n" | {{ grubUtil }} | awk ''/grub.pbkdf/{print $NF}'' )" > {{ grubPassFile }}'
- cwd: /root
- require:
- file: user_cfg_permissions-{{ stig_id }}

grubuser_superDef-{{ grubUserFile }}:
grubuser_superDef-{{ grubUserFile }}-{{ stig_id }}:
file.replace:
- name: '{{ grubUserFile }}'
- pattern: 'superusers=".*"'
- repl: 'superusers="{{ grubUser }}"'

grubuser_userSub-{{ grubUserFile }}:
grubuser_userSub-{{ grubUserFile }}-{{ stig_id }}:
file.replace:
- name: '{{ grubUserFile }}'
- pattern: 'password_pbkdf2 .* \\'
- repl: 'password_pbkdf2 {{ grubUser }} \\'

regen_grubCfg:
regen_grubCfg-{{ stig_id }}:
cmd.run:
- name: '/sbin/grub2-mkconfig -o /boot/grub2/grub.cfg '
- cwd: /root
- require:
- file: grubuser_superDef-{{ grubUserFile }}
- file: grubuser_userSub-{{ grubUserFile }}
- onchanges:
- file: grubuser_superDef-{{ grubUserFile }}-{{ stig_id }}
- file: grubuser_userSub-{{ grubUserFile }}-{{ stig_id }}
- onchanges_in:
- file: fix_perms_grubCfg-{{ stig_id }}

fix_perms_grubCfg-{{ stig_id }}:
file.managed:
- name: '/boot/grub2/grub.cfg'
- mode: '0600'
- owner: 'root'
- selinux:
serange: 's0'
serole: 'object_r'
setype: 'boot_t'
seuser: 'unconfined_u'
- user: 'root'
{%- endif %}
33 changes: 0 additions & 33 deletions ash-linux/el8/STIGbyID/cat1/files/RHEL-08-010150.sh

This file was deleted.

12 changes: 12 additions & 0 deletions ash-linux/el8/STIGbyID/cat1/grub2_info.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{%- set grubUser = salt.pillar.get('ash-linux:lookup:grub-user', 'grubuser') %}
{%- set grubClearPass = salt.pillar.get('ash-linux:lookup:grub-passwd', 'AR34llyB4dP4ssw*rd') %}

{%-
set grubEncryptedPass = salt.cmd.shell(
'printf "%s\n%s\n" "' + grubClearPass + '" "' + grubClearPass + '" |
/bin/grub2-mkpasswd-pbkdf2 |
grep "hash of" |
sed "s/^.* is //"',
ignore_retcode=True
)
%}
1 change: 1 addition & 0 deletions ash-linux/el8/STIGbyID/cat1/init.sls
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include:
- ash-linux.el8.STIGbyID.cat1.RHEL-08-010140
- ash-linux.el8.STIGbyID.cat1.RHEL-08-010150
- ash-linux.el8.STIGbyID.cat1.RHEL-08-no_pam_nullok
Loading