[Elasticsearch] Fix authentication failure when password contains YAML special characters#18436
Draft
maramos-elastic wants to merge 1 commit intomainfrom
Draft
[Elasticsearch] Fix authentication failure when password contains YAML special characters#18436maramos-elastic wants to merge 1 commit intomainfrom
maramos-elastic wants to merge 1 commit intomainfrom
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
💔 Build Failed
Failed CI StepsHistory |
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