Loading...
Loading...
Manage Elasticsearch RBAC: native users, roles, role mappings, document- and field-level security. Use when creating users or roles, assigning privileges, or mapping external realms like LDAP/SAML.
npx skill4agent add elastic/agent-skills elasticsearch-authzDeployment note: Feature availability differs between self-managed, ECH, and Serverless. See Deployment Compatibility for details.
| Item | Description |
|---|---|
| Elasticsearch URL | Cluster endpoint (e.g. |
| Kibana URL | Required only when setting Kibana feature/space privileges |
| Authentication | Valid credentials (see the elasticsearch-authn skill) |
| Cluster privileges | |
logs-*| Component | Question to answer |
|---|---|
| Who | New native user, existing user, or external realm user (LDAP, SAML, etc.) |
| What | Which indices, data streams, or Kibana features |
| Access level | Read, write, manage, or a specific set of privileges |
| Scope | All documents/fields, or restricted by region, department, sensitivity? |
| Kibana? | Does the request mention any Kibana feature (dashboards, Discover, etc.) |
| Deployment? | Self-managed, ECH, or Serverless? Serverless has a different user model. |
curl "${ELASTICSEARCH_URL}/_security/role" <auth_flags>| Scenario | Action |
|---|---|
| New native user | Create the user with the role and a strong generated password. (Self-managed / ECH only.) |
| Existing native user | Fetch current roles, append the new role, update the user with the full array. (Self-managed / ECH only.) |
| External realm user | Create a role mapping that matches the user's realm attributes to the role. (Self-managed / ECH only.) |
| Serverless user | Use the cloud-access-management skill. Assign a predefined role or create a custom role first, then assign it via the Cloud API. |
analystlogs-*metrics-*analystlogs-*metrics-*GET /_security/rolelogs-metrics-dashboard-viewerPOST /_security/user/analystroles: ["logs-metrics-dashboard-viewer"]Native user management applies to self-managed and ECH deployments. On Serverless, users are managed at the organization level — skip this section.
curl -X POST "${ELASTICSEARCH_URL}/_security/user/${USERNAME}" \
<auth_flags> \
-H "Content-Type: application/json" \
-d '{
"password": "'"${PASSWORD}"'",
"roles": ["'"${ROLE_NAME}"'"],
"full_name": "'"${FULL_NAME}"'",
"email": "'"${EMAIL}"'",
"enabled": true
}'PUT /_security/user/${USERNAME}passwordcurl -X POST "${ELASTICSEARCH_URL}/_security/user/${USERNAME}/_password" \
<auth_flags> -H "Content-Type: application/json" \
-d '{"password": "'"${NEW_PASSWORD}"'"}'
curl -X PUT "${ELASTICSEARCH_URL}/_security/user/${USERNAME}/_disable" <auth_flags>
curl -X PUT "${ELASTICSEARCH_URL}/_security/user/${USERNAME}/_enable" <auth_flags>
curl "${ELASTICSEARCH_URL}/_security/user/${USERNAME}" <auth_flags>
curl -X DELETE "${ELASTICSEARCH_URL}/_security/user/${USERNAME}" <auth_flags>PUT /_security/role/{name}clusterindicesPUT /api/security/role/{name}clusterindicescurl -X PUT "${ELASTICSEARCH_URL}/_security/role/${ROLE_NAME}" \
<auth_flags> \
-H "Content-Type: application/json" \
-d '{
"description": "'"${ROLE_DISPLAY_NAME}"'",
"cluster": [],
"indices": [
{
"names": ["'"${INDEX_PATTERN}"'"],
"privileges": ["read", "view_index_metadata"]
}
]
}'curl -X PUT "${KIBANA_URL}/api/security/role/${ROLE_NAME}" \
<auth_flags> \
-H "kbn-xsrf: true" \
-H "Content-Type: application/json" \
-d '{
"description": "'"${ROLE_DISPLAY_NAME}"'",
"elasticsearch": {
"cluster": [],
"indices": [
{
"names": ["'"${INDEX_PATTERN}"'"],
"privileges": ["read", "view_index_metadata"]
}
]
},
"kibana": [
{
"base": [],
"feature": {
"discover": ["read"],
"dashboard": ["read"]
},
"spaces": ["*"]
}
]
}'curl "${ELASTICSEARCH_URL}/_security/role/${ROLE_NAME}" <auth_flags>
curl "${ELASTICSEARCH_URL}/_security/role" <auth_flags>
curl -X DELETE "${ELASTICSEARCH_URL}/_security/role/${ROLE_NAME}" <auth_flags>grantexceptcurl -X PUT "${ELASTICSEARCH_URL}/_security/role/pii-redacted-reader" \
<auth_flags> \
-H "Content-Type: application/json" \
-d '{
"description": "PII Redacted Reader",
"indices": [
{
"names": ["customers-*"],
"privileges": ["read"],
"field_security": {
"grant": ["*"],
"except": ["ssn", "credit_card", "date_of_birth"]
}
}
]
}'curl -X PUT "${ELASTICSEARCH_URL}/_security/role/emea-logs-reader" \
<auth_flags> \
-H "Content-Type: application/json" \
-d '{
"description": "EMEA Logs Reader",
"indices": [
{
"names": ["logs-*"],
"privileges": ["read"],
"query": "{\"term\": {\"region\": \"emea\"}}"
}
]
}'queryregionemeametadata{{_user.metadata.<key>}}curl -X PUT "${ELASTICSEARCH_URL}/_security/role/department-reader" \
<auth_flags> \
-H "Content-Type: application/json" \
-d '{
"description": "Department Reader",
"indices": [
{
"names": ["records-*"],
"privileges": ["read"],
"query": "{\"template\": {\"source\": \"{\\\"term\\\": {\\\"department\\\": \\\"{{_user.metadata.department}}\\\"}}\"}}"
}
]
}'"metadata": {"department": "engineering"}departmentengineeringterms_setminimum_should_match_fieldterms_setqueryfield_securitySelf-managed and ECH only. On Serverless, use the cloud-access-management skill — see Serverless User Access.
rolescurl -X PUT "${ELASTICSEARCH_URL}/_security/user/${USERNAME}" \
<auth_flags> \
-H "Content-Type: application/json" \
-d '{
"roles": ["role-a", "role-b"]
}'rolesRole mappings are not available on Serverless (both ES and Kibana APIs are disabled). Use the cloud-access-management skill instead — see Serverless User Access.
curl -X PUT "${ELASTICSEARCH_URL}/_security/role_mapping/saml-default-access" \
<auth_flags> \
-H "Content-Type: application/json" \
-d '{
"roles": ["viewer"],
"enabled": true,
"rules": {
"field": { "realm.name": "saml1" }
}
}'curl -X PUT "${ELASTICSEARCH_URL}/_security/role_mapping/ldap-admins" \
<auth_flags> \
-H "Content-Type: application/json" \
-d '{
"roles": ["superuser"],
"enabled": true,
"rules": {
"all": [
{ "field": { "realm.name": "ldap1" } },
{ "field": { "groups": "cn=admins,ou=groups,dc=example,dc=com" } }
]
}
}'role_templatesrolescurl -X PUT "${ELASTICSEARCH_URL}/_security/role_mapping/ldap-group-roles" \
<auth_flags> \
-H "Content-Type: application/json" \
-d '{
"role_templates": [
{
"template": { "source": "{{#tojson}}groups{{/tojson}}" },
"format": "json"
}
],
"enabled": true,
"rules": {
"field": { "realm.name": "ldap1" }
}
}'curl "${ELASTICSEARCH_URL}/_security/role_mapping/saml-default-access" <auth_flags>
curl "${ELASTICSEARCH_URL}/_security/role_mapping" <auth_flags>
curl -X DELETE "${ELASTICSEARCH_URL}/_security/role_mapping/saml-default-access" <auth_flags>admindeveloperviewerjoelogs-*PUT /_security/role/logs-reader"description": "Logs Reader"indices: [{ names: ["logs-*"], privileges: ["read", "view_index_metadata"] }]POST /_security/user/joe"roles": ["logs-reader"]logs-*PUT <KIBANA_URL>/api/security/role/logs-dashboard-viewerelasticsearch.indiceskibana[].featureapm-*GET /_security/user/alice"roles": ["viewer"]apm-readerindices: [{ names: ["apm-*"], privileges: ["read", "view_index_metadata"] }]PUT /_security/user/alice"roles": ["viewer", "apm-reader"]alice@example.comcolorsPUT <KIBANA_URL>/api/security/role/colors-rw-kibanaelasticsearch.indicesreadwriteview_index_metadatacolorskibana[].featuredashboarddiscovercolors-rw-kibanaPOST /_security/user/manager_a"metadata": {"department": "engineering"}PUT /_security/role/hr-department-viewer
{
"description": "HR Department Viewer",
"indices": [
{
"names": ["hr-*"],
"privileges": ["read"],
"field_security": { "grant": ["*"], "except": ["ssn", "salary", "date_of_birth"] },
"query": "{\"template\": {\"source\": \"{\\\"term\\\": {\\\"department\\\": \\\"{{_user.metadata.department}}\\\"}}\"}}"
}
]
}elasticelasticreadview_index_metadataclusterqueryfield_securityindices:data/read/searchmanage_ingest_pipelinesmonitormanagealllogs-readerapm-data-viewermetrics-writercustom-rolenew-roledescription"Logs Reader""APM Data Viewer""Read-only access to all logs-* indices for the operations team"X9k#mP2vL!qR7wZnchangemepassword123rolesrolesviewerrole_templatesallanyfieldexceptenabled: false