influxdata / influxdata/kapacitor
Kapacitor scraping requests send the authorization field in an unauthenticated request
- Dominant language
- Go
- Stars
- 2.4k
- Forks
- 479
- Avg merge
- 4d 16h
- Merged PRs (30d)
- 4
Description
With the following Kapacitor scraping configuration we are seeing the remote endpoint return `401 Unauthorized`:
```
[[scraper]]
enabled = true
name = "prometheus-test"
discoverer-id = "mystatic"
discoverer-service = "static-discovery"
db = "prometheus_raw"
rp = "autogen"
type = "prometheus"
scheme = "http"
metrics-path = "/api/v1/nodes/knode1/proxy/metrics/cadvisor"
scrape-interval = "30s"
scrape-timeout = "30s"
[[static-discovery]]
enabled = true
id = "mystatic"
targets = ["localhost:8001"]
```
This is due to the fact that even though we have configured no authentication in our scraping configuration, Kapacitor will still send `Authorization: Basic Og==` in the header of the scraping request. This causes the endpoint to try and validate the credentials, even though sending no credentials will result in a successful request (manually tested stripping the Authorization header field with success).
HTTP Request and Response:
```
GET /api/v1/nodes/jng4knode1/proxy/metrics/cadvisor HTTP/1.1
Host: localhost:8001
User-Agent: Prometheus/
Accept: application/vnd.google.protobuf;proto=io.prometheus.client.MetricFamily;encoding=delimited;q=0.7,text/plain;version=0.0.4;q=0.3,*/*;q=0.1
Authorization: Basic Og==
X-Prometheus-Scrape-Timeout-Seconds: 30.000000
Accept-Encoding: gzip
Connection: close
HTTP/1.1 401 Unauthorized
Content-Length: 129
Content-Type: application/json
Date: Tue, 22 Oct 2019 23:04:20 GMT
Connection: close
{"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"Unauthorized","reason":"Unauthorized","code":401}
```
It seems like we should omit the authorization header field if the configuration has not defined any authentication.
Kapacitor version:
```
root@kapacitor-b24zw:/# kapacitor version
Kapacitor OSS 1.5.2 (git: HEAD 3086452d00830e01d932838d8c6d1df818648ad3)
```
Installed from `https://dl.influxdata.com/kapacitor/releases/kapacitor_1.5.2_amd64.deb`, and running on 64-bit Ubuntu 16.04
Contributor guide
Research direction
No source file, entry point, or test is named. Reproduce the shown scraper configuration, then trace how scraping requests construct authentication headers; done means an unauthenticated configuration sends no Authorization header while configured credentials still work, with a regression test covering both cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, prometheus
- Domain
- backend, observability
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100