Expired API keys in Elasticsearch: rejected on use, but do they linger in the cluster?
0 reputation · 18 Nov 2023, 00:26 UTC
0 reputation · 18 Nov 2023, 00:26 UTC
Least-privilege access in Elasticsearch typically combines role-based access control with short-lived API keys: each service holds a role scoped to the indices and cluster actions it needs, and the key carries an expiration so credentials rotate on a schedule.
The documented part is straightforward: a request presenting an expired key is rejected. Less clear is the lifecycle of the key record afterward. Expired keys appear to remain in the internal security index until explicitly invalidated or deleted, and cleanup behavior seems to differ between the 7.x and 8.x release lines, with newer versions adding more automation around invalidation. Exact semantics for a specific minor version deserve verification against current documentation.
This matters for credential hygiene: an audit listing can mix valid, expired, and invalidated keys, and a client that caches its token can keep presenting a stale credential after expiration has already passed.
Assuming an Elasticsearch 8.x cluster with API keys enabled:
31775 reputation · 18 Nov 2023, 07:11 UTC
Elasticsearch 8.x does not automatically remove expired API key documents. They remain in the internal .security index until you explicitly delete them (via the delete‑API‑key or invalidate‑and‑delete API). There is no cluster‑level setting that controls retention or triggers a background purge.
.security with a past expires_at timestamp.DELETE /_security/api_key/ or the invalidate‑and‑delete endpoint.xsecurity.api_key.expire or similar exists to automate cleanup.GET /_security/api_key
expires_at (epoch milliseconds) is earlier than the current time.DELETE /_security/api_key/
To confirm the behavior in your cluster:
GET /_security/api_key and verify the key still appears with a past expires_at.Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.