Scenario: I want to block www-data from using cron.
I have added a few other users into cron.allow
, chmod 600
it.
I would expect no other users jobs get executed.
Still, crontab -u www-data -e
allows me to edit its crontab.
That would be fine by me. One could use it to detect tampering attempts. Created cron.deny
anyhow, the crontab is additionally not even editable.
crontab -u www-data -e
The user www-data cannot use this program (crontab)
This is the first thing I do on a clean server (Ubuntu 18.04). A few hours later, a cryptominer comes in, writes somehow /var/spool/cron/crontab/www-data
- the jobs get executed. But cron.allow
, cron.deny
are still in place - meaning the setup was ignored.
...that cannot be the intended behavior...
fileCrontabWww="/var/spool/cron/crontab/www-data"
echo 'MAILTO=root' > "$fileCrontabWww"
chown root:root "$fileCrontabWww"
chmod 200 "$fileCrontabWww"
Jobs are not executed any more. But I had to lock it down to 200 permissions, because the cron is reading the files as root. journalctl -u cron
shows:
cron[680]: (www-data) INSECURE MODE (mode 0600 expected) (crontabs/www-data)
Oh well. I have what I needed. But is this how to work with cron in attempt to harden it? Or was the usecase scenario never played through?
Also an interesting fact, from https://help.ubuntu.com/community/CronHowto
Note, userids on your system which do not appear in /etc/shadow will NOT have operational crontabs, if you desire to enter a user in /etc/passwd, but NOT /etc/shadow that user's crontab will never run.
Which is not really usable as restrictive approach, because of unexpected side consequences.
From Differences between `/etc/crontab`, files under `/etc/cron.d/` and `/var/spool/cron/crontabs/root`?
/var/spool/cron/crontabs is the stuff managed by the crontab command.
But the management tool and the worker somehow drift apart, showing inconsistent behavior. What is the workflow here?
crontab
file when you hardened? – waltinator Sep 20 '20 at 01:09chown root:crontab
the configuration files... SElinux is way too much time investment right now for me, I am a programmer, not a sys admin so I have a huge technology gap to overcome. – informatik-handwerk.de Sep 20 '20 at 21:36