Elasticsearch API key role_descriptors bounded by creator privileges
0 reputation · 03 Jul 2021, 21:12 UTC
0 reputation · 03 Jul 2021, 21:12 UTC
We need to issue Elasticsearch API keys for an external integration that must not reuse the built-in elastic user or inherit full cluster access. The documented behavior is that a key created via POST /_security/api_key inherits all privileges of the creating user unless role_descriptors are supplied. Those descriptors are capped by the creator's permissions.
This creates an unresolved design decision: if the creator is an administrator with broad access, the resulting key cannot be scoped more narrowly than that administrator's role, even if the integration only needs read access to one index. We are evaluating whether the only supported pattern is a dedicated low-privileged user for key issuance, or if another documented mechanism exists to decouple the key's effective permissions from the creator's privileges.
Behavior may vary by version because security defaults and TLS setup changed in Elasticsearch 8.x, so local test clusters may not reflect production constraints. It is unconfirmed whether version-specific changes affect role_descriptors validation against creator privileges.
Is there a supported way to create an API key whose permissions are narrower than the creating user's privileges without introducing a creator account? If role_descriptors are always bounded by the creator, what is the recommended least-privilege pattern for external integrations in 8.x? Does the API expose a validation error that reveals the privilege boundary when a descriptor is rejected?
35775 reputation · 03 Jul 2021, 22:39 UTC
Yes. A dedicated low-privileged creator is not required. An administrator—or any identity holding manage_api_key—can create an API key whose permissions are narrower than their own by passing role_descriptors to POST /_security/api_key. When descriptors are present, they replace the default inherited privilege set, and each requested privilege is validated against the creator's effective permissions.
Well-established across 7.x and 8.x: without role_descriptors, the key inherits all of the creator's privileges. With descriptors, the key is limited to the specified roles. Validation is strict: a descriptor requesting a cluster privilege, index privilege, or run-as capability that the creator lacks is rejected with an authorization or validation error, not silently truncated.
Version-sensitive: the exact HTTP status and error message text vary by minor release, particularly around 8.x security defaults such as TLS and the security index. Treat any specific error string as requiring verification against your cluster's exact version.
external_integration_read, granting only read on the required indices.manage_api_key. It does not need superuser access; it only needs the ability to create keys and assign the target role via descriptors.role_descriptors referencing that role. The creator's broader privileges are not inherited when descriptors are supplied.POST /_security/api_key
{
"name": "external-integration-key",
"role_descriptors": {
"external-integration-read": {
"cluster": [],
"indices": [
{
"names": [ "target-index-*" ],
"privileges": [ "read" ]
}
]
}
}
}GET /_security/api_key to confirm the stored descriptors.Authorization header against a read endpoint and a write endpoint to confirm the boundary.If the creator identity lacks manage_api_key, the request fails with an authorization error before descriptor validation begins. Confirming that the creator holds manage_api_key determines whether you need to adjust the creator's role or only the descriptors; without it, the least-privilege pattern above cannot be applied.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.