From 11ec45e7101698cc5f3c7d8f43823ee349610060 Mon Sep 17 00:00:00 2001 From: DiniFarb Date: Tue, 11 Jul 2023 07:36:36 +0200 Subject: [PATCH] feat: Skip TLS verify in loading config from url Signed-off-by: DiniFarb --- config/config.go | 12 ++++++++++-- exporter.go | 6 +++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/config/config.go b/config/config.go index a4bb108f..53e6115d 100644 --- a/config/config.go +++ b/config/config.go @@ -14,6 +14,7 @@ package config import ( + "crypto/tls" "fmt" "io" "net/http" @@ -36,7 +37,7 @@ type Resolver struct { } // NewResolver returns a Resolver structure. -func NewResolver(file string, logger log.Logger) (*Resolver, error) { +func NewResolver(file string, logger log.Logger, insecure_skip_verify bool) (*Resolver, error) { flags := map[string]string{} var fileBytes []byte url, err := url.ParseRequestURI(file) @@ -45,7 +46,14 @@ func NewResolver(file string, logger log.Logger) (*Resolver, error) { } if url.Scheme == "http" || url.Scheme == "https" { _ = level.Info(logger).Log("msg", fmt.Sprintf("Loading configuration file from URL: %v", file)) - resp, err := http.Get(file) + tr := &http.Transport{ + TLSClientConfig: &tls.Config{InsecureSkipVerify: insecure_skip_verify}, + } + if insecure_skip_verify { + _ = level.Warn(logger).Log("msg", "Loading configuration file with TLS verification disabled") + } + client := &http.Client{Transport: tr} + resp, err := client.Get(file) if err != nil { return nil, err } diff --git a/exporter.go b/exporter.go index 9cabd07c..a14729c3 100644 --- a/exporter.go +++ b/exporter.go @@ -105,6 +105,10 @@ func main() { "config.file", "YAML configuration file to use. Values set in this file will be overridden by CLI flags.", ).String() + insecure_skip_verify = app.Flag( + "config.file.insecure-skip-verify", + "Skip TLS verification in loading YAML configuration.", + ).Default("false").Bool() webConfig = webflag.AddFlags(app, ":9182") metricsPath = app.Flag( "telemetry.path", @@ -152,7 +156,7 @@ func main() { _ = level.Debug(logger).Log("msg", "Logging has Started") if *configFile != "" { - resolver, err := config.NewResolver(*configFile, logger) + resolver, err := config.NewResolver(*configFile, logger, *insecure_skip_verify) if err != nil { _ = level.Error(logger).Log("msg", "could not load config file", "err", err) os.Exit(1)