Why Apache www-data user have to attached in every group of user's virtual server?

SYSTEM INFORMATION
OS type and version Ubuntu 22.04.5
Webmin version 2.202
Virtualmin version 7.30.4
Webserver version Apache 2.4.52
Related packages Apache

I need to seperate Apache user (www-data) with the user on every Virtual Server to minimizing cross contamination and improve security aspect. But why when www-data is removed from the group of VirtualServer’s user group, it’ll error with this error message:

(13)Permission denied: [remote w.x.y.z:63099] AH00035: access to /favicon.ico denied (filesystem path ‘/home/xxx/public_html’) because search permissions are missing on a component of the path.

And the web will show an error with Forbidden in the browser.

How do I overcome that error? Please let me know. Thank you.

Because Apache needs to be able to read files in that directory to serve them.

This isn’t “cross contamination”. The Apache user never executes code that users choose (unless you’ve installed mod_php or use CGI without suexec).

The only way to do otherwise would be to basically run a whole new web server for every user. There’s mpm-itk that automates this, but that isn’t available in the standard repos on any OS we support. http://mpm-itk.sesse.net/

mpm-itk also has some big caveats that make it a bit scary. It runs as root, for example, while Apache as we configure it drops privileges after binding to ports 80 and 443. It also has a notable performance and resource usage penalty.

If you’ve seen or configured web servers that didn’t have Apache with secondary group membership in all domain owner groups, it was almost certainly because security was worse and permissions were looser on the public_html dirs and the paths leading up to them.

So, what you’re seeing with that secondary group membership is a tool to allow tighter permissions on homes, rather than a loosening of permissions.

If you must remove it, and if you’re only using traditional Linux permissions and ownership, you’ll have to loosen permissions on the path to public_html in all of your homes, and the umask will need to be loosened so files created by the user or any apps are readable by Apache.

There are other ways to balance the compromise, and there are new ways to restrict file access in Linux, like POSIX ACLs or contexts in SELinux, but those are probably too hard to use for most casual web hosting administrators. Our File Manager has tools for working with ACLs and attributes, but I’d recommend you get real familiar with them before trying to implement server-wide security that way. And, nobody (statistically speaking) understands SELinux, so nobody will ever use that, so I wouldn’t even bother trying to go down that path.

So, the short answer to your question, “How do I overcome that error?” Probably something like this:

chmod 755 /home/domain
chmod 755 /home/domain/public_html
chmod 644 -R /home/domain/public_html/*

But, notice that what you currently have, by default on a Virtualmin system, is 750 and 640, respectively, which is notably more locked down. (Go look at other systems to see what they’re doing. If they’re not doing what we’re doing, they’re probably doing something worse. And, if they’re not, please tell us about it. We implemented this 20 years ago. Things change, and we’re open to new things, but not somewhat experimental things like mpm-itk.)

More on the topic from the Apache wiki (and note we do a slight improvement over their suggestion, which is enabled by Linux having a very high limit on the number of secondary groups and basically no penalty for having a gazillion secondary groups…some OSes we supported in the past didn’t allow that, and compromises were required): PrivilegeSeparation - HTTPD - Apache Software Foundation

1 Like

Thank you for your explanations. :+1:

I have 1 more question, what is the most secure chmod values for folders and for files inside public_html folder when I’m using Virtualmin? Thanks

*The virtual server hosted Yii and Laravel Framework fyi.

Dont you mean apache ? Virtualmin is just a gui that configures the underlying services in an easy way, it’s up to you to restrict the service to suit your needs

There are default permissions. If you add 3rd party software then not much anyone can do about that.

That’s what I meant, Apache.
I need some clue, I’m afraid that web app could easily be hacked if don’t configure those permission properly.

Hem… Ok.

I have another question.
In my Virtualhost config generated by virtualmin is like this:

<Directory /home/xxx/public_html/>
Options -Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch
Require all granted
AllowOverride All
Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch

Why there is no -ExecCGI instead ExecCGI in the option of AllowOverride?
Does it safe (won’t broken the functional things of web apps, etc) to remove ExecCGI in the option of AllowOverride?

I just need to disable any phpscript that could be used to hack/inject into the Virtual Server. Thanks

You can configure AllowOverride any way you want. CGI would run as the domain owner user, though, if overridden, so it’s not like the user is being given a way to escalate. But, if you don’t want them to be able to run CGI, you can certainly make it impossible to override anything you want.

CGI isn’t very common these days, so disabling it entirely is completely reasonable.

I’m sorry, but what does that mean? I’m a bit confused here. Could you tell me more about that? Thanks.

I am saying you can configure your system any way you want. You don’t need my permission to alter the AllowOverride Options.

I didn’t ask your permission, but I asked your suggestion about The most secure Virtualhost Config in Apache to apply in my Virtualmin. I’m in confuse with options ExecCGI, IncludesNOEXEC, and so on.
Thanks.

Its all documented, google it.
Apache docs
https://httpd.apache.org/docs/2.4/mod/core.html#allowoverride

You keep saying “secure”, but these are not security questions.

This topic was automatically closed 8 days after the last reply. New replies are no longer allowed.