Repository navigation
[Elasticsearch]: Authentication fails when password contains YAML special characters (e.g. double quotes) #18434
Description
Integration Name
Elasticsearch [elasticsearch]
Dataset Name
All metrics datasets (cluster_stats, node_stats, node, index, index_recovery, index_summary, ccr, enrich, ingest_pipeline, ml_job, pending_tasks, shard)
Integration Version
1.20.1
Agent Version
8.19.1
Agent Output Type
elasticsearch
Elasticsearch Version
8.19.1
OS Version and Architecture
Linux (x86_64)
Software/API Version
N/A
Error Message
The elasticsearch/metrics input enters a Degraded state with HTTP 401 errors when the configured password contains YAML special characters such as double quotes ("):
Degraded
Error fetching data for metricset elasticsearch.cluster_stats: error determining if
connected Elasticsearch node is master: HTTP error 401 in : 401 Unauthorized
The same error pattern appears across all metrics datasets that share the same template structure.
Event Original
N/A — this is an authentication/configuration issue, not a pipeline/parsing issue.
What did you do?
Configured the Elasticsearch integration's metrics input (elasticsearch/metrics) with a username and password where the password value contains double-quote characters, for example:
password: "mysecret"
(i.e. the literal password string includes the " characters as part of the value, not as YAML delimiters)
What did you see?
All metrics datasets immediately enter a Degraded state with 401 Unauthorized responses from Elasticsearch.
Inspecting the compiled agent configuration (components-actual.yaml) shows the password is stored without the surrounding quote characters:
# With a password value of: "mysecret"
password:
kind:
stringvalue: mysecret # <-- double quotes stripped by YAML parserThis happens because the Handlebars template renders the password directly as an unquoted YAML scalar:
# stream.yml.hbs (all metrics datasets)
{{#if password}}
password: {{password}}
{{/if}}When {{password}} expands to "mysecret", the rendered YAML line becomes:
password: "mysecret"YAML interprets the double quotes as string delimiters, so the parsed value is mysecret — the quotes are silently dropped. The agent then authenticates with the wrong password.
Verification with curl confirms the distinction:
# Fails (quotes stripped by shell — same as what the agent experiences):
curl -k -u monitoring_user:"mysecret" -X GET 'https://localhost:9200/_cluster/stats?pretty'
# {"type":"security_exception","reason":"unable to authenticate user..."}
# Succeeds (quotes preserved via single-quoting):
curl -k -u 'monitoring_user:"mysecret"' -X GET 'https://localhost:9200/_cluster/stats?pretty'Logging in via Kibana UI with the same password works correctly because the UI handles the value as a raw string.
What did you expect to see?
Authentication should succeed regardless of whether the password contains YAML special characters. The compiled agent config should preserve the password value exactly as entered, including any double quotes, backslashes, or other special characters.
Anything else?
Root cause: The .hbs stream templates for every Elasticsearch metrics dataset use password: {{password}} without quoting, so the YAML parser interprets characters like " as structural syntax rather than literal content.
Fix: Replace {{password}} with {{escape_string password}} in all 12 metrics dataset stream templates. The escape_string Handlebars helper (registered in Fleet's template engine) wraps the value in YAML single quotes and escapes any interior single quotes by doubling them, safely preserving all special characters.
For example, a password of "mysecret" would render as:
password: '"mysecret"'which YAML correctly parses back to the string "mysecret" (with the double quotes intact).
The same pattern is already used correctly in other integrations (e.g. ibmmq, apache_tomcat, websphere_application_server) and with other sensitive fields in cloudflare (escape_string auth_key).
Workaround: Use a password that does not contain YAML special characters, or authenticate via API key instead of username/password.
Activity
[Elasticsearch] Fix auth failure when password contains YAML special …
[Elasticsearch] Fix auth failure when password contains YAML special …
github-actions commentedon Apr 16, 2026
tl;dr: The failure is reproducible and rooted in unquoted credential templating in Elasticsearch stream templates (
password: {{password}}), and the direct fix is to switch to escaped/quoted rendering across all 12 Elasticsearch metrics datasets (and preferablyusername/api_keytoo for consistency and safety).Recommendation
Adopt the escaping approach from PR
#18435(or equivalent): replace raw credential interpolation in Elasticsearch stream templates with YAML-safe escaped output (e.g.{{escape_string password}}). Apply the same pattern consistently tousernameandapi_keyfields to avoid adjacent YAML scalar edge cases.Findings
Current Elasticsearch templates render credentials as raw YAML scalars (no quoting/escaping):
packages/elasticsearch/data_stream/node/agent/stream/stream.yml.hbs:8→username: {{username}}packages/elasticsearch/data_stream/node/agent/stream/stream.yml.hbs:11→password: {{password}}packages/elasticsearch/data_stream/node/agent/stream/stream.yml.hbs:14→api_key: {{api_key}}Same
password: {{password}}pattern appears in all 12 metrics streams:.../cluster_stats/.../stream.yml.hbs:11.../node_stats/.../stream.yml.hbs:11.../node/.../stream.yml.hbs:11.../index/.../stream.yml.hbs:11.../index_recovery/.../stream.yml.hbs:12.../index_summary/.../stream.yml.hbs:11.../ccr/.../stream.yml.hbs:11.../enrich/.../stream.yml.hbs:11.../ingest_pipeline/.../stream.yml.hbs:11.../ml_job/.../stream.yml.hbs:11.../pending_tasks/.../stream.yml.hbs:11.../shard/.../stream.yml.hbs:11Manifest confirms these are user-configurable credentials:
packages/elasticsearch/manifest.yml:46-66(username,password,api_key).Repo precedent exists for quoted password rendering:
packages/apache_tomcat/data_stream/cache/agent/stream/stream.yml.hbs:13→password: "{{password}}"packages/ibmmq/data_stream/qmgr/agent/stream/stream.yml.hbs:14→password: "{{password}}"Related PR context:
#18435documents this exact issue and proposes{{escape_string password}}for the same 12 templates, but the PR is currently closed and unmerged.Issue body access limitation:
#18434body text directly via MCP due integrity filtering, so analysis is based on title + code + PR context.Verification
I verified YAML behavior with a local parser using representative rendered outputs:
Additional parser checks also showed plain-scalar pitfalls for special characters (e.g. alias/object coercion):
This confirms raw scalar insertion can change value semantics or produce parse errors depending on input.
Detailed Action Plan
Update Elasticsearch stream templates to YAML-safe credential rendering:
{{password}}with escaped/quoted form (as in#18435,{{escape_string password}}).Extend same safety to adjacent credentials:
usernameandapi_keylines (:8/:14in most files) and apply equivalent escaping strategy for consistency.Add regression coverage in Elasticsearch package tests:
",:,#,',*,{}, and verify rendered config preserves intended literal value.api_keycase (currently test defaults mostly use simplepassword: changeme).Validate package behavior end-to-end:
Related Items
api_key) in Elasticsearch packagepackages/elasticsearch/manifest.yml:46-66packages/elasticsearch/data_stream/node/agent/stream/stream.yml.hbs:8-14packages/apache_tomcat/data_stream/cache/agent/stream/stream.yml.hbs:10-13packages/ibmmq/data_stream/qmgr/agent/stream/stream.yml.hbs:11-14Note
🔒 Integrity filter blocked 34 items
The following items were blocked because they don't meet the GitHub integrity level.
issue_read: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".search_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".search_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".search_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".search_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".search_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".search_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".search_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".search_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".search_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".search_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".search_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".search_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".search_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".search_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".search_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".To allow these resources, lower
min-integrityin your GitHub frontmatter:What is this? | From workflow: Issue Triage
Give us feedback! React with 🚀 if perfect, 👍 if helpful, 👎 if not.
[Elasticsearch] Fix authentication failure when password contains YAM…
elastic-vault-github-plugin-prod commentedon May 6, 2026
Package elasticsearch - 1.20.2 containing this change is available at https://epr.elastic.co/package/elasticsearch/1.20.2/
[Elasticsearch] Fix authentication failure when password contains YAM…