diff mbox series

[PATCHv2] logrotate: fix permission issue for test2

Message ID 20240620032737.1421923-1-po-hsu.lin@canonical.com
State Accepted
Headers show
Series [PATCHv2] logrotate: fix permission issue for test2 | expand

Commit Message

Po-Hsu Lin June 20, 2024, 3:27 a.m. UTC
When running this logrotate test on Ubuntu, this test will fail with:
  logrotate_tests 2 TINFO: sleep 1 min to wait for rotating logs
  logrotate_tests 2 TFAIL: [ -f /var/log/tst_largelogfile.1.gz ] failed unexpectedly
  logrotate_tests 2 TFAIL: Failed to create a compressed file

Look more closely to what this test is trying to do we will see there
are two issues here in the tst_largelog.conf:

1. "include /etc/logrotate.d"
This will rotate other log files defined here, since we are just testing
the log rotation capability I think there is no need to rotate log files
other than the testfile itself.

2. Permission issue
Trying to rotate the target file on Ubuntu will cause the following error:
  error: skipping "/var/log/tst_largelogfile" because parent directory has
         insecure permissions (It's world writable or writable by group which
         is not "root") Set "su" directive in config file to tell logrotate
         which user/group should be used for rotation.

Fix these by removing the extra include, reuse the existing user/group
setting for test1 with setup() as suggested by Petr Vorel.

Signed-off-by: Po-Hsu Lin <po-hsu.lin@canonical.com>
---
 .../commands/logrotate/logrotate_tests.sh      | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

Comments

Petr Vorel June 20, 2024, 5:05 a.m. UTC | #1
Hi Po-Hsu Lin,

thanks a lot, merged!

FYI I added a following commit to require root for the test
(/var/log directory usually needs it).

Kind regards,
Petr
Petr Vorel June 20, 2024, 5:09 a.m. UTC | #2
Hi Po-Hsu,

> When running this logrotate test on Ubuntu, this test will fail with:
>   logrotate_tests 2 TINFO: sleep 1 min to wait for rotating logs
>   logrotate_tests 2 TFAIL: [ -f /var/log/tst_largelogfile.1.gz ] failed unexpectedly
>   logrotate_tests 2 TFAIL: Failed to create a compressed file

> Look more closely to what this test is trying to do we will see there
> are two issues here in the tst_largelog.conf:

> 1. "include /etc/logrotate.d"
> This will rotate other log files defined here, since we are just testing
> the log rotation capability I think there is no need to rotate log files
> other than the testfile itself.

BTW (for next time): I would have separated these 2 changes into 2 commits.

Kind regards,
Petr

> 2. Permission issue
> Trying to rotate the target file on Ubuntu will cause the following error:
>   error: skipping "/var/log/tst_largelogfile" because parent directory has
>          insecure permissions (It's world writable or writable by group which
>          is not "root") Set "su" directive in config file to tell logrotate
>          which user/group should be used for rotation.
Po-Hsu Lin June 20, 2024, 6:43 a.m. UTC | #3
On Thu, Jun 20, 2024 at 1:09 PM Petr Vorel <pvorel@suse.cz> wrote:

> Hi Po-Hsu,
>
> > When running this logrotate test on Ubuntu, this test will fail with:
> >   logrotate_tests 2 TINFO: sleep 1 min to wait for rotating logs
> >   logrotate_tests 2 TFAIL: [ -f /var/log/tst_largelogfile.1.gz ] failed
> unexpectedly
> >   logrotate_tests 2 TFAIL: Failed to create a compressed file
>
> > Look more closely to what this test is trying to do we will see there
> > are two issues here in the tst_largelog.conf:
>
> > 1. "include /etc/logrotate.d"
> > This will rotate other log files defined here, since we are just testing
> > the log rotation capability I think there is no need to rotate log files
> > other than the testfile itself.
>
> BTW (for next time): I would have separated these 2 changes into 2 commits.
>
> OK no problem,
thank you.
Po-Hsu



> Kind regards,
> Petr
>
> > 2. Permission issue
> > Trying to rotate the target file on Ubuntu will cause the following
> error:
> >   error: skipping "/var/log/tst_largelogfile" because parent directory
> has
> >          insecure permissions (It's world writable or writable by group
> which
> >          is not "root") Set "su" directive in config file to tell
> logrotate
> >          which user/group should be used for rotation.
>
>
>
diff mbox series

Patch

diff --git a/testcases/commands/logrotate/logrotate_tests.sh b/testcases/commands/logrotate/logrotate_tests.sh
index 1f3e61294..c382fd1e4 100755
--- a/testcases/commands/logrotate/logrotate_tests.sh
+++ b/testcases/commands/logrotate/logrotate_tests.sh
@@ -25,7 +25,16 @@  TST_NEEDS_CMDS="crontab file grep logrotate"
 TST_TESTFUNC=test
 TST_NEEDS_TMPDIR=1
 TST_CNT=2
+TST_SETUP=setup
 TST_CLEANUP=cleanup
+PERMISSION=
+
+setup()
+{
+	local group="syslog"
+	grep -q $group /etc/group || group="root"
+	PERMISSION="su root $group"
+}
 
 cleanup()
 {
@@ -47,10 +56,6 @@  check_log()
 
 test1()
 {
-	local group="syslog"
-
-	grep -q $group /etc/group || group="root"
-
 	cat >tst_logrotate.conf <<-EOF
         #****** Begin Config file *******
         # create new (empty) log files after rotating old ones
@@ -60,7 +65,7 @@  test1()
         compress
 
         /var/log/tst_logfile {
-                su root $group
+                $PERMISSION
                 rotate 5
                 weekly
         }
@@ -95,9 +100,8 @@  test2()
         create
         # compress the log files
         compress
-        # RPM packages drop log rotation information into this directory
-        include /etc/logrotate.d
         /var/log/tst_largelogfile {
+            $PERMISSION
             rotate 5
             size=2k
         }