Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
kmcdonell committed Oct 23, 2024
2 parents 43e1ed8 + 8a121a8 commit ceccf46
Show file tree
Hide file tree
Showing 22 changed files with 1,206 additions and 178 deletions.
10 changes: 8 additions & 2 deletions build/rpm/pcp.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -2692,6 +2692,7 @@ exit 0

%post testsuite
%if "@enable_selinux@" == "true"
PCP_PMDAS_DIR=@pcp_pmdas_dir@
PCP_SELINUX_DIR=@pcp_selinux_dir@/packages/targeted
semodule -r pcpqa >/dev/null 2>&1 || true
%selinux_modules_install -s targeted "$PCP_SELINUX_DIR/pcp-testsuite.pp.bz2"
Expand Down Expand Up @@ -2749,9 +2750,11 @@ for PMDA in $needinstall ; do
done
# auto-enable these usually optional pmie rules
%{run_pmieconf "$PCP_PMIECONFIG_DIR" config.default dmthin}
# managed via /usr/lib/systemd/system-preset/90-default.preset nowadays:
%if 0%{?rhel} > 0 && 0%{?rhel} < 10
%if "@enable_systemd@" == "true"
systemctl restart pcp-reboot-init pmcd pmlogger pmie >/dev/null 2>&1
systemctl enable pcp-reboot-init pmcd pmlogger pmie >/dev/null 2>&1
systemctl restart pmcd pmlogger pmie >/dev/null 2>&1
systemctl enable pmcd pmlogger pmie >/dev/null 2>&1
%else
/sbin/chkconfig --add pmcd >/dev/null 2>&1
/sbin/chkconfig --add pmlogger >/dev/null 2>&1
Expand All @@ -2760,6 +2763,7 @@ done
/sbin/service pmlogger condrestart
/sbin/service pmie condrestart
%endif
%endif

%if "@pmda_systemd@" == "true"
%preun pmda-systemd
Expand Down Expand Up @@ -3077,6 +3081,8 @@ PCP_SA_DIR=@pcp_sa_dir@
%if "@enable_systemd@" == "true"
# clean up any stale symlinks for deprecated pm*-poll services
rm -f %{_sysconfdir}/systemd/system/pm*.requires/pm*-poll.* >/dev/null 2>&1 || true
systemctl restart pcp-reboot-init >/dev/null 2>&1
systemctl enable pcp-reboot-init >/dev/null 2>&1

%systemd_postun_with_restart pmcd.service
%systemd_post pmcd.service
Expand Down
10 changes: 7 additions & 3 deletions build/rpm/redhat.spec
Original file line number Diff line number Diff line change
Expand Up @@ -2887,6 +2887,7 @@ exit 0

%post testsuite
%if !%{disable_selinux}
PCP_PMDAS_DIR=%{_pmdasdir}
PCP_SELINUX_DIR=%{_selinuxdir}
semodule -r pcpqa >/dev/null 2>&1 || true
%selinux_modules_install -s targeted "$PCP_SELINUX_DIR/pcp-testsuite.pp.bz2"
Expand Down Expand Up @@ -3225,10 +3226,11 @@ for PMDA in dm nfsclient openmetrics ; do
done
# auto-enable these usually optional pmie rules
%{run_pmieconf "$PCP_PMIECONFIG_DIR" config.default dmthin}
%if 0%{?rhel} <= 9
# managed via /usr/lib/systemd/system-preset/90-default.preset nowadays:
%if 0%{?rhel} > 0 && 0%{?rhel} < 10
%if !%{disable_systemd}
systemctl restart pcp-reboot-init pmcd pmlogger pmie >/dev/null 2>&1
systemctl enable pcp-reboot-init pmcd pmlogger pmie >/dev/null 2>&1
systemctl restart pmcd pmlogger pmie >/dev/null 2>&1
systemctl enable pmcd pmlogger pmie >/dev/null 2>&1
%else
/sbin/chkconfig --add pmcd >/dev/null 2>&1
/sbin/chkconfig --add pmlogger >/dev/null 2>&1
Expand All @@ -3247,6 +3249,8 @@ PCP_LOG_DIR=%{_logsdir}
%if !%{disable_systemd}
# clean up any stale symlinks for deprecated pm*-poll services
rm -f %{_sysconfdir}/systemd/system/pm*.requires/pm*-poll.* >/dev/null 2>&1 || true
systemctl restart pcp-reboot-init >/dev/null 2>&1
systemctl enable pcp-reboot-init >/dev/null 2>&1

%systemd_postun_with_restart pmcd.service
%systemd_post pmcd.service
Expand Down
235 changes: 235 additions & 0 deletions qa/1770
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
#!/bin/sh
# PCP QA Test No. 1770
# Exercise different pmdaproc access control settings.
#
# Copyright (c) 2024 Red Hat.
#

