Skip to content

Commit

Permalink
Merge pull request #4743 from iokomin/add_rule_syslog_files_tests
Browse files Browse the repository at this point in the history
Add syslog_files rules test scenarios
  • Loading branch information
mildas committed Aug 22, 2019
2 parents 4d2d00c + c4655f4 commit 365a295
Show file tree
Hide file tree
Showing 28 changed files with 1,128 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

RSYSLOG_CONF='/etc/rsyslog.conf'
LOG_FILE_PREFIX=test
RSYSLOG_TEST_DIR=/tmp
declare -a RSYSLOG_TEST_LOGS

# This function creates test rsyslog log files
# Parameters: $1 - number of log files to be created
function create_rsyslog_test_logs {
local count=$1

RSYSLOG_TEST_DIR=$(mktemp -d)
RSYSLOG_TEST_LOGS=()

if [ $? -ne 0 ]; then
echo "Failed to create RSYSLOG_TEST_DIR"
exit 1
fi

if ! [[ "$count" =~ ^[0-9]+$ ]] || [ $count -eq 0 ]; then
echo "Argument 'count' is not a positive number: $count"
exit 1
fi

for ind in $(seq 1 $count); do
local testlog=${RSYSLOG_TEST_DIR}/${LOG_FILE_PREFIX}${ind}.log
touch ${testlog}
RSYSLOG_TEST_LOGS+=("${testlog}")
done;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash
# profiles = xccdf_org.ssgproject.content_profile_pci-dss
# platform = multi_platform_rhel,multi_platform_fedora,multi_platform_ol

# Check rsyslog.conf with root group-owner log from rules and
# non root group-owner log from $IncludeConfig fails.

source ../rsyslog_log_utils.sh

GROUP_TEST=testssg
groupadd $GROUP_TEST

GROUP_ROOT=root

# setup test data
create_rsyslog_test_logs 2

# setup test log files ownership
chgrp $GROUP_ROOT ${RSYSLOG_TEST_LOGS[0]}
chgrp $GROUP_TEST ${RSYSLOG_TEST_LOGS[1]}

# create test configuration file
test_conf=${RSYSLOG_TEST_DIR}/test1.conf
cat << EOF > ${test_conf}
# rsyslog configuration file
#### RULES ####
*.* ${RSYSLOG_TEST_LOGS[1]}
EOF

# create rsyslog.conf configuration file
cat << EOF > $RSYSLOG_CONF
# rsyslog configuration file
#### RULES ####
*.* ${RSYSLOG_TEST_LOGS[0]}
#### MODULES ####
\$IncludeConfig ${test_conf}
EOF
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash
# profiles = xccdf_org.ssgproject.content_profile_pci-dss
# platform = multi_platform_rhel,multi_platform_fedora,multi_platform_ol

# Check rsyslog.conf with root group-owner log from rules and
# root group-owner log from $IncludeConfig passes.

source ../rsyslog_log_utils.sh

GROUP=root

# setup test data
create_rsyslog_test_logs 2

# setup test log files ownership
chgrp $GROUP ${RSYSLOG_TEST_LOGS[0]}
chgrp $GROUP ${RSYSLOG_TEST_LOGS[1]}

# create test configuration file
test_conf=${RSYSLOG_TEST_DIR}/test1.conf
cat << EOF > ${test_conf}
# rsyslog configuration file
#### RULES ####
*.* ${RSYSLOG_TEST_LOGS[1]}
EOF

# create rsyslog.conf configuration file
cat << EOF > $RSYSLOG_CONF
# rsyslog configuration file
#### RULES ####
*.* ${RSYSLOG_TEST_LOGS[0]}
#### MODULES ####
\$IncludeConfig ${test_conf}
EOF
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash
# profiles = xccdf_org.ssgproject.content_profile_pci-dss
# platform = Red Hat Enterprise Linux 8,multi_platform_fedora,Oracle Linux 8

# Check rsyslog.conf with root group-owner log from rules and
# non root group-owner log from include() fails.

source ../rsyslog_log_utils.sh

GROUP_TEST=testssg
groupadd $GROUP_TEST

GROUP_ROOT=root

# setup test data
create_rsyslog_test_logs 2

# setup test log files ownership
chgrp $GROUP_ROOT ${RSYSLOG_TEST_LOGS[0]}
chgrp $GROUP_TEST ${RSYSLOG_TEST_LOGS[1]}

# create test configuration file
test_conf=${RSYSLOG_TEST_DIR}/test1.conf
cat << EOF > ${test_conf}
# rsyslog configuration file
#### RULES ####
*.* ${RSYSLOG_TEST_LOGS[1]}
EOF

# create rsyslog.conf configuration file
cat << EOF > $RSYSLOG_CONF
# rsyslog configuration file
#### RULES ####
*.* ${RSYSLOG_TEST_LOGS[0]}
#### MODULES ####
include(file="${test_conf}")
EOF
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash
# profiles = xccdf_org.ssgproject.content_profile_pci-dss
# platform = Red Hat Enterprise Linux 8,multi_platform_fedora,Oracle Linux 8

# Check rsyslog.conf with root group-owner log from rules and
# root group-owner log from include() passes.

source ../rsyslog_log_utils.sh

GROUP=root

# setup test data
create_rsyslog_test_logs 2

# setup test log files ownership
chgrp $GROUP ${RSYSLOG_TEST_LOGS[0]}
chgrp $GROUP ${RSYSLOG_TEST_LOGS[1]}

# create test configuration file
test_conf=${RSYSLOG_TEST_DIR}/test1.conf
cat << EOF > ${test_conf}
# rsyslog configuration file
#### RULES ####
*.* ${RSYSLOG_TEST_LOGS[1]}
EOF

# create rsyslog.conf configuration file
cat << EOF > $RSYSLOG_CONF
# rsyslog configuration file
#### RULES ####
*.* ${RSYSLOG_TEST_LOGS[0]}
#### MODULES ####
include(file="${test_conf}")
EOF
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash
# profiles = xccdf_org.ssgproject.content_profile_pci-dss
# platform = Red Hat Enterprise Linux 8,multi_platform_fedora,Oracle Linux 8

# Check rsyslog.conf with root group-owner log from rules and
# non root group-owner log from include() fails.

source ../rsyslog_log_utils.sh

GROUP_ROOT=root

GROUP_TEST=testssg
groupadd $GROUP_TEST

# setup test data
create_rsyslog_test_logs 3

# setup test log files ownership
chgrp $GROUP_ROOT ${RSYSLOG_TEST_LOGS[0]}
chgrp $GROUP_ROOT ${RSYSLOG_TEST_LOGS[1]}
chgrp $GROUP_TEST ${RSYSLOG_TEST_LOGS[2]}

# create test configuration file
test_conf=${RSYSLOG_TEST_DIR}/test1.conf
cat << EOF > ${test_conf}
# rsyslog configuration file
#### RULES ####
*.* ${RSYSLOG_TEST_LOGS[1]}
EOF

# create test2 configuration file
test_conf2=${RSYSLOG_TEST_DIR}/test2.conf
cat << EOF > ${test_conf2}
# rsyslog configuration file
#### RULES ####
*.* ${RSYSLOG_TEST_LOGS[2]}
EOF

# create rsyslog.conf configuration file
cat << EOF > $RSYSLOG_CONF
# rsyslog configuration file
#### RULES ####
*.* ${RSYSLOG_TEST_LOGS[0]}
#### MODULES ####
include(file="${test_conf}")
\$IncludeConfig ${test_conf2}
EOF
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash
# profiles = xccdf_org.ssgproject.content_profile_pci-dss
# platform = Red Hat Enterprise Linux 8,multi_platform_fedora,Oracle Linux 8

# Check rsyslog.conf with root group-owner log from rules and
# root group-owner log from include() passes.

source ../rsyslog_log_utils.sh

GROUP=root

# setup test data
create_rsyslog_test_logs 3

# setup test log files ownership
chgrp $GROUP ${RSYSLOG_TEST_LOGS[0]}
chgrp $GROUP ${RSYSLOG_TEST_LOGS[1]}
chgrp $GROUP ${RSYSLOG_TEST_LOGS[2]}

# create test configuration file
test_conf=${RSYSLOG_TEST_DIR}/test1.conf
cat << EOF > ${test_conf}
# rsyslog configuration file
#### RULES ####
*.* ${RSYSLOG_TEST_LOGS[1]}
EOF

# create test2 configuration file
test_conf2=${RSYSLOG_TEST_DIR}/test2.conf
cat << EOF > ${test_conf2}
# rsyslog configuration file
#### RULES ####
*.* ${RSYSLOG_TEST_LOGS[2]}
EOF

# create rsyslog.conf configuration file
cat << EOF > $RSYSLOG_CONF
# rsyslog configuration file
#### RULES ####
*.* ${RSYSLOG_TEST_LOGS[0]}
#### MODULES ####
include(file="${test_conf}")
\$IncludeConfig ${test_conf2}
EOF
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash
# profiles = xccdf_org.ssgproject.content_profile_pci-dss
# platform = Red Hat Enterprise Linux 8,multi_platform_fedora,Oracle Linux 8

# Check rsyslog.conf with root group-owner log from rules and
# root group-owner log from multiline include() passes.

source ../rsyslog_log_utils.sh

GROUP=root

# setup test data
create_rsyslog_test_logs 2

# setup test log files ownership
chgrp $GROUP ${RSYSLOG_TEST_LOGS[0]}
chgrp $GROUP ${RSYSLOG_TEST_LOGS[1]}

# create test configuration file
test_conf=${RSYSLOG_TEST_DIR}/test1.conf
cat << EOF > ${test_conf}
# rsyslog configuration file
#### RULES ####
*.* ${RSYSLOG_TEST_LOGS[1]}
EOF

# create rsyslog.conf configuration file
cat << EOF > $RSYSLOG_CONF
# rsyslog configuration file
#### RULES ####
*.* ${RSYSLOG_TEST_LOGS[0]}
#### MODULES ####
include(
file="${test_conf}"
)
EOF
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
# profiles = xccdf_org.ssgproject.content_profile_pci-dss
# platform = multi_platform_rhel,multi_platform_fedora,multi_platform_ol

# Check if log file with non root group-owner in rsyslog.conf fails.

source ../rsyslog_log_utils.sh

GROUP=testssg

groupadd $GROUP

# setup test data
create_rsyslog_test_logs 1

# setup test log file ownership
chgrp $GROUP ${RSYSLOG_TEST_LOGS[0]}

# add rule with non-root group owned log file
cat << EOF > $RSYSLOG_CONF
# rsyslog configuration file
#### RULES ####
*.* ${RSYSLOG_TEST_LOGS[0]}
EOF
Loading

0 comments on commit 365a295

Please sign in to comment.