V8.00.000.2025.06.17
All checks were successful
🛡️ Shell Script Linting / 🛡️ Shell Script Linting (push) Successful in 2m7s

Signed-off-by: Marc S. Weidner <msw@coresecret.dev>
This commit is contained in:
2025-10-21 14:29:32 +01:00
parent 13b5f09e24
commit aa49722611
6 changed files with 219 additions and 96 deletions

View File

@@ -62,6 +62,7 @@ installation_toolset() {
[pwgen]="pwgen" [pwgen]="pwgen"
[rsyslogd]="rsyslog" [rsyslogd]="rsyslog"
[sudo]="sudo" [sudo]="sudo"
[pam_systemd]="libpam-systemd"
[tree]="tree" [tree]="tree"
[unzip]="unzip" [unzip]="unzip"
[lsusb]="usbutils" [lsusb]="usbutils"

View File

@@ -62,14 +62,13 @@ EOF
### fail2ban ufw aggressive mode, one attempt for jumphost configuration. ### fail2ban ufw aggressive mode, one attempt for jumphost configuration.
cat << EOF >> "${var_target}/etc/fail2ban/jail.d/ciss-default.conf" cat << EOF >> "${var_target}/etc/fail2ban/jail.d/ciss-default.conf"
[DEFAULT] [DEFAULT]
usedns = yes dbpurgeage = 384d
# 127.0.0.1/8 IPv4 loopback range (local host) # 127.0.0.1/8 - IPv4 loopback range (local host)
# ::1/128 IPv6 loopback # ::1/128 - IPv6 loopback
# fe80::/10 IPv6 link-local (on-link only; NDP/RA/DAD) # fe80::/10 - IPv6 link-local (on-link only; NDP/RA/DAD)
# fc00::/7 IPv6 ULA (private LAN addresses) # ff00::/8 - IPv6 multicast (not an unicast host)
# ff00::/8 IPv6 multicast (not an unicast host) # ::/128 - IPv6 unspecified (all zeros; never a real peer)
# ::/128 IPv6 unspecified (all zeros; never a real peer) ignoreip = 127.0.0.1/8 ::1/128 fe80::/10 ff00::/8 ::/128
ignoreip = 127.0.0.1/8 ::1/128 fe80::/10 fc00::/7 ff00::/8 ::/128
# ${VAR_FINAL_FQDN} # ${VAR_FINAL_FQDN}
${VAR_FINAL_IPV4} ${VAR_FINAL_IPV4}
EOF EOF
@@ -94,53 +93,74 @@ EOF
fi fi
cat << EOF >> "${var_target}/etc/fail2ban/jail.d/ciss-default.conf" cat << EOF >> "${var_target}/etc/fail2ban/jail.d/ciss-default.conf"
maxretry = 3 usedns = yes
findtime = 1d
bantime = 1h
bantime.increment = true
bantime.factor = 1
bantime.maxtime = 16d
bantime.overalljails = true
bantime.rndtime = 877s
[recidive] [recidive]
enabled = true enabled = true
filter = recidive banaction = ufw[blocktype=deny]
logpath = /var/log/fail2ban/fail2ban.log*
banaction = iptables-allports
maxretry = 3
findtime = 16d
bantime = 8d bantime = 8d
bantime.increment = true bantime.increment = true
bantime.factor = 1 bantime.factor = 1
bantime.maxtime = 96d bantime.maxtime = 128d
bantime.multipliers = 1, 2, 4, 8 bantime.multipliers = 1 2 4 8 16
bantime.overalljails = true bantime.overalljails = true
bantime.rndtime = 877s bantime.rndtime = 877s
filter = recidive
findtime = 16d
logpath = /var/log/fail2ban/fail2ban.log*
maxretry = 3
[sshd] [sshd]
enabled = true enabled = true
backend = systemd backend = systemd
bantime = 1h
bantime.increment = true
bantime.factor = 1
bantime.maxtime = 16d
bantime.multipliers = 1 2 4 8 16 32 64 128 256 384
bantime.overalljails = true
bantime.rndtime = 877s
filter = sshd filter = sshd
mode = normal findtime = 16m
mode = aggressive
port = ${VAR_SSH_PORT} port = ${VAR_SSH_PORT}
protocol = tcp protocol = tcp
logpath = /var/log/auth.log
maxretry = 4 maxretry = 4
# #
# ufw aggressive approach: # CISS aggressive approach:
# Any valid client communicating with our server should be going directly to the service ports opened in ufw (ssh, 80, ...). # Any valid client communicating with our server should be going directly to the service ports opened in ufw (ssh, 80, ...).
# Any client touching other ports is treated as malicious and therefore should be blocked access to ALL ports after 1 attempt. # Any client touching other ports is treated as malicious and therefore should be blocked access to ALL ports after 1 attempt.
# There is no necessity to ping our servers excessively. Any client pinging us more than 1 times will be blocked.
# #
[icmp]
enabled = true
banaction = ufw[blocktype=deny]
bantime = 1h
bantime.increment = true
bantime.factor = 1
bantime.maxtime = 16d
bantime.multipliers = 1 2 4 8 16 32 64 128 256 384
bantime.overalljails = true
bantime.rndtime = 877s
filter = ciss.icmp
findtime = 16m
logpath = /var/log/ufw.log
maxretry = 1
[ufw] [ufw]
enabled = true enabled = true
banaction = ufw[blocktype=deny]
bantime = 1h
bantime.increment = true
bantime.factor = 1
bantime.maxtime = 16d
bantime.multipliers = 1 2 4 8 16 32 64 128 256 384
bantime.overalljails = true
bantime.rndtime = 877s
filter = ciss.ufw filter = ciss.ufw
action = iptables-allports findtime = 16m
logpath = /var/log/ufw.log logpath = /var/log/ufw.log
maxretry = 1 maxretry = 1
@@ -152,14 +172,13 @@ EOF
### fail2ban ufw aggressive mode, 32 attempts for NO jumphost configuration. ### fail2ban ufw aggressive mode, 32 attempts for NO jumphost configuration.
cat << EOF >> "${var_target}/etc/fail2ban/jail.d/ciss-default.conf" cat << EOF >> "${var_target}/etc/fail2ban/jail.d/ciss-default.conf"
[DEFAULT] [DEFAULT]
usedns = yes dbpurgeage = 384d
# 127.0.0.1/8 IPv4 loopback range (local host) # 127.0.0.1/8 - IPv4 loopback range (local host)
# ::1/128 IPv6 loopback # ::1/128 - IPv6 loopback
# fe80::/10 IPv6 link-local (on-link only; NDP/RA/DAD) # fe80::/10 - IPv6 link-local (on-link only; NDP/RA/DAD)
# fc00::/7 IPv6 ULA (private LAN addresses) # ff00::/8 - IPv6 multicast (not an unicast host)
# ff00::/8 IPv6 multicast (not an unicast host) # ::/128 - IPv6 unspecified (all zeros; never a real peer)
# ::/128 IPv6 unspecified (all zeros; never a real peer) ignoreip = 127.0.0.1/8 ::1/128 fe80::/10 ff00::/8 ::/128
ignoreip = 127.0.0.1/8 ::1/128 fe80::/10 fc00::/7 ff00::/8 ::/128
# ${VAR_FINAL_FQDN} # ${VAR_FINAL_FQDN}
${VAR_FINAL_IPV4} ${VAR_FINAL_IPV4}
EOF EOF
@@ -172,55 +191,76 @@ EOF
fi fi
cat << EOF >> "${var_target}/etc/fail2ban/jail.d/ciss-default.conf" cat << EOF >> "${var_target}/etc/fail2ban/jail.d/ciss-default.conf"
maxretry = 3 usedns = yes
findtime = 1d
bantime = 1h
bantime.increment = true
bantime.factor = 1
bantime.maxtime = 16d
bantime.overalljails = true
bantime.rndtime = 877s
[recidive] [recidive]
enabled = true enabled = true
filter = recidive banaction = ufw[blocktype=deny]
logpath = /var/log/fail2ban/fail2ban.log*
banaction = iptables-allports
maxretry = 3
findtime = 16d
bantime = 8d bantime = 8d
bantime.increment = true bantime.increment = true
bantime.factor = 1 bantime.factor = 1
bantime.maxtime = 96d bantime.maxtime = 128d
bantime.multipliers = 1, 2, 4, 8 bantime.multipliers = 1 2 4 8 16
bantime.overalljails = true bantime.overalljails = true
bantime.rndtime = 877s bantime.rndtime = 877s
filter = recidive
findtime = 16d
logpath = /var/log/fail2ban/fail2ban.log*
maxretry = 3
[sshd] [sshd]
enabled = true enabled = true
backend = systemd backend = systemd
bantime = 1h
bantime.increment = true
bantime.factor = 1
bantime.maxtime = 16d
bantime.multipliers = 1 2 4 8 16 32 64 128 256 384
bantime.overalljails = true
bantime.rndtime = 877s
filter = sshd filter = sshd
mode = normal findtime = 16m
mode = aggressive
port = ${VAR_SSH_PORT} port = ${VAR_SSH_PORT}
protocol = tcp protocol = tcp
logpath = /var/log/auth.log
maxretry = 4 maxretry = 4
# #
# ufw aggressive approach: # CISS aggressive approach:
# Any valid client communicating with our server should be going directly to the service ports opened in ufw (ssh, 80, ...). # Any valid client communicating with our server should be going directly to the service ports opened in ufw (ssh, 80, ...).
# Any client touching other ports is treated as malicious and therefore should be blocked access to ALL ports after 8 attempts. # Any client touching other ports is treated as malicious and therefore should be blocked access to ALL ports after 3 attempts.
# There is no necessity to ping our servers excessively. Any client pinging us more than 3 times will be blocked.
# #
[icmp]
enabled = true
banaction = ufw[blocktype=deny]
bantime = 1h
bantime.increment = true
bantime.factor = 1
bantime.maxtime = 16d
bantime.multipliers = 1 2 4 8 16 32 64 128 256 384
bantime.overalljails = true
bantime.rndtime = 877s
filter = ciss.icmp
findtime = 16m
logpath = /var/log/ufw.log
maxretry = 3
[ufw] [ufw]
enabled = true enabled = true
banaction = ufw[blocktype=deny]
bantime = 1h
bantime.increment = true
bantime.factor = 1
bantime.maxtime = 16d
bantime.multipliers = 1 2 4 8 16 32 64 128 256 384
bantime.overalljails = true
bantime.rndtime = 877s
filter = ciss.ufw filter = ciss.ufw
action = iptables-allports findtime = 16m
logpath = /var/log/ufw.log logpath = /var/log/ufw.log
maxretry = 4 maxretry = 3
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=conf # vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=conf
EOF EOF
@@ -234,12 +274,23 @@ EOF
fi fi
insert_header "${var_target}/etc/fail2ban/filter.d/ciss.icmp.conf"
insert_comments "${var_target}/etc/fail2ban/filter.d/ciss.icmp.conf"
cat << EOF >> "${var_target}/etc/fail2ban/filter.d/ciss.icmp.conf"
[Definition]
# Generic ICMP/ICMPv6 blocks
failregex = ^.*UFW (?:BLOCK|REJECT).*?\bSRC=<HOST>\b.*?\bPROTO=ICMP\b.*$
^.*UFW (?:BLOCK|REJECT).*?\bSRC=<HOST>\b.*?\bPROTO=ICMPv6\b.*$
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=conf
EOF
insert_header "${var_target}/etc/fail2ban/filter.d/ciss.ufw.conf" insert_header "${var_target}/etc/fail2ban/filter.d/ciss.ufw.conf"
insert_comments "${var_target}/etc/fail2ban/filter.d/ciss.ufw.conf" insert_comments "${var_target}/etc/fail2ban/filter.d/ciss.ufw.conf"
cat << EOF >> "${var_target}/etc/fail2ban/filter.d/ciss.ufw.conf" cat << EOF >> "${var_target}/etc/fail2ban/filter.d/ciss.ufw.conf"
[Definition] [Definition]
failregex = \[UFW BLOCK\].+SRC=<HOST> DST # Match UFW BLOCK/REJECT with a source IP and *any* port field (SPT or DPT), protocol may be missing.
failregex = ^.*UFW (?:BLOCK|REJECT).*?\bSRC=<HOST>\b.*?(?:\bDPT=\d+\b|\bSPT=\d+\b).*$
ignoreregex = ignoreregex =
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=conf # vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=conf
@@ -287,19 +338,23 @@ EOF
cp "${var_target}/etc/logrotate.d/fail2ban" "${var_target}/root/.ciss/cdi/backup/etc/logrotate.d/fail2ban.bak" cp "${var_target}/etc/logrotate.d/fail2ban" "${var_target}/root/.ciss/cdi/backup/etc/logrotate.d/fail2ban.bak"
cat << EOF >| "${var_target}/etc/logrotate.d/fail2ban" cat << EOF >| "${var_target}/etc/logrotate.d/fail2ban"
/var/log/fail2ban/fail2ban.log { /var/log/fail2ban/fail2ban.log {
daily daily
rotate 384 rotate 384
compress maxage 384
# Do not rotate if empty
notifempty notifempty
dateext
dateyesterday
compress
compresscmd /usr/bin/zstd
compressext .zst
compressoptions -20
uncompresscmd /usr/bin/unzstd
delaycompress delaycompress
shred
missingok missingok
postrotate postrotate
fail2ban-client flushlogs 1>/dev/null fail2ban-client flushlogs 1>/dev/null
endscript endscript
# If fail2ban runs as non-root it still needs to have write access # If fail2ban runs as non-root it still needs to have write access
# to logfiles. # to logfiles.
# create 640 fail2ban adm # create 640 fail2ban adm

View File

@@ -36,27 +36,49 @@ hardening_logrotate() {
cat << EOF >> "${var_target}/etc/logrotate.conf" cat << EOF >> "${var_target}/etc/logrotate.conf"
# See "man logrotate" for details. Global options do not affect preceding include directives. # See "man logrotate" for details. Global options do not affect preceding include directives.
# rotate log files daily # Rotate log files daily
daily daily
# keep 384 daily worth of backlogs # Keep 384 daily worth of backlogs.
rotate 384 rotate 384
# hard cap: delete rotated logs older than 384 days # Hard cap: delete rotated logs older than 384 days.
maxage 384 maxage 384
# create new (empty) log files after rotating old ones # Do not rotate the log if it is empty (this overrides the ifempty option).
notifempty
# Create new (empty) log files after rotating old ones.
create create
# use date as a suffix of the rotated file # Use date as a suffix of the rotated file.
dateext dateext
# gzip older rotations # Use yesterday's instead of today's date to create the dateext extension, so that the rotated log file has a date in its name
# that is the same as the timestamps within it.
dateyesterday
# Enable compression
compress compress
# keep the most recent rotation uncompressed for one cycle # Use zstd instead of gzip.
compresscmd /usr/bin/zstd
# File extension for compressed logs.
compressext .zst
# Set zstd level 3 (default).
compressoptions -20
# How to decompress for 'logrotate -d' or similar.
uncompresscmd /usr/bin/unzstd
# Keep the most recent rotation uncompressed for one cycle.
delaycompress delaycompress
# Delete log files using shred -u instead of unlink().
shred
# packages drop log rotation information into this directory # packages drop log rotation information into this directory
include /etc/logrotate.d include /etc/logrotate.d

View File

@@ -976,7 +976,6 @@ auth required pam_permit.so
# And here are more per-package modules (the "Additional" block): # And here are more per-package modules (the "Additional" block):
# End of pam-auth-update config.
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=conf # vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=conf
EOF EOF
do_log "info" "file_only" "4520() Written: [/etc/pam.d/common-auth]." do_log "info" "file_only" "4520() Written: [/etc/pam.d/common-auth]."
@@ -987,6 +986,63 @@ EOF
# shellcheck disable=SC2034 # shellcheck disable=SC2034
readonly -f write_pam_common_auth readonly -f write_pam_common_auth
#######################################
# Writes CISS Header for '/etc/pam.d/common-session'.
# Globals:
# None
# Arguments:
# 1: TARGET
# Returns:
# 0: on success
#######################################
write_pam_common_session() {
### Declare Arrays, HashMaps, and Variables.
declare -r var_target="$1"
mv "${var_target}/etc/pam.d/common-session" "${var_target}/root/.ciss/cdi/backup/etc/pam.d/common-session"
insert_header "${var_target}/etc/pam.d/common-session"
insert_comments "${var_target}/etc/pam.d/common-session"
cat << EOF >> "${var_target}/etc/pam.d/common-session"
#
# /etc/pam.d/common-session - session-related modules common to all services
#
# This file is included from other service-specific PAM config files, and should contain a list of modules that define tasks to
# be performed at the start and end of interactive sessions.
# As of pam 1.0.1-6, this file is managed by pam-auth-update by default. To take advantage of this, it is recommended that you
# configure any local modules either before or after the default block, and use pam-auth-update to manage selection of other
# modules. See pam-auth-update(8) for details.
# Here are the per-package modules (the "Primary" block).
session [default=1] pam_permit.so
# Reset the umask for new sessions.
session optional pam_umask.so
# Here is the fallback if no module succeeds.
session requisite pam_deny.so
# Prime the stack with a positive return value if there is not one already; this avoids us returning an error just because
# nothing sets a success code since the modules above will each just jump around.
session required pam_permit.so
# And here are more per-package modules (the "Additional" block).
session required pam_unix.so
session optional pam_systemd.so
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=conf
EOF
do_log "info" "file_only" "4520() Written: [/etc/pam.d/common-session]."
return 0
}
### Prevents accidental 'unset -f'.
# shellcheck disable=SC2034
readonly -f write_pam_common_session
####################################### #######################################
# Writes CISS Header for '/etc/pam.d/login'. # Writes CISS Header for '/etc/pam.d/login'.
# Globals: # Globals:

View File

@@ -13,15 +13,10 @@
: "${XDG_CACHE_HOME:=${HOME}/.cache}" : "${XDG_CACHE_HOME:=${HOME}/.cache}"
: "${XDG_DATA_HOME:=${HOME}/.local/share}" : "${XDG_DATA_HOME:=${HOME}/.local/share}"
: "${XDG_STATE_HOME:=${HOME}/.local/state}" : "${XDG_STATE_HOME:=${HOME}/.local/state}"
if [ -z "${XDG_RUNTIME_DIR:-}" ]; then
if [ -d "/run/user/$(id -u)" ]; then
XDG_RUNTIME_DIR="/run/user/$(id -u)"
else
XDG_RUNTIME_DIR="/tmp/xdg-runtime-$(id -u)"
fi
fi
export XDG_CONFIG_HOME XDG_CACHE_HOME XDG_DATA_HOME XDG_STATE_HOME XDG_RUNTIME_DIR # Do NOT set XDG_RUNTIME_DIR here.
export XDG_CONFIG_HOME XDG_CACHE_HOME XDG_DATA_HOME XDG_STATE_HOME
### Zsh history -> XDG_STATE_HOME (best-effort; zsh might not read /etc/profile) ### Zsh history -> XDG_STATE_HOME (best-effort; zsh might not read /etc/profile)
if [ "${ENABLE_XDG_ZSH_HISTORY:-1}" = "1" ] && [ -n "${ZSH_VERSION:-}" ]; then if [ "${ENABLE_XDG_ZSH_HISTORY:-1}" = "1" ] && [ -n "${ZSH_VERSION:-}" ]; then

View File

@@ -13,15 +13,9 @@
: "${XDG_CACHE_HOME:=${HOME}/.cache}" : "${XDG_CACHE_HOME:=${HOME}/.cache}"
: "${XDG_DATA_HOME:=${HOME}/.local/share}" : "${XDG_DATA_HOME:=${HOME}/.local/share}"
: "${XDG_STATE_HOME:=${HOME}/.local/state}" : "${XDG_STATE_HOME:=${HOME}/.local/state}"
if [ -z "${XDG_RUNTIME_DIR:-}" ]; then # Do NOT set XDG_RUNTIME_DIR here.
if [ -d "/run/user/$(id -u)" ]; then
XDG_RUNTIME_DIR="/run/user/$(id -u)"
else
XDG_RUNTIME_DIR="/tmp/xdg-runtime-$(id -u)"
fi
fi
export XDG_CONFIG_HOME XDG_CACHE_HOME XDG_DATA_HOME XDG_STATE_HOME XDG_RUNTIME_DIR export XDG_CONFIG_HOME XDG_CACHE_HOME XDG_DATA_HOME XDG_STATE_HOME
### Zsh history -> XDG_STATE_HOME (best-effort; zsh might not read /etc/profile) ### Zsh history -> XDG_STATE_HOME (best-effort; zsh might not read /etc/profile)
if [ "${ENABLE_XDG_ZSH_HISTORY:-1}" = "1" ] && [ -n "${ZSH_VERSION:-}" ]; then if [ "${ENABLE_XDG_ZSH_HISTORY:-1}" = "1" ] && [ -n "${ZSH_VERSION:-}" ]; then