seq=`basename $0`
echo "QA output created by $seq"

. ./common.secure

_get_libpcp_config
$authentication || _notrun "No authentication support available"

sasl_notrun_checks saslpasswd2 sasldblistusers2
$pluginviewer -a | grep 'Plugin "sasldb"' >/dev/null
test $? -eq 0 || _notrun "SASL sasldb auxprop plugin unavailable"
$pluginviewer -c | grep 'Plugin "plain"' >/dev/null 2>&1
test $? -eq 0 || _notrun 'No client support for plain authentication'
$pluginviewer -s | grep 'Plugin "plain"' >/dev/null 2>&1
test $? -eq 0 || _notrun 'No server support for plain authentication'

$sudo rm -rf $tmp $tmp.* $seq.full

signal=$PCP_BINADM_DIR/pmsignal
status=1 # failure is the default!
need_restore=false
groupid=`id -g`
userid=`id -u`

_cleanup()
{
cd $here

# restore any modified pmcd and pmproxy configuration files
if $need_restore
then
need_restore=false
_restore_config $PCP_SYSCONF_DIR/proc
_restore_config $PCP_SYSCONF_DIR/labels
_restore_config $PCP_SYSCONF_DIR/pmproxy
_restore_config $PCP_SASLCONF_DIR/pmcd.conf
fi

_service pmcd stop >>$seq.full 2>&1
_service pmcd start >>$seq.full 2>&1
_wait_for_pmcd

if $pmproxy_was_running
then
echo "Restart pmproxy ..." >>$here/$seq.full
_service pmproxy restart >>$here/$seq.full 2>&1
_wait_for_pmproxy
else
echo "Stopping pmproxy ..." >>$here/$seq.full
_service pmproxy stop >>$here/$seq.full 2>&1
fi

$sudo rm -rf $tmp $tmp.*
}

trap "_cleanup; exit \$status" 0 1 2 3 15

full_hostname=`hostname --fqdn`

pmproxy_was_running=false
[ -f $PCP_RUN_DIR/pmproxy.pid ] && pmproxy_was_running=true
echo "pmproxy_was_running=$pmproxy_was_running" >>$here/$seq.full

_filter_credentials()
{
sed \
-e 's/"groupid": '$groupid',/"groupid": GID/g' \
-e 's/"userid": '$userid'/"userid": UID/g' \
#end
}

_filter_username()
{
sed -e "s/user $username/user USER/"
}

_filter_listusers2()
{
sed \
-e "s/^$username/USER/" \
-e "s/@$full_hostname:/@HOST:/" \
-e "s/@$hostname:/@HOST:/" \
#end
}

_filter_json()
{
tee -a $seq.full | \
sed -e 's,"machineid": .*,"machineid": "MACHINEID",g' \
-e 's,"context": .*,"context": "CONTEXT",g' \
-e 's,"hostname": .*,"hostname": "HOSTNAME",g' \
-e 's,"domainname": .*,"domainname": "DOMAINNAME",g' \
-e 's,"source": .*,"source": "SOURCE",g' \
-e 's,"hostspec": .*,"hostspec": "HOSTSPEC",g' \
-e 's,"timestamp": .*,"timestamp": "TIMESTAMP",g' \
# end
}

_filter_values()
{
_filter_json | \
$PCP_AWK_PROG '
BEGIN { instances=0; count=0 }
/"instances": \[$/ { instances=1; print $0, " ..." }
/\]/ { instances=0 }
{ if (instances != 1) { print } else { count++ } }
END { if (count > 1) { print "GOOD VALUES"} else { print "NO VALUES" } }'
}

_test_log()
{
echo && echo "=== $@ ===" | tee -a $here/$seq.full
}

_json_log()
{
pmjson | tee -a $here/$seq.full
}

echo "hostname=$hostname" >>$seq.full
echo "full_hostname=$full_hostname" >>$seq.full

