mirror of
https://github.com/netdata/netdata.git
synced 2025-04-06 14:35:32 +00:00
Bug fix for netdata behind authenticated proxies (#5216)
* Was incorrectly updating the headers when the Authorization header was being sent * Use X-Auth-Token instead of Authorization header, to allow the management API to work authenticated behind proxies as well
This commit is contained in:
parent
67cd486e7a
commit
68e5ce8f9a
3 changed files with 9 additions and 16 deletions
|
@ -41,7 +41,7 @@ check () {
|
|||
|
||||
cmd () {
|
||||
echo -e "${WHITE}Cmd '${1}', expecting '${2}'"
|
||||
RESPONSE=$(curl -s "http://$URL/api/v1/manage/health?${1}" -H "Authorization: Bearer $TOKEN" 2>&1)
|
||||
RESPONSE=$(curl -s "http://$URL/api/v1/manage/health?${1}" -H "X-Auth-Token: $TOKEN" 2>&1)
|
||||
if [ "${RESPONSE}" != "${2}" ] ; then
|
||||
echo -e "${RED}ERROR: Response '${RESPONSE}' != '${2}'"
|
||||
err=$((err+1))
|
||||
|
|
|
@ -61,7 +61,7 @@ The API is available by default, but it is protected by an `api authorization to
|
|||
You can access the API via GET requests, by adding the bearer token to an `Authorization` http header, like this:
|
||||
|
||||
```
|
||||
curl "http://myserver/api/v1/manage/health?cmd=RESET" -H "Authorization: Bearer Mytoken"
|
||||
curl "http://myserver/api/v1/manage/health?cmd=RESET" -H "X-Auth-Token: Mytoken"
|
||||
```
|
||||
|
||||
The command `RESET` just returns netdata to the default operation, with all health checks and notifications enabled.
|
||||
|
@ -71,13 +71,13 @@ If you've configured and entered your token correclty, you should see the plain
|
|||
|
||||
If all you need is temporarily disable all health checks, then you issue the following before your maintenance period starts:
|
||||
```
|
||||
curl "http://myserver/api/v1/manage/health?cmd=DISABLE ALL" -H "Authorization: Bearer Mytoken"
|
||||
curl "http://myserver/api/v1/manage/health?cmd=DISABLE ALL" -H "X-Auth-Token: Mytoken"
|
||||
```
|
||||
The effect of disabling health checks is that the alarm criteria are not evaluated at all and nothing is written in the alarm log.
|
||||
If you want the health checks to be running but to not receive any notifications during your maintenance period, you can instead use this:
|
||||
|
||||
```
|
||||
curl "http://myserver/api/v1/manage/health?cmd=SILENCE ALL" -H "Authorization: Bearer Mytoken"
|
||||
curl "http://myserver/api/v1/manage/health?cmd=SILENCE ALL" -H "X-Auth-Token: Mytoken"
|
||||
```
|
||||
|
||||
Alarms may then still be raised and logged in netdata, so you'll be able to see them via the UI.
|
||||
|
@ -85,7 +85,7 @@ Alarms may then still be raised and logged in netdata, so you'll be able to see
|
|||
Regardless of the option you choose, at the end of your maintenance period you revert to the normal state via the RESET command.
|
||||
|
||||
```
|
||||
curl "http://myserver/api/v1/manage/health?cmd=RESET" -H "Authorization: Bearer Mytoken"
|
||||
curl "http://myserver/api/v1/manage/health?cmd=RESET" -H "X-Auth-Token: Mytoken"
|
||||
```
|
||||
|
||||
### Disable or silence specific alarms
|
||||
|
@ -108,7 +108,7 @@ To clear all selectors and reset the mode to default, use the `RESET` command.
|
|||
The following example silences notifications for all the alarms with context=load:
|
||||
|
||||
```
|
||||
curl "http://myserver/api/v1/manage/health?cmd=SILENCE&context=load" -H "Authorization: Bearer Mytoken"
|
||||
curl "http://myserver/api/v1/manage/health?cmd=SILENCE&context=load" -H "X-Auth-Token: Mytoken"
|
||||
```
|
||||
|
||||
#### Selection criteria
|
||||
|
|
|
@ -732,7 +732,7 @@ static inline char *http_header_parse(struct web_client *w, char *s, int parse_u
|
|||
hash_accept_encoding = simple_uhash("Accept-Encoding");
|
||||
hash_donottrack = simple_uhash("DNT");
|
||||
hash_useragent = simple_uhash("User-Agent");
|
||||
hash_authorization = simple_uhash("Authorization");
|
||||
hash_authorization = simple_uhash("X-Auth-Token");
|
||||
}
|
||||
|
||||
char *e = s;
|
||||
|
@ -777,15 +777,8 @@ static inline char *http_header_parse(struct web_client *w, char *s, int parse_u
|
|||
}
|
||||
else if(parse_useragent && hash == hash_useragent && !strcasecmp(s, "User-Agent")) {
|
||||
w->user_agent = strdupz(v);
|
||||
} else if(hash == hash_authorization&& !strcasecmp(s, "Authorization")) {
|
||||
if (strlen(v) > 8) { // Must contain at least "Bearer "
|
||||
char *auth_key=v+6;
|
||||
*auth_key='\0';
|
||||
if (!strcasecmp(v,"Bearer")) {
|
||||
auth_key++;
|
||||
w->auth_bearer_token=strdupz(auth_key);
|
||||
}
|
||||
}
|
||||
} else if(hash == hash_authorization&& !strcasecmp(s, "X-Auth-Token")) {
|
||||
w->auth_bearer_token = strdupz(v);
|
||||
}
|
||||
#ifdef NETDATA_WITH_ZLIB
|
||||
else if(hash == hash_accept_encoding && !strcasecmp(s, "Accept-Encoding")) {
|
||||
|
|
Loading…
Add table
Reference in a new issue