mirror of
https://github.com/ovh/debian-cis.git
synced 2024-12-22 22:15:24 +01:00
ADD(4.4): add logrotate permissions checking
This commit is contained in:
parent
d0ab72dd26
commit
e2ad0a5dcc
@ -17,14 +17,45 @@ HARDENING_LEVEL=3
|
||||
# shellcheck disable=2034
|
||||
DESCRIPTION="Configure logrotate to assign appropriate permissions."
|
||||
|
||||
FILE="/etc/logrotate.conf"
|
||||
PATTERN="^\s*create\s+\S+"
|
||||
PERMISSIONS=0640
|
||||
|
||||
# This function will be called if the script status is on enabled / audit mode
|
||||
audit() {
|
||||
:
|
||||
does_pattern_exist_in_file "$FILE" "$PATTERN"
|
||||
if [ "$FNRET" != 0 ]; then
|
||||
crit "Logrotate permissions are not configured"
|
||||
else
|
||||
if grep -E "$PATTERN" "$FILE" | grep -E -v "\s(0)?[0-6][04]0\s"; then
|
||||
crit "Logrotate permissions are not set to $PERMISSIONS"
|
||||
else
|
||||
ok "Logrotate permissions are well configured"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# This function will be called if the script status is on enabled mode
|
||||
apply() {
|
||||
:
|
||||
does_pattern_exist_in_file "$FILE" "$PATTERN"
|
||||
if [ "$FNRET" != 0 ]; then
|
||||
warn "Logrotate permissions are not configured, fixing it"
|
||||
add_end_of_file "$FILE" "create $PERMISSIONS root utmp"
|
||||
else
|
||||
RESULT=$(grep -E "$PATTERN" "$FILE" | grep -E -v "\s(0)?[0-6][04]0\s")
|
||||
if [[ -n "$RESULT" ]]; then
|
||||
warn "Logrotate permissions are not set to $PERMISSIONS, fixing it"
|
||||
d_IFS=$IFS
|
||||
c_IFS=$'\n'
|
||||
IFS=$c_IFS
|
||||
for SOURCE in $RESULT; do
|
||||
replace_in_file "$FILE" "$SOURCE" "create $PERMISSIONS root utmp"
|
||||
done
|
||||
IFS=$d_IFS
|
||||
else
|
||||
ok "Logrotate permissions are well configured"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# This function will check config parameters required
|
||||
|
@ -7,5 +7,18 @@ test_audit() {
|
||||
# shellcheck disable=2154
|
||||
run blank /opt/debian-cis/bin/hardening/"${script}".sh --audit-all
|
||||
|
||||
# TODO fill comprehensive tests
|
||||
describe Tests purposely failing
|
||||
echo "create 0660 root utmp" >/etc/logrotate.conf
|
||||
register_test retvalshouldbe 1
|
||||
register_test contain "Logrotate permissions are not set to"
|
||||
run noncompliant /opt/debian-cis/bin/hardening/"${script}".sh --audit-all
|
||||
|
||||
describe correcting situation
|
||||
sed -i 's/audit/enabled/' /opt/debian-cis/etc/conf.d/"${script}".cfg
|
||||
/opt/debian-cis/bin/hardening/"${script}".sh --apply || true
|
||||
|
||||
describe Checking resolved state
|
||||
register_test retvalshouldbe 0
|
||||
register_test contain "Logrotate permissions are well configured"
|
||||
run resolved /opt/debian-cis/bin/hardening/"${script}".sh --audit-all
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user