feat: Skip TLS verify in loading config from url

Signed-off-by: DiniFarb <andreas.vogt89@bluewin.ch>
This commit is contained in:
DiniFarb 2023-07-11 07:36:36 +02:00 committed by Ben Reedy
parent 6797126e78
commit 11ec45e710
No known key found for this signature in database
GPG Key ID: 235C15B6086C9D7E
2 changed files with 15 additions and 3 deletions

View File

@ -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
}

View File

@ -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)