Internet-Draft API Key Rotation November 2026
Tishkin Expires 3 June 2027 [Page]
Workgroup:
Network Working Group
Internet-Draft:
draft-tishkin-api-key-rotation-00
Published:
Intended Status:
Standards Track
Expires:
Author:
D. Tishkin

API Key Rotation

Abstract

This document defines a well-known URI for discovering API key rotation and status endpoints, and the requests used to rotate an API key and retrieve its status.

Status of This Memo

This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79.

Internet-Drafts are working documents of the Internet Engineering Task Force (IETF). Note that other groups may also distribute working documents as Internet-Drafts. The list of current Internet-Drafts is at https://datatracker.ietf.org/drafts/current/.

Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress."

This Internet-Draft will expire on 3 June 2027.

▲

Table of Contents

1. Introduction

Many HTTP APIs authenticate clients using API keys. Regular rotation limits the harm caused by a leaked key, but each provider exposes rotation through its own procedure, if at all, so clients rarely automate it.

This document defines a well-known URI [RFC8615] that points to two endpoints: one to replace an API key with a new one, and one to retrieve the status of an API key.

1.1. Protocol Overview

A client that already holds an API key can use this protocol to exchange it for a replacement. An API that supports rotation publishes a discovery document at /.well-known/api-key-rotation. The document identifies the rotation endpoint and a status endpoint that the client can query independently.

To rotate its key, the client presents the existing API key to the rotation endpoint and receives a replacement in the response. The existing key identifies the key to replace and authorizes the exchange.

Once a rotation succeeds, the previous API key is retired immediately. Its only remaining use is to retry the completed rotation request with the original Idempotency-Key value [I-D.ietf-httpapi-idempotency-key-header] and retrieve the replacement key already issued. This is possible only during the issuer's documented recovery period.

2. Conventions and Definitions

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all capitals, as shown here.

API key:

A bearer credential issued by an API to a client and presented on requests.

Issuer:

The HTTPS origin [RFC6454] that hosts the API key rotation and status endpoints.

3. Discovery

3.1. Discovery Request

The client obtains the API's HTTPS origin from its configuration and sends a GET request to /.well-known/api-key-rotation at that origin [RFC8615].

The discovery endpoint MUST be accessible without authentication. The client MUST NOT send an API key or follow redirects when fetching the discovery document.

The server MUST return the discovery document with a 200 OK status code and the application/json media type. The document is a JSON object [RFC8259] with the following members:

issuer:

OPTIONAL. A string containing an HTTPS origin in the ASCII serialization defined by [RFC6454]. If this member is absent, the issuer origin is the origin from which the discovery document was retrieved.

rotation:

REQUIRED. A string containing the absolute path of the API key rotation endpoint.

status:

REQUIRED. A string containing the absolute path of the API key status endpoint.

Both endpoint paths MUST conform to the path-absolute production in [RFC3986]. The client constructs each endpoint URI by appending its path to the serialized issuer origin.

The client MUST use the document only if the response status is 200 OK and the document conforms to the requirements above. The client MUST ignore unrecognized members.

If the issuer origin differs from the origin of the discovery document, the client MUST use the advertised endpoints only if it is configured to trust the issuer origin for API key management for this API.

3.2. Example

The client sends the following HTTP/1.1 request over HTTPS to api.example.com:

GET /.well-known/api-key-rotation HTTP/1.1
Host: api.example.com
Accept: application/json

The server returns the following response:

HTTP/1.1 200 OK
Content-Type: application/json

{
    "issuer": "https://keys.example.com",
    "rotation": "/v1/keys/rotate",
    "status": "/v1/keys/status"
}

If the client is configured to trust https://keys.example.com for API key management for this API, it uses the following endpoint URIs:

  • Rotation endpoint: https://keys.example.com/v1/keys/rotate

  • Status endpoint: https://keys.example.com/v1/keys/status

If issuer were absent, the client would construct both endpoint URIs using https://api.example.com.

4. API Key Rotation

4.1. Rotation Request

The client sends a POST request [RFC9110] to the rotation endpoint obtained from the discovery document. The client MUST present the API key to be replaced in the Authorization header field using the Bearer authentication scheme [RFC6750]. The presented key identifies the key to replace and authorizes the exchange. The request has no content. The client MUST NOT follow redirects.

