k0lter / autopostgresqlbackup

Automated tool to make periodic backups of PostgreSQL databases
52 stars 17 forks source link

/etc/profile: TMOUT: readonly variable #22

Open TheFlipside opened 1 year ago

TheFlipside commented 1 year ago

I'm using autopostgresqlbackup on multiple Rocky Linux 8.7 systems and I always set the following in /etc/profile:

TMOUT=300 readonly TMOUT export TMOUT

This is not an uncommon practice and a recommendation by many hardening guides.

For autopostgresqlbackup though it leads to multiple warnings/errors in the report: /etc/profile: line 88: TMOUT: readonly variable

The backup is done correctly though so I wondered if there is a workaround for this message not to appear in the reports?

k0lter commented 1 year ago

@TheFlipside What does your crontab look like?

TheFlipside commented 1 year ago

/etc/cron.daily/autopostgresqlbackup:

#!/bin/sh

if [ -x /usr/sbin/autopostgresqlbackup ]; then
    /usr/sbin/autopostgresqlbackup
fi
k0lter commented 1 year ago

To work around this issue I guess you could fix this crontab like this:

#!/bin/sh

if [ -x /usr/sbin/autopostgresqlbackup ]; then
    /bin/bash --noprofile /usr/sbin/autopostgresqlbackup
fi
TheFlipside commented 1 year ago

I altered the cronjob but unfortunately the problem still persisted. Looking into it, it seems since bash gets invoked by cron the environment is sill inherited from the parent process.

I will try the pointed out solution using env -i bash --norc --noprofile as soon as I get to it.

TheFlipside commented 1 year ago

I tried multiple workarounds using env -i /bin/bash --norc --noprofile /usr/sbin/autopostgresqlbackup and also exec env TMOUT=0 /bin/bash /usr/sbin/autopostgresqlbackup as i found as answer somewhere When the session variable is "Read Only" you have to replace the current shell process with the command by "exec"

But unfortunately none of the attempts changed the behaviour and I still get the error message in the email sent after the cronjob

k0lter commented 1 year ago

I guess that /bin/sh is a symlink to /bin/bash. Another proposal, change the shebang with another posix compatible shell (like zsh, dash or another one)

#!/bin/zsh

if [ -x /usr/sbin/autopostgresqlbackup ]; then
    /bin/bash --noprofile /usr/sbin/autopostgresqlbackup
fi
k0lter commented 1 year ago

Another one with bash only:

#!/bin/bash --noprofile

if [ -x /usr/sbin/autopostgresqlbackup ]; then
    /bin/bash --noprofile /usr/sbin/autopostgresqlbackup
fi
TheFlipside commented 1 year ago

i tried both solutions, unfortunately none changed the problem