Skip to content

Conversation

barkbay
Copy link
Contributor

@barkbay barkbay commented Oct 13, 2025

Follow up of #8817

Some characters like ] or " can break some scripts or configurations.

@prodsecmachine
Copy link
Collaborator

prodsecmachine commented Oct 13, 2025

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Licenses 0 0 0 0 0 issues
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@botelastic botelastic bot added the triage label Oct 13, 2025
function fail {
timestamp=$(date --iso-8601=seconds)
echo "{\"timestamp\": \"${timestamp}\", \"message\": \"readiness probe failed\", "$1"}" | tee /proc/1/fd/2 2> /dev/null
echo '{"timestamp": "'"${timestamp}"'", "message": "readiness probe failed", '"${1}"'}'| tee /proc/1/fd/2 2> /dev/null
Copy link
Contributor Author

Choose a reason for hiding this comment

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

                                                                              ^--^ SC2027 (warning): The surrounding quotes actually unquote this. Remove or escape them.

exit 0
else
fail " \"status\": \"${status}\", \"version\":\"${version}\" "
fail " \"status\": \"${status}\" "
Copy link
Contributor Author

Choose a reason for hiding this comment

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

                                              ^--------^ SC2154 (warning): version is referenced but not assigned.

# request the health endpoint and expect http status code 200. Turning globbing off for unescaped IPv6 addresses
status=$(curl -g -o /dev/null -w "%{http_code}" ` + url + ` ` + basicAuthArgs + ` -k -s --max-time ${READINESS_PROBE_TIMEOUT})
status=$(curl -g -o /dev/null -w "%{http_code}" ` + url + ` ` + basicAuthArgs + ` -k -s --max-time "${READINESS_PROBE_TIMEOUT}")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

                                                                                                                                                                                  ^------------------------^ SC2086 (info): Double quote to prevent globbing and word splitting

function fail {
timestamp=$(date --iso-8601=seconds)
echo "{\"timestamp\": \"${timestamp}\", \"message\": \"readiness probe failed\", "$1"}" | tee /proc/1/fd/2 2> /dev/null
timestamp=$(date +%Y-%m-%dT%H:%M:%S%z)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

date: unrecognized option '--iso-8601=seconds'
BusyBox v1.37.0 (2024-09-30 10:39:57 UTC) multi-call binary.

Not sure for how long we had this bug 😐

@barkbay
Copy link
Contributor Author

barkbay commented Oct 13, 2025

We can escape it but I wonder if we should remove \" in

Symbols = "~!@#$%^&*()_+`-={}|[]\\:\"<>?,./"
, this can create invalid json or yaml and is currently breaking stack monitoring.

Edit: I added a function to sanitize the string.

@barkbay barkbay added the >bug Something isn't working label Oct 13, 2025
@botelastic botelastic bot removed the triage label Oct 13, 2025
@botelastic botelastic bot removed the triage label Oct 13, 2025
@barkbay
Copy link
Contributor Author

barkbay commented Oct 13, 2025

buildkite test this -f p=gke,t=TestVersionUpgrade*

@barkbay barkbay changed the title Fix EntSearch readiness script Sanitize or escape passwords in configurations and scripts Oct 13, 2025
@barkbay barkbay changed the title Sanitize or escape passwords in configurations and scripts Escape passwords in configurations and scripts Oct 13, 2025
@barkbay
Copy link
Contributor Author

barkbay commented Oct 13, 2025

We have another issue for Logstash which offers a way to inject the ES password through environment variables, as described in the documentation or in the following example:

  pipelines:
    - pipeline.id: main
      config.string: |
        input { exec { command => 'uptime' interval => 10 } }
        output {
          elasticsearch {
            hosts => [ "${TEST_ES_HOSTS}" ]
            ssl_enabled => true
            ssl_certificate_authorities => "${TEST_ES_SSL_CERTIFICATE_AUTHORITY}"
            user => "${TEST_ES_USER}"
            password => "${TEST_ES_PASSWORD}"
          }
        }

If there is " in the generated password, this is going to break Logstash deployment with following error:

[2025-10-13T12:55:22,445][ERROR][logstash.agent           ] Failed to execute action {:action=>LogStash::PipelineAction::Create/pipeline_id:main, :exception=>"LogStash::ConfigurationError", :message=>"Expected one of [ \\t\\r\\n], \"#\", \"{\", \"}\" at line 8, column 20 (byte 412) after output {\n  elasticsearch {\n    hosts => [ \"https://monitoring-f9cb-es-http.e2e-mercury.svc:9200\" ]\n    ssl_enabled => true\n    ssl_certificate_authorities => \"/mnt/elastic-internal/elasticsearch-association/e2e-mercury/monitoring-f9cb/certs/ca.crt\"\n    user => \"e2e-mercury-logstash-sample-f9cb-e2e-mercury-monitoring-f9cb-logstash-user\"\n    password => \"]\"", :backtrace=>["/usr/share/logstash/logstash-core/lib/logstash/compiler.rb:32:in `compile_imperative'", "org/logstash/execution/AbstractPipelineExt.java:285:in `initialize'", "org/logstash/execution/AbstractPipelineExt.java:223:in `initialize'", "/usr/share/logstash/logstash-core/lib/logstash/java_pipeline.rb:47:in `initialize'", "org/jruby/RubyClass.java:950:in `new'", "/usr/share/logstash/logstash-core/lib/logstash/pipeline_action/create.rb:50:in `execute'", "/usr/share/logstash/logstash-core/lib/logstash/agent.rb:431:in `block in converge_state'"]}

In above case the password was starting with ]". (" was part of the password)