The client MUST include the Idempotency-Key request header field defined in [I-D.ietf-httpapi-idempotency-key-header]. Its value identifies one rotation attempt. The client MUST generate a fresh, unpredictable value for each new attempt and MUST reuse the same value when retrying that attempt. A retry MUST be sent to the same rotation endpoint with the same API key.

The server MUST bind each rotation attempt to both the presented API key and the Idempotency-Key value. The Idempotency-Key value alone MUST NOT authorize a rotation or disclosure of its result.

4.2. Successful Rotation

On the first successful request for a rotation attempt, the server MUST issue a new API key with the same permissions as the key it replaces. The server MUST activate the replacement and retire the previous key as a single operation. At most one key in a sequence of replacements can be valid for ordinary API requests at any time.

Once the rotation succeeds, the server MUST reject the previous key for ordinary API requests and for any new rotation attempt. For a limited period, the client can still present the previous key to retrieve the result of the completed attempt, as described in Section 4.4.

4.3. Successful Response

The server MUST return 200 OK with the application/json media type and the Cache-Control: no-store header field [RFC9111]. The response body MUST be a JSON object [RFC8259] with the following members:

api_key:

REQUIRED. A string containing the secret value of the replacement API key.

expires_at:

OPTIONAL. A string specifying when the replacement key expires for ordinary API access. The value MUST be a date-time as defined in [RFC3339], expressed in UTC with the Z offset. At or after that time, the server MUST reject ordinary API requests authenticated with that key. If this member is absent, the expiration time is unspecified to the client.

Expiration for ordinary API access does not by itself retire the key. A client can still exchange an expired key while the issuer permits its rotation. A key that has been explicitly revoked MUST NOT authorize an exchange.

4.4. Retries and Concurrent Requests

If the client does not receive the rotation response, it can retry the same POST request at the same rotation endpoint using both the API key presented in the original request and the original Idempotency-Key value. If the original request is still being processed, the server SHOULD return 409 Conflict as described in [I-D.ietf-httpapi-idempotency-key-header].

The issuer MUST define and document the period during which a client can recover a completed rotation result. The RECOMMENDED duration is 10 minutes. The recovery period begins when the server completes the rotation. A retry MUST NOT restart or extend that period.

During the recovery period, a matching retry is the only way to retrieve the replacement key from the rotation endpoint after the original exchange. The server MUST verify that both the retired API key and the Idempotency-Key value match the successful attempt. If they match and the replacement key remains valid for ordinary API access, the server MUST return 200 OK with the same api_key and, if originally present, the same expires_at. The server MUST make this result available even if the original response never reaches the client.

The server MUST NOT disclose the replacement key if either value is missing or does not match, or if the replacement key has expired, been revoked, or been replaced again. Once the recovery period ends, the server MUST reject the retired key even when it is presented with the original Idempotency-Key value.

Concurrent rotation attempts using the same API key MUST produce at most one replacement. Once one attempt succeeds, a request carrying a different Idempotency-Key value MUST NOT initiate another rotation or retrieve the successful attempt's result.

4.5. Example

The client sends the following request over HTTPS. The Idempotency-Key field value is a quoted string, as specified in [I-D.ietf-httpapi-idempotency-key-header].

POST /v1/keys/rotate HTTP/1.1
Host: keys.example.com
Authorization: Bearer example-old-key
Idempotency-Key: "8e03978e-40d5-43e8-bc93-6894a57f9324"
Content-Length: 0

The server completes the rotation and returns the replacement key. In this example, it also supplies the optional expiration time.

HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: no-store
Content-Length: 65

{"api_key":"example-new-key","expires_at":"2027-03-31T12:00:00Z"}

If the response is lost, the client can resend this request within the issuer's documented recovery period. The rotation endpoint verifies example-old-key together with the original Idempotency-Key value and returns the same example-new-key and expires_at. After the recovery period ends, the endpoint rejects even this exact retry.

5. API Key Status

5.1. Status Request

The client sends a GET request [RFC9110] to the status endpoint obtained from the status member of the discovery document. The client MUST present the API key only in the Authorization header field using the Bearer authentication scheme [RFC6750]. The request has no content. The client MUST NOT follow redirects.

The status endpoint reports the status of the presented key. A status request MUST NOT change the key's status, expiration time, last rotation time, or recovery period.

5.2. Status Response