# real QA test starts here
_save_config $PCP_SYSCONF_DIR/proc
_save_config $PCP_SYSCONF_DIR/labels
_save_config $PCP_SYSCONF_DIR/pmproxy
_save_config $PCP_SASLCONF_DIR/pmcd.conf
need_restore=true
$sudo rm -rf $PCP_SYSCONF_DIR/labels/* $PCP_SYSCONF_DIR/proc/*

# start pmcd in sasldb authenticating mode
echo 'mech_list: plain' >$tmp.sasl
echo "sasldb_path: $tmp.passwd.db" >>$tmp.sasl
$sudo cp $tmp.sasl $PCP_SASLCONF_DIR/pmcd.conf
$sudo chown pcp:pcp $PCP_SASLCONF_DIR/pmcd.conf
ls -l $PCP_SASLCONF_DIR/pmcd.conf >>$seq.full
$sudo -u pcp cat $PCP_SASLCONF_DIR/pmcd.conf >>$seq.full

echo "Creating temporary sasldb, add user running QA to it" | tee -a $seq.full
echo y | saslpasswd2 -p -a pmcd -f $tmp.passwd.db $username

echo "Verify saslpasswd2 has successfully added a new user" | tee -a $seq.full
sasldblistusers2 -f $tmp.passwd.db \
| tee -a $seq.full \
| _filter_listusers2

echo "Ensure pmcd can read the password file" | tee -a $seq.full
$sudo chown pcp:pcp $tmp.passwd.db
ls -l $tmp.passwd.db >>$seq.full
$sudo -u pcp od -c $tmp.passwd.db >>$seq.full

echo "New pmdaproc config without any authentication" | tee -a $seq.full
cat >$tmp.nobody <<EOF
allowed = nobody
mapped = false
EOF

echo "New pmdaproc config with remote authentication" | tee -a $seq.full
cat >$tmp.remote <<EOF
allowed = bob, $username, root
mapped = false
EOF

echo "New pmdaproc config with mapped authentication" | tee -a $seq.full
cat >$tmp.mapped <<EOF
allowed = $username
mapped = true
EOF

echo "Start pmcd with this shiny new sasldb and no access"
$sudo cp $tmp.nobody $PCP_SYSCONF_DIR/proc/access.conf
_service pmcd restart 2>&1 | tee -a $seq.full >$tmp.out
_wait_for_pmcd

echo "Start pmproxy with mandatory authentication"
_service pmproxy stop >/dev/null
_service pmproxy start >>$here/$seq.full 2>&1

test "$PCPQA_SYSTEMD" = yes && $sudo systemctl daemon-reload

_test_log "Establish context for an unauthenticated user"
response=$(curl -s "http://localhost:44322/pmapi/context")
echo "${response}" | pmjson | _filter_json | _filter_credentials
ctx_unauthenticated=$(echo "${response}" | pmpython -c 'import sys,json; print(json.load(sys.stdin)["context"])')

_test_log "I/O metric access using unauthenticated context"
curl -s "http://localhost:44322/pmapi/$ctx_unauthenticated/fetch?names=proc.io.write_bytes" | _json_log | _filter_values
echo

echo "Restart pmcd with this sasldb and remote auth mode"
$sudo cp $tmp.remote $PCP_SYSCONF_DIR/proc/access.conf
_service pmcd restart 2>&1 | tee -a $seq.full >$tmp.out
_wait_for_pmcd

_test_log "Establish context for authenticated user"
response=$(curl -s --user $username:y "http://localhost:44322/pmapi/context")
echo "${response}" | pmjson | _filter_json | _filter_credentials
ctx_authenticated=$(echo "${response}" | pmpython -c 'import sys,json; print(json.load(sys.stdin)["context"])')

_test_log "I/O metric access using authenticated context"
curl -s --user $username:y "http://localhost:44322/pmapi/$ctx_authenticated/fetch?names=proc.io.write_bytes" | _json_log | _filter_values
echo

echo "Restart pmcd with this sasldb and mapped auth mode"
$sudo cp $tmp.mapped $PCP_SYSCONF_DIR/proc/access.conf
_service pmcd restart 2>&1 | tee -a $seq.full >$tmp.out
_wait_for_pmcd

_test_log "Establish context for authenticated user"
response=$(curl -s --user $username:y "http://localhost:44322/pmapi/context")
echo "${response}" | pmjson | _filter_json | _filter_credentials
ctx_authenticated=$(echo "${response}" | pmpython -c 'import sys,json; print(json.load(sys.stdin)["context"])')

_test_log "I/O metric access using mapped authentication"
curl -s --user $username:y "http://localhost:44322/pmapi/$ctx_authenticated/fetch?names=proc.io.write_bytes" | _json_log | _filter_values
echo

echo >>$here/$seq.full
echo "=== pmcd log ===" >>$here/$seq.full
cat $PCP_LOG_DIR/pmcd/pmcd.log >>$here/$seq.full
echo "=== pmproxy log ===" >>$here/$seq.full
cat $PCP_LOG_DIR/pmproxy/pmproxy.log >>$here/$seq.full
echo "=== proc PMDA log ===" >>$here/$seq.full
cat $PCP_LOG_DIR/pmcd/proc.log >>$here/$seq.full

# success, all done
status=0
exit
Loading

0 comments on commit ceccf46

Please sign in to comment.