mmalik / tests / selinux

Forked from tests/selinux 6 years ago
Clone

Blame selinux-policy/dhclient-and-similar/runtest.sh

565cbef
#!/bin/bash
565cbef
# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
565cbef
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
565cbef
#
565cbef
#   runtest.sh of /CoreOS/selinux-policy/Regression/dhclient-and-similar
565cbef
#   Description: SELinux interferes with dhclient and related programs
565cbef
#   Author: Milos Malik <mmalik@redhat.com>
565cbef
#
565cbef
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
565cbef
#
565cbef
#   Copyright (c) 2020 Red Hat, Inc. All rights reserved.
565cbef
#
565cbef
#   This copyrighted material is made available to anyone wishing
565cbef
#   to use, modify, copy, or redistribute it subject to the terms
565cbef
#   and conditions of the GNU General Public License version 2.
565cbef
#
565cbef
#   This program is distributed in the hope that it will be
565cbef
#   useful, but WITHOUT ANY WARRANTY; without even the implied
565cbef
#   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
565cbef
#   PURPOSE. See the GNU General Public License for more details.
565cbef
#
565cbef
#   You should have received a copy of the GNU General Public
565cbef
#   License along with this program; if not, write to the Free
565cbef
#   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
565cbef
#   Boston, MA 02110-1301, USA.
565cbef
#
565cbef
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
565cbef
565cbef
# Include Beaker environment
565cbef
. /usr/share/beakerlib/beakerlib.sh || exit 1
565cbef
565cbef
PACKAGE="selinux-policy"
565cbef
SERVICE_PACKAGE="chrony"
565cbef
SERVICE_NAME="chronyd"
565cbef
565cbef
rlJournalStart
565cbef
    rlLog "If this test fails, please contact mmalik on IRC #selinux"
565cbef
    rlLog "This test should fail if tested bugs are NOT fixed yet"
565cbef
    rlPhaseStartSetup
26a276d
        rlRun "rlImport 'selinux-policy/common'" 0,1
565cbef
        rlSESatisfyRequires
565cbef
        rlAssertRpm ${PACKAGE}
565cbef
        rlAssertRpm ${PACKAGE}-targeted
565cbef
        rlAssertRpm ${SERVICE_PACKAGE}
565cbef
565cbef
        rlServiceStart ${SERVICE_NAME}
bd2e475
        rlFileBackup --missing-ok /run/chrony-dhcp
565cbef
565cbef
        rlSESetEnforce
565cbef
        rlSEStatus
565cbef
        rlSESetTimestamp
565cbef
        sleep 2
565cbef
    rlPhaseEnd
565cbef
7582d85
    if ! rlIsRHEL 8 && ! rlIsCentOS 8 ; then
37878fa
    rlPhaseStartTest "bz#1897388"
37878fa
        rlSEMatchPathCon "/usr/sbin/dhclient-script" "dhcpc_exec_t"
37878fa
        rlSEMatchPathCon "/usr/bin/chronyc" "chronyc_exec_t"
37878fa
        rlSESearchRule "allow dhcpc_t chronyc_exec_t : file { getattr open read execute } [ ]"
37878fa
        rlSESearchRule "type_transition dhcpc_t chronyc_exec_t : process chronyc_t"
37878fa
        rlSESearchRule "allow dhcpc_t chronyc_t : process { transition } [ ]"
37878fa
    rlPhaseEnd
7710067
7710067
    rlPhaseStartTest "bz#2035117 + bz#2093709 + bz#2094155"
7710067
        rlSEMatchPathCon "/usr/sbin/dhclient-script" "dhcpc_exec_t"
7710067
        rlSEMatchPathCon "/run/chrony-dhcp" "chronyd_var_run_t"
7710067
        rlSEMatchPathCon "/run/chrony-dhcp/eth0.sources" "chronyd_var_run_t"
7710067
        rlSESearchRule "type_transition dhcpc_t var_run_t : dir chronyd_var_run_t chrony-dhcp"
7710067
        rlSESearchRule "allow dhcpc_t chronyd_var_run_t : dir { read write } [ ]"
7710067
        rlSESearchRule "allow dhcpc_t chronyd_var_run_t : file { create getattr append } [ ]"
7710067
    rlPhaseEnd
c40e0ae
    fi
37878fa
37878fa
    rlPhaseStartTest "real scenario"
7710067
        rlRun "rm -rf /run/chrony-dhcp"
bd2e475
        rlRun "restorecon -Rv /run /var -e /var/ARTIFACTS" 0-255
565cbef
        rlRun "dhclient"
37878fa
        DHCLIENT_PID=`pgrep dhclient`
37878fa
        rlRun "ps -efZ | grep dhclient"
37878fa
        rlRun "ps -efZ | grep ':dhcpc_t:.*dhclient'"
7582d85
        if ! rlIsRHEL 8 && ! rlIsCentOS 8 ; then
bd2e475
            rlRun "ls -alZ /run/chrony-dhcp"
bd2e475
        fi
565cbef
    rlPhaseEnd
565cbef
565cbef
    rlPhaseStartCleanup
565cbef
        sleep 2
565cbef
        rlSECheckAVC
37878fa
        kill ${DHCLIENT_PID}
7710067
        rlFileRestore
565cbef
        rlServiceRestore ${SERVICE_NAME}
565cbef
    rlPhaseEnd
565cbef
rlJournalPrintText
565cbef
rlJournalEnd
565cbef