easyengine icon indicating copy to clipboard operation
easyengine copied to clipboard

php5-fpm pools (shared-hosting model)

Open andremacola opened this issue 12 years ago • 74 comments

Is it possible to determine/create php pools for each site? I would like to run every site with custom users and groups and not all with www-data

like: ee site create mysite.com --wp --umyuserr:gmygroup

Then ee create the php-fpm .conf file and the user:group.

I'm doing this manually every time.

andremacola avatar Mar 06 '14 23:03 andremacola

This enhancement, in my opinion, needs to be priority #1 for the EasyEngine team. Wordpress is a gaping security hole. Add some plugins in, and you're begging to get your site compromised.

I'm scared to host more than one site with EasyEngine. If one gets infected, they all are accessible (They all run under www-data access). I put a c99 shell on one of my sites to see what someone could do if they broke in... Full and unrestricted access to all other websites. Terrifying.

AndrewPaglusch avatar Apr 30 '15 23:04 AndrewPaglusch

I deal with clients who are running multiple WordPress sites, which they're running on a large server using WHM. Whenever I even try to get them to nginx, they only have one question, if one site gets infected, would it affect the other sites or not. Also, lets say, I put each site on a different server, then as system admin, I'll have to go through updating each server, which is going to consume a lot of time.

With shared hosting model, I will only have to take care of a single large server hosting multiple sites, and each site, in theory, should not be able to access other site's data/files. Now if we add users to the same group, then there's going to be a problem, with group permissions, they can read each other's files, which mean, any user can read wp-config.php of any other user's site, and can simply modify it to have his/her content.

All the servers I've dealt with, using WHM are running on CentOS, and here's how it works Apache runs with user "nobody" It starts the php for executing any php script with the user that php file belongs to public_html folder under each user has owner like user:nobody but user does not belong to the group nobody, therefore cannot access other user's files. but since public_html is belonging to the group nobody, apache can access it to serve static files when it is run by user nobody.

The longer we go without implementing this, the more time its going to take to implement.

gagan0123 avatar Jul 06 '15 14:07 gagan0123

I agree this is a problem. From a security angle, this is a bug, not a feature. Do we have this attached to a milestone yet?

cobbman avatar Jul 07 '15 01:07 cobbman

I haven't seen it yet. I'm glad this is finally getting some attention again. I've been checking daily for this feature (or bug fix) to be implied. On Jul 6, 2015 8:40 PM, "William" [email protected] wrote:

I agree. This issue should be priority #1 https://github.com/rtCamp/easyengine/issues/1. From a security angle, this is a bug, not a feature. Do we have this attached to a milestone yet?

— Reply to this email directly or view it on GitHub https://github.com/rtCamp/easyengine/issues/150#issuecomment-119042776.

AndrewPaglusch avatar Jul 07 '15 02:07 AndrewPaglusch

Just finished testing a few scenarios, mentioning the one that seems to be working fine.

nginx to be run by user www-data (its worker process and the cache manager main process is run by root which spawns these processes)

ee site create example.com --php Algorithm create directory /var/www/example.com/ create user example-com remove directory /home/example-com/ set example-com's home directory /var/www/example.com/ don't add example-com to group www-data create directories htdocs, logs under chown -R example-com:www-data /var/www/example.com/ find /var/www/example.com/ -type f|xargs -I file chmod 640 file find /var/www/example.com/ -type d|xargs -I file chmod 750 file create php-fpm pool for this user write the site's nginx config with the newly created php-fpm pool(right now php-fpm pool is in a common conf file will have to move it from there)

Now the nginx can read all these directories to fetch the static content and send without having to invoke php-fpm. php-fpm will be running the script via that user, so theoretically, it should not be able to access anything apart from the user's home directory. For WordPress sites, updating/installing new plugins won't be an issue since it would be run by php-fpm which is running using the user for that directory, so it will be able to replace/add new files on the filesystem. To even increase the security a bit, we can chmod 600 to the config files containing database information, so no db access to even the group(just to be safe) For security, php-fpm is never going to have an php-fpm pool with www-data user, otherwise it would jeopardise the whole operation.

gagan0123 avatar Jul 07 '15 10:07 gagan0123

@gagan0123

Thanks for the Algorithm!!!

harshadyeola avatar Jul 07 '15 10:07 harshadyeola

@harshadyeola

Happy to be of help :smile:

gagan0123 avatar Jul 07 '15 10:07 gagan0123

@gagan0123 Nicely done! A dev can get this implemented soon.

AndrewPaglusch avatar Jul 07 '15 18:07 AndrewPaglusch

Better would be to create a group example-com also, and add www-data user to that group. And then in php-fpm pool you should set user and group to example-com and example-com so the php process is run under that user and group and socket should have the same owner and group. In your scenario I don't see what are you using for group setting in php-fom pool...

DavorSaric avatar Jul 07 '15 18:07 DavorSaric

@AbbyNormal

Thats even better :+1:

Got your point, if we run php fpm with example-com:example-com, it will create new files with the owner example-com:example-com, which will make the files unreadable by nginx. Using the group of the user that issue will be gone, as www-data will be given read permission to the folder via the group it gets added to, and php fpm can run with example-com:example-com

gagan0123 avatar Jul 08 '15 04:07 gagan0123

Im really surprised this isnt already the case that the sites are isolated from each other. I would have thought this would have been part of the initial design. Don't you always want to do this when you have multiple WP sites? Definitely dont want all your sites compromised just because one does.

MACscr avatar Jul 25 '15 21:07 MACscr

Still waiting for an official solution. When need to add a new custom owner website, I do manually create the php pool, folders owners and nginx configuration.

andremacola avatar Jul 25 '15 21:07 andremacola

@rahul286 Any news on this?

gleert avatar Sep 16 '15 21:09 gleert

this would make EE perfect!

vvaz avatar Sep 17 '15 18:09 vvaz

@gagan0123 Do you have a script made which would automate the scenario you mentioned above?

cobbman avatar Oct 01 '15 19:10 cobbman

Ironically a site was compromised on my server yesterday, and it spread to every single other site in EasyEngine, including the utility folder /var/www/22222. So yeah, I'd really like to have this implemented. For now, I'm writing my own methods to do this, but the struggle is real - sites do get hacked.

cobbman avatar Oct 11 '15 15:10 cobbman

This is a must have!!

gleert avatar Oct 11 '15 15:10 gleert

@ William, I agree and I've held off on a full production release on EE until this is addressed. In the meantime, do you mind sharing what the malware was so I can make sure I address it from all directions?

Thank you!

On Sunday, October 11, 2015, William [email protected] wrote:

Ironically a site was compromised on my server yesterday, and it spread to every single other site in EasyEngine, including the utility folder /var/www/22222. So yeah, I'd really like to have this implemented. For now, I'm writing my own methods to do this, but the struggle is real - sites do get hacked.

— Reply to this email directly or view it on GitHub https://github.com/rtCamp/easyengine/issues/150#issuecomment-147208700.

MattyLB avatar Oct 11 '15 15:10 MattyLB

Here's a pastebin of the code which gets copied onto the top of each file.

http://pastebin.com/Bjc22WMf

Currently I've stopped nginx, php and mysql until I can get every site cleaned. Luckily I have backups, but it spreads to the clean files within minutes after re-uploading them. So I'm going to try cleaning everything before putting nginx back online.

cobbman avatar Oct 11 '15 19:10 cobbman

@bigwilliam .. Did you try to find out what caused this infection?

  1. Are you behind the sever firewall iptables/fail2ban?
  2. If it was a wordpress installation. any loosely written plugin caused this issue?
  3. Did you scan your server with ClamAv?
  4. Did you check the logs . ?

I had a similar issue .I fixed it by tracing the ip trying to post and then get some malicious files in my theme and plugins folder . If you check your access logs in real time you might get some clue or trace of infected files location.

Thanks

liquidia avatar Oct 12 '15 07:10 liquidia