From 612a90d844e3497a0aaafbc34650c119410ce58f Mon Sep 17 00:00:00 2001 From: Samson-W Date: Sat, 15 Jul 2023 02:03:40 +0800 Subject: [PATCH] Fix #50: Autofix improvement: Ensure journald is configured to write logfiles to persistent disk --- .../8.7.2_journald_config_storage.sh | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100755 bin/hardening/8.7.2_journald_config_storage.sh diff --git a/bin/hardening/8.7.2_journald_config_storage.sh b/bin/hardening/8.7.2_journald_config_storage.sh new file mode 100755 index 0000000..bda9602 --- /dev/null +++ b/bin/hardening/8.7.2_journald_config_storage.sh @@ -0,0 +1,70 @@ +#!/bin/bash + +# +# harbian-audit for Debian GNU/Linux 9/10/11/12 +# + +# +# 8.7.1 Ensure journald is configured to compress large log files (Scored) +# Author : Samson wen, Samson +# + +set -e # One error, it's over +set -u # One variable unset, it's over + +HARDENING_LEVEL=3 + +CONFFILE='/etc/systemd/journald.conf' +OPTION='Storage' +OPTION_VAL='persistent' + +# This function will be called if the script status is on enabled / audit mode +audit () { + check_param_pair_by_str $CONFFILE $OPTION $OPTION_VAL + if [ $FNRET = 0 ]; then + ok "$OPTION set is $OPTION_VAL in $CONFFILE." + elif [ $FNRET = 1 ]; then + crit "$CONFFILE is not found!" + elif [ $FNRET = 2 ]; then + crit "$OPTION set is not $OPTION_VAL in $CONFFILE!" + elif [ $FNRET = 3 ]; then + crit "$OPTION is not present in $CONFFILE!" + fi +} + +apply () { + if [ $FNRET = 0 ]; then + ok "$OPTION set is $OPTION_VAL in $CONFFILE." + elif [ $FNRET = 1 ]; then + crit "$CONFFILE is not found, please check!" + elif [ $FNRET = 2 ]; then + warn "$OPTION set is not $OPTION_VAL in $CONFFILE, reset to $OPTION_VAL" + reset_option_str_to_journald $CONFFILE $OPTION $OPTION_VAL + elif [ $FNRET = 3 ]; then + warn "$OPTION is not present in $CONFFILE, add to $CONFFILE" + add_end_of_file $CONFFILE "${OPTION}=${OPTION_VAL}" + fi +} + +# This function will check config parameters required +check_config() { + : +} + +# Source Root Dir Parameter +if [ -r /etc/default/cis-hardening ]; then + . /etc/default/cis-hardening +fi +if [ -z "$CIS_ROOT_DIR" ]; then + echo "There is no /etc/default/cis-hardening file nor cis-hardening directory in current environment." + echo "Cannot source CIS_ROOT_DIR variable, aborting." + exit 128 +fi + +# Main function, will call the proper functions given the configuration (audit, enabled, disabled) +if [ -r $CIS_ROOT_DIR/lib/main.sh ]; then + . $CIS_ROOT_DIR/lib/main.sh +else + echo "Cannot find main.sh, have you correctly defined your root directory? Current value is $CIS_ROOT_DIR in /etc/default/cis-hardening" + exit 128 +fi