Hello @alxsss,
I've put in place this basic pipeline to test out.
To check if the credentials are sent, I'm relying on https://postman-echo.com/post
, which is an echo service: it sends back what we sent out.
input {
exec {
command => 'echo "myusername mypassword something else as message"'
interval => 30
}
}
filter {
grok {
match => {
"message" => "(?<username>.*?) (?<password>.*?) %{GREEDYDATA:message}"
}
overwrite => [ "message" ]
}
http {
url => "https://postman-echo.com/post"
verb => "POST"
body_format => text
body => "%{[message]}"
headers => {
"mytest" => "logstash"
}
user => "%{[username]}"
password => "%{[password]}"
}
}
output {
stdout {
codec => rubydebug
}
}
Result:
{
"headers" => {
"date" => "Mon, 11 May 2020 23:14:19 GMT",
"content-type" => "application/json; charset=utf-8",
"content-length" => "466",
"connection" => "keep-alive",
"etag" => "W/\"1d2-HVEOO8HN2rGf3X1N7ql/SDl9d+k\"",
"vary" => "Accept-Encoding",
"set-cookie" => "sails.sid=s%3Aqvmn6ZsRnmikZbk8GJVYjvE8kLoCPWTE.dFGnbRZ66lezZI9nn8vo38phZdpI6kMgZDZulvsMHnQ; Path=/; HttpOnly"
},
"command" => "echo \"myusername mypassword something else as message\"",
"@version" => "1",
"@timestamp" => 2020-05-11T23:14:18.258Z,
"username" => "myusername",
"body" => {
"headers" => {
"x-amzn-trace-id" => "Root=1-5eb9dc4b-18148626079b62e5d55063f7",
"accept-encoding" => "gzip,deflate",
"content-length" => "26",
"x-forwarded-proto" => "https",
"content-type" => "text/plain",
"x-forwarded-port" => "443",
"host" => "postman-echo.com",
"mytest" => "logstash",
"user-agent" => "Manticore 0.6.4",
"authorization" => "Basic JXtbdXNlcm5hbWVdfTole1twYXNzd29yZF19"
},
"data" => "something else as message\n",
"form" => {},
"json" => nil,
"url" => "https://postman-echo.com/post",
"args" => {},
"files" => {}
},
"host" => "vm-VirtualBox",
"password" => "mypassword",
"message" => "something else as message\n"
}
The headers contain:
"authorization" => "Basic JXtbdXNlcm5hbWVdfTole1twYXNzd29yZF19"
Which actually represent:
%{[username]}:%{[password]}
This means the values are not interpolated by the plugin.
As a workaround, I might suggest to generate the base64 via a ruby
filter:
input {
exec {
command => 'echo "myusername mypassword something else as message"'
interval => 30
}
}
filter {
grok {
match => {
"message" => "(?<username>.*?) (?<password>.*?) %{GREEDYDATA:message}"
}
overwrite => [ "message" ]
}
ruby {
init => "require 'base64'"
code => "event.set('auth_header', 'Basic ' + Base64.strict_encode64(event.get('username')+':'+event.get('password')))"
}
http {
url => "https://postman-echo.com/post"
verb => "POST"
body_format => text
body => "%{[message]}"
headers => {
"authorization" => "%{[auth_header]}"
"mytest" => "logstash"
}
remove_field => [ "auth_header"]
}
}
output {
stdout {
codec => rubydebug
}
}
Result:
{
"username" => "myusername",
"password" => "mypassword",
"@version" => "1",
"command" => "echo \"myusername mypassword something else as message\"",
"headers" => {
"vary" => "Accept-Encoding",
"content-type" => "application/json; charset=utf-8",
"date" => "Mon, 11 May 2020 23:33:09 GMT",
"content-length" => "458",
"set-cookie" => "sails.sid=s%3AFC-7qJuQoB_EaSOwrILfyUAI32dQRtIs.RG0Etoc%2BxtV4UHaXmR9nzGsFb7uAzOE0DgLK6M64MVg; Path=/; HttpOnly",
"etag" => "W/\"1ca-XAUDTnV4N9fHTUtt3M0czbNbfYU\"",
"connection" => "keep-alive"
},
"@timestamp" => 2020-05-11T23:33:08.421Z,
"body" => {
"data" => "something else as message\n",
"files" => {},
"args" => {},
"form" => {},
"headers" => {
"authorization" => "Basic bXl1c2VybmFtZTpteXBhc3N3b3Jk",
"mytest" => "logstash",
"x-forwarded-port" => "443",
"content-length" => "26",
"content-type" => "text/plain",
"accept-encoding" => "gzip,deflate",
"user-agent" => "Manticore 0.6.4",
"x-amzn-trace-id" => "Root=1-5eb9e0b5-aa646f61c470f74a1ce03573",
"x-forwarded-proto" => "https",
"host" => "postman-echo.com"
},
"json" => nil,
"url" => "https://postman-echo.com/post"
},
"message" => "something else as message\n",
"host" => "vm-VirtualBox"
}
The headers contain:
"authorization" => "Basic bXl1c2VybmFtZTpteXBhc3N3b3Jk"
Which actually represent:
myusername:mypassword
I've opened a Github issue on the plugin repository: https://github.com/logstash-plugins/logstash-filter-http/issues/24