diff --git a/selinux-policy/pam_timestamp-and-related/Makefile b/selinux-policy/pam_timestamp-and-related/Makefile new file mode 100644 index 0000000..d619c1a --- /dev/null +++ b/selinux-policy/pam_timestamp-and-related/Makefile @@ -0,0 +1,69 @@ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Makefile of /CoreOS/selinux-policy/Regression/pam_timestamp-and-related +# Description: Does SELinux cooperate with pam_timestamp_check and pam_timestamp.so? +# Author: Milos Malik +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2020 Red Hat, Inc. All rights reserved. +# +# This copyrighted material is made available to anyone wishing +# to use, modify, copy, or redistribute it subject to the terms +# and conditions of the GNU General Public License version 2. +# +# This program is distributed in the hope that it will be +# useful, but WITHOUT ANY WARRANTY; without even the implied +# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +# PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public +# License along with this program; if not, write to the Free +# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +# Boston, MA 02110-1301, USA. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +export TEST=/CoreOS/selinux-policy/Regression/pam_timestamp-and-related +export TESTVERSION=1.0 + +BUILT_FILES= + +FILES=$(METADATA) runtest.sh Makefile PURPOSE ssh.exp + +.PHONY: all install download clean + +run: $(FILES) build + ./runtest.sh + +build: $(BUILT_FILES) + chmod a+x runtest.sh ssh.exp + chcon -t bin_t runtest.sh ssh.exp + +clean: + rm -f *~ $(BUILT_FILES) + +include /usr/share/rhts/lib/rhts-make.include + +$(METADATA): Makefile + @echo "Owner: Milos Malik " > $(METADATA) + @echo "Name: $(TEST)" >> $(METADATA) + @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) + @echo "Path: $(TEST_DIR)" >> $(METADATA) + @echo "Description: Does SELinux cooperate with pam_timestamp_check and pam_timestamp.so?" >> $(METADATA) + @echo "Type: Regression" >> $(METADATA) + @echo "TestTime: 10m" >> $(METADATA) + @echo "RunFor: pam" >> $(METADATA) + @echo "RunFor: selinux-policy" >> $(METADATA) + @echo "Requires: audit libselinux libselinux-utils policycoreutils selinux-policy selinux-policy-targeted setools-console expect openssh-clients pam psmisc binutils shadow-utils" >> $(METADATA) + @echo "RhtsRequires: library(selinux-policy/common)" >> $(METADATA) + @echo "Environment: AVC_ERROR=+no_avc_check" >> $(METADATA) + @echo "Priority: Normal" >> $(METADATA) + @echo "License: GPLv2" >> $(METADATA) + @echo "Confidential: no" >> $(METADATA) + @echo "Destructive: no" >> $(METADATA) + @echo "Releases: -RHEL4 -RHEL5 -RHEL6" >> $(METADATA) + @echo "Bug: 1791957" >> $(METADATA) # RHEL-8 + + rhts-lint $(METADATA) + diff --git a/selinux-policy/pam_timestamp-and-related/PURPOSE b/selinux-policy/pam_timestamp-and-related/PURPOSE new file mode 100644 index 0000000..61c4f1e --- /dev/null +++ b/selinux-policy/pam_timestamp-and-related/PURPOSE @@ -0,0 +1,11 @@ +PURPOSE of /CoreOS/selinux-policy/Regression/pam_timestamp-and-related +Author: Milos Malik + +Does SELinux cooperate with pam_timestamp_check and pam_timestamp.so? +Confined and unconfined users are tested using SSH. + +This TC uses following parameters which can be overriden: + * ALLOWED_USERS - which SELinux users should be tested? + * DENIED_USERS - which SELinux users should NOT be tested? + * TIMESTAMP_DIR - in which directory is the _pam_timestamp_key file stored? + diff --git a/selinux-policy/pam_timestamp-and-related/main.fmf b/selinux-policy/pam_timestamp-and-related/main.fmf new file mode 100644 index 0000000..a83b2cb --- /dev/null +++ b/selinux-policy/pam_timestamp-and-related/main.fmf @@ -0,0 +1,2 @@ +path: /selinux-policy/pam_timestamp-and-related +tier: 2 diff --git a/selinux-policy/pam_timestamp-and-related/runtest.sh b/selinux-policy/pam_timestamp-and-related/runtest.sh new file mode 100755 index 0000000..b19a2f3 --- /dev/null +++ b/selinux-policy/pam_timestamp-and-related/runtest.sh @@ -0,0 +1,102 @@ +#!/bin/bash +# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# runtest.sh of /CoreOS/selinux-policy/Regression/pam_timestamp-and-related +# Description: Does SELinux cooperate with pam_timestamp_check and pam_timestamp.so? +# Author: Milos Malik +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2020 Red Hat, Inc. All rights reserved. +# +# This copyrighted material is made available to anyone wishing +# to use, modify, copy, or redistribute it subject to the terms +# and conditions of the GNU General Public License version 2. +# +# This program is distributed in the hope that it will be +# useful, but WITHOUT ANY WARRANTY; without even the implied +# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +# PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public +# License along with this program; if not, write to the Free +# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +# Boston, MA 02110-1301, USA. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Include Beaker environment +. /usr/bin/rhts-environment.sh || exit 1 +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +PACKAGE="selinux-policy" +ROOT_PASSWORD="redhat" +SERVICE_PACKAGE="pam" +DENIED_USERS=${DENIED_USERS:-"guest_u xguest_u"} +ALLOWED_USERS=${ALLOWED_USERS:-"staff_u user_u sysadm_u unconfined_u"} +TIMESTAMP_DIR=${TIMESTAMP_DIR:-"/run/pam_timestamp"} + +rlJournalStart + rlPhaseStartSetup + rlRun "rlImport 'selinux-policy/common'" + rlSESatisfyRequires + rlAssertRpm ${PACKAGE} + rlAssertRpm ${PACKAGE}-targeted + rlAssertRpm ${SERVICE_PACKAGE} + + rlFileBackup /etc/shadow + rlFileBackup ${TIMESTAMP_DIR}/_pam_timestamp_key + + rlSESetEnforce + rlSEStatus + rlSESetTimestamp + sleep 2 + rlPhaseEnd + + rlPhaseStartTest "bz#1791957" + rlSEMatchPathCon "/run" "var_run_t" + rlSEMatchPathCon "${TIMESTAMP_DIR}" "pam_var_run_t" + rlSEMatchPathCon "/usr/sbin/pam_timestamp_check" "pam_timestamp_exec_t" + rlSESearchRule "allow sshd_t var_run_t : dir { write add_name } [ ]" + rlSESearchRule "type_transition sshd_t var_run_t : dir pam_var_run_t" + rlSESearchRule "allow sshd_t pam_var_run_t : dir { create } [ ]" + rlRun "strings /usr/sbin/pam_timestamp_check | grep ${TIMESTAMP_DIR}" + rlRun "strings /usr/lib64/security/pam_timestamp.so | grep ${TIMESTAMP_DIR}" + rlPhaseEnd + + rlPhaseStartTest "real scenario -- confined users" + rlRun "setsebool ssh_sysadm_login on" + rlRun "mkdir -p ${TIMESTAMP_DIR}" + rlRun "touch ${TIMESTAMP_DIR}/_pam_timestamp_key" + rlRun "restorecon -RvF ${TIMESTAMP_DIR}" + rlLog "configuration says not to test SELinux users: ${DENIED_USERS}" + for SELINUX_USER in ${ALLOWED_USERS} ; do + USER_NAME="user${RANDOM}" + USER_SECRET="S3kr3t${RANDOM}" + rlRun "useradd -Z ${SELINUX_USER} ${USER_NAME}" + rlRun "echo ${USER_SECRET} | passwd --stdin ${USER_NAME}" + rlRun "restorecon -RvF /home/${USER_NAME}" + rlRun "./ssh.exp ${USER_NAME} ${USER_SECRET} localhost /usr/sbin/pam_timestamp_check" + rlRun "./ssh.exp ${USER_NAME} ${USER_SECRET} localhost /usr/sbin/pam_timestamp_check -k" + ( sleep 5 ; ps -efZ > /home/${USER_NAME}/processes.txt ; killall pam_timestamp_check ) & + rlRun "./ssh.exp ${USER_NAME} ${USER_SECRET} localhost /usr/sbin/pam_timestamp_check -d" + if [[ ${SELINUX_USER} == "unconfined_u" ]] ; then + rlRun "grep \"${SELINUX_USER}:${SELINUX_USER/_u/_r}:${SELINUX_USER/_u/_t}:.*pam_timestamp_check\" /home/${USER_NAME}/processes.txt" + else + rlRun "grep \"${SELINUX_USER}:${SELINUX_USER/_u/_r}:pam_timestamp_t:.*pam_timestamp_check\" /home/${USER_NAME}/processes.txt" + fi + rlRun "userdel -rfZ ${USER_NAME}" + done + rlRun "setsebool ssh_sysadm_login off" + rlPhaseEnd + + rlPhaseStartCleanup + sleep 2 + rlSECheckAVC + rlRun "rm -f ${TIMESTAMP_DIR}/_pam_timestamp_key" + rlFileRestore + rlPhaseEnd +rlJournalPrintText +rlJournalEnd + diff --git a/selinux-policy/pam_timestamp-and-related/ssh.exp b/selinux-policy/pam_timestamp-and-related/ssh.exp new file mode 100755 index 0000000..58c9647 --- /dev/null +++ b/selinux-policy/pam_timestamp-and-related/ssh.exp @@ -0,0 +1,20 @@ +#!/usr/bin/expect -f +# Expect script for SSH logging as $username to $hostname using $password and executing $command. +# Usage: +# ./ssh.exp username password hostname command +set username [lrange $argv 0 0] +set password [lrange $argv 1 1] +set hostname [lrange $argv 2 2] +set command [lrange $argv 3 10] +set timeout 15 +# connect to remote host and execute given command +log_user 1 +spawn ssh -t $username@$hostname $command +expect { + -nocase "yes/no" { send -- "yes\r" ; exp_continue } + -nocase "password" { send -- "$password\r" } +} +log_user 1 +# send -- "\r" +expect eof +