mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-02-19 15:30:17 +00:00
vmalert: mark some url flags as sensitive (#2965)
Other components, such as `vmagent`, mark these flags as sensitive and hide them from the `/metrics` endpoint by default. This commit adds similar handling to the `vmalert` component, hiding them by default, to prevent logging of secrets inappropriately. Showing of these values is controlled by an additional flag. Follow up to https://github.com/VictoriaMetrics/VictoriaMetrics/pull/2947
This commit is contained in:
parent
a9c5766ebc
commit
240acdf3b7
4 changed files with 35 additions and 1 deletions
|
@ -8,12 +8,15 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmalert/utils"
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmalert/utils"
|
||||||
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/flagutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
addr = flag.String("datasource.url", "", "VictoriaMetrics or vmselect url. Required parameter. "+
|
addr = flag.String("datasource.url", "", "VictoriaMetrics or vmselect url. Required parameter. "+
|
||||||
"E.g. http://127.0.0.1:8428 . See also -remoteRead.disablePathAppend")
|
"E.g. http://127.0.0.1:8428 . See also -remoteRead.disablePathAppend")
|
||||||
appendTypePrefix = flag.Bool("datasource.appendTypePrefix", false, "Whether to add type prefix to -datasource.url based on the query type. Set to true if sending different query types to the vmselect URL.")
|
appendTypePrefix = flag.Bool("datasource.appendTypePrefix", false, "Whether to add type prefix to -datasource.url based on the query type. Set to true if sending different query types to the vmselect URL.")
|
||||||
|
showDatasourceURL = flag.Bool("datasource.showURL", false, "Whether to show -datasource.url in the exported metrics. "+
|
||||||
|
"It is hidden by default, since it can contain sensitive info such as auth key")
|
||||||
|
|
||||||
basicAuthUsername = flag.String("datasource.basicAuth.username", "", "Optional basic auth username for -datasource.url")
|
basicAuthUsername = flag.String("datasource.basicAuth.username", "", "Optional basic auth username for -datasource.url")
|
||||||
basicAuthPassword = flag.String("datasource.basicAuth.password", "", "Optional basic auth password for -datasource.url")
|
basicAuthPassword = flag.String("datasource.basicAuth.password", "", "Optional basic auth password for -datasource.url")
|
||||||
|
@ -47,6 +50,13 @@ var (
|
||||||
`In VM "round_digits" limits the number of digits after the decimal point in response values.`)
|
`In VM "round_digits" limits the number of digits after the decimal point in response values.`)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// InitSecretFlags must be called after flag.Parse and before any logging
|
||||||
|
func InitSecretFlags() {
|
||||||
|
if !*showDatasourceURL {
|
||||||
|
flagutil.RegisterSecretFlag("datasource.url")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Param represents an HTTP GET param
|
// Param represents an HTTP GET param
|
||||||
type Param struct {
|
type Param struct {
|
||||||
Key, Value string
|
Key, Value string
|
||||||
|
|
|
@ -79,6 +79,9 @@ func main() {
|
||||||
flag.CommandLine.SetOutput(os.Stdout)
|
flag.CommandLine.SetOutput(os.Stdout)
|
||||||
flag.Usage = usage
|
flag.Usage = usage
|
||||||
envflag.Parse()
|
envflag.Parse()
|
||||||
|
remoteread.InitSecretFlags()
|
||||||
|
remotewrite.InitSecretFlags()
|
||||||
|
datasource.InitSecretFlags()
|
||||||
buildinfo.Init()
|
buildinfo.Init()
|
||||||
logger.Init()
|
logger.Init()
|
||||||
err := templates.Load(*ruleTemplatesPath, true)
|
err := templates.Load(*ruleTemplatesPath, true)
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
|
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmalert/datasource"
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmalert/datasource"
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmalert/utils"
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmalert/utils"
|
||||||
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/flagutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -14,6 +15,9 @@ var (
|
||||||
"state. This configuration makes sense only if `vmalert` was configured with `remoteWrite.url` before and has been successfully persisted its state. "+
|
"state. This configuration makes sense only if `vmalert` was configured with `remoteWrite.url` before and has been successfully persisted its state. "+
|
||||||
"E.g. http://127.0.0.1:8428. See also -remoteRead.disablePathAppend")
|
"E.g. http://127.0.0.1:8428. See also -remoteRead.disablePathAppend")
|
||||||
|
|
||||||
|
showRemoteReadURL = flag.Bool("remoteRead.showURL", false, "Whether to show -remoteRead.url in the exported metrics. "+
|
||||||
|
"It is hidden by default, since it can contain sensitive info such as auth key")
|
||||||
|
|
||||||
basicAuthUsername = flag.String("remoteRead.basicAuth.username", "", "Optional basic auth username for -remoteRead.url")
|
basicAuthUsername = flag.String("remoteRead.basicAuth.username", "", "Optional basic auth username for -remoteRead.url")
|
||||||
basicAuthPassword = flag.String("remoteRead.basicAuth.password", "", "Optional basic auth password for -remoteRead.url")
|
basicAuthPassword = flag.String("remoteRead.basicAuth.password", "", "Optional basic auth password for -remoteRead.url")
|
||||||
basicAuthPasswordFile = flag.String("remoteRead.basicAuth.passwordFile", "", "Optional path to basic auth password to use for -remoteRead.url")
|
basicAuthPasswordFile = flag.String("remoteRead.basicAuth.passwordFile", "", "Optional path to basic auth password to use for -remoteRead.url")
|
||||||
|
@ -36,6 +40,13 @@ var (
|
||||||
oauth2Scopes = flag.String("remoteRead.oauth2.scopes", "", "Optional OAuth2 scopes to use for -remoteRead.url. Scopes must be delimited by ';'.")
|
oauth2Scopes = flag.String("remoteRead.oauth2.scopes", "", "Optional OAuth2 scopes to use for -remoteRead.url. Scopes must be delimited by ';'.")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// InitSecretFlags must be called after flag.Parse and before any logging
|
||||||
|
func InitSecretFlags() {
|
||||||
|
if !*showRemoteReadURL {
|
||||||
|
flagutil.RegisterSecretFlag("remoteRead.url")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Init creates a Querier from provided flag values.
|
// Init creates a Querier from provided flag values.
|
||||||
// Returns nil if addr flag wasn't set.
|
// Returns nil if addr flag wasn't set.
|
||||||
func Init() (datasource.QuerierBuilder, error) {
|
func Init() (datasource.QuerierBuilder, error) {
|
||||||
|
|
|
@ -7,12 +7,15 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmalert/utils"
|
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmalert/utils"
|
||||||
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/flagutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
addr = flag.String("remoteWrite.url", "", "Optional URL to VictoriaMetrics or vminsert where to persist alerts state "+
|
addr = flag.String("remoteWrite.url", "", "Optional URL to VictoriaMetrics or vminsert where to persist alerts state "+
|
||||||
"and recording rules results in form of timeseries. For example, if -remoteWrite.url=http://127.0.0.1:8428 is specified, "+
|
"and recording rules results in form of timeseries. For example, if -remoteWrite.url=http://127.0.0.1:8428 is specified, "+
|
||||||
"then the alerts state will be written to http://127.0.0.1:8428/api/v1/write . See also -remoteWrite.disablePathAppend")
|
"then the alerts state will be written to http://127.0.0.1:8428/api/v1/write . See also -remoteWrite.disablePathAppend")
|
||||||
|
showRemoteWriteURL = flag.Bool("remoteWrite.showURL", false, "Whether to show -remoteWrite.url in the exported metrics. "+
|
||||||
|
"It is hidden by default, since it can contain sensitive info such as auth key")
|
||||||
|
|
||||||
basicAuthUsername = flag.String("remoteWrite.basicAuth.username", "", "Optional basic auth username for -remoteWrite.url")
|
basicAuthUsername = flag.String("remoteWrite.basicAuth.username", "", "Optional basic auth username for -remoteWrite.url")
|
||||||
basicAuthPassword = flag.String("remoteWrite.basicAuth.password", "", "Optional basic auth password for -remoteWrite.url")
|
basicAuthPassword = flag.String("remoteWrite.basicAuth.password", "", "Optional basic auth password for -remoteWrite.url")
|
||||||
|
@ -41,6 +44,13 @@ var (
|
||||||
oauth2Scopes = flag.String("remoteWrite.oauth2.scopes", "", "Optional OAuth2 scopes to use for -notifier.url. Scopes must be delimited by ';'.")
|
oauth2Scopes = flag.String("remoteWrite.oauth2.scopes", "", "Optional OAuth2 scopes to use for -notifier.url. Scopes must be delimited by ';'.")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// InitSecretFlags must be called after flag.Parse and before any logging
|
||||||
|
func InitSecretFlags() {
|
||||||
|
if !*showRemoteWriteURL {
|
||||||
|
flagutil.RegisterSecretFlag("remoteWrite.url")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Init creates Client object from given flags.
|
// Init creates Client object from given flags.
|
||||||
// Returns nil if addr flag wasn't set.
|
// Returns nil if addr flag wasn't set.
|
||||||
func Init(ctx context.Context) (*Client, error) {
|
func Init(ctx context.Context) (*Client, error) {
|
||||||
|
|
Loading…
Reference in a new issue