Skip to content

maxuru ~ % cat memcached/require-authentication

Require authentication on Memcached

Severity: highApplies to: Memcached 1.5.13+Applies to: Memcached 1.6.x
The fix/etc/memcached.conf
Terminal window
# Requires a binary built with --enable-sasl
-S

“Memcached has no authentication” is not quite right

Section titled ““Memcached has no authentication” is not quite right”

It is the most repeated sentence about this software, and it is close enough to true that it keeps getting repeated — but the accurate version is more useful:

Memcached has two authentication mechanisms, both off by default, and both build-time options. The defaults are settings.sasl = false and settings.auth_file = NULL. So a stock daemon really does accept every connection, but that is a configuration state rather than a missing feature.

The distinction matters because it changes what you do. “No authentication” leads people to conclude the network is the only possible control and stop there. In fact you can often turn something on — and where you genuinely cannot, knowing why tells you the network control has to be airtight.

-S enables SASL authentication. Two consequences follow immediately, and memcached states both as hard errors rather than warnings:

  • It forces the binary protocol. SASL is not implemented in the ASCII protocol, so -S together with ASCII is refused outright. Every client has to speak binary.
  • It rules out UDP. Binary SASL and UDP cannot be enabled together. Not a practical loss, since UDP should be off anyway.

The larger obstacle is the build. SASL needs ./configure --enable-sasl, and distribution packages frequently omit it — which is exactly why the “memcached has no authentication” folklore persists. If -S gives you This server is not built with SASL support., no amount of configuration will help; you need a different binary.

Credentials come from the system SASL configuration (typically /etc/sasl2/memcached.conf plus a sasldb2 database created with saslpasswd2), not from a memcached file.

-Y <file> enables a much simpler scheme: a plain file of user:password lines that works with the ASCII protocol.

Terminal window
-Y /etc/memcached.auth
Terminal window
sudo install -m 600 -o memcache -g memcache /dev/null /etc/memcached.auth
printf 'appuser:%s\n' "$(openssl rand -base64 24)" | sudo tee /etc/memcached.auth

Be aware it is still labelled (EXPERIMENTAL) in the current help text. That is memcached’s own word, not a hedge added here, and it is the honest reason not to present this as the default recommendation. It is simpler than SASL, it avoids the rebuild, and it is a genuine improvement over nothing — but it carries an upstream caveat, your client library has to support the set handshake, and credentials cross the wire in the clear unless TLS is on.

Be honest about the ordering. Authentication here is worth having and is not the primary control:

  1. Bind it properly. This is the one that always works, needs no rebuild, and is rated critical for that reason.
  2. Add authentication if your build supports it. Defence in depth for the case where the network boundary turns out to be wrong.
  3. If neither mechanism is available, treat the network control as load-bearing rather than as a first layer — firewall the port and consider the Unix socket, which removes the network surface entirely.

This is why the page is high and not critical: on most installs it is not the control that closes the exposure, and pretending otherwise would send people rebuilding a binary when a -l flag was the actual fix.