Skip to content

[Elasticsearch] Fix authentication failure when password contains YAML special characters - #18436

Merged
maramos-elastic merged 3 commits into
mainfrom
18434-elasticsearch-password-yaml-special-chars
May 6, 2026
Merged

[Elasticsearch] Fix authentication failure when password contains YAML special characters#18436
maramos-elastic merged 3 commits into
mainfrom
18434-elasticsearch-password-yaml-special-chars

Conversation

@maramos-elastic

Copy link
Copy Markdown
Contributor

Summary

Fixes #18434

Passwords containing YAML special characters (e.g. double quotes ") cause 401 Unauthorized errors 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:

{{#if password}}
password: {{password}}
{{/if}}

When a password such as "mysecret" is rendered, the template produces:

password: "mysecret"

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 a 401 Unauthorized response.

Fix

Replace {{password}} with {{escape_string password}} in all 12 metrics dataset stream templates:

  • data_stream/cluster_stats/agent/stream/stream.yml.hbs
  • data_stream/node_stats/agent/stream/stream.yml.hbs
  • data_stream/node/agent/stream/stream.yml.hbs
  • data_stream/index/agent/stream/stream.yml.hbs
  • data_stream/index_recovery/agent/stream/stream.yml.hbs
  • data_stream/index_summary/agent/stream/stream.yml.hbs
  • data_stream/ccr/agent/stream/stream.yml.hbs
  • data_stream/enrich/agent/stream/stream.yml.hbs
  • data_stream/ingest_pipeline/agent/stream/stream.yml.hbs
  • data_stream/ml_job/agent/stream/stream.yml.hbs
  • data_stream/pending_tasks/agent/stream/stream.yml.hbs
  • data_stream/shard/agent/stream/stream.yml.hbs

The escape_string helper (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 as mysecret):

password: "mysecret"

After (password "mysecret" → stored correctly as "mysecret"):

password: '"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 the components-actual.yaml preserves the full password value, and that metrics collection succeeds without 401 errors.

Checklist

…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
@maramos-elastic maramos-elastic self-assigned this Apr 16, 2026
Comment thread packages/elasticsearch/elasticsearch/transform/index_pivot/transform.yml Outdated
Comment thread packages/elasticsearch/data_stream/ccr/agent/stream/stream.yml.hbs Outdated
@elastic-vault-github-plugin-prod

elastic-vault-github-plugin-prod Bot commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

🚀 Benchmarks report

Package elasticsearch 👍(2) 💚(2) 💔(1)

Expand to view
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

@consulthys consulthys left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGT Stack Monitoring

@consulthys consulthys added Feature:Stack Monitoring Stack Monitoring Feature Team:Stack Monitoring Stack Monitoring team [elastic/stack-monitoring] labels Apr 30, 2026
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.
@elasticmachine

Copy link
Copy Markdown

💚 Build Succeeded

History

cc @maramos-elastic

@maramos-elastic
maramos-elastic marked this pull request as ready for review May 6, 2026 17:26
@maramos-elastic
maramos-elastic requested a review from a team as a code owner May 6, 2026 17:26

@pickypg pickypg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks @andrewkroh for the 👀

@maramos-elastic
maramos-elastic merged commit faa758a into main May 6, 2026
12 checks passed
@maramos-elastic
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature:Stack Monitoring Stack Monitoring Feature Integration:elasticsearch Elasticsearch Team:Stack Monitoring Stack Monitoring team [elastic/stack-monitoring]

5 participants