Getting ClamAV Daemon working in Ubuntu 18.04

Getting ClamAV Daemon working in Ubuntu 18.04

napisao/la Mark Sharp -
Broj odgovora: 10
Slika Core developers Slika Particularly helpful Moodlers Slika Plugin developers

This is really a note to self, but I've spent all day trying to figure this out, so thought it might be useful to others. I do have a couple of questions though, so if someone knows about systemd that would be great.

Running Moodle 3.4 on Ubuntu 18.04 with apache2.

I was getting the following error:

ClamAV has failed to run.
The return error message was "An error occured".
Here is the output from ClamAV:
/tmp/phpXejPcp: lstat() failed: No such file or directory. ERROR

So clearly a permissions error on /tmp

I followed instructions like: add the user (clamav) to the apache group (www-data).

No change.

Finally got to a setting in systemd:

PrivateTmp=true

https://www.freedesktop.org/software/systemd/man/systemd.exec.html#PrivateTmp=

(on Ubuntu 18.04 this is found here: /etc/systemd/system/multi-user.target.wants/apache2.service)

This, it turns out, creates Private dirs in tmp for each service. And for security's sake, one service's tmp files can't be read by another.

So the obvious thing to do is set that to false. And after restarting the daemon and apache2, it does indeed work.

But... doesn't that undo that cross process security feature? I guess so. Does that really matter? I'm not qualified to say. I'd be happy to hear from someone who actually knows.

So I did a bit more digging, and found that there is another setting:

JoinsNamespaceOf=

https://www.freedesktop.org/software/systemd/man/systemd.unit.html#JoinsNamespaceOf=

This can be used to join 2 namespaces into a single private tmp area.

So, in /etc/systemd/system/multi-user.target.wants/clamav-daemon.service I set:

[Unit]
...
JoinsNamespaceOf=apache2.service

(add it under [Unit] if it's not already there)

And in /etc/systemd/system/multi-user.target.wants/apache2.service, I reverted to PrivateTmp=true

Restarted services etc and this also works.

I would love to hear opinions of which is the best solution, or if I completely barked up the wrong tree.

Ta

Happy nearly Friday.
Prosjek ocjena:Useful (4)
Odgovor na Mark Sharp

Re: Getting ClamAV Daemon working in Ubuntu 18.04

napisao/la Alan Hefner -

Thank you. This has seemed to help with the errors messages I was receiving. 

Odgovor na Alan Hefner

Re: Getting ClamAV Daemon working in Ubuntu 18.04

napisao/la Alan Hefner -
I had thought the namespace setting fixed the error I was getting but it appears that it has not. Going to try the PrivateTmp setting and see if that has any effect on the errors.
Odgovor na Mark Sharp

Re: Getting ClamAV Daemon working in Ubuntu 18.04

napisao/la erotavlas erotavlas -

Hi,

I have the same issue with zentyal 6.2 based on ubuntu 18.04. Unfortunately, both of your solutions did not work in my case.

As you can read here, the same problem is not present if apache is configure via PHP fast-cgi. However this solution has some problem with latest versions of moodle (3.8.2 and 3.9).

So, at the moment, I have to maintain the warning.

Odgovor na Mark Sharp

Ova poruka je uklonjena

Sadržaj ove poruke je izbrisan i ne može mu se više pristupiti.
Odgovor na Izbrisan korisnik

Re: Getting ClamAV Daemon working in Ubuntu 18.04

napisao/la koen roggemans -
Slika Core developers Slika Documentation writers Slika Moodle HQ Slika Particularly helpful Moodlers Slika Plugin developers Slika Translators
I have the same problem. Neither the JoinsNameSpaceOf=apache2.service or the PrivateTmp=false setting work.
I had to switch back to command line tužan
Odgovor na koen roggemans

Re: Getting ClamAV Daemon working in Ubuntu 18.04

napisao/la Renan Piazza do Prado -

Probably late, but i just fixed this issue on my server (debian), the clamav-daemon.service file need to have JoinsNamespaceOf=apache2.service on the [Unit] and PrivateTmp=true on the [Service] , like this:

[Unit]
...
JoinsNamespaceOf=apache2.service
[Service]
...
PrivateTmp=true
The apache2 file just need to have the PrivateTmp=true. Do a  systemd daemon-reload after editing the systemd files and restart the clamav-daemon.



Odgovor na Renan Piazza do Prado

Re: Getting ClamAV Daemon working in Ubuntu 18.04

napisao/la koen roggemans -
Slika Core developers Slika Documentation writers Slika Moodle HQ Slika Particularly helpful Moodlers Slika Plugin developers Slika Translators
Thank you for your contribution. Not too late I'm afraid. Still not working (on Ubuntu 18.04)
I followed your suggestion and had most of the settings already. I just needed to add PrivateTmp=true in the [Service]-section from /etc/systemd/system/multi-user.target.wants/clamav-daemon.service

Reloading the systemd daemon on Ubuntu is with systemctl daemon-reload

But I still get the same reading error on /tmp when using the daemon in stead of command line. Command line performance is awfull.
Odgovor na Renan Piazza do Prado

Re: Getting ClamAV Daemon working in Ubuntu 20.04

napisao/la heli g -
Thank you so much for this. It solved the issue for me on Ubuntu 20.04. Repeating for posterity:

Edit the clamav start up file
sudo nano  /etc/systemd/system/multi-user.target.wants/clamav-daemon.service

Add to the end of the correct sections

[Unit]
...
JoinsNamespaceOf=apache2.service

[Service]
...
PrivateTmp=true

Restart services

sudo systemctl daemon-reload
sudo systemctl restart clamav-daemon.service