Live data from Hacker News

How to set up a safe and secure Web server

arstechnica.com

71–80 of 148 posts

Re: How to set up a safe and secure Web server

#71
post #33

http://stackoverflow.com/questions/72394/what-should-a-devel... can't believe that hasn't been on HN before, so added it: http://news.ycombinator.com/item?id=4841329

What is really amazing is that these sort of questions (and detailed answers) are not welcome on StackOverflow:

Locked: "This question exists because it has historical significance, but it is not considered a good, on-topic question for this site, so please do not use it as evidence that you can ask similar questions here. This question and its answers are frozen and cannot be changed. More info: FAQ."

At least the list of references there is useful.

Re: How to set up a safe and secure Web server

#72
post #55

If you want a safe and secure Web server, use what your distribution gives you. Don't add third party sources if you can avoid it, ie. don't need features Instead, go with what your distribution gives you. The people who put your favourite distribution together work on making the system safe and secure as a whole. People who don't think it is safe and secure file bugs and they get fixed. And you have one place to get…

I disagree with that. Apache's defaults on most distros isn't secure. Even 'enterprise' level distributions often fall into the following traps when packaging Apache:

1-> auto indexing enabled (should be disabled)

2-> user directories enabled (should be disabled)

3-> server signatures 'on' (should be 'off')

4-> server tokens set to 'full' (should be 'prod')

5-> hidden (dot prefixed) files not always blacklisted as unauthorised files in Apache config

6-> same as above for editor specific back up files (eg file~). But this is only an issue for people who bulk upload or edit files on the live server (very naughty).

7-> having less optimal SSL configurations (Apache's default SSL set up isn't PCI compliant).

(IIRC there's a couple of other Apache tweaks, but that's just off the top of my head)

Then you have issues with PHP (eg logging to STDOUT so web users can view PHP errors).

And that's just covering the webserver configuration. There's still holes that need plugging if you actually want to run a secure web server; one of my favourite tools for that is using fail2ban which will auto-blacklist IPs in iptables (Linux firewall) based on if certain attacks are detected. For example it can prevent brute force attacks on SSH brute force attacks (which negates the need to run denyhosts as recommended in the article), HTTP auth, FTP, mail servers, etc.

And touching on SSH, many data centres will enable root log ins on their OS pre-installs by default. Your first job on any such box will be creating a user account and then disabling root log ins (PermitRootLogin no -> /etc/ssh/sshd_config).

Then there's a whole stack of optimisations you can run on iptables to adaptively prevent port scanning, forged TCP/IP packets and such like.

Also many distributions ship FTP, which is insecure by default. Anyone sys admin requiring FTP hosting would be better off using a chrooted SFTP environment (so the security benefits of SSH plus the sandboxed (chroot) environment that FTP often benefits).

Let's also not forget the plethora of internal services (databases, MTAs (mail servers), etc). If you're reading this article then you're probably not a trained systems administrator or not working for a large enough company where each server is running in it's own environment. Thus your MySQL / Postgre / whatever databases are running on your webservers. So you need to ensure that your database is only listening on localhost (127.0.0.1). Same applied for your MTA, unless you are intentionally providing a mail services (it is advisable to have an MTA installed even if you're not providing mail services because you can then set up daemons like fail2ban to automatically e-mail you when attempted break ins happen; which will in turn allow you to spot any determined hackers and permanently ban their IP from your box).

And lastly, if you're really paranoid, run your webserver inside a Linux/UNIX container (FreeBSD Jail, Solaris Zone, Linux OpenVZ) instead of inside a virtual machine as there have been hacks where attackers can break out of the VM and gain access to the host system (as of yet, I've not heard such attacks from containers, but if anyone has any evidence of that then I'd love to know). Running inside a container will give your webserver the sandboxed environment to work with plus an easy route for backups / snapshotting meaning minimal downtime and data loss should the worst happen and your server does become compromised.

(source: http://www.youtube.com/watch?v=hCPFlwSCmvU - it's a plugged vulnerability, but it will give you an idea about the kind of issues VMs face when compared to containers)

In short; distribution's don't ship secure defaults. They ship a happy medium between usability and security. However if you have an internet facing box (particularly one not hidden behind a hardware firewall, as many budget set ups are not), then the happy medium isn't secure enough.

Re: How to set up a safe and secure Web server

#74
post #7

Frankly, articles like these are a deterrent to all but the most techie of people. Why go through all this and shell $270 when you can get an Amazon EC2 instance free for a year!

Honestly, its a much easier setup on your own box. You have the option of a GUI, and I've found installing a linux distro on my own box to be much easier than figuring out EC2.

I'm not sure where a GUI comes in handy here - it's not like there's any good GUI (in the traditional sense) tools for fiddling with webserver config.

Even were I to want one on a webserver on the localhost I'd probably just install webmin or something, which you can do equally well on a VM somewhere else.

Re: How to set up a safe and secure Web server

#78
post #31

Ah well, it's rather a "how i set up a small web server for fiddling around with stuff" not so much a professional article about security. Sorry, but the first page is like "mhh, yeah, geeks hate MS, let's use the other choices" under the hood. Why? Because it doesn't really mention a technical choice against MS. Don't get me wrong i would never ever use Windows Server but when i'd write such an article i'd have to f…

As a professional developer and amateur sysadmin, I have to say Ubuntu is a great choice, and I will never use CentOS again. The main reason being how updated packages are in Ubuntu, and outdated in CentOS. I don't know about the other options.

Quick (non-security) updates means less testing and more potential bugs and security problems. This is fine for a dev workstation, but less fine for a production server. Personally I use Debian on my servers since it gives me a solid base I can trust and then I manually install the few pieces that I need more up to date versions of.

In my case that's Node.js, Redis, nginx and occasionally python 2.7, and of those I'd be installing Redis (I often run beta releases) and nginx (want to compile in my own modules) by hand on Ubuntu as well. Sure this is slightly more work, but it gives me more control and I feel a more stable server environment.

Re: How to set up a safe and secure Web server

#79
post #70

Vurtualization is not for production. Why to have this useless layer, which messes up your CPU caches even more, interfere with you IO and complicates memory model? What for? Virtualization was build for server providers to make easy money, not for server owners to gain performance advantages. Vistualization is not for production. Production servers need less code, not more. It is the same kind of mistake as JVM - we…

Use virtualization (or LXC containers) for ease of management and to better allocate complementary workloads according to the resources they require and to how redundant you need them to be. Chances are your physical boxes will have one resource almost always 100% idle and having your workloads virtualized allows you to better use them. Also, virtualization allows you to more easily fix problems - you just delete the…

The first three paragraphs are just a marketing-speak.)

The last one is more interesting. Have you noticed that your solution was in a splitting workload, not in sharing it with other processes?

In general, splitting (dividing/partitioning/isolating) is a good idea, sharing (sharing resources) is a bad one.

Sharing, unless your data is read-only, like a txt segments of code, is a source of problems, not a solution. Partitioning, on the other hand, is a universal, natural way.

Re: How to set up a safe and secure Web server

#80

Vurtualization is not for production. Why to have this useless layer, which messes up your CPU caches even more, interfere with you IO and complicates memory model? What for? Virtualization was build for server providers to make easy money, not for server owners to gain performance advantages. Vistualization is not for production. Production servers need less code, not more. It is the same kind of mistake as JVM - we…

How is this the top comment? I'm sure some of your points may be salient, but practical experience says virtualization works just fine for production. Same with the JVM.

I agree with you. I don't understand how this comment got so high with such short-sighted arguments, I would expect people here to have a little more insight.
Post reply on HN