I don't know what to do for this one. My feeling is that we should not advise users to rely on internally generated passwords. Also using env variables to propagate credentials feels wrong, I believe this sample would be broken as soon as the password is regenerated.

@barkbay
Copy link
Contributor Author

barkbay commented Oct 14, 2025

buildkite test this -f p=gke,t=TestSamples

"metadata": {
"annotations": {
"elasticsearch.k8s.elastic.co/monitoring-config-hash": "421654492"
"elasticsearch.k8s.elastic.co/monitoring-config-hash": "3826168075"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rhr323 If we include this change (I mean the " around the password in Metricbeat config) then I think this is going to recreate the ES Pods for clusters which have stack monitoring is enabled. We should then add 3.2.0 to https://www.elastic.co/docs/deploy-manage/upgrade/orchestrator/upgrade-cloud-on-k8s#k8s-beta-to-ga-rolling-restart (we can also revert it since we just decided to not include symbols, but may end up re-introduce it eventually later so idk 🤷‍♂️ )

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks! I'll update the docs accordingly.

@barkbay barkbay marked this pull request as ready for review October 14, 2025 12:04
Copy link
Collaborator

@pebrc pebrc left a comment

Choose a reason for hiding this comment

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

LGTM

@barkbay barkbay merged commit 3267994 into elastic:main Oct 14, 2025
9 checks passed
@barkbay barkbay deleted the fix-readiness-scripts branch October 14, 2025 14:48
barkbay added a commit to barkbay/cloud-on-k8s that referenced this pull request Oct 14, 2025
* Fix EntSearch readiness script

* iso-8601=seconds is not a valid flag with busybox

* Sanitize password string in Stackmon config

* Fix TestReconcileConfig_ReadinessProbe

* Update stack mon sidecar expected config

* Do not include symbols for now
@barkbay barkbay added the exclude-from-release-notes Exclude this PR from appearing in the release notes label Oct 14, 2025
barkbay added a commit that referenced this pull request Oct 14, 2025
* Fix EntSearch readiness script

* iso-8601=seconds is not a valid flag with busybox

* Sanitize password string in Stackmon config

* Fix TestReconcileConfig_ReadinessProbe

* Update stack mon sidecar expected config

* Do not include symbols for now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>bug Something isn't working exclude-from-release-notes Exclude this PR from appearing in the release notes v3.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants