<?xml version="1.0"?>
<!DOCTYPE rfc SYSTEM "rfc2629.dtd">
<?rfc toc="yes"?>
<?rfc compact="yes"?>
<?rfc subcompact="no"?>
<?rfc strict="yes"?>
<?rfc symrefs="yes"?>
<?rfc linkmailto="no"?>
<rfc ipr="trust200902" category="std" 
     docName="draft-newman-imap-unauth-02">
<front>
<title>IMAP UNAUTHENTICATE for Connection Reuse</title>
<author initials="C." surname="Newman" fullname="Chris Newman">
 <organization>Oracle</organization>
 <address>
  <postal>
   <street>440 E. Huntington Dr., Suite 400</street>
   <city>Arcadia</city>
   <region>CA</region>
   <code>91006</code>
   <country>US</country>
  </postal>
  <email>chris.newman@oracle.com</email>
 </address>
</author>
<date month="March" year="2018" />
<area>Applications</area>
<keyword>I-D</keyword>
<keyword>Internet-Draft</keyword>
<abstract><t>
This specification extends the Internet Message Access Protocol (IMAP)
to allow an administrative client to reuse the same IMAP connection on
behalf of multiple IMAP user identities.
</t></abstract>
</front>
<middle>
<section title="Introduction">
<t>
Modern IMAP <xref target="RFC3501"/> server deployments often have peer
systems with administrative privilege that perform actions on behalf of
IMAP end-users. For example, a voice mail gateway can use IMAP to store
a user's voicemail and mark that voicemail as \Seen when the user
listens to it via the phone interface. These systems can issue the IMAP
AUTHENTICATE command with administrative credentials to act on behalf of
other users. However, with the IMAP base specification, these
specialized IMAP clients must close the connection and create a new
connection for each user. For efficiency reasons, it is desirable for
these clients to reuse the same connection, particularly if SSL has been
negotiated. This specification proposes the UNAUTHENTICATE command to
achieve this goal.
</t><t>
The IMAP state machine described in section 3 of RFC 3501 does not
have a transition from authenticated or selected state to not
authenticated state. The UNAUTHENTICATE command adds a transition from
authenticated or selected state to not authenticated state.
</t>
</section>

<section title="Conventions Used in This Document">
<t>The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in <xref target="RFC2119"/>.</t>
</section>

<section title="UNAUTHENTICATE Command">
<t><list style="hanging" hangIndent="12">
<t hangText="Arguments:">None</t>
<t hangText="Responses:">no specific response for this command</t>
<t hangText="Result:">OK - completed, now in not authenticated state<vspace/>BAD - command unknown or arguments invalid</t>
</list>
This command directs the server to reset all connection state, except for state at the TLS <xref
target="RFC5465"/> layer. Upon completion, the server connection is
placed in not authenticated state. This represents transition <xref
format="counter" target="unauth-trans"/> in the <xref
target="state-machine">State Machine Diagram</xref>.</t>
<t>
If a mailbox was selected, the mailbox ceases to be selected but no expunge event is generated. If a SASL <xref target="RFC4422"/> security layer was active, it terminates immediately after the server sends the CRLF following the OK response. For the client, it terminates immediately after the CRLF following the UNAUTHENTICATE command.
</t>
<t>
After sending this command, the client is free to issue a new
AUTHENTICATE or LOGIN command as permitted based on the server's
capabilities. If no SASL security layer was active, the client is
permitted to pipeline the UNAUTHENTICATE command with a subsequent
AUTHENTICATE command. If the IMAP server also advertises SASL-IR <xref
target="RFC4959"/>, this permits an administrative client to
re-authenticate in one round trip. Because of this pipelining
optimization, a server advertising UNAUTHENTICATE is not permitted to
respond to the UNAUTHENTICATE command with a NO response if it is unable
to reset state associated with the connection. Servers MAY close the
connection with an untagged BYE response if this preferably rare
situation occurs.
</t>
<t>Servers MAY choose to advertise the UNAUTHENTICATE capability only after
authentication has completed. As a result, clients need to issue an IMAP
CAPABILITY command after authentication in order to determine the
availability of UNAUTHENTICATE.</t>
<t>The IMAP ID <xref target="RFC2971"/> command provides properties
about the client primarily for use in server log or audit files. Because
IMAP ID is not related to application authentication or user identity in
any way and caching it for the duration of the client connection can be
useful, the interaction between IMAP ID and the UNAUTHENTICATE command
is implementation defined.</t>
</section>

<section title="Interactions">
<t>This section describes interactions between this extension and other IMAP extensions or usage models.</t>

<section title="Stateful Extensions">
<t>This lists some IMAP extensions that have connection state that MUST be reset if both the specified extension is advertised and the UNAUTHENTICATE command is advertised and used. This list may not be complete; the requirement to reset connection state applies to all current and future extensions except STARTTLS and ID.
<list style="symbols">
<t>Cached identity information, such a group memberships, that are used to evaluate access control lists <xref target="RFC4314"/> MUST be reset.</t>
<t>CONDSTORE servers <xref target="RFC4551"/> MUST behave as if no CONDSTORE enabling command had been issued after an UNAUTHENTICATE command is issued.</t>
<t>If IMAP COMPRESS <xref target="RFC4978"/> is active, the compression layer terminates after the server sends the CRLF following the OK response and after the client sends the CRLF following the UNAUTHENTICATE command. In the event it matters, the compression layer terminates before a SASL layer terminates.</t>
<t>Any extensions enabled by the IMAP ENABLE <xref target="RFC5161"/> command cease to be enabled when the UNAUTHENTICATE command is issued. This includes, but is not limited to, CONDSTORE <xref target="RFC4551"/>, QRESYNC <xref target="RFC5162"/>, METADATA <xref target="RFC5464"/>, METADATA-SERVER <xref target="RFC5464"/> and UTF8=ACCEPT <xref target="RFC6855"/>.</t>
<t>A server advertising SEARCHRES <xref target="RFC5182"/> discards any saved search results so that '$' subsequently represents the empty set.</t>
<t>A server advertising LANGUAGE <xref target="RFC5255"/> will revert to the "i-default" language.</t>
<t>When a server advertises CONTEXT=SEARCH or CONTEXT=SORT <xref target="RFC5267"/>, the UNAUTHENTICATE command includes an implicit CANCELUPDATE for all server contexts.</t>
<t>When a server advertises NOTIFY <xref target="RFC5465"/>, the UNAUTHENTICATE command cancels server state related to the NOTIFY command and reverts to default IMAP base-specification behavior for notifications.</t>
</list></t>
</section>

<section title="Client Certificates, SASL EXTERNAL and imaps">
<t>When a TLS <xref target="RFC5246"/> security layer is negotiated
either via the STARTTLS command or use of the imaps port <xref
target="RFC6186"/>, IMAP servers MAY be configured to request a client
certificate and IMAP clients MAY provide one. Client credentials at the
TLS layer do not normally impact the application layer without use of
the SASL EXTERNAL mechanism <xref target="RFC4422"/> in an IMAP
AUTHENTICATE command that directs the server to use the provided
client certificate to authenticate as the specified IMAP user. The
UNAUTHENTICATE command breaks any application-level binding of the TLS
client credentials but does not discard the client credentials. As a
result, an administrative client may use a client certificate with
administrative privilege to act on behalf of multiple IMAP users in the
same connection via the EXTERNAL mechanism and the UNAUTHENTICATE
command.</t>
<t>Some server implementations using the imaps port will request and use
a TLS client certificate to authenticate immediately as the default IMAP
identity associated with that certificate. These implementations
indicate this behavior by using the PREAUTH greeting as indicated by
transition <xref target="preauth" format="counter"/> in the <xref
target="state-machine">State Machine Diagram</xref>. As a result, TLS
client certificates can not be used for administrative proxy
authentication with the imaps port unless the UNAUTHENTICATE command is
also advertised. In that case, an administrative client can respond to
the PREAUTH greeting with an UNAUTHENTICATE command and then issue an
AUTHENTICATE EXTERNAL command.</t>
</section>
</section>

<section anchor="state-machine" title="Revised State Machine">
<figure>
<artwork>
                   +----------------------+
                   |connection established|
                   +----------------------+
                              ||
                              \/
            +--------------------------------------+
            |          server greeting             |
            +--------------------------------------+
                      || (1)       || (2)        || (3)
                      \/           ||            ||
            +-----------------+    ||            ||
            |Not Authenticated|&lt;===||=========++ ||
            +-----------------+    ||     (7) || ||
             || (8)   || (4)       ||         || ||
             ||       \/           \/         || ||
             ||     +----------------+        || ||
             ||     |                |========++ ||
             ||     | Authenticated  |&lt;=++    || ||
             ||     +----------------+  ||    || ||
             ||       || (8)   || (5)   ||(6) || ||
             ||       ||       \/       ||    || ||
             ||       ||    +--------+  ||    || ||
             ||       ||    |Selected|==++    || ||
             ||       ||    |        |========++ ||
             ||       ||    +--------+           ||
             ||       ||       || (8)            ||
             \/       \/       \/                \/
            +--------------------------------------+
            |               Logout                 |
            +--------------------------------------+
                              ||
                              \/
                +-------------------------------+
                |both sides close the connection|
                +-------------------------------+
</artwork>
</figure>
<t>Revised IMAP state machine transitions:
<list style="numbers">
<t>connection without pre-authentication (OK greeting)</t>
<t anchor="preauth">pre-authenticated connection (PREAUTH greeting)</t>
<t>rejected connection (BYE greeting)</t>
<t>successful LOGIN or AUTHENTICATE command</t>
<t>successful SELECT or EXAMINE command</t>
<t>CLOSE, UNSELECT <xref target="RFC3691"/> or failed SELECT or EXAMINE command</t>
<t anchor="unauth-trans">UNAUTHENTICATE command</t>
<t>LOGOUT command, server shutdown, or connection closed</t>
</list>
</t>
</section>

