TMAegis
More rules for tomcat

TMA-TOMCAT-4.4

Restrict access to Tomcat logs directory

MediumLevel 1Automatedtomcat

Description

The Tomcat $CATALINA_HOME/logs directory contains Tomcat logs. It is recommended that the ownership of this directory be tomcat_admin:tomcat. It is also recommended that the permissions on this directory deny read, write, and execute for the world (o- rwx). $CATALINA_BASE/logs must not match -perm /o+rwx and must be owned by $TOMCAT_OWNER:$TOMCAT_GROUP; expects 0 findings. Reads $CATALINA_BASE (default /opt/tomcat) and $CATALINA_HOME (default: $CATALINA_BASE); set them for packaged installs (e.g. CATALINA_BASE=/var/lib/tomcat10, CATALINA_HOME=/usr/share/tomcat10). XML comments are ignored. The expected owner/group are tomcat_admin:tomcat as in the benchmark; override with TOMCAT_OWNER / TOMCAT_GROUP.

How it is checked

Audit method: Shell command

shell
B=${CATALINA_BASE:-/opt/tomcat}; H=${CATALINA_HOME:-$B}; O=${TOMCAT_OWNER:-tomcat_admin}; G=${TOMCAT_GROUP:-tomcat}; x(){ [ -r "$1" ] || return 1; awk 'BEGIN{RS="<!--"} NR==1{print;next} {i=index($0,"-->"); if(i) print substr($0,i+3)}' "$1" | tr '\n\t\r' '   ' | tr '<' '\n'; }; p="$B/logs"; [ -e "$p" ] || exit 1; find -L "$p" -maxdepth 0 \( -perm /o+rwx -o ! -user "$O" -o ! -group "$G" \) -print 2>/dev/null | wc -l
Expected output
0

How it is fixed

Fix method: Guidance or infrastructure patch

chown tomcat_admin:tomcat $CATALINA_BASE/logs && chmod o-rwx $CATALINA_BASE/logs. Restart Tomcat afterwards.

Properties

Operating systems
Any
Tags
tomcatpermissions
Reference
CIS Apache Tomcat 10.1 Benchmark v1.0.0 - 4.4 Restrict access to Tomcat logs directory

Check this host

Run this on a machine you are allowed to audit. The scan is read-only.

shell
tmaegis scan --target tomcat