Skip to content

Commit 358d6af

Browse files
authored
Merge pull request #329 from JedMeister/beta-build
Config related v19.x/Trixie updates - mostly webserver and security related
2 parents 3779914 + 371a7b7 commit 358d6af

19 files changed

Lines changed: 635 additions & 220 deletions

File tree

conf/apache-ssl

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash -e
2+
3+
# try to enable mod, if not available just continue
4+
a2enmod ssl || true
5+
6+
# tweak mod_evasive defaults
7+
CONF=/etc/apache2/mods-available/ssl.conf
8+
if [[ -f "$CONF" ]]; then
9+
# tighten ssl protocol support
10+
ssl_protocol="# Hardened TKL default\nSSLProtocol -all +TLSv1.2 +TLSv1.3"
11+
sed -Ei "\|^SSLProtocol| s|^(.*)|#\1\n$ssl_protocol|" "$CONF"
12+
13+
cipher_suites=$(cat <<EOF
14+
# Explict Cipher suites recommended by Mozilla
15+
# https://ssl-config.mozilla.org/#server=apache&version=2.4.65&config=intermediate&openssl=3.5.1&guideline=5.7
16+
# (updated by TurnKey "common/conf/turnkey.d/zz-ssl-ciphers" script)
17+
SSLCipherSuite ZZ_SSL_CIPHERS
18+
EOF
19+
)
20+
sed -Ei "\|^SSLCipherSuite| s|^(.*)|#\1\n$cipher_suites|" "$CONF"
21+
22+
cat >> "$CONF" <<EOF
23+
24+
# Additional default TKL Apache SSL/TLS config
25+
26+
SSLOpenSSLConfCmd Curves X25519:prime256v1:secp384r1
27+
28+
# Explictly disable SSL compression (should default to off anyway...)
29+
# Note enabling SSL compression makes Apache vulnerable to CRIME attack.
30+
SSLCompression off
31+
32+
# Default certificate file to use (provided by TurnKey)
33+
SSLCertificateFile /etc/ssl/private/cert.pem
34+
# Default TKL cert.pem includes key so this can remain unset
35+
#SSLCertificateKeyFile /etc/ssl/private/cert.key
36+
37+
# enable HTTP/2, if available
38+
Protocols h2 http/1.1
39+
40+
# OCSP Stapling
41+
SSLUseStapling On
42+
SSLStaplingCache "shmcb:logs/ssl_stapling(32768)"
43+
44+
# HTTP Strict Transport Security (mod_headers is required)
45+
Header always set Strict-Transport-Security "max-age=63072000"
46+
47+
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
48+
EOF
49+
else
50+
echo "fatal: conf file $CONF not found" >&2
51+
exit 1
52+
fi

conf/tomcat

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
1-
#!/bin/sh -ex
1+
#!/bin/bash -ex
22

3-
fatal() { echo "FATAL [$(basename $0)]: $@" 1>&2; exit 1; }
3+
fatal() { echo "FATAL [$(basename "$0")]: $*" 1>&2; exit 1; }
44

5-
TOMCAT=tomcat10
5+
if [[ -e /var/lib/tomcat10 ]]; then
6+
TOMCAT=tomcat10
7+
elif [[ -e /var/lib/tomcat11 ]]; then
8+
TOMCAT=tomcat11
9+
else
10+
fatal "Tomcat version could not be determined"
11+
fi
612

713
CATALINA_HOME="/usr/share/$TOMCAT"
814
CATALINA_BASE="/var/lib/$TOMCAT"
915
CATALINA_TMPDIR="$CATALINA_BASE/temp"
1016

11-
# identify JVM to use
12-
## We check for openjdk 17
13-
[ -e /usr/lib/jvm/java-17-openjdk-amd64 ] && JVM=java-17-openjdk-amd64
14-
[ -z "$JVM" ] && fatal "JVM to use could not be identified"
17+
# identify JVM to use - Trixie provides openjdk 21 & 25
18+
if [[ -e /usr/lib/jvm/java-21-openjdk-amd64 ]]; then
19+
JVM=java-21-openjdk-amd64
20+
JINFO=$(ls /usr/lib/jvm/.*java*21*jinfo)
21+
elif [[ -e /usr/lib/jvm/java-25-openjdk-amd64 ]]; then
22+
JVM=java-25-openjdk-amd64
23+
JINFO=$(ls /usr/lib/jvm/.*java*25*jinfo)
24+
else
25+
fatal "JVM to use could not be identified"
26+
fi
27+
1528

1629
# configure java/tomcat environment
1730
cat >> /etc/environment<<EOF
@@ -22,15 +35,14 @@ JAVA_HOME="/usr/lib/jvm/${JVM}"
2235
EOF
2336

