8.7. Securing the Memcached service
To secure the Memcached caching service against denial-of-service (DoS) attacks and unauthorized access, configure it to accept only local traffic and enable user authentication. This prevents DDoS amplification and ensures only authorized clients access stored data.
Memcached is an open source, high-performance, distributed memory object caching system. It can improve the performance of dynamic web applications by lowering database load.
Memcached is an in-memory key-value store for small chunks of arbitrary data, such as strings and objects, from results of database calls, API calls, or page rendering. Memcached allows assigning memory from underutilized areas to applications that require more memory.
In 2018, vulnerabilities of DDoS amplification attacks by exploiting Memcached servers exposed to the public internet were discovered. These attacks took advantage of Memcached communication that uses the UDP protocol for transport. The attack was effective because of the high amplification ratio, where a request with the size of a few hundred bytes could generate a response of a few megabytes or even hundreds of megabytes in size.
In most situations, you do not need to expose the memcached service to the public internet. Public exposure might cause security problems, making it possible for remote attackers to leak or modify information stored in Memcached.
8.7.1. Memcached hardening against DDoS attacks 링크 복사링크가 클립보드에 복사되었습니다!
Harden the Memcached service against distributed denial-of-service (DDoS) attacks. This helps prevent attackers from overwhelming the service and degrading performance.
To mitigate security risks, perform as many of the following steps as applicable for your configuration:
Configure a firewall in your LAN. If your Memcached server should be accessible only in your local network, do not route external traffic to ports used by the
memcachedservice. For example, remove the default port11211from the list of allowed ports:# firewall-cmd --remove-port=11211/udp # firewall-cmd --runtime-to-permanentIf you use a single Memcached server on the same machine as your application, set up
memcachedto listen to localhost traffic only. Modify theOPTIONSvalue in the/etc/sysconfig/memcachedfile:OPTIONS="-l 127.0.0.1,::1"Enable Simple Authentication and Security Layer (SASL) authentication:
Modify or add the
/etc/sasl2/memcached.conffile:sasldb_path: /path.to/memcached.sasldbAdd an account in the SASL database:
# saslpasswd2 -a memcached -c cacheuser -f /path.to/memcached.sasldbEnsure that the database is accessible for the
memcacheduser and group:# chown memcached:memcached /path.to/memcached.sasldbEnable SASL support in Memcached by adding the
-Svalue to theOPTIONSparameter in the/etc/sysconfig/memcachedfile:OPTIONS="-S"Restart the Memcached server to apply the changes:
# systemctl restart memcached- Add the username and password created in the SASL database to the Memcached client configuration of your application.
Encrypt communication between Memcached clients and servers with TLS:
Enable encrypted communication between Memcached clients and servers with TLS by adding the
-Zvalue to theOPTIONSparameter in the/etc/sysconfig/memcachedfile:OPTIONS="-Z"-
Add the certificate chain file path in the PEM format using the
-o ssl_chain_certoption. -
Add a private key file path using the
-o ssl_keyoption.