Skip to content

Commit 89044cb

Browse files
committed
Fix authselect remediation with multiple features
The ansible_authselect_force_reselect and bash_authselect_force_reselect macros were using unquoted command substitution which triggered SC2046 shellcheck warnings about word splitting. The issue was that "authselect current --raw" returns a profile with features as separate words (e.g., "sssd with-faillock with-fingerprint"), and intentional word splitting is required for authselect to properly parse the profile name and features as separate arguments. Fixed by using proper word splitting patterns: - Bash: Use read -ra to safely split into array, then expand with "@" - Ansible: Split into two tasks - capture output, then expand variable This resolves shellcheck SC2046 warnings while maintaining correct functionality for profiles with multiple features. Fixes: #14600
1 parent e7e8a8c commit 89044cb

6 files changed

Lines changed: 60 additions & 3 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
# packages = authselect,pam
3+
# platform = Oracle Linux 8,Oracle Linux 9,multi_platform_rhel,multi_platform_fedora
4+
# remediation = ansible
5+
6+
authselect create-profile test_profile -b sssd
7+
authselect select "custom/test_profile" --force
8+
9+
# Enable multiple features to test the scenario where "authselect current --raw"
10+
# returns a string with spaces (e.g., "custom/test_profile with-faillock with-fingerprint")
11+
authselect enable-feature with-faillock
12+
authselect enable-feature with-fingerprint
13+
14+
authselect apply-changes
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
# packages = authselect,pam
3+
# platform = Oracle Linux 8,Oracle Linux 9,multi_platform_rhel,multi_platform_fedora
4+
5+
authselect create-profile test_profile -b sssd
6+
authselect select "custom/test_profile" --force
7+
8+
# Enable other features but not with-faillock to simulate a system
9+
# that has authselect configured with features, but missing the required faillock
10+
authselect enable-feature with-fingerprint
11+
authselect enable-feature with-silent-lastlog
12+
13+
authselect apply-changes
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
# packages = authselect,pam
3+
# platform = Oracle Linux 8,Oracle Linux 9,multi_platform_rhel,multi_platform_fedora
4+
5+
# Simulate a real RHEL system with sssd profile and multiple features enabled
6+
# This is the scenario reported in issue #14600 where "authselect current --raw"
7+
# returns "sssd with-fingerprint with-silent-lastlog"
8+
authselect select sssd --force
9+
authselect enable-feature with-faillock
10+
authselect enable-feature with-fingerprint
11+
authselect enable-feature with-silent-lastlog
12+
13+
authselect apply-changes
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
# packages = authselect,pam
3+
# platform = Oracle Linux 8,Oracle Linux 9,multi_platform_rhel,multi_platform_fedora
4+
5+
# Test with sssd profile and one feature (not faillock) enabled
6+
# This simulates a system where "authselect current --raw" returns "sssd with-fingerprint"
7+
authselect select sssd --force
8+
authselect enable-feature with-fingerprint
9+
10+
authselect apply-changes

shared/macros/10-ansible.jinja

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -930,9 +930,15 @@ The following macro remediates Audit syscall rule in :code:`/etc/audit/audit.rul
930930

931931
#}}
932932
{{% macro ansible_authselect_force_reselect(rule_title=None) -%}}
933+
- name: '{{{ rule_title }}} - Get current authselect profile'
934+
ansible.builtin.command:
935+
cmd: authselect current --raw
936+
register: authselect_current_profile
937+
changed_when: false
938+
933939
- name: '{{{ rule_title }}} - Force reselect authselect profile'
934-
ansible.builtin.shell:
935-
cmd: authselect select "$(authselect current --raw)" --force
940+
ansible.builtin.command:
941+
cmd: "authselect select {{ authselect_current_profile.stdout }} --force"
936942
{{%- endmacro %}}
937943

938944
{{#

shared/macros/10-bash.jinja

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2484,7 +2484,8 @@ fi
24842484

24852485
#}}
24862486
{{% macro bash_authselect_force_reselect() -%}}
2487-
authselect select "$(authselect current --raw)" --force
2487+
read -ra authselect_args < <(authselect current --raw)
2488+
authselect select "${authselect_args[@]}" --force
24882489
{{%- endmacro %}}
24892490

24902491

0 commit comments

Comments
 (0)