Skip to content

Conversation

alexcams
Copy link
Contributor

Avoid double-encoding opaque Elasticsearch API keys.

Previously, API keys that were already in encoded format were incorrectly re-encoded, causing connection failures. This update ensures that only raw keys are encoded, supporting both opaque and id:api-key formats without issue.

Closes #236

Thanks for contributing to Logstash! If you haven't already signed our CLA, here's a handy link: https://www.elastic.co/contributor-agreement/

@alexcams alexcams marked this pull request as draft September 17, 2025 11:22
@alexcams alexcams force-pushed the 236-support-opaque-api_key branch from bb5ffb2 to 9842249 Compare September 18, 2025 10:04
@alexcams alexcams force-pushed the 236-support-opaque-api_key branch from 4c20b87 to d98b81d Compare September 22, 2025 11:26
@alexcams alexcams marked this pull request as ready for review September 22, 2025 11:29
Copy link
Contributor

@andsel andsel left a comment

Choose a reason for hiding this comment

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

Left some notes about code style.

@alexcams alexcams requested a review from andsel September 22, 2025 15:00
Copy link
Contributor

@andsel andsel left a comment

Choose a reason for hiding this comment

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

One final touch to make things even straight

@alexcams alexcams force-pushed the 236-support-opaque-api_key branch from e6e6a21 to 70ef0d2 Compare September 23, 2025 08:40
@alexcams alexcams requested a review from andsel September 23, 2025 10:53
Copy link
Contributor

@andsel andsel left a comment

Choose a reason for hiding this comment

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

2 final nitpicks then we are ready to go :-)

CHANGELOG.md Outdated
@@ -1,3 +1,6 @@
## 5.2.1
- Support both, encoded and non encoded api-key formats on plugin configuration [#237](https://github.com/logstash-plugins/logstash-input-elasticsearch/pull/237)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- Support both, encoded and non encoded api-key formats on plugin configuration [#237](https://github.com/logstash-plugins/logstash-input-elasticsearch/pull/237)
- Added support for encoded and non encoded api-key formats on plugin configuration [#237](https://github.com/logstash-plugins/logstash-input-elasticsearch/pull/237)
return {} unless (api_key&.value)

token = ::Base64.strict_encode64(api_key.value)
token = base64?(api_key.value) ? api_key.value : Base64.strict_encode64(api_key.value)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
token = base64?(api_key.value) ? api_key.value : Base64.strict_encode64(api_key.value)
token = base64?(api_key.value) ? api_key.value : Base64.strict_encode64(api_key.value)
@alexcams alexcams force-pushed the 236-support-opaque-api_key branch from 70ef0d2 to cdb00d0 Compare September 23, 2025 11:35
Copy link
Contributor

@andsel andsel left a comment

Choose a reason for hiding this comment

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

LGTM

@alexcams alexcams merged commit efcc00b into logstash-plugins:main Sep 23, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants