Blame SOURCES/scap-security-guide-0.1.30-downstream-rhbz#1357019.patch

f04235
From bfaac3332c7e06b4252746f6da514fd44e74b0e6 Mon Sep 17 00:00:00 2001
f04235
From: Jan Lieskovsky <jlieskov@redhat.com>
f04235
Date: Wed, 10 Aug 2016 15:47:58 +0200
f04235
Subject: [PATCH] [BugFix] [RHEL/7] Rewrite RHEL-7 remediation for
f04235
 'smartcard_auth' rule since per downstream bug:  
f04235
 https://bugzilla.redhat.com/show_bug.cgi?id=1357019
f04235
f04235
we can't use 'authconfig' binary direct call, because it will
f04235
discard the changes as performed and required by other remediation
f04235
scripts also touching /etc/pam.d/system-auth{,-ac} file
f04235
f04235
Therefore return to previous version updating necessary files
f04235
directly via 'sed' tool (rather than using 'authconfig' binary)
f04235
f04235
Note: While on the rule also update XCCDF link providing further
f04235
info how to setup smartcard auth (since the current one returns
f04235
HTTP 404 Not Found)
f04235
---
f04235
 RHEL/7/input/xccdf/system/accounts/physical.xml |  2 +-
f04235
 RHEL/7/input/remediations/bash/smartcard_auth.sh  | 61 +++++++++++++++++++++++--
f04235
 2 files changed, 58 insertions(+), 5 deletions(-)
f04235
f04235
diff --git a/RHEL/7/input/xccdf/system/accounts/physical.xml b/RHEL/7/input/xccdf/system/accounts/physical.xml
f04235
index b3ac250..d229469 100644
f04235
--- a/RHEL/7/input/xccdf/system/accounts/physical.xml
f04235
+++ b/RHEL/7/input/xccdf/system/accounts/physical.xml
f04235
@@ -375,7 +375,7 @@ is not enabled by default and must be enabled in the system settings.
f04235
 <description>
f04235
 To enable smart card authentication, consult the documentation at:
f04235
 
    f04235
    -
  • https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7-Beta/html/System-Level_Authentication_Guide/authconfig-addl-auth.html#authconfig-smartcard
  • f04235
    +
  • https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/System-Level_Authentication_Guide/smartcards.html#authconfig-smartcards
  • f04235
     
    f04235
     For guidance on enabling SSH to authenticate against a Common Access Card (CAC), consult documentation at:
    f04235
     
      f04235
      diff --git a/RHEL/7/input/remediations/bash/smartcard_auth.sh b/RHEL/7/input/remediations/bash/smartcard_auth.sh
      f04235
      index 6292515..2fe5cc8 100644
      f04235
      --- a/RHEL/7/input/remediations/bash/smartcard_auth.sh
      f04235
      +++ b/RHEL/7/input/remediations/bash/smartcard_auth.sh
      f04235
      @@ -8,11 +8,64 @@ package_command install pam_pkcs11
      f04235
       # Enable pcscd.socket systemd activation socket
      f04235
       service_command enable pcscd.socket
      f04235
       
      f04235
      -# Enable smartcard authentication (but allow also other ways
      f04235
      -# to login not to possibly cut off the system in question)
      f04235
      -/usr/sbin/authconfig --enablesmartcard --updateall
      f04235
      +# Configure the expected /etc/pam.d/system-auth{,-ac} settings directly
      f04235
      +#
      f04235
      +# The code below will configure system authentication in the way smart card
      f04235
      +# logins will be enabled, but also user login(s) via other method to be allowed
      f04235
      +#
      f04235
      +# NOTE: It is not possible to use the 'authconfig' command to perform the
      f04235
      +#       remediation for us, because call of 'authconfig' would discard changes
      f04235
      +#       for other remediations (see RH BZ#1357019 for details)
      f04235
      +#
      f04235
      +#	Therefore we need to configure the necessary settings directly.
      f04235
      +#
      f04235
       
      f04235
      -# Define constants to be reused below
      f04235
      +# Define system-auth config location
      f04235
      +SYSTEM_AUTH_CONF="/etc/pam.d/system-auth"
      f04235
      +# Define expected 'pam_env.so' row in $SYSTEM_AUTH_CONF
      f04235
      +PAM_ENV_SO="auth.*required.*pam_env.so"
      f04235
      +
      f04235
      +# Define 'pam_succeed_if.so' row to be appended past $PAM_ENV_SO row into $SYSTEM_AUTH_CONF
      f04235
      +SYSTEM_AUTH_PAM_SUCCEED="\
      f04235
      +auth        \[success=1 default=ignore\] pam_succeed_if.so service notin \
      f04235
      +login:gdm:xdm:kdm:xscreensaver:gnome-screensaver:kscreensaver quiet use_uid"
      f04235
      +# Define 'pam_pkcs11.so' row to be appended past $SYSTEM_AUTH_PAM_SUCCEED
      f04235
      +# row into SYSTEM_AUTH_CONF file
      f04235
      +SYSTEM_AUTH_PAM_PKCS11="\
      f04235
      +auth        \[success=done authinfo_unavail=ignore ignore=ignore default=die\] \
      f04235
      +pam_pkcs11.so nodebug"
      f04235
      +
      f04235
      +# Define smartcard-auth config location
      f04235
      +SMARTCARD_AUTH_CONF="/etc/pam.d/smartcard-auth"
      f04235
      +# Define 'pam_pkcs11.so' auth section to be appended past $PAM_ENV_SO into $SMARTCARD_AUTH_CONF
      f04235
      +SMARTCARD_AUTH_SECTION="\
      f04235
      +auth        [success=done ignore=ignore default=die] pam_pkcs11.so wait_for_card card_only"
      f04235
      +# Define expected 'pam_permit.so' row in $SMARTCARD_AUTH_CONF
      f04235
      +PAM_PERMIT_SO="account.*required.*pam_permit.so"
      f04235
      +# Define 'pam_pkcs11.so' password section
      f04235
      +SMARTCARD_PASSWORD_SECTION="\
      f04235
      +password    required      pam_pkcs11.so"
      f04235
      +
      f04235
      +# First Correct the SYSTEM_AUTH_CONF configuration
      f04235
      +if ! grep -q 'pam_pkcs11.so' "$SYSTEM_AUTH_CONF"
      f04235
      +then
      f04235
      +	# Append (expected) pam_succeed_if.so row past the pam_env.so into SYSTEM_AUTH_CONF file
      f04235
      +	sed -i --follow-symlinks -e '/^'"$PAM_ENV_SO"'/a '"$SYSTEM_AUTH_PAM_SUCCEED" "$SYSTEM_AUTH_CONF"
      f04235
      +	# Append (expected) pam_pkcs11.so row past the pam_succeed_if.so into SYSTEM_AUTH_CONF file
      f04235
      +	sed -i --follow-symlinks -e '/^'"$SYSTEM_AUTH_PAM_SUCCEED"'/a '"$SYSTEM_AUTH_PAM_PKCS11" "$SYSTEM_AUTH_CONF"
      f04235
      +fi
      f04235
      +
      f04235
      +# Then also correct the SMARTCARD_AUTH_CONF
      f04235
      +if ! grep -q 'pam_pkcs11.so' "$SMARTCARD_AUTH_CONF"
      f04235
      +then
      f04235
      +	# Append (expected) SMARTCARD_AUTH_SECTION row past the pam_env.so into SMARTCARD_AUTH_CONF file
      f04235
      +	sed -i --follow-symlinks -e '/^'"$PAM_ENV_SO"'/a '"$SMARTCARD_AUTH_SECTION" "$SMARTCARD_AUTH_CONF"
      f04235
      +	# Append (expected) SMARTCARD_PASSWORD_SECTION row past the pam_permit.so into SMARTCARD_AUTH_CONF file
      f04235
      +	sed -i --follow-symlinks -e '/^'"$PAM_PERMIT_SO"'/a '"$SMARTCARD_PASSWORD_SECTION" "$SMARTCARD_AUTH_CONF"
      f04235
      +fi
      f04235
      +
      f04235
      +# Perform /etc/pam_pkcs11/pam_pkcs11.conf settings below
      f04235
      +# Define selected constants for later reuse
      f04235
       SP="[:space:]"
      f04235
       PAM_PKCS11_CONF="/etc/pam_pkcs11/pam_pkcs11.conf"
      f04235