|
|
7f95c9d |
#!/bin/bash
|
|
|
7f95c9d |
# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
|
|
|
7f95c9d |
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
7f95c9d |
#
|
|
|
7f95c9d |
# runtest.sh of /CoreOS/selinux-policy/Regression/bgpd-and-similar
|
|
|
7f95c9d |
# Description: SELinux interferes with bgpd and related programs
|
|
|
7f95c9d |
# Author: Milos Malik <mmalik@redhat.com>
|
|
|
7f95c9d |
#
|
|
|
7f95c9d |
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
7f95c9d |
#
|
|
|
7f95c9d |
# Copyright (c) 2022 Red Hat, Inc. All rights reserved.
|
|
|
7f95c9d |
#
|
|
|
7f95c9d |
# This copyrighted material is made available to anyone wishing
|
|
|
7f95c9d |
# to use, modify, copy, or redistribute it subject to the terms
|
|
|
7f95c9d |
# and conditions of the GNU General Public License version 2.
|
|
|
7f95c9d |
#
|
|
|
7f95c9d |
# This program is distributed in the hope that it will be
|
|
|
7f95c9d |
# useful, but WITHOUT ANY WARRANTY; without even the implied
|
|
|
7f95c9d |
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
7f95c9d |
# PURPOSE. See the GNU General Public License for more details.
|
|
|
7f95c9d |
#
|
|
|
7f95c9d |
# You should have received a copy of the GNU General Public
|
|
|
7f95c9d |
# License along with this program; if not, write to the Free
|
|
|
7f95c9d |
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
7f95c9d |
# Boston, MA 02110-1301, USA.
|
|
|
7f95c9d |
#
|
|
|
7f95c9d |
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
7f95c9d |
|
|
|
7f95c9d |
# Include Beaker environment
|
|
|
7f95c9d |
. /usr/share/beakerlib/beakerlib.sh || exit 1
|
|
|
7f95c9d |
|
|
|
7f95c9d |
PACKAGE="selinux-policy"
|
|
|
7f95c9d |
FILE_PATH="/usr/sbin/bgpd"
|
|
|
7f95c9d |
SERVICE_PACKAGE="openbgpd"
|
|
|
7f95c9d |
SERVICE_NAME="bgpd"
|
|
|
7f95c9d |
PROCESS_NAME="bgpd"
|
|
|
b720e41 |
if rlIsRHEL 9 || rlIsCentOS 9 ; then
|
|
|
7f95c9d |
FILE_CONTEXT="bin_t"
|
|
|
7f95c9d |
PROCESS_CONTEXT="unconfined_service_t"
|
|
|
7f95c9d |
else
|
|
|
7f95c9d |
FILE_CONTEXT="zebra_exec_t"
|
|
|
7f95c9d |
PROCESS_CONTEXT="zebra_t"
|
|
|
7f95c9d |
fi
|
|
|
7f95c9d |
|
|
|
7f95c9d |
rlJournalStart
|
|
|
7f95c9d |
rlPhaseStartSetup
|
|
|
7f95c9d |
rlRun "rlImport 'selinux-policy/common'"
|
|
|
7f95c9d |
rlSESatisfyRequires
|
|
|
7f95c9d |
rlAssertRpm ${PACKAGE}
|
|
|
7f95c9d |
rlAssertRpm ${PACKAGE}-targeted
|
|
|
889bc16 |
if ! rpm -q ${SERVICE_PACKAGE} ; then
|
|
|
889bc16 |
rlRun "yum -y install ${SERVICE_PACKAGE} --enablerepo epel"
|
|
|
889bc16 |
fi
|
|
|
7f95c9d |
rlAssertRpm ${SERVICE_PACKAGE}
|
|
|
7f95c9d |
|
|
|
7f95c9d |
rlServiceStop ${SERVICE_NAME}
|
|
|
7f95c9d |
rlFileBackup /etc/bgpd.conf
|
|
|
7f95c9d |
|
|
|
7f95c9d |
rlSESetEnforce
|
|
|
7f95c9d |
rlSEStatus
|
|
|
7f95c9d |
rlSESetTimestamp
|
|
|
7f95c9d |
sleep 2
|
|
|
7f95c9d |
rlPhaseEnd
|
|
|
7f95c9d |
|
|
|
7f95c9d |
rlPhaseStartTest "bz#1830170 + bz#2055578"
|
|
|
7f95c9d |
rlSEMatchPathCon "${FILE_PATH}" "${FILE_CONTEXT}"
|
|
|
7f95c9d |
if rlIsRHEL 5 ; then
|
|
|
7f95c9d |
SOURCE_TYPE="initrc_t"
|
|
|
7f95c9d |
BOOLEANS="[ ]"
|
|
|
7f95c9d |
elif rlIsRHEL 6 ; then
|
|
|
7f95c9d |
SOURCE_TYPE="initrc_t"
|
|
|
7f95c9d |
else # RHEL-7 etc.
|
|
|
7f95c9d |
SOURCE_TYPE="init_t" # systemd runs the process
|
|
|
7f95c9d |
fi
|
|
|
7f95c9d |
rlSESearchRule "allow ${SOURCE_TYPE} ${FILE_CONTEXT} : file { getattr open read execute } $BOOLEANS"
|
|
|
7f95c9d |
rlSESearchRule "allow ${SOURCE_TYPE} ${PROCESS_CONTEXT} : process { transition } $BOOLEANS"
|
|
|
7f95c9d |
rlSESearchRule "type_transition ${SOURCE_TYPE} ${FILE_CONTEXT} : process ${PROCESS_CONTEXT} $BOOLEANS"
|
|
|
7f95c9d |
rlPhaseEnd
|
|
|
7f95c9d |
|
|
|
7f95c9d |
rlPhaseStartTest "real scenario -- standalone service"
|
|
|
7f95c9d |
rlRun "sed -i 's/^\(include.*\)$/# \1/' /etc/bgpd.conf"
|
|
|
7582d85 |
if rlIsRHEL 8 || rlIsCentOS 8 ; then
|
|
|
482173e |
# work around BZ#1830170 that was closed as WONTFIX
|
|
|
482173e |
rlRun "chcon -t bin_t /usr/sbin/bgpd"
|
|
|
482173e |
PROCESS_CONTEXT="unconfined_service_t"
|
|
|
482173e |
fi
|
|
|
7f95c9d |
rlSEService - ${SERVICE_NAME} ${PROCESS_NAME} ${PROCESS_CONTEXT} "start status" 1
|
|
|
d7ee078 |
rlRun "restorecon -Rv /run /var -e /var/ARTIFACTS" 0-255
|
|
|
7f95c9d |
rlSEService - ${SERVICE_NAME} ${PROCESS_NAME} ${PROCESS_CONTEXT} "restart status stop status" 1
|
|
|
7582d85 |
if rlIsRHEL 8 || rlIsCentOS 8 ; then
|
|
|
482173e |
# work around BZ#1830170 that was closed as WONTFIX
|
|
|
482173e |
rlRun "restorecon -v /usr/sbin/bgpd"
|
|
|
482173e |
fi
|
|
|
7f95c9d |
rlPhaseEnd
|
|
|
7f95c9d |
|
|
|
7f95c9d |
rlPhaseStartCleanup
|
|
|
7f95c9d |
sleep 2
|
|
|
7f95c9d |
rlSECheckAVC
|
|
|
7f95c9d |
|
|
|
7f95c9d |
rlFileRestore
|
|
|
7f95c9d |
rlServiceRestore ${SERVICE_NAME}
|
|
|
7f95c9d |
rlPhaseEnd
|
|
|
7f95c9d |
rlJournalPrintText
|
|
|
7f95c9d |
rlJournalEnd
|
|
|
7f95c9d |
|