I am trying to build a service monitor and am at the point where I would be making a call to change an index setting in Elasticsearch. Elasticsearch 7.10.0 running and secured with HTTPS. I have the following running:
$ESAPI = @{
Key = "stuff-Glg"
Id = "otherstuff-"
}
$ESAPI.Cred = [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes("$($ESAPI.Id):$($ESAPI.Key)"))
$body = '{"blocks.write":false}'
$headers = @{ 'Authorization' = "ApiKey $($ESApi.Cred)"}
Invoke-RestMethod -Method PUT -Uri "$($ESPro)://$($ESHost):$($ESPort)/$($matches.index)/_settings?pretty" -Body $body -ContentType Application/Json -Headers $headers
I get the below error:
Invoke-RestMethod : {
"error" : {
"root_cause" : [
{
"type" : "security_exception",
"reason" : "missing authentication credentials for REST request [/contoso-2020.52/_settings?pretty]",
"header" : {
"WWW-Authenticate" : [
"Basic realm=\"security\" charset=\"UTF-8\"",
"Bearer realm=\"security\"",
"ApiKey"
]
}
}
]
Research appears to show that I have to supply the username/password associated with the API key (and testing confirmed this). Is there a way to change index settings without hardcoding user credentials into a script?