If the server can report the status of the presented key, it MUST return 200 OK with the application/json media type. The response body MUST be a JSON object [RFC8259] with the following members:

status:

REQUIRED. A string indicating the status of the presented key at the time of the request. This document defines the following values:

  • active — The key is valid for authenticating ordinary API requests, subject to its permissions.

  • revoked — The issuer has explicitly revoked the key. It can no longer authenticate ordinary API requests or authorize rotation.

  • expired — The key has reached its expiration time for ordinary API access. It can still be exchanged at the rotation endpoint if the issuer permits rotation of expired keys.

expires_at:

OPTIONAL. The time at which the presented key expires for ordinary API access, as defined for the rotation response. If this member is absent, the expiration time is unspecified to the client.

last_rotated_at:

OPTIONAL. The time at which the server issued the presented key as a replacement in a successful rotation. If the presented key was issued initially and has never been rotated, the server MUST omit this member. Retrieving the same replacement key during the recovery period MUST NOT change this timestamp.

When present, expires_at and last_rotated_at MUST each be a string containing an RFC 3339 date-time expressed in UTC with the Z offset [RFC3339].

If the presented key has both expired and been explicitly revoked, the server MUST report revoked. An expired or revoked key can receive a 200 OK status response because the lookup itself succeeded.

If the presented key is unknown, the server MUST return 404 Not Found. The server MUST also return 404 Not Found for a key retired by successful rotation, both during and after the recovery period. During that period, the client can retrieve the replacement key only by retrying the original request at the rotation endpoint as described in Section 4.4.

If the request omits the Authorization header field, the server MUST return 401 Unauthorized with a WWW-Authenticate: Bearer challenge. The server MUST include Cache-Control: no-store [RFC9111] in all responses from the status endpoint.

5.3. Examples

The client sends the following request over HTTPS:

GET /v1/keys/status HTTP/1.1
Host: keys.example.com
Authorization: Bearer example-active-key
Accept: application/json

The server reports that the key is active. It issued this key during a successful rotation on November 29, 2026. The key expires for ordinary API access on March 31, 2027.

HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: no-store
Content-Length: 96

{"status":"active","expires_at":"2027-03-31T12:00:00Z","last_rotated_at":"2026-11-29T09:15:00Z"}

For an explicitly revoked key, the server can omit both optional members:

HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: no-store
Content-Length: 20

{"status":"revoked"}

For a key that expired without ever being rotated, the server can report the expiration time. It omits last_rotated_at because no rotation occurred.

HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: no-store
Content-Length: 56

{"status":"expired","expires_at":"2026-11-01T00:00:00Z"}

For an unknown key or a key retired by rotation, the server returns:

HTTP/1.1 404 Not Found
Cache-Control: no-store
Content-Length: 0

6. Security Considerations

6.1. Possession and Compromise of an API Key

An API key used by this protocol is a bearer credential. Any party in possession of a key that is eligible for rotation can exchange it for a replacement. The issuer cannot distinguish the legitimate client from another holder of the same key on the basis of possession alone. The security considerations for bearer credentials in Section 5 of [RFC6750] apply.

If the legitimate client completes rotation first, possession of the retired key alone is insufficient to recover the replacement. If another holder completes rotation first, that holder obtains the replacement and the legitimate client's key is retired. Issuers SHOULD provide a means independent of the compromised key to revoke the currently active replacement and restore access to the legitimate client.

A key that has expired for ordinary API access remains sensitive for as long as the issuer accepts it for rotation. A holder of that key can still exchange it for a key that grants API access. Issuers SHOULD document how long an expired key remains eligible for rotation.

6.2. Discovery and Endpoint Authentication

Clients MUST use HTTPS and validate the server identity when retrieving the discovery document and when contacting either advertised endpoint. If the advertised issuer differs from the discovery origin, the client MUST verify that it is configured to trust that issuer for key management for this API before sending a key. An issuer value in the discovery document cannot by itself establish that trust.

An attacker able to modify the discovery document could direct clients to a credential-collecting endpoint, including a different path on an otherwise trusted origin. The operator MUST restrict who can publish or modify the discovery document and who controls the advertised endpoint paths. The security considerations in Section 4 of [RFC8615] apply.

6.3. Recovery of a Rotation Result

