Skip to content

Commit

Permalink
Use less restrictive API to check if template exists (#13847)
Browse files Browse the repository at this point in the history
Switches from using `HEAD _template/{name}` to `GET _cat/templates/{name}` to check if a template exists before trying to load it.

The significance is that the `_cat/templates` API requires only the `monitor` cluster privilege and not the far more permissive `manage_index_templates`. With this change, the default Beats configuration works without any unnecessary write privileges for publishing.
  • Loading branch information
Christoph Wurm authored Oct 3, 2019
1 parent 0c76357 commit b28ac98
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Added `monitoring.cluster_uuid` setting to associate Beat data with specified ES cluster in Stack Monitoring UI. {pull}13182[13182]
- Add autodetection mode for add_kubernetes_metadata and enable it by default in included configuration files. {pull}13473[13473]
- Add `providers` setting to `add_cloud_metadata` processor. {pull}13812[13812]
- Use less restrictive API to check if template exists. {pull}13847[13847]

*Auditbeat*

Expand Down
10 changes: 5 additions & 5 deletions libbeat/template/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"io/ioutil"
"net/http"
"os"
"strings"

"github.com/elastic/beats/libbeat/beat"
"github.com/elastic/beats/libbeat/common"
Expand Down Expand Up @@ -124,11 +125,10 @@ func (l *ESLoader) templateExists(templateName string) bool {
if l.client == nil {
return false
}
status, _, _ := l.client.Request("HEAD", "/_template/"+templateName, "", nil, nil)
if status != http.StatusOK {
return false
}
return true

status, body, _ := l.client.Request("GET", "/_cat/templates/"+templateName, "", nil, nil)

return status == http.StatusOK && strings.Contains(string(body), templateName)
}

// Load reads the template from the config, creates the template body and prints it to the configured file.
Expand Down

0 comments on commit b28ac98

Please sign in to comment.