elasticsearch-authn by elastic/agent-skills
npx skills add https://github.com/elastic/agent-skills --skill elasticsearch-authn使用任何已配置的受支持身份验证领域对 Elasticsearch 集群进行身份验证。此技能涵盖所有内置领域、凭据验证以及完整的 API 密钥生命周期。
关于角色、用户、角色分配和角色映射,请参阅 elasticsearch-authz 技能。
关于详细的 API 端点,请参阅 references/api-reference.md。
部署说明: 并非所有领域在所有部署类型上都可用。有关自托管、ECH 与 Serverless 的详细信息,请参阅部署兼容性。
ELASTICSEARCH_PASSWORD、ELASTICSEARCH_API_KEY)。当缺少必需的变量时,指示用户在项目根目录的 .env 文件中设置它——切勿直接提示输入值。.env 而非终端导出。 代理可能在沙盒化的 shell 会话中运行命令,该会话不继承用户的终端环境。工作目录中的 .env 文件在所有执行上下文中都是可靠的。仅当用户明确偏好时,才建议使用 作为备选方案。广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
export_authenticate)| 项目 | 描述 |
|---|---|
| Elasticsearch URL | 集群端点(例如 https://localhost:9200 或 Cloud 部署 URL) |
| 凭据 | 取决于领域——请参阅下面的方法 |
| 已配置的领域 | 身份验证领域及其身份后端必须已配置(领域链、IdP、LDAP/AD、Kerberos、PKI/TLS) |
如果缺少任何必需的值,请指示用户将其添加到项目根目录的 .env 文件中。终端导出可能对在单独 shell 会话中运行的代理不可见——.env 文件是可靠的默认选择。切勿要求用户将凭据粘贴到聊天中——秘密信息不得出现在对话历史记录中。
Elasticsearch 按配置的顺序(领域链)评估领域。第一个能够对请求进行身份验证的领域胜出。内部领域由 Elasticsearch 管理;外部领域委托给企业身份系统。
用户存储在专用的 Elasticsearch 索引中。交互式使用的最简单方法。通过 Kibana 或用户管理 API 进行管理(请参阅 elasticsearch-authz 技能)。
curl -u "${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD}" "${ELASTICSEARCH_URL}/_security/_authenticate"
用户定义在每个集群节点的平面文件中(elasticsearch-users CLI)。无论许可证状态如何始终处于活动状态,使其成为付费领域被禁用时的灾难恢复后备方案。仅在自托管部署上可用。
curl -u "${FILE_USER}:${FILE_PASSWORD}" "${ELASTICSEARCH_URL}/_security/_authenticate"
使用用户名和密码针对外部 LDAP 目录进行身份验证。仅限自托管——在 ECH 或 Serverless 上不可用。通常与角色映射结合使用,将 LDAP 组转换为 Elasticsearch 角色。
curl -u "${LDAP_USER}:${LDAP_PASSWORD}" "${ELASTICSEARCH_URL}/_security/_authenticate"
请求与原生领域相同——Elasticsearch 通过领域链将其路由到 LDAP 领域。
针对 Active Directory 域进行身份验证。仅限自托管——在 ECH 或 Serverless 上不可用。类似于 LDAP,但使用 AD 特定的默认值(用户主体名称、sAMAccountName)。通常与角色映射结合使用,用于 AD 组到角色的转换。
curl -u "${AD_USER}:${AD_PASSWORD}" "${ELASTICSEARCH_URL}/_security/_authenticate"
使用在 TLS 握手期间提供的 X.509 客户端证书进行身份验证。需要 PKI 领域和 HTTP 层上的 TLS。在 ECH 上,PKI 支持有限——请检查部署设置。在 Serverless 上不可用。最适合相互 TLS 环境中的服务到服务通信。
curl --cert "${CLIENT_CERT}" --key "${CLIENT_KEY}" --cacert "${CA_CERT}" \
"${ELASTICSEARCH_URL}/_security/_authenticate"
启用 SAML 2.0 Web 浏览器 SSO,主要用于 Kibana 身份验证。在自托管上,在 elasticsearch.yml 中配置。在 ECH 上,通过 Cloud 部署设置 UI 配置。在 Serverless 上,SAML 在组织级别处理,无法按项目配置。标准 REST 客户端无法使用——基于浏览器的重定向流程由 Kibana 处理。为编程 API 访问,请与 SAML 一起配置另一个领域(例如原生或 API 密钥)。
启用 OpenID Connect SSO,主要用于 Kibana 身份验证。在自托管上,在 elasticsearch.yml 中配置。在 ECH 上,通过 Cloud 部署设置 UI 配置。在 Serverless 上不可用。与 SAML 类似,它依赖于浏览器重定向,不适合直接由 REST 客户端使用。对于与 OIDC 一起的编程访问,请使用 API 密钥或原生用户。
自定义应用程序可以通过 POST /_security/oidc/authenticate 将 OIDC 令牌交换为 Elasticsearch 访问令牌,但这需要实现完整的 OIDC 重定向流程。
接受外部身份提供者颁发的 JWT 作为承载令牌。在自托管上,在 elasticsearch.yml 中配置。在 ECH 上,通过 Cloud 部署设置 UI 配置。在 Serverless 上不可用。支持两种令牌类型:
id_token(默认)——用于用户代表流程的 OpenID Connect ID 令牌。
access_token ——用于应用程序身份流程的 OAuth2 客户端凭据。
curl -H "Authorization: Bearer ${JWT_TOKEN}" "${ELASTICSEARCH_URL}/_security/_authenticate"
每个 JWT 领域处理一种令牌类型。如果需要 id_token 和 access_token,请配置单独的领域。
通过 SPNEGO 机制使用 Kerberos 票据进行身份验证。仅限自托管——在 ECH 或 Serverless 上不可用。需要正常工作的 KDC 基础设施、正确的 DNS 和时间同步。
kinit "${KERBEROS_PRINCIPAL}"
curl --negotiate -u : "${ELASTICSEARCH_URL}/_security/_authenticate"
--negotiate 标志启用 SPNEGO。-u : 是 curl 要求的,但用户名被忽略——使用来自 kinit 的主体。需要 curl 7.49+ 并支持 GSS-API/SPNEGO。
不是一个领域,而是一种独立的身份验证机制。在 Authorization 标头中传递 Base64 编码的 API 密钥。推荐用于编程和自动化访问。
curl -H "Authorization: ApiKey ${ELASTICSEARCH_API_KEY}" "${ELASTICSEARCH_URL}/_security/_authenticate"
ELASTICSEARCH_API_KEY 是创建密钥时返回的 encoded 值(id:api_key 的 Base64 编码)。
在继续之前始终验证凭据:
curl <auth_flags> "${ELASTICSEARCH_URL}/_security/_authenticate"
检查 username、roles 和 authentication_realm.type 以确认身份和方法:
authentication_realm.type | 领域 |
|---|---|
native | 原生 |
file | 文件 |
ldap | LDAP |
active_directory | Active Directory |
pki | PKI |
saml | SAML |
oidc | OpenID Connect |
jwt | JWT |
kerberos | Kerberos |
对于 API 密钥,authentication_type 是 "api_key"(不是领域类型)。
curl -X POST "${ELASTICSEARCH_URL}/_security/api_key" \
<auth_flags> \
-H "Content-Type: application/json" \
-d '{
"name": "'"${KEY_NAME}"'",
"expiration": "30d",
"role_descriptors": {
"'"${ROLE_NAME}"'": {
"cluster": [],
"indices": [
{
"names": ["'"${INDEX_PATTERN}"'"],
"privileges": ["read"]
}
]
}
}
}'
响应包含 id、api_key 和 encoded。安全地存储 encoded——它无法再次检索。
省略 role_descriptors 以继承经过身份验证的用户当前权限的快照。
限制: API 密钥无法创建具有权限的另一个 API 密钥。派生密钥创建时没有有效访问权限。请改用
POST /_security/api_key/grant和用户凭据。
curl "${ELASTICSEARCH_URL}/_security/api_key?name=${KEY_NAME}" <auth_flags>
curl -X DELETE "${ELASTICSEARCH_URL}/_security/api_key" \
<auth_flags> \
-H "Content-Type: application/json" \
-d '{"name": "'"${KEY_NAME}"'"}'
请求: "创建一个只能从 metrics-* 读取的 API 密钥。"
POST /_security/api_key
{
"name": "metrics-reader-key",
"expiration": "90d",
"role_descriptors": {
"metrics-reader": {
"indices": [
{
"names": ["metrics-*"],
"privileges": ["read", "view_index_metadata"]
}
]
}
}
}
GET /_security/_authenticate
{
"username": "joe",
"authentication_realm": { "name": "ldap1", "type": "ldap" },
"authentication_type": "realm"
}
curl -H "Authorization: Bearer ${JWT_TOKEN}" "https://my-cluster:9200/_security/_authenticate"
确认响应显示 authentication_realm.type 为 "jwt"。
| 方法 | 最适合 | 权衡 |
|---|---|---|
| 原生用户 | 交互式使用,简单设置 | 密码必须存储或提示输入 |
| 文件用户 | 灾难恢复,引导程序 | 必须在每个节点上配置 |
| API 密钥 | 编程访问,CI/CD,范围限定访问 | 创建后无法检索 |
| LDAP / AD | 企业目录集成 | 需要访问目录服务器的网络连接 |
| PKI 证书 | 服务到服务,相互 TLS 环境 | 需要 PKI 基础设施和 PKI 领域 |
| SAML | 通过企业 IdP 进行 Kibana SSO | 仅限浏览器;不适用于 REST 客户端 |
| OIDC | 通过 OpenID Connect 提供者进行 Kibana SSO | 仅限浏览器;不适用于 REST 客户端 |
| JWT | 基于令牌的服务和用户身份验证 | 需要外部令牌颁发者和领域配置 |
| Kerberos | Windows/企业 Kerberos 环境 | 需要 KDC、DNS、时间同步基础设施 |
对于自动化工作流,优先使用 API 密钥——它们支持细粒度范围限定和独立的过期时间。对于 Kibana SSO,使用 SAML 或 OIDC。对于企业目录集成,使用 LDAP 或 AD 并配合角色映射(请参阅 elasticsearch-authz)。
切勿将内置的 elastic 超级用户或任何具有 superuser 角色的帐户用于日常操作、自动化或应用程序访问。相反,创建一个仅具有任务所需权限的专用用户或 API 密钥。elastic 用户应仅保留用于初始集群设置和紧急恢复。
POST /_security/api_key/grant。expiration。在生产中避免使用无限期的密钥。role_descriptors 限定 API 密钥的范围。切勿为自动化系统创建无范围限定的密钥。GET /_security/_authenticate 验证凭据。changeme 或 password123。并非所有身份验证领域在所有部署类型上都可用。自托管集群支持所有领域。Elastic Cloud Hosted (ECH) 由 Elastic 管理,没有节点级访问权限。Serverless 是完全托管的 SaaS。
| 领域 | 自托管 | ECH | Serverless |
|---|---|---|---|
| 原生 | 是 | 是 | 不可用 |
| 文件 | 是 | 不可用 | 不可用 |
| LDAP | 是 | 不可用 | 不可用 |
| Active Directory | 是 | 不可用 | 不可用 |
| PKI | 是 | 有限 | 不可用 |
| SAML | 是 | 是(部署配置) | 组织级别 |
| OIDC | 是 | 是(部署配置) | 不可用 |
| JWT | 是 | 是(部署配置) | 不可用 |
| Kerberos | 是 | 不可用 | 不可用 |
| API 密钥 | 是 | 是 | 是 |
ECH 说明:
elasticsearch-users CLI 不可用。elastic 超级用户可用,但仍应避免用于日常使用。Serverless 说明:
每周安装数
157
代码库
GitHub 星标数
89
首次出现
10 天前
安全审计
安装于
cursor137
github-copilot126
codex126
opencode125
gemini-cli125
amp124
Authenticate to an Elasticsearch cluster using any supported authentication realm that is already configured. This skill covers all built-in realms, credential verification, and the full API key lifecycle.
For roles, users, role assignment, and role mappings, see the elasticsearch-authz skill.
For detailed API endpoints, see references/api-reference.md.
Deployment note: Not all realms are available on every deployment type. See Deployment Compatibility for self-managed vs. ECH vs. Serverless details.
ELASTICSEARCH_PASSWORD, ELASTICSEARCH_API_KEY). When a required variable is missing, instruct the user to set it in a .env file in the project root — never prompt for the value directly..env over terminal exports. Agents may run commands in a sandboxed shell session that does not inherit the user's terminal environment. A .env file in the working directory is reliable across all execution contexts. Only suggest export as a fallback when the user explicitly prefers it._authenticate)| Item | Description |
|---|---|
| Elasticsearch URL | Cluster endpoint (e.g. https://localhost:9200 or a Cloud deployment URL) |
| Credentials | Depends on the realm — see the methods below |
| Realms configured | Authentication realms and their identity backends must already be configured (realm chain, IdP, LDAP/AD, Kerberos, PKI/TLS) |
If any required value is missing, instruct the user to add it to a .env file in the project root. Terminal exports may not be visible to agents running in a separate shell session — the .env file is the reliable default. Never ask the user to paste credentials into the chat — secrets must not appear in conversation history.
Elasticsearch evaluates realms in a configured order (the realm chain). The first realm that can authenticate the request wins. Internal realms are managed by Elasticsearch; external realms delegate to enterprise identity systems.
Users stored in a dedicated Elasticsearch index. Simplest method for interactive use. Managed via Kibana or the user management APIs (see the elasticsearch-authz skill).
curl -u "${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD}" "${ELASTICSEARCH_URL}/_security/_authenticate"
Users defined in flat files on each cluster node (elasticsearch-users CLI). Always active regardless of license state, making it the fallback for disaster recovery when paid realms are disabled. Only available on self-managed deployments.
curl -u "${FILE_USER}:${FILE_PASSWORD}" "${ELASTICSEARCH_URL}/_security/_authenticate"
Authenticates against an external LDAP directory using username and password. Self-managed only — not available on ECH or Serverless. Typically combined with role mappings to translate LDAP groups to Elasticsearch roles.
curl -u "${LDAP_USER}:${LDAP_PASSWORD}" "${ELASTICSEARCH_URL}/_security/_authenticate"
The request is identical to native — Elasticsearch routes it to the LDAP realm via the realm chain.
Authenticates against an Active Directory domain. Self-managed only — not available on ECH or Serverless. Similar to LDAP but uses AD-specific defaults (user principal name, sAMAccountName). Typically combined with role mappings for AD group-to-role translation.
curl -u "${AD_USER}:${AD_PASSWORD}" "${ELASTICSEARCH_URL}/_security/_authenticate"
Authenticates using X.509 client certificates presented during the TLS handshake. Requires a PKI realm and TLS on the HTTP layer. On ECH, PKI support is limited — check deployment settings. Not available on Serverless. Best for service-to-service communication in mutual TLS environments.
curl --cert "${CLIENT_CERT}" --key "${CLIENT_KEY}" --cacert "${CA_CERT}" \
"${ELASTICSEARCH_URL}/_security/_authenticate"
Enables SAML 2.0 Web Browser SSO, primarily for Kibana authentication. On self-managed, configure in elasticsearch.yml. On ECH, configure through the Cloud deployment settings UI. On Serverless, SAML is handled at the organization level and not configurable per project. Not usable by standard REST clients — the browser-based redirect flow is handled by Kibana. Configure another realm (e.g. native or API keys) alongside SAML for programmatic API access.
Enables OpenID Connect SSO, primarily for Kibana authentication. On self-managed, configure in elasticsearch.yml. On ECH, configure through the Cloud deployment settings UI. Not available on Serverless. Like SAML, it relies on browser redirects and is not suited for direct REST client use. For programmatic access alongside OIDC, use API keys or native users.
Custom applications can exchange OIDC tokens for Elasticsearch access tokens via POST /_security/oidc/authenticate, but this requires implementing the full OIDC redirect flow.
Accepts JWTs issued by an external identity provider as bearer tokens. On self-managed, configure in elasticsearch.yml. On ECH, configure through the Cloud deployment settings UI. Not available on Serverless. Supports two token types:
id_token (default) — OpenID Connect ID tokens for user-on-behalf-of flows.
access_token — OAuth2 client credentials for application identity flows.
curl -H "Authorization: Bearer ${JWT_TOKEN}" "${ELASTICSEARCH_URL}/_security/_authenticate"
Each JWT realm handles one token type. Configure separate realms for id_token and access_token if both are needed.
Authenticates using Kerberos tickets via the SPNEGO mechanism. Self-managed only — not available on ECH or Serverless. Requires a working KDC infrastructure, proper DNS, and time synchronization.
kinit "${KERBEROS_PRINCIPAL}"
curl --negotiate -u : "${ELASTICSEARCH_URL}/_security/_authenticate"
The --negotiate flag enables SPNEGO. The -u : is required by curl but the username is ignored — the principal from kinit is used. Requires curl 7.49+ with GSS-API/SPNEGO support.
Not a realm, but a distinct authentication mechanism. Pass a Base64-encoded API key in the Authorization header. Preferred for programmatic and automated access.
curl -H "Authorization: ApiKey ${ELASTICSEARCH_API_KEY}" "${ELASTICSEARCH_URL}/_security/_authenticate"
ELASTICSEARCH_API_KEY is the encoded value (Base64 of id:api_key) returned when the key was created.
Always verify credentials before proceeding:
curl <auth_flags> "${ELASTICSEARCH_URL}/_security/_authenticate"
Check username, roles, and authentication_realm.type to confirm identity and method:
authentication_realm.type | Realm |
|---|---|
native | Native |
file | File |
ldap | LDAP |
active_directory | Active Directory |
pki | PKI |
saml |
For API keys, authentication_type is "api_key" (not a realm type).
curl -X POST "${ELASTICSEARCH_URL}/_security/api_key" \
<auth_flags> \
-H "Content-Type: application/json" \
-d '{
"name": "'"${KEY_NAME}"'",
"expiration": "30d",
"role_descriptors": {
"'"${ROLE_NAME}"'": {
"cluster": [],
"indices": [
{
"names": ["'"${INDEX_PATTERN}"'"],
"privileges": ["read"]
}
]
}
}
}'
The response contains id, api_key, and encoded. Store encoded securely — it cannot be retrieved again.
Omit role_descriptors to inherit a snapshot of the authenticated user's current privileges.
Limitation: An API key cannot create another API key with privileges. The derived key is created with no effective access. Use
POST /_security/api_key/grantwith user credentials instead.
curl "${ELASTICSEARCH_URL}/_security/api_key?name=${KEY_NAME}" <auth_flags>
curl -X DELETE "${ELASTICSEARCH_URL}/_security/api_key" \
<auth_flags> \
-H "Content-Type: application/json" \
-d '{"name": "'"${KEY_NAME}"'"}'
Request: "Create an API key that can only read from metrics-*."
POST /_security/api_key
{
"name": "metrics-reader-key",
"expiration": "90d",
"role_descriptors": {
"metrics-reader": {
"indices": [
{
"names": ["metrics-*"],
"privileges": ["read", "view_index_metadata"]
}
]
}
}
}
GET /_security/_authenticate
{
"username": "joe",
"authentication_realm": { "name": "ldap1", "type": "ldap" },
"authentication_type": "realm"
}
curl -H "Authorization: Bearer ${JWT_TOKEN}" "https://my-cluster:9200/_security/_authenticate"
Confirm the response shows authentication_realm.type as "jwt".
| Method | Best for | Trade-offs |
|---|---|---|
| Native user | Interactive use, simple setups | Password must be stored or prompted |
| File user | Disaster recovery, bootstrap | Must be configured on every node |
| API key | Programmatic access, CI/CD, scoped access | Cannot be retrieved after creation |
| LDAP / AD | Enterprise directory integration | Requires network access to directory server |
| PKI certificate | Service-to-service, mutual TLS environments | Requires PKI infrastructure and PKI realm |
| SAML | Kibana SSO via enterprise IdP | Browser-only; not for REST clients |
| OIDC | Kibana SSO via OpenID Connect provider | Browser-only; not for REST clients |
| JWT | Token-based service and user authentication | Requires external token issuer and realm config |
| Kerberos |
Prefer API keys for automated workflows — they support fine-grained scoping and independent expiration. For Kibana SSO, use SAML or OIDC. For enterprise directory integration, use LDAP or AD with role mappings (see elasticsearch-authz).
Never use the built-in elastic superuser or any superuser-role account for day-to-day operations, automation, or application access. Instead, create a dedicated user or API key with only the privileges the task requires. The elastic user should be reserved for initial cluster setup and emergency recovery only.
POST /_security/api_key/grant for programmatic key creation.expiration on API keys. Avoid indefinite keys in production.role_descriptors. Never create unscoped keys for automated systems.GET /_security/_authenticate to verify credentials before running management operations.changeme or password123.Not all authentication realms are available on every deployment type. Self-managed clusters support all realms. Elastic Cloud Hosted (ECH) is managed by Elastic with no node-level access. Serverless is fully managed SaaS.
| Realm | Self-managed | ECH | Serverless |
|---|---|---|---|
| Native | Yes | Yes | Not available |
| File | Yes | Not available | Not available |
| LDAP | Yes | Not available | Not available |
| Active Directory | Yes | Not available | Not available |
| PKI | Yes | Limited | Not available |
| SAML | Yes | Yes (deployment config) | Organization-level |
| OIDC | Yes | Yes (deployment config) | Not available |
| JWT |
ECH notes:
elasticsearch-users CLI are not available.elastic superuser is available but should still be avoided for routine use.Serverless notes:
Weekly Installs
157
Repository
GitHub Stars
89
First Seen
10 days ago
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
cursor137
github-copilot126
codex126
opencode125
gemini-cli125
amp124
市场调研技能:全面指南与框架,助您分析竞争对手、识别市场机会
71 周安装
Python数据分析技能 - 掌握Pandas、NumPy数据操作与Jupyter工作流
71 周安装
Docker专家技能:NestJS/Next.js容器化、Docker Compose配置与微服务编排最佳实践
71 周安装
yfinance MCP 服务器 - 获取 Yahoo Finance 实时和历史金融数据 | 股票价格、期权、财报、新闻
71 周安装
Salesforce B2C Business Manager 扩展开发指南:自定义管理界面菜单、表单与对话框
71 周安装
Godot 4 性能优化指南:多线程、对象池、渲染批处理与物理查询优化
71 周安装
| SAML |
oidc | OpenID Connect |
jwt | JWT |
kerberos | Kerberos |
| Windows/enterprise Kerberos environments |
| Requires KDC, DNS, time sync infrastructure |
| Yes |
| Yes (deployment config) |
| Not available |
| Kerberos | Yes | Not available | Not available |
| API keys | Yes | Yes | Yes |