2437
# this may not be 100% safe
25-
JINFO=$(ls /usr/lib/jvm/.*java*17*jinfo)
2638
JINFO=${JINFO%.jinfo}
2739
JINFO=${JINFO#*.}
2840
# not sure if this is actually needed
29-
update-java-alternatives --jre-headless -s $JINFO
41+
update-java-alternatives --jre-headless -s "$JINFO"
3042
sed -i "s/^#JAVA_HOME.*/JAVA_HOME=\/usr\/lib\/jvm\/${JVM}/" /etc/default/$TOMCAT
3143

3244
# configure Apache if needed (Jk connector to Tomcat)
33-
if [ -e /etc/apache2/sites-available/jktomcat.conf ]; then
45+
if [[ -e /etc/apache2/sites-available/jktomcat.conf ]]; then
3446
a2dissite 000-default
3547
a2ensite jktomcat
3648

@@ -46,12 +58,12 @@ fi
4658
# create convenience links to original conf that we overwrite
4759
conf_files="tomcat-users.xml server.xml"
4860
for conf in $conf_files; do
49-
ln -s /usr/share/$TOMCAT/etc/$conf /etc/$TOMCAT/$conf.orig
61+
ln -s "/usr/share/$TOMCAT/etc/$conf" "/etc/$TOMCAT/$conf.orig"
5062
done
5163

5264
# from https://bugs.launchpad.net/ubuntu/+source/tomcat7/+bug/1232258
5365
create_link() {
54-
ln -s $CATALINA_BASE/$1 $CATALINA_HOME/$1
66+
ln -s "$CATALINA_BASE/$1" "$CATALINA_HOME/$1"
5567
}
5668
create_link common
5769
create_link server

conf/turnkey.d/postfix-local

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ postconf -e smtpd_banner='$myhostname ESMTP'
2020
#postconf -e smtpd_tls_cert_file=/etc/ssl/private/cert.pem
2121
#postconf -e smtpd_tls_key_file=/etc/ssl/private/cert.key
2222

23-
# despite name, accepts more bits (i.e. > 1024 bits)
24-
postconf -e smtpd_tls_dh1024_param_file=/etc/ssl/private/dhparams.pem
25-
postconf -e smtpd_tls_mandatory_protocols='!SSLv2, !SSLv3, !TLSv1, !TLSv1.1'
26-
postconf -e smtpd_tls_protocols='!SSLv2, !SSLv3, !TLSv1, !TLSv1.1'
23+
postconf -e smtpd_tls_auth_only=yes
24+
postconf -e tls_preempt_cipherlist=no
25+
postconf -e smtpd_tls_mandatory_protocols='>=TLSv1.2'
26+
postconf -e smtpd_tls_protocols='>=TLSv1.2'
27+
postconf -e smtp_tls_mandatory_ciphers=medium
2728
postconf -e smtpd_tls_mandatory_ciphers=medium
2829

2930
# ciphers set by common/conf/turnkey.d/zz-ssl-ciphers
3031
postconf -e tls_medium_cipherlist="ZZ_SSL_CIPHERS"
31-
postconf -e tls_preempt_cipherlist=no
3232

33-
service postfix start
33+
postmulti -x postfix start
3434
systemctl enable postfix@-.service
35-
service postfix stop
35+
postmulti -x postfix stop

conf/turnkey.d/zz-ssl-ciphers

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,57 +6,57 @@
66
# It provides a common set of hardened SSL/TLS ciphers fo all webserver apps
77
# Base configuration is provided by relevant overlay files
88

9-
set ${CERTFILE:="/etc/ssl/private/cert.pem"}
10-
set ${CRTFILE:="/usr/local/share/ca-certificates/cert.crt"}
11-
set ${KEYFILE:="/etc/ssl/private/cert.key"}
12-
set ${DHPARAMS:="/etc/ssl/private/dhparams.pem"}
9+
set "${CERTFILE:="/etc/ssl/private/cert.pem"}"
10+
set "${CRTFILE:="/usr/local/share/ca-certificates/cert.crt"}"
11+
set "${KEYFILE:="/etc/ssl/private/cert.key"}"
12+
set "${DHPARAMS:="/etc/ssl/private/dhparams.pem"}"
1313

14-
# Secure Cipher List recommended by Mozilla https://ssl-config.mozilla.org/
15-
# See https://github.com/turnkeylinux/tracker/issues/1380 for more info
16-
# Note separate cipher list no longer required for Tomcat9
17-
SECURE_CIPHER_LIST="ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384"
14+
# "Intermediate" Secure Cipher List recommended by Mozilla:
15+
# https://ssl-config.mozilla.org/
1816

19-
# Compatible Cipher List recommended for older clients - reduced security score (currently not used)
20-
COMPATIBLE_CIPHER_LIST="ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA256:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA"
17+
SECURE_CIPHER_LIST="ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-CHACHA20-POLY1305"
18+
19+
# Tomcat 10 & 11 use slightly different cipher list - requires Java 10+
20+
TOMCAT_SECURE_CIPHER_LIST="TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-CHACHA20-POLY1305"
2121

2222
fatal() {
23-
echo "fatal: $@" 1>&2
23+
echo "fatal: $*" 1>&2
2424
exit 1
2525
}
2626

2727
# Postfix
2828
CONF=/etc/postfix/main.cf
29-
if [ -f "$CONF" ]; then
29+
if [[ -f "$CONF" ]]; then
3030
sed -i "/tls_medium_cipherlist/ s|ZZ_SSL_CIPHERS|$SECURE_CIPHER_LIST|" $CONF
3131
fi
3232

3333
# Apache2
3434
CONF="/etc/apache2/mods-available/ssl.conf"
35-
if [ -f "$CONF" ]; then
35+
if [[ -f "$CONF" ]]; then
3636
sed -i "s|^\(\s*SSLCipherSuite\s\+\).*$|\1${SECURE_CIPHER_LIST}|g" $CONF
3737
a2enmod ssl
3838
a2enconf security
3939
fi
4040

4141
# Nginx
4242
CONF="/etc/nginx/snippets/ssl.conf"
43-
if [ -f "$CONF" ]; then
43+
if [[ -f "$CONF" ]]; then
4444
# SSL enabled by default (see overlay)
4545
sed -i "s|ssl_ciphers '.*|ssl_ciphers '${SECURE_CIPHER_LIST}';|" $CONF
4646
fi
4747

4848
# Lighttpd
4949
CONF="/etc/lighttpd/ssl-params.conf"
50-
if [ -f "$CONF" ]; then
50+
if [[ -f "$CONF" ]]; then
5151
sed -i "/CipherString/ s|ZZ_SSL_CIPHERS|$SECURE_CIPHER_LIST|" $CONF
5252
lighty-enable-mod ssl
5353
fi
5454

5555
# Tomcat
56-
# As of v15.x TKL uses Debian Tomcat default ciphers
56+
# Note uses slightly different cipher list in TKL v19.x
5757
for CONF in /etc/tomcat*/server.xml; do
58-
if [ -f "$CONF" ]; then
59-
sed -i "s|ciphers=|ciphers=\"${SECURE_CIPHER_LIST}\"|" $CONF
58+
if [[ -f "$CONF" ]]; then
59+
sed -i "s|ciphers=|ciphers=\"${TOMCAT_SECURE_CIPHER_LIST}\"|" "$CONF"
6060
fi
6161
done
6262

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
#
21
# Disable access to the entire file system except for the directories that
32
# are explicitly allowed later.
43
#
5-
# This currently breaks the configurations that come with some web application
6-
# Debian packages.
4+
# This currently breaks some web app configurations
75
#
86
#<Directory />
97
# AllowOverride None
108
# Require all denied
119
#</Directory>
1210

13-
1411
# Changing the following options will not really affect the security of the
1512
# server, but might make attacks slightly more difficult in some cases.
1613

@@ -21,9 +18,6 @@
2118
# and compiled in modules.
2219
# Set to one of: Full | OS | Minimal | Minor | Major | Prod
2320
# where Full conveys the most information, and Prod the least.
24-
#ServerTokens Minimal
25-
#ServerTokens OS
26-
#ServerTokens Full
2721
ServerTokens Prod
2822

2923
#
@@ -34,7 +28,6 @@ ServerTokens Prod
3428
# Set to "EMail" to also include a mailto: link to the ServerAdmin.
3529
# Set to one of: On | Off | EMail
3630
ServerSignature Off
37-
#ServerSignature On
3831

3932
#
4033
# Allow TRACE method
@@ -44,34 +37,35 @@ ServerSignature Off
4437
#
4538
# Set to one of: On | Off | extended
4639
TraceEnable Off
47-
#TraceEnable On
4840

4941
#
5042
# Forbid access to version control directories
5143
#
5244
# If you use version control systems in your document root, you should
53-
# probably deny access to their directories. For example, for subversion:
45+
# probably deny access to their directories.
46+
#
47+
# Examples:
5448
#
55-
<DirectoryMatch "/\.svn">
56-
Require all denied
57-
</DirectoryMatch>
58-
<DirectoryMatch "/\.git">
59-
Require all denied
60-
</DirectoryMatch>
49+
#RedirectMatch 404 /\.git
50+
#RedirectMatch 404 /\.svn
51+
52+
# Forbid acccess to any/all dot files/dirs
53+
RedirectMatch 404 "/\."
54+
# Note this will also deny access to .well-known so needs to be disabled if
55+
# using non-TurnKey Let's Encrypt tool - e.g. certbot
6156

6257
#
6358
# Setting this header will prevent MSIE from interpreting files as something
6459
# else than declared by the content type in the HTTP headers.
6560
# Requires mod_headers to be enabled.
6661
#
67-
#Header set X-Content-Type-Options: "nosniff"
62+
Header set X-Content-Type-Options: "nosniff"
6863

6964
#
7065
# Setting this header will prevent other sites from embedding pages from this
7166
# site as frames. This defends against clickjacking attacks.
7267
# Requires mod_headers to be enabled.
73-
#
74-
#Header set X-Frame-Options: "sameorigin"
7568

69+
Header set Content-Security-Policy "frame-ancestors 'self';"
7670

7771
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

0 commit comments

Comments
 (0)