Skip to content

Commit

Permalink
systemtests: split off python-pam from bconsole-pam test
Browse files Browse the repository at this point in the history
  • Loading branch information
pstorz committed Jan 24, 2020
1 parent b7fa571 commit 64852c2
Show file tree
Hide file tree
Showing 34 changed files with 431 additions and 9 deletions.
7 changes: 6 additions & 1 deletion systemtests/CMakeLists.txt
Expand Up @@ -614,6 +614,7 @@ endif()


message(STATUS "Looking for pam test requirements ...")
find_program(PYTHON python)

find_program(PAMTESTER pamtester)

Expand Down Expand Up @@ -644,6 +645,11 @@ else()
endif()


if(ENABLE_BCONSOLE_PAM_TEST AND PYTHON )
list(APPEND SYSTEM_TESTS "python-pam")
else()
list(APPEND SYSTEM_TESTS_DISABLED "python-pam")
endif()



Expand All @@ -653,7 +659,6 @@ endif()
message(STATUS "Looking for webui test requirements ...")

find_program(PERL perl)
find_program(PYTHON python)
find_program(PHP php)
find_program(CHROMEDRIVER chromedriver)
pythonmodulestatus("selenium") # sets PYTHON_SELENIUM_FOUND to TRUE or FALSE
Expand Down
6 changes: 0 additions & 6 deletions systemtests/tests/bconsole-pam/testrunner
Expand Up @@ -127,12 +127,6 @@ if ! grep -q "Running Jobs:" ${tmp}/log5.out; then
fi


#
# run Python Unit Tests
#
run_python_unittests


if ! ${rscripts}/bareos-ctl-dir status >/dev/null; then
set_error "Director does not run anymore. This should not happen."
exit 1
Expand Down
33 changes: 33 additions & 0 deletions systemtests/tests/python-pam/bin/check_pam_exec_available.sh
@@ -0,0 +1,33 @@
#!/bin/sh

#
# Verify that our test pam configuration works.
# It uses
# * pam_wrapper to redirect PAM to our test environemnt, using a specific service file
# * pamtester to test PAM without the need to run Bareos
# * pam_exec.so is defined in the bareos PAM service file.
# It is configured to accept all logins where USERNAME = PASSWORD.
#

set -e
set -u

export PAM_WRAPPER=1
export PAM_WRAPPER_SERVICE_DIR=etc/pam.d/bareos_discover_pam_exec

if ! [ -e "${PAM_WRAPPER_SERVICE_DIR}" ]; then
echo "PAM service file ${PAM_WRAPPER_SERVICE_DIR} not found"
exit 1
fi

# DEBUG
#export PAM_WRAPPER_DEBUGLEVEL=4

# PAM_WRAPPER creates extra environments in /tmp/pam.*/

# PAM_WRAPPER_LIBRARIES will be set my cmake
USERNAME="user"
PASSWORD="user"
echo "$PASSWORD" | LD_PRELOAD=${PAM_WRAPPER_LIBRARIES} pamtester bareos_discover_pam_exec "$USERNAME" authenticate > /dev/null 2>&1

exit $?
74 changes: 74 additions & 0 deletions systemtests/tests/python-pam/bin/pam_exec_check.sh
@@ -0,0 +1,74 @@
#!/bin/sh

# auth optional pam_exec.so expose_authtok debug log=/tmp/pam.log /usr/bin/sc_pam_wlan.sh

# called by:
# auth optional pam_exec.so expose_authtok /usr/bin/sc_pam_wlan.sh

# pam_exec options:
# debug
# expose_authtok
# During authentication the calling command can read the password from stdin(3).
# (PAM_TYPE=auth only)
# log=file
# The output of the command is appended to file
# type=type
# Only run the command if the module type matches the given type.
# stdout
# Per default the output of the executed command is written to /dev/null.
# With this option, the stdout output of the executed command is redirected
# to the calling application.
# It's in the responsibility of this application what happens with the output.
# The log option is ignored.
# quiet
# Per default pam_exec.so will echo the exit status of the external command
# if it fails. Specifying this option will suppress the message.
# seteuid
# Per default pam_exec.so will execute the external command
# with the real user ID of the calling process.
# Specifying this option means the command is run with the effective user ID.

# PAM_TYPE:
# "auth"
# ...
# "open_session"
# "close_session"

RC_OK=0
RC_SKIP=1
RC_NOK=2

echo "$0"
#echo "current user: $USER ($UID)"

