From 6bef910f875f3f76768a97c96ba1adb6fe197862 Mon Sep 17 00:00:00 2001
From: Alexander Scheel <ascheel@redhat.com>
Date: Tue, 7 May 2019 16:04:29 -0400
Subject: [PATCH] su to radiusd user/group when rotating logs

Ported from:
https://github.com/FreeRADIUS/freeradius-server/commit/1f233773962bf1a9c2d228a180eacddb9db2d574

The su directive to logrotate ensures that log rotation happens under the
owner of the logs. Otherwise, logrotate runs as root:root, potentially
enabling privilege escalation if a RCE is discovered against the
FreeRADIUS daemon.

Signed-off-by: Alexander Scheel <ascheel@redhat.com>
Integrated-by: Yahu Gao <yahu.gao@windriver.com>
---
 debian/freeradius.logrotate  | 3 +++
 redhat/freeradius-logrotate  | 1 +
 scripts/logrotate/freeradius | 3 +++
 suse/radiusd-logrotate       | 1 +
 4 files changed, 8 insertions(+)

diff --git a/debian/freeradius.logrotate b/debian/freeradius.logrotate
index 02f95c0..b4925f4 100644
--- a/debian/freeradius.logrotate
+++ b/debian/freeradius.logrotate
@@ -16,6 +16,7 @@ notifempty
 #
 /var/log/freeradius/radius.log {
 	copytruncate
+	su freerad freerad
 }
 
 #
@@ -37,6 +38,7 @@ notifempty
 #
 /var/log/freeradius/sqllog.sql {
 	nocreate
+	su freerad freerad
 }
 
 # There are different detail-rotating strategies you can use.  One is
@@ -48,4 +50,5 @@ notifempty
 # detail files.  You do not need to comment out the below for method #2.
 /var/log/freeradius/radacct/*/detail {
 	nocreate
+	su freerad freerad
 }
diff --git a/redhat/freeradius-logrotate b/redhat/freeradius-logrotate
index 6faf336..a824e5f 100644
--- a/redhat/freeradius-logrotate
+++ b/redhat/freeradius-logrotate
@@ -9,6 +9,7 @@ rotate 4
 missingok
 compress
 delaycompress
+su radiusd radiusd
 
 #
 #  The main server log
diff --git a/scripts/logrotate/freeradius b/scripts/logrotate/freeradius
index cbeeb5f..1c0fb59 100644
--- a/scripts/logrotate/freeradius
+++ b/scripts/logrotate/freeradius
@@ -19,6 +19,7 @@ notifempty
 #
 /var/log/radius/radius.log {
 	copytruncate
+	su radiusd radiusd
 }
 
 #
@@ -40,6 +41,7 @@ notifempty
 #
 /var/log/radius/sqllog.sql {
 	nocreate
+	su radiusd radiusd
 }
 
 # There are different detail-rotating strategies you can use.  One is
@@ -51,4 +53,5 @@ notifempty
 # detail files.  You do not need to comment out the below for method #2.
 /var/log/radius/radacct/*/detail {
 	nocreate
+	su radiusd radiusd
 }
diff --git a/suse/radiusd-logrotate b/suse/radiusd-logrotate
index b72267b..5ae1c9e 100644
--- a/suse/radiusd-logrotate
+++ b/suse/radiusd-logrotate
@@ -11,6 +11,7 @@ missingok
 compress
 delaycompress
 notifempty
+su radiusd radiusd
 
 #
 #  The main server log
-- 
1.8.3.1

