You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Lines starting with > configure output options for files or directories to be referenced later by query rules. os_asl_log_files_permissions_configure sets 640 regardless, making directories non-listable.
Query rules can have file and directory (store_dir is used de facto even though it is not mentioned in the man) configured inline. Above code completely ignores files configured inline.
Filenames are not required to be absolute:
If the pathname specified is not an absolute path, syslogd will treat the given path as relative to /var/log (for /etc/asl.conf), or for other output modules relative to /var/log/module/NAME where NAME is the module name.
If log rotation is in use, actual filename will have a timestamp or a counter appended to it.
Ownership is root:admin by default, but can be configured directly within configuration files by setting uid=0 gid=0, and similar for permissions mode=0640 (or mode 0750 for directories). Provided fixes do not modify configuration files themselves, which means that newly created log files won't have correct group and mode set.
According to man asl.conf there is an additional parameter
access Sets read access controls for messages that match the
associated query pattern. syslogd will restrict read
access to matching messages to a specific user and
group. The user ID number and group ID number must fol-
low the ``access'' keyword as parameters.
Files which have it, configure access to root:admin (0:80). I've no idea whether it should be hardened to root:wheel.
are directories and should have 750 permissions, not 640.
/etc/asl.conf has ? [= Facility com.apple.alf.logging] file appfirewall.log file_max=5M all_max=50M, but appfirewall.log is not mentioned in the output at all.
/etc/asl/com.apple.MessageTracer has * store_dir /var/log/DiagnosticMessaged ttl=30, which is also missed.
There are other missing log files beyond these two.
system.log was mentioned in /etc/asl.conf, which means it's actually /var/log/system.log on disc.
cdscheduler.log was mentioned in /etc/asl/com.apple.cdscheduler, which means it's actually /var/log//module/com.apple.cdscheduler/cdscheduler.log on disc.
/var/log/asl/Logs/aslmanager has style=lcl-b and is actually stored as /var/log/asl/Logs/aslmanager.%Y%m%dT%H%M%S%z on disc. stat doesn't glob potential suffixes:
Only one of file, directory, or store_dir is actually possible.
Appending uid=0 gid=0 mode=0640 to the very end is correct and actually affects the file in question (rather than breaking the configuration file completely).
If a file was configured with > then a reference to it from ? or * doesn't need to be configured again (unless inline overrides for uid, gid or mode are present).
Checking uid and gid in configuration files:
uid_gid_err=$( awk -v l=0 -v err=0 ' function count_err(has_uid, has_gid, i) { has_uid = has_gid = 0 for (i = 2; i <= NF; ++i) { if ($i ~ /^uid=/) { ++has_uid if ($i != "uid=0") { ++err } } else if ($i ~ /^gid=/) { ++has_gid if ($i != "gid=0") { ++err } } } if (has_uid != 0 || has_uid != 1) { ++err } if (has_gid != 1) { ++err } } function file_seen(j, i) { for (i in logfiles) { if (logfiles[i] == $j) { return 1 } } return 0 } $1 == ">" { logfiles[l++] = $2 count_err() } $1 == "?" || $1 == "*" { for (i = 2; i <= NF; ++i) { if ($i ~ /^(file|directory|store_dir)$/) { if (!file_seen(++i) || $0 ~ /[[:space:]][ug]id=/) { count_err() } break } } } END { print err }' /etc/asl{.conf,/*})echo"$uid_gid_err"
Fixing uid and gid in configuration files:
forconfin /etc/asl{.conf,/*};do
conf_content=$(<"$conf")
awk -v l=0 ' function fix_uid_gid() { gsub(/([[:space:]]+[ug]id=[[:digit:]]+)+([[:space:]]+|$)/, " ") sub(/[[:space:]]*$/, " uid=0 gid=0") } function file_seen(j, i) { for (i in logfiles) { if (logfiles[i] == $j) { return 1 } } return 0 } $1 == ">" { logfiles[l++] = $2 fix_uid_gid() } $1 == "?" || $1 == "*" { for (i = 2; i <= NF; ++i) { if ($i ~ /^(file|directory|store_dir)$/) { if (!file_seen(++i) || $0 ~ /[[:space:]][ug]id=/) { fix_uid_gid() } break } } } { print }'>"$conf"<<<"$conf_content"done
Checking mode in configuration files (cannot really know whether the file is a directory, assumes that directory already have execute permissions set):
mode_err=$( awk -v l=0 -v err=0 ' function count_err(has_mode, i) { has_mode = 0 for (i = 2; i <= NF; ++i) { if ($i ~ /^mode=/) { ++has_mode if ($i != "mode=0750" || $i != "mode=0640") { ++err } } } if (has_mode != 1) { ++err } } function file_seen(j, i) { for (i in logfiles) { if (logfiles[i] == $j) { return 1 } } return 0 } $1 == ">" { logfiles[l++] = $2 count_err() } $1 == "?" || $1 == "*" { for (i = 2; i <= NF; ++i) { if ($i ~ /^(file|directory|store_dir)$/) { if (!file_seen(++i) || $0 ~ /[[:space:]]mode=/) { count_err() } break } } } END { print err }' /etc/asl{.conf,/*})
Fixing mode in configuration files:
forconfin /etc/asl{.conf,/*};do
conf_content=$(<"$conf")
awk -v l=0 ' function fix_mode(mode) { mode = $0 ~ /[[:space:]]mode=07/ ? " mode=0750" : " mode=0640" gsub(/([[:space:]]+mode=[[:digit:]]+)+([[:space:]]+|$)/, " ") sub(/[[:space:]]*$/, mode) } function file_seen(j, i) { for (i in logfiles) { if (logfiles[i] == $j) { return 1 } } return 0 } $1 == ">" { logfiles[l++] = $2 fix_mode() } $1 == "?" || $1 == "*" { for (i = 2; i <= NF; ++i) { if ($i ~ /^(file|directory|store_dir)$/) { if (!file_seen(++i) || $0 ~ /[[:space:]]mode=/) { fix_mode() } break } } } { print }'>"$conf"<<<"$conf_content"done
Changes these configuration file fixes make can be inspected by running:
forconfin /etc/asl{.conf,/*};do
conf_content=$(<"$conf")
diff --color=always --unified "$conf"<(awk -v l=0 ' COPY FIX FOR EITHER UID/GID OR MODE HERE'<<<"$conf_content")done
The text was updated successfully, but these errors were encountered:
os_asl_log_files_owner_group_configure
andos_asl_log_files_permissions_configure
both use the following code to collect the names of log files:According to man asl.conf:
>
configure output options for files or directories to be referenced later by query rules.os_asl_log_files_permissions_configure
sets 640 regardless, making directories non-listable.file
anddirectory
(store_dir
is used de facto even though it is not mentioned in theman
) configured inline. Above code completely ignores files configured inline.root:admin
by default, but can be configured directly within configuration files by settinguid=0 gid=0
, and similar for permissionsmode=0640
(ormode 0750
for directories). Provided fixes do not modify configuration files themselves, which means that newly created log files won't have correct group and mode set.man asl.conf
there is an additional parameterroot:admin
(0:80). I've no idea whether it should be hardened toroot:wheel
.Examples
On my machine (Sonoma 14.2.1):
produces
are directories and should have 750 permissions, not 640.
/etc/asl.conf
has? [= Facility com.apple.alf.logging] file appfirewall.log file_max=5M all_max=50M
, butappfirewall.log
is not mentioned in the output at all./etc/asl/com.apple.MessageTracer
has* store_dir /var/log/DiagnosticMessaged ttl=30
, which is also missed.There are other missing log files beyond these two.
system.log
was mentioned in/etc/asl.conf
, which means it's actually/var/log/system.log
on disc.cdscheduler.log
was mentioned in/etc/asl/com.apple.cdscheduler
, which means it's actually/var/log//module/com.apple.cdscheduler/cdscheduler.log
on disc./var/log/asl/Logs/aslmanager
hasstyle=lcl-b
and is actually stored as/var/log/asl/Logs/aslmanager.%Y%m%dT%H%M%S%z
on disc.stat
doesn't glob potential suffixes:Suggestions for filesystem checks
Log filenames collection:
Checking for ownership.
Notes:
awk 'END { print NR }'
doesn't requirexargs
to remove spaces compared towc -l
.Fixing ownership:
Checking for permissions:
Fixing permissions:
Suggestions for configuration file checks
All code below assumes that:
file
,directory
, orstore_dir
is actually possible.uid=0 gid=0 mode=0640
to the very end is correct and actually affects thefile
in question (rather than breaking the configuration file completely).>
then a reference to it from?
or*
doesn't need to be configured again (unless inline overrides foruid
,gid
ormode
are present).Checking
uid
andgid
in configuration files:Fixing
uid
andgid
in configuration files:Checking
mode
in configuration files (cannot really know whether the file is a directory, assumes that directory already have execute permissions set):Fixing
mode
in configuration files:Changes these configuration file fixes make can be inspected by running:
The text was updated successfully, but these errors were encountered: