[Elasticsearch] Fix authentication failure when password contains YAML special characters - #18436
Merged
maramos-elastic merged 3 commits intoMay 6, 2026
Merged
Conversation
…characters Use the escape_string Handlebars helper for the password field in all 12 Elasticsearch metrics dataset stream templates. Previously, passwords containing YAML special characters (e.g. double quotes) were rendered as unquoted YAML scalars, causing the YAML parser to strip the special chars before passing the value to the Beat. For example, a password of "mysecret" rendered as: password: "mysecret" which YAML parses as the string 'mysecret' (quotes stripped), causing 401 Unauthorized errors. With escape_string, the same password renders as: password: '"mysecret"' which YAML correctly parses back to '"mysecret"'. Fixes: #18434
andrewkroh
reviewed
Apr 30, 2026
Contributor
🚀 Benchmarks reportPackage
|
| Data stream | Previous EPS | New EPS | Diff (%) | Result |
|---|---|---|---|---|
gc |
4975.12 | 2958.58 | -2016.54 (-40.53%) | 💔 |
To see the full report comment with /test benchmark fullreport
Escape username values in data_stream agent stream templates using the escape_string Handlebars helper (passwords were already escaped) to prevent authentication failures when credentials contain YAML special characters. Update changelog text to mention username. Replace hardcoded pipeline name in transform/index_pivot/transform.yml with '{{ ingestPipelineName "monitoring_indices" }}' to generate the correct versioned pipeline name.
💚 Build Succeeded
History
|
maramos-elastic
marked this pull request as ready for review
May 6, 2026 17:26
pickypg
approved these changes
May 6, 2026
pickypg
left a comment
Member
There was a problem hiding this comment.
LGTM. Thanks @andrewkroh for the 👀
maramos-elastic
deleted the
18434-elasticsearch-password-yaml-special-chars
branch
May 6, 2026 17:30
herrBez
pushed a commit
to herrBez/integrations
that referenced
this pull request
Jun 1, 2026
…L special characters (elastic#18436) * [Elasticsearch] Fix auth failure when password contains YAML special characters Use the escape_string Handlebars helper for the password field in all 12 Elasticsearch metrics dataset stream templates. Previously, passwords containing YAML special characters (e.g. double quotes) were rendered as unquoted YAML scalars, causing the YAML parser to strip the special chars before passing the value to the Beat. For example, a password of "mysecret" rendered as: password: "mysecret" which YAML parses as the string 'mysecret' (quotes stripped), causing 401 Unauthorized errors. With escape_string, the same password renders as: password: '"mysecret"' which YAML correctly parses back to '"mysecret"'. Fixes: elastic#18434 * Update hardcoded version in transform * Escape usernames; use ingestPipelineName Escape username values in data_stream agent stream templates using the escape_string Handlebars helper (passwords were already escaped) to prevent authentication failures when credentials contain YAML special characters. Update changelog text to mention username. Replace hardcoded pipeline name in transform/index_pivot/transform.yml with '{{ ingestPipelineName "monitoring_indices" }}' to generate the correct versioned pipeline name. --------- Co-authored-by: Valentin Crettaz <valentin.crettaz@elastic.co>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #18434
Passwords containing YAML special characters (e.g. double quotes
") cause401 Unauthorizederrors in all Elasticsearch metrics datasets because the compiled agent configuration strips those characters during YAML parsing.Root cause
All 12 Elasticsearch metrics dataset stream templates used the bare Handlebars expression:
When a password such as
"mysecret"is rendered, the template produces:YAML treats the double quotes as string delimiters, so the parsed value is
mysecret— the characters are silently dropped. The Beat then authenticates with a truncated password and receives a401 Unauthorizedresponse.Fix
Replace
{{password}}with{{escape_string password}}in all 12 metrics dataset stream templates:data_stream/cluster_stats/agent/stream/stream.yml.hbsdata_stream/node_stats/agent/stream/stream.yml.hbsdata_stream/node/agent/stream/stream.yml.hbsdata_stream/index/agent/stream/stream.yml.hbsdata_stream/index_recovery/agent/stream/stream.yml.hbsdata_stream/index_summary/agent/stream/stream.yml.hbsdata_stream/ccr/agent/stream/stream.yml.hbsdata_stream/enrich/agent/stream/stream.yml.hbsdata_stream/ingest_pipeline/agent/stream/stream.yml.hbsdata_stream/ml_job/agent/stream/stream.yml.hbsdata_stream/pending_tasks/agent/stream/stream.yml.hbsdata_stream/shard/agent/stream/stream.yml.hbsThe
escape_stringhelper (registered in Fleet's Handlebars engine) wraps the value in YAML single quotes and escapes any interior single quotes by doubling them — safely preserving all special characters including",\,:,#, etc.Before (password
"mysecret"→ stored asmysecret):After (password
"mysecret"→ stored correctly as"mysecret"):This pattern is already used correctly by other integrations for similar fields (e.g.
ibmmq,apache_tomcat,websphere_application_server,cloudflare).Testing
Configure an Elasticsearch integration policy with a password containing
"characters and confirm thecomponents-actual.yamlpreserves the full password value, and that metrics collection succeeds without401errors.Checklist