if [ "$PAM_TYPE" != "auth" ]; then
echo "only pam type auth supported, not $PAM_TYPE"
exit $RC_SKIP
fi

echo "PAM settings:"
echo "User: $PAM_USER"
echo "Ruser: $PAM_RUSER"
echo "Rhost: $PAM_RHOST"
echo "Service: $PAM_SERVICE"
echo "TTY: $PAM_TTY"

USERNAME="$PAM_USER"
# This does not work in PAM environment
# if [ -z "$PAM_USER" ]; then
# read -p "PE Login: " USERNAME
# fi


read -p "PE Passwort: " PASSWORD


if [ "$USERNAME" = "$PASSWORD" ]; then
echo "grant access for $USERNAME"
RC=$RC_OK
else
echo "deny access for $USERNAME"
RC=$RC_NOK
fi

exit $RC
@@ -0,0 +1,8 @@
Catalog {
Name = MyCatalog
#dbdriver = "@DEFAULT_DB_TYPE@"
dbdriver = "XXX_REPLACE_WITH_DATABASE_DRIVER_XXX"
dbname = "@db_name@"
dbuser = "@db_user@"
dbpassword = "@db_password@"
}
@@ -0,0 +1,7 @@
Client {
Name = bareos-fd
Description = "Client resource of the Director itself."
Address = localhost
Password = "@fd_password@" # password for FileDaemon
FD PORT = @fd_port@
}
@@ -0,0 +1,6 @@
Console {
Name = "PamConsole-notls"
Password = "secret"
UsePamAuthentication = yes
TLS Enable = no
}
@@ -0,0 +1,5 @@
Console {
Name = "PamConsole"
Password = "secret"
UsePamAuthentication = yes
}
@@ -0,0 +1,5 @@
Console {
Name = "admin"
Password = "secret"
Profile = "operator"
}
@@ -0,0 +1,27 @@
Director { # define myself
Name = bareos-dir
QueryFile = "@scriptdir@/query.sql"
Maximum Concurrent Jobs = 10
Password = "@dir_password@" # Console password
Messages = Daemon
Auditing = yes

# Enable the Heartbeat if you experience connection losses
# (eg. because of your router or firewall configuration).
# Additionally the Heartbeat can be enabled in bareos-sd and bareos-fd.
#
# Heartbeat Interval = 1 min

# remove comment in next line to load dynamic backends from specified directory
Backend Directory = @backenddir@

# remove comment from "Plugin Directory" to load plugins from specified directory.
# if "Plugin Names" is defined, only the specified plugins will be loaded,
# otherwise all director plugins (*-dir.so) from the "Plugin Directory".
#
# Plugin Directory = "@python_plugin_module_src_dir@"
# Plugin Names = ""
Working Directory = "@working_dir@"
Pid Directory = "@piddir@"
DirPort = @dir_port@
}
@@ -0,0 +1,11 @@
FileSet {
Name = "Catalog"
Description = "Backup the catalog dump and Bareos configuration files."
Include {
Options {
signature = MD5
}
File = "@working_dir@/@db_name@.sql" # database dump
File = "@confdir@" # configuration
}
}
@@ -0,0 +1,11 @@
FileSet {
Name = "SelfTest"
Description = "fileset just to backup some files for selftest"
Include {
Options {
Signature = MD5 # calculate md5 checksum per file
}
#File = "@sbindir@"
File=<@tmpdir@/file-list
}
}
@@ -0,0 +1,11 @@
Job {
Name = "RestoreFiles"
Description = "Standard Restore template. Only one such job is needed for all standard Jobs/Clients/Storage ..."
Type = Restore
Client = bareos-fd
FileSet = SelfTest
Storage = File
Pool = Incremental
Messages = Standard
Where = @tmp@/bareos-restores
}
@@ -0,0 +1,5 @@
Job {
Name = "backup-bareos-fd"
JobDefs = "DefaultJob"
Client = "bareos-fd"
}
@@ -0,0 +1,15 @@
JobDefs {
Name = "DefaultJob"
Type = Backup
Level = Incremental
Client = bareos-fd
FileSet = "SelfTest"
Storage = File
Messages = Standard
Pool = Incremental
Priority = 10
Write Bootstrap = "@working_dir@/%c.bsr"
Full Backup Pool = Full # write Full Backups into "Full" Pool
Differential Backup Pool = Differential # write Diff Backups into "Differential" Pool
Incremental Backup Pool = Incremental # write Incr Backups into "Incremental" Pool
}
@@ -0,0 +1,7 @@
Messages {
Name = Daemon
Description = "Message delivery for daemon messages (no job)."
console = all, !skipped, !saved, !audit
append = "@logdir@/bareos.log" = all, !skipped, !audit
append = "@logdir@/bareos-audit.log" = audit
}
@@ -0,0 +1,7 @@
Messages {
Name = Standard
Description = "Reasonable message delivery -- send most everything to email address and to the console."
console = all, !skipped, !saved, !audit
append = "@logdir@/bareos.log" = all, !skipped, !saved, !audit
catalog = all, !skipped, !saved, !audit
}
@@ -0,0 +1,10 @@
Pool {
Name = Differential
Pool Type = Backup
Recycle = yes # Bareos can automatically recycle Volumes
AutoPrune = yes # Prune expired volumes
Volume Retention = 90 days # How long should the Differential Backups be kept? (#09)
Maximum Volume Bytes = 10G # Limit Volume size to something reasonable
Maximum Volumes = 100 # Limit number of Volumes in Pool
Label Format = "Differential-" # Volumes will be labeled "Differential-<volume-id>"
}
@@ -0,0 +1,10 @@
Pool {
Name = Full
Pool Type = Backup
Recycle = yes # Bareos can automatically recycle Volumes
AutoPrune = yes # Prune expired volumes
Volume Retention = 365 days # How long should the Full Backups be kept? (#06)
Maximum Volume Bytes = 50G # Limit Volume size to something reasonable
Maximum Volumes = 100 # Limit number of Volumes in Pool
Label Format = "Full-" # Volumes will be labeled "Full-<volume-id>"
}
@@ -0,0 +1,10 @@
Pool {
Name = Incremental
Pool Type = Backup
Recycle = yes # Bareos can automatically recycle Volumes
AutoPrune = yes # Prune expired volumes
Volume Retention = 30 days # How long should the Incremental Backups be kept? (#12)
Maximum Volume Bytes = 1G # Limit Volume size to something reasonable
Maximum Volumes = 100 # Limit number of Volumes in Pool
Label Format = "Incremental-" # Volumes will be labeled "Incremental-<volume-id>"
}
@@ -0,0 +1,4 @@
Pool {
Name = Scratch
Pool Type = Scratch
}
@@ -0,0 +1,18 @@
Profile {
Name = operator
Description = "Profile allowing normal Bareos operations."

Command ACL = !.bvfs_clear_cache, !.exit, !.sql
Command ACL = configure, !create, !delete, !purge, !prune, !sqlquery, !umount, !unmount
Command ACL = *all*

Catalog ACL = *all*
Client ACL = *all*
FileSet ACL = *all*
Job ACL = *all*
Plugin Options ACL = *all*
Pool ACL = *all*
Schedule ACL = *all*
Storage ACL = *all*
Where ACL = *all*
}
@@ -0,0 +1,8 @@
Storage {
Name = File
Address = @hostname@ # N.B. Use a fully qualified name here (do not use "localhost" here).
Password = "@sd_password@"
Device = FileStorage
Media Type = File
SD Port = @sd_port@
}
@@ -0,0 +1,4 @@
User {
Name = "user1"
Profile = operator
}
@@ -0,0 +1,4 @@
User {
Name = "user2"
Profile = operator
}
10 changes: 10 additions & 0 deletions systemtests/tests/python-pam/etc/bareos/bconsole-default.conf.in
@@ -0,0 +1,10 @@
#
# Bareos User Agent (or Console) Configuration File
#

Director {
Name = @basename@-dir
DIRport = @dir_port@
address = @hostname@
Password = "@dir_password@"
}
15 changes: 15 additions & 0 deletions systemtests/tests/python-pam/etc/bareos/bconsole.conf.in
@@ -0,0 +1,15 @@
#
# Bareos User Agent (or Console) Configuration File
#

Director {
Name = @basename@-dir
DIRport = @dir_port@
address = @hostname@
Password = ""
}

Console {
Name = PamConsole
Password = "secret"
}
4 changes: 4 additions & 0 deletions systemtests/tests/python-pam/etc/pam.d/bareos.in
@@ -0,0 +1,4 @@
#
# PAM settings for service bareos.
#
auth required pam_exec.so expose_authtok debug quiet log=@PROJECT_BINARY_DIR@/tests/@TEST_NAME@/log/pam_exec_check.log @PROJECT_BINARY_DIR@/tests/@TEST_NAME@/bin/pam_exec_check.sh

0 comments on commit 64852c2

Please sign in to comment.