<section title="Formal Syntax">
<t>The following syntax specification uses the Augmented Backus-Naur
Form (ABNF) as described in <xref target="RFC5234"/>. Amended terms are
defined in <xref target="RFC3501"/>.</t>
<figure>
<artwork type="ABNF">
  capability     =/ "UNAUTHENTICATE"

  command-auth   =/ "UNAUTHENTICATE"

  command-select =/ "UNAUTHENTICATE"
</artwork>
</figure>
</section>

<section title="IANA Considerations">
<t>
The IANA shall add the UNAUTHENTICATE capability to the IMAP4 Capabilities Registry.
</t>
</section>

<section title="Security Considerations">
<t>
The original IMAP state machine was designed to allow a server
implementation approach where each IMAP authentication identity matches
an operating system identity and the server revokes all administrative
privilege onces authentication completes. This extension is not
compatible with that implementation approach. However, that approach has
significant performance costs on Unix systems, and this extension is
designed for environments where efficiency is a relatively high priority
deployment goal. So this extension is appropriate for some deployments
but may not be appropriate for the most security sensitive environments.
</t>
<t>
IMAP server implementations are complicated and can retain a lot of
state related to an authenticated user. Server implementers need to
take care to reset all server state such that authentication as a
subsequent user does not inherit any data or privileges from the
previous user. State data associated with a user can include cached
identity information such as group membership used to evaluate access
control lists <xref target="RFC4314"/>, active notifications
<xref target="RFC5465"/>, access to per-user data such as flags, etc.
</t>
<t>
IMAP server systems are often deployed in a two-tier model where a
server-side IMAP proxy routes to an IMAP back-end which handles all
connections for a subset of possible users. Some IMAP proxies enter a
pass-through mode after authentication. The UNAUTHENTICATE command, if
enabled, would allow a client to bypass any security restrictions
present in the proxy layer but not in the back-end server layer on a
subsequent authentication. As a result, IMAP server implementations of
this extension MUST provide a way to disable it when it is not needed.
Use of an IMAP proxy that processes the UNAUTHENTICATE command at the
proxy layer eliminates this concern. Another option to mitigate this
concern is for servers to only enable the UNAUTHENTICATE extension if
the supplied authentication credentials were associated with an
administrative identity.
</t>
</section>

<section title="Privacy Considerations">
<t>For the most part, this extension will have no impact on the privacy
considerations already present in an IMAP implementation. However, if
this extension were used between data centers, it could improve end-user
privacy by increasing the difficultly of traffic analysis due to
connection re-use.</t>
</section>

</middle>
<back>
<references title="Normative References">
<?rfc include="reference.RFC.2119"?> <!-- Key words -->
<?rfc include="reference.RFC.3501"?> <!-- IMAP -->
<?rfc include="reference.RFC.5234"?> <!-- ABNF -->
</references>
<references title="Informative References">
<?rfc include="reference.RFC.2971"?> <!-- IMAP ID -->
<?rfc include="reference.RFC.3691"?> <!-- IMAP UNSELECT -->
<?rfc include="reference.RFC.4422"?> <!-- SASL -->
<?rfc include="reference.RFC.4314"?> <!-- IMAP ACL -->
<?rfc include="reference.RFC.4551"?> <!-- IMAP CONDSTORE -->
<?rfc include="reference.RFC.4959"?> <!-- IMAP SASL-IR -->
<?rfc include="reference.RFC.4978"?> <!-- IMAP COMPRESS -->
<?rfc include="reference.RFC.5161"?> <!-- IMAP ENABLE -->
<?rfc include="reference.RFC.5162"?> <!-- IMAP QRESYNC -->
<?rfc include="reference.RFC.5182"?> <!-- IMAP SAVE SEARCH -->
<?rfc include="reference.RFC.5246"?> <!-- TLS 1.2 -->
<?rfc include="reference.RFC.5255"?> <!-- IMAP I18N -->
<?rfc include="reference.RFC.5267"?> <!-- IMAP CONTEXT -->
<?rfc include="reference.RFC.5464"?> <!-- IMAP METADATA -->
<?rfc include="reference.RFC.5465"?> <!-- IMAP NOTIFY -->
<?rfc include="reference.RFC.6186"?> <!-- Mail Access SRV Records -->
<?rfc include="reference.RFC.6855"?> <!-- IMAP UTF8 -->
</references>
<section anchor="design" title="Design Considerations">
<t>
The author deliberately choose to add a separate UNAUTHENTICATE
command instead of allowing the LOGIN or AUTHENTICATE commands to be
issued when the connection is in a state other than unauthenticated
state. The primary reason for this choice is because the code that
transitions from not authenticated state to authenticated state in a
server is often the most security sensitive code as it needs to assume
and handle unconditionally hostile attackers. That sensitive code
is simpler if it only handles a single server state (unauthenticated)
and the state transition is as simple as possible. Smaller and simpler
code is easier to audit and write in a secure way.
</t><t>
A secondary reason to have a separate command is that it is simpler to
enable or disable the feature with that design. See the discussion in
the security considerations section recommending implementations provide
a way to disable this extension.
</t>
</section>
<section title="Acknowledgements">
<t>Thanks to Fred Batty for implementing UNAUTHENTICATE, and to Cyrus
Daboo for constructive suggestions to improve this draft.</t>
</section>
</back>
</rfc>
