Validate Distributor endpoints before publication
This commit is contained in:
@@ -119,9 +119,8 @@ func validateDistributorNotify(cfg DistributorNotifyConfig) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
parsed, err := url.Parse(cfg.Endpoint)
|
||||
if err != nil || parsed.Scheme == "" || parsed.Host == "" {
|
||||
return fmt.Errorf("notify.distributor.endpoint must be an absolute URL when enabled")
|
||||
if err := ValidateDistributorEndpoint(cfg.Endpoint); err != nil {
|
||||
return fmt.Errorf("notify.distributor.endpoint %w", err)
|
||||
}
|
||||
if cfg.TokenEnv == "" {
|
||||
return fmt.Errorf("notify.distributor.token_env is required when enabled")
|
||||
@@ -172,6 +171,25 @@ func validateDistributorNotify(cfg DistributorNotifyConfig) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ValidateDistributorEndpoint verifies the endpoint grammar accepted by the
|
||||
// pinned Distributor upload client.
|
||||
func ValidateDistributorEndpoint(endpoint string) error {
|
||||
parsed, err := url.Parse(endpoint)
|
||||
if err != nil || parsed.Scheme == "" || parsed.Host == "" {
|
||||
return fmt.Errorf("must be an absolute URL")
|
||||
}
|
||||
if parsed.Scheme != "http" && parsed.Scheme != "https" {
|
||||
return fmt.Errorf("must use http or https")
|
||||
}
|
||||
if parsed.User != nil {
|
||||
return fmt.Errorf("must not include userinfo")
|
||||
}
|
||||
if parsed.RawQuery != "" || parsed.Fragment != "" {
|
||||
return fmt.Errorf("must not include query or fragment")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateDistributorBatchNotify(cfg DistributorBatchNotifyConfig) error {
|
||||
if !cfg.Enabled {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user