Skip to content

Commit a67b0f3

Browse files
committed
support base64 encoded api key
1 parent 3ef3c0c commit a67b0f3

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

lib/logstash/outputs/elasticsearch/http_client_builder.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,10 @@ def self.setup_api_key(logger, params)
190190

191191
return {} unless (api_key && api_key.value)
192192

193-
{ "Authorization" => "ApiKey " + Base64.strict_encode64(api_key.value) }
193+
# support key_id:key for b64(key_id:key)
194+
api_key_b64 = api_key.value.match?(/:/) ? Base64.strict_encode64(api_key.value) : api_key
195+
196+
{ "Authorization" => "ApiKey " + api_key_b64 }
194197
end
195198

196199
private

spec/unit/outputs/elasticsearch_spec.rb

+10-2
Original file line numberDiff line numberDiff line change
@@ -1520,14 +1520,22 @@
15201520
describe "API key" do
15211521
let(:manticore_options) { subject.client.pool.adapter.manticore.instance_variable_get(:@options) }
15221522
let(:api_key) { "some_id:some_api_key" }
1523-
let(:base64_api_key) { "ApiKey c29tZV9pZDpzb21lX2FwaV9rZXk=" }
1523+
let(:base64_api_key) { "c29tZV9pZDpzb21lX2FwaV9rZXk=" }
15241524

15251525
shared_examples 'secure api-key authenticated client' do
15261526
let(:do_register) { true }
15271527

15281528
it 'adds the appropriate Authorization header to the manticore client' do
1529-
expect(manticore_options[:headers]).to eq({ "Authorization" => base64_api_key })
1529+
expect(manticore_options[:headers]).to eq({ "Authorization" => "ApiKey #{base64_api_key}" })
15301530
end
1531+
1532+
context "when api_key is already base64 encoded" do
1533+
let(:api_key) { base64_api_key }
1534+
it 'passes the base64 encoded api to the headers as-is' do
1535+
expect(manticore_options[:headers]).to eq({ "Authorization" => "ApiKey #{base64_api_key}" })
1536+
end
1537+
end
1538+
15311539
it 'is provides ssl_enabled=>true to the http client builder' do; aggregate_failures do
15321540
expect(described_class::HttpClientBuilder).to have_received(:build).with(anything, anything, hash_including('ssl_enabled'=>true))
15331541
end; end

0 commit comments

Comments
 (0)