Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

In Debian, I have installed memcached (using this guide) to lower the otherwise unmanageable load on mysql database. The database is on a separate server, and memcached and Varnish are on the front server. Is it a potential security hole to leave memcached unprotected by a firewall? If so, how should I secure it? The situation is especially worrisome,as I've received (unproved) reports of cookie thefts on the server. Thanks

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

Just block the memcached port in firewall and allow access only from the database server. This should give you some protection. Also you can bring up a SSL tunnel between the mysql and memcached server and make the memcached-mysql data flow through it only.

For the SSL tunnel you can use IPSEC, to set it up you can follow the tutorial at http://wiki.debian.org/IPsec or http://lartc.org/howto/lartc.ipsec.tunnel.html

For blocking the port for all ip's except one you can issue an iptables command like:

iptables -A INPUT -s 2.2.2.2/32 -p tcp --destination-port 11211 -j ALLOW
iptables -A INPUT -s 0.0.0.0/0 -p tcp --destination-port 11211 -j DROP

or:

iptables -A INPUT -s !2.2.2.2/32 -p tcp --destination-port 11211 -j DROP

Also as I understand your webserver and memcached server are on the same machine? If so then it is your webserver that will communicate with memcached rather then the mysql server. It will just either get the data from cache or if it's not present in the cache will get it from the mysql server. In this case it's just enough to bind memcached to localhost so only your webserver can access memcached using php, ruby, python or any other language code, this should as safe as it can be.

share|improve this answer
    
Will you please elaborate on how to do these, assuming that my web server's IP is at 1.1.1.1 and database servers' Ip 2.2.2.2? Thanks –  alfish Sep 4 '12 at 21:44
    
I've edited my answer with more info. –  Logic Wreck Sep 4 '12 at 21:57
    
As you notices, memcached is on the webserver, so I think you need to edit the iptables rules accrodingly. –  alfish Sep 4 '12 at 22:00
    
Well - if it's on the webserver then probably there is no need to do that, it's better to just bind it to localhost on the webserver since it will be the webserver which will use it directly and not mysql. This will really be the safest option. –  Logic Wreck Sep 4 '12 at 22:04
    
So, just to clarify, to bind memcached to the localhost. I need to put 127.0.0.1 instead of 2.2.2.2 in the rules above. Correct? –  alfish Sep 4 '12 at 22:05
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.