Getting ClamAV Daemon working in Ubuntu 18.04

Getting ClamAV Daemon working in Ubuntu 18.04

by Mark Sharp -
Number of replies: 10
Picture of Core developers Picture of Particularly helpful Moodlers Picture of 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.
Average of ratings: Useful (4)
In reply to Mark Sharp

Re: Getting ClamAV Daemon working in Ubuntu 18.04

by Alan Hefner -

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

In reply to Alan Hefner

Re: Getting ClamAV Daemon working in Ubuntu 18.04

by 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.
In reply to Mark Sharp

Re: Getting ClamAV Daemon working in Ubuntu 18.04

by 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.

In reply to Mark Sharp

This forum post has been removed

The content of this forum post has been removed and can no longer be accessed.
In reply to Deleted user

Re: Getting ClamAV Daemon working in Ubuntu 18.04

by koen roggemans -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of 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 sad
In reply to koen roggemans

Re: Getting ClamAV Daemon working in Ubuntu 18.04

by 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.



Average of ratings: Useful (1)
In reply to Renan Piazza do Prado

Re: Getting ClamAV Daemon working in Ubuntu 18.04

by koen roggemans -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of 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.
In reply to koen roggemans

Re: Getting ClamAV Daemon working in Ubuntu 18.04

by erotavlas erotavlas -
Hi,
I upgraded to php-7.4 via PPA and my problem with clamAV is gone. Moreover, even performance seems better.
In reply to Renan Piazza do Prado

Re: Getting ClamAV Daemon working in Ubuntu 20.04

by 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