During the recovery period, possession of both the retired API key and the original Idempotency-Key value allows the holder to retrieve the replacement key. Clients and servers MUST protect this pair from disclosure. In particular, implementations MUST NOT record API key values or successful rotation response bodies in logs or traces. The Cache-Control: no-store directive does not protect data captured by application logging or tracing.

Any component that returns a stored rotation result MUST verify the binding to the presented API key and the original Idempotency-Key value before disclosing the replacement. This requirement also applies when an intermediary or middleware handles retries on behalf of the rotation endpoint. A response cache indexed solely by Idempotency-Key could disclose one client's key to another client.

The issuer MUST protect any stored recovery result against unauthorized access. Recovery MUST cease when the documented period ends or when the replacement expires, is revoked, or is rotated again, whichever occurs first. A shorter recovery period limits the time during which a captured request can be replayed. A longer period gives clients more time to recover from a lost response.

6.4. Enforcement Across Servers

If several servers accept the same API key, they must enforce retirement consistently. A server that continues to accept a retired key from a stale credential cache would allow the previous holder to retain API access after rotation. The issuer MUST coordinate activation of the replacement, retirement of the previous key, and creation of the recovery record so that a partial failure or concurrent request cannot leave two keys active or commit a rotation without its recovery result.

6.5. Status Disclosure

The status endpoint allows a holder of a candidate key value to determine whether the issuer recognizes it and, when supplied, to learn its expiration and last rotation times. Issuers SHOULD generate API keys with sufficient randomness to make guessing impractical and SHOULD rate-limit unsuccessful lookups. Status responses and error messages MUST NOT include the presented key or disclose the value of a replacement key.

7. IANA Considerations

IANA is requested to register the following entry in the "Well-Known URIs" registry in accordance with Section 3.1 of [RFC8615].

URI suffix:

api-key-rotation

Change controller:

IETF

Specification document(s):

This document, Section 3.1.

Status:

permanent

8. Normative References

[RFC8615]
Nottingham, M., "Well-Known Uniform Resource Identifiers (URIs)", RFC 8615, DOI 10.17487/RFC8615, , <https://www.rfc-editor.org/info/rfc8615>.
[I-D.ietf-httpapi-idempotency-key-header]
Jena, J., Dalal, S., and D. Tishkin, "The Idempotency-Key HTTP Header Field", Work in Progress, Internet-Draft, draft-ietf-httpapi-idempotency-key-header-09, , <https://datatracker.ietf.org/doc/html/draft-ietf-httpapi-idempotency-key-header-09>.
[RFC2119]
Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, DOI 10.17487/RFC2119, , <https://www.rfc-editor.org/info/rfc2119>.
[RFC8174]
Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, , <https://www.rfc-editor.org/info/rfc8174>.
[RFC6454]
Barth, A., "The Web Origin Concept", RFC 6454, DOI 10.17487/RFC6454, , <https://www.rfc-editor.org/info/rfc6454>.
[RFC8259]
Bray, T., Ed., "The JavaScript Object Notation (JSON) Data Interchange Format", STD 90, RFC 8259, DOI 10.17487/RFC8259, , <https://www.rfc-editor.org/info/rfc8259>.
[RFC3986]
Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform Resource Identifier (URI): Generic Syntax", STD 66, RFC 3986, DOI 10.17487/RFC3986, , <https://www.rfc-editor.org/info/rfc3986>.
[RFC9110]
Fielding, R., Ed., Nottingham, M., Ed., and J. Reschke, Ed., "HTTP Semantics", STD 97, RFC 9110, DOI 10.17487/RFC9110, , <https://www.rfc-editor.org/info/rfc9110>.
[RFC6750]
Jones, M. and D. Hardt, "The OAuth 2.0 Authorization Framework: Bearer Token Usage", RFC 6750, DOI 10.17487/RFC6750, , <https://www.rfc-editor.org/info/rfc6750>.
[RFC9111]
Fielding, R., Ed., Nottingham, M., Ed., and J. Reschke, Ed., "HTTP Caching", STD 98, RFC 9111, DOI 10.17487/RFC9111, , <https://www.rfc-editor.org/info/rfc9111>.
[RFC3339]
Klyne, G. and C. Newman, "Date and Time on the Internet: Timestamps", RFC 3339, DOI 10.17487/RFC3339, , <https://www.rfc-editor.org/info/rfc3339>.

Author's Address

Dmitrii Tishkin