In SMTP AUTH (RFC 4954), how does PLAIN differ from a token mechanism such as OAUTHBEARER, and why are both kept inside TLS?
answer
- the AUTH keyword in the EHLO reply
- SASL: one mechanism, many protocols
- NUL-separated identities, base64 encoded
- a bearer token instead of a password
- the list may change after STARTTLS
basics
~20 sPLAIN (RFC 4616) sends the username and reusable password, merely base64-encoded; OAUTHBEARER (RFC 7628) sends a short-lived OAuth 2.0 bearer token instead. Either can be replayed by whoever reads the session, so both belong only inside TLS.
solid answer
~50 sSMTP AUTH is an ESMTP extension: the server lists its SASL mechanisms on the `AUTH` line of the EHLO reply, and RFC 4954 notes that list MAY change after `STARTTLS`. With `PLAIN` (RFC 4616) the client sends `[authzid] NUL authcid NUL password`, base64-encoded, which is encoding, not encryption, so the reusable password is exposed to anyone who reads the session. RFC 4954 requires every implementation to implement PLAIN over TLS and says a server MUST be configurable to refuse plaintext mechanisms until TLS or similar protection is in place. `OAUTHBEARER` (RFC 7628, 2015) carries an OAuth 2.0 bearer token, and RFC 7628 says TLS MUST protect it, because whoever holds a bearer token can use it until it expires. The gain is that a token is limited in lifetime and scope and can be revoked without changing a password. The replies to know: `235 2.7.0` success, `535 5.7.8` bad credentials, `454 4.7.0` a temporary server fault.
code
ini · 4 lines# Postfix main.cf: offer SASL only inside TLS
smtpd_sasl_auth_enable = yes
smtpd_tls_auth_only = yes
smtpd_sasl_security_options = noanonymousgo deeper
Remember that the server advertises AUTH and its mechanisms in the EHLO reply, that PLAIN carries a password and OAUTHBEARER a token, and that both belong inside TLS.
Explain what each mechanism actually sends, why base64 is not protection, how 235, 334, 454, 535 and 534 differ, and why the mechanism list can change after STARTTLS.
Show the server configuration that refuses plaintext mechanisms on clear sessions, and how you would read a client's failures in the log to tell bad credentials from a server-side fault.
Weigh password mechanisms against tokens as an estate-wide choice: tokens contain a leak and can be revoked, but every device and application must support them and someone must operate the token issuer.
## Where authentication sits in a submission session **SMTP AUTH** (RFC 4954, July 2007) adds one verb, `AUTH`, to ESMTP. A server that supports it lists the word `AUTH` in its EHLO reply, followed by the names of the **SASL** mechanisms it will accept. SASL, the Simple Authentication and Security Layer, is a framework shared by SMTP, IMAP, POP3 and other protocols, so a mechanism such as PLAIN is defined once and reused everywhere. The client picks a mechanism, may send an **initial response** on the same line, and the server either asks for more with a `334` continuation or finishes with a final reply. RFC 4954 also notes that the list of mechanisms **MAY change after a successful `STARTTLS`**, which is why a client re-issues EHLO after the upgrade and reads the list again. How the TLS upgrade itself works is covered with STARTTLS and transport security; what matters here is that authentication happens *after* it. An administrator testing their own submission server sees a sequence like this (credentials redacted): 1. `S: 220 mail.example.com ESMTP` 2. `C: EHLO client.example.com`, then the TLS upgrade, then EHLO again 3. `S: 250-AUTH PLAIN OAUTHBEARER` 4. `C: AUTH PLAIN <base64 of authzid, authcid and password, redacted>` 5. `S: 235 2.7.0 Authentication successful` ## PLAIN and the token mechanisms compared | Mechanism | Defined in | What crosses the wire | If someone reads it | |---|---|---|---| | `PLAIN` | RFC 4616 (2006) | authorisation identity, user name and password, NUL-separated, base64 | the reusable password is theirs | | `OAUTHBEARER` | RFC 7628 (2015) | an OAuth 2.0 bearer token plus a few key/value pairs | the token works for them until it expires | RFC 4954's own examples show the effect of the upgrade: before `STARTTLS` the server lists only `GSSAPI` and `DIGEST-MD5`, and `PLAIN` appears in the list only after TLS is up. **PLAIN** is simple and universal: RFC 4954 says client and server implementations **MUST implement PLAIN running over TLS**, so it is the interoperable baseline. Its weakness is that base64 is a reversible encoding; the password that unlocks the mailbox, and often other services, travels in a form anyone can decode. **OAUTHBEARER** replaces the password with a **bearer token**, defined by RFC 6750: a string that grants access to whoever presents it. RFC 7628 says **TLS MUST be used** with OAUTHBEARER to protect that token. What the token buys is containment: it expires, it is scoped to a purpose, it can be revoked centrally, and the user's password never reaches the mail server. On failure, RFC 7628 has the server return an error result in JSON with a `status` field; the client then sends a dummy response so the server can finish the exchange. Some services document their own, non-standard token mechanisms instead; read what the service documents rather than assuming the name. How a client obtains and refreshes the token is covered with OAuth 2.0 tokens. ## The replies a submission client must handle RFC 4954 section 6 pairs each reply with an enhanced status code: - `235 2.7.0` authentication succeeded. - `334` server challenge or prompt; an empty prompt is `334 ` with no text. - `454 4.7.0` temporary authentication failure: the client SHOULD NOT prompt for a new password and should report a server fault. - `535 5.7.8` credentials invalid: the client SHOULD ask the user for new credentials. - `534 5.7.9` mechanism too weak for this user under server policy: retry with a stronger one. - `530 5.7.0` authentication required, returned to other commands when policy demands it. - `538 5.7.11` encryption required: RFC 4954 keeps it **for historical purposes only** and says modern servers SHOULD NOT advertise mechanisms they will not accept unencrypted. ## Configuring a server so passwords never cross in clear RFC 4954 says a server **MUST** be capable of a configuration that permits **no plaintext password mechanism** until STARTTLS has been negotiated or other protection is in place, and sites **SHOULD NOT** run without it. In Postfix, the reference MTA: - `smtpd_tls_auth_only` (default `no`) set to `yes` stops Postfix from announcing or accepting SASL authentication on unencrypted connections. - `smtpd_sasl_security_options` defaults to `noanonymous`; adding `noplaintext` refuses PLAIN-style mechanisms, and `smtpd_sasl_tls_security_options` (default: a copy of the former) can then allow them inside TLS. - `smtpd_sasl_auth_enable` defaults to `no`, so authentication is off until you enable it. ## Mistakes worth catching in an interview - Calling base64 "encryption". - Assuming a token mechanism removes the need for TLS: a captured bearer token is as good as a password until it expires. - Treating `535` and `454` alike: one means wrong credentials, the other a server that could not check them. - Thinking SMTP AUTH authenticates a *domain* to the receiving MX. It authenticates a *user* to their own submission server; domain checks are the job of sender authentication.
- What changes for the server operator when clients move from PLAIN to OAUTHBEARER?The server no longer checks a password against its own store; it must validate a token issued elsewhere and fail the exchange when the token is expired, revoked or wrongly scoped. On failure RFC 7628 returns a JSON error with a `status` field, the client sends a dummy response, and the server ends the exchange. Password rotation stops being the control; token lifetime and revocation take its place.
- Why must a client run EHLO again after STARTTLS before choosing a mechanism?RFC 4954 says the advertised mechanism list MAY change after a successful STARTTLS. A server that refuses plaintext mechanisms on a clear session will only list PLAIN once TLS is up, so a client that reused the first list would see no usable mechanism or pick a weaker one.
- AUTH PLAIN protects the password because it is base64-encoded.
- OAUTHBEARER makes TLS unnecessary because tokens expire anyway.
- A 535 reply means the server is down, so retry with the same password.
- The mechanisms listed before STARTTLS are the full set the server supports.
- SMTP AUTH proves to the recipient's MX that the sending domain is genuine.