maxuru ~ % cat memcached/require-authentication
Require authentication on Memcached
/etc/memcached.conf# 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.
SASL — the real one
Section titled “SASL — the real one”-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
-Stogether 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.
The ASCII auth file, and its caveat
Section titled “The ASCII auth file, and its caveat”-Y <file> enables a much simpler scheme: a plain file of user:password lines
that works with the ASCII protocol.
-Y /etc/memcached.authsudo install -m 600 -o memcache -g memcache /dev/null /etc/memcached.authprintf 'appuser:%s\n' "$(openssl rand -base64 24)" | sudo tee /etc/memcached.authBe 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.
Where this leaves you
Section titled “Where this leaves you”Be honest about the ordering. Authentication here is worth having and is not the primary control:
- Bind it properly. This is the one that
always works, needs no rebuild, and is rated
criticalfor that reason. - Add authentication if your build supports it. Defence in depth for the case where the network boundary turns out to be wrong.
- 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.
Related
Section titled “Related”- Bind Memcached to localhost — the control that does the work on most installs.
- Enable TLS — without it, these credentials cross the network in the clear.