From fd14fe27641f2ec95bb14bd6b0594c376a5f2a21 Mon Sep 17 00:00:00 2001 From: leonardo-albertovich Date: Fri, 4 Aug 2023 16:18:36 +0200 Subject: [PATCH] in_prometheus_scrape: added authorization support (#7785) Signed-off-by: Leonardo Alminana --- plugins/in_prometheus_scrape/prom_scrape.c | 25 ++++++++++++++++++++++ plugins/in_prometheus_scrape/prom_scrape.h | 7 ++++++ 2 files changed, 32 insertions(+) diff --git a/plugins/in_prometheus_scrape/prom_scrape.c b/plugins/in_prometheus_scrape/prom_scrape.c index 21b8eb5b40c..68d4540bca9 100644 --- a/plugins/in_prometheus_scrape/prom_scrape.c +++ b/plugins/in_prometheus_scrape/prom_scrape.c @@ -100,6 +100,13 @@ static int collect_metrics(struct prom_scrape *ctx) flb_http_buffer_size(c, ctx->buffer_max_size); + /* Auth headers */ + if (ctx->http_user && ctx->http_passwd) { /* Basic */ + flb_http_basic_auth(c, ctx->http_user, ctx->http_passwd); + } else if (ctx->bearer_token) { /* Bearer token */ + flb_http_bearer_auth(c, ctx->bearer_token); + } + ret = flb_http_do(c, &b_sent); if (ret != 0) { flb_plg_error(ctx->ins, "http do error"); @@ -218,6 +225,24 @@ static struct flb_config_map config_map[] = { "Set the metrics URI endpoint, it must start with a forward slash." }, + { + FLB_CONFIG_MAP_STR, "http_user", NULL, + 0, FLB_TRUE, offsetof(struct prom_scrape, http_user), + "Set HTTP auth user" + }, + + { + FLB_CONFIG_MAP_STR, "http_passwd", "", + 0, FLB_TRUE, offsetof(struct prom_scrape, http_passwd), + "Set HTTP auth password" + }, + + { + FLB_CONFIG_MAP_STR, "bearer_token", NULL, + 0, FLB_TRUE, offsetof(struct prom_scrape, bearer_token), + "Set bearer token auth" + }, + /* EOF */ {0} }; diff --git a/plugins/in_prometheus_scrape/prom_scrape.h b/plugins/in_prometheus_scrape/prom_scrape.h index 86161b5d040..9510abfef5d 100644 --- a/plugins/in_prometheus_scrape/prom_scrape.h +++ b/plugins/in_prometheus_scrape/prom_scrape.h @@ -33,6 +33,13 @@ struct prom_scrape struct flb_upstream *upstream; struct flb_input_instance *ins; /* input plugin instance */ size_t buffer_max_size; /* Maximum buffer size */ + + /* HTTP Auth */ + flb_sds_t http_user; + flb_sds_t http_passwd; + + /* Bearer Token Auth */ + flb_sds_t bearer_token; }; #endif