Skip to content

Commit

Permalink
feat:validate proxyURL for alertManagerCfg (prometheus-operator#6466)
Browse files Browse the repository at this point in the history
validate in convertHttpConfig
  • Loading branch information
yp969803 committed May 4, 2024
1 parent db27c61 commit fb5dc91
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/alertmanager/amcfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -1541,6 +1541,11 @@ func (cb *configBuilder) convertHTTPConfig(ctx context.Context, in monitoringv1a
out.BearerToken = bearerToken
}

if in.ProxyURL != "" {
_, err := url.Parse(in.ProxyURL)
return nil, fmt.Errorf("failed to parse proxyURL's: %w", err)
}

if in.OAuth2 != nil {
clientID, err := cb.store.GetKey(ctx, crKey.Namespace, in.OAuth2.ClientID)
if err != nil {
Expand Down Expand Up @@ -1724,6 +1729,11 @@ func (hc *httpClientConfig) sanitize(amVersion semver.Version, logger log.Logger
return err
}

if hc.ProxyURL != "" {
_, err := url.Parse(hc.ProxyURL)
return err
}

return hc.OAuth2.sanitize(amVersion, logger)
}

Expand Down
34 changes: 34 additions & 0 deletions pkg/alertmanager/amcfg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2946,6 +2946,40 @@ func TestHTTPClientConfig(t *testing.T) {
TLSConfig: &tlsConfig{},
},
},
{
name: "Invalid proxyURL",
in: &httpClientConfig{
ProxyURL: "https://www.example.com:invalidport",
EnableHTTP2: ptr.To(false),
TLSConfig: &tlsConfig{
MinVersion: "TLS12",
MaxVersion: "TLS12",
},
},
againstVersion: httpConfigV25Allowed,
expectErr: true,
},
{
name: "Valid proxyURL",
in: &httpClientConfig{
ProxyURL: "http://proxy.svc.cluster.local:80",
EnableHTTP2: ptr.To(false),
TLSConfig: &tlsConfig{
MinVersion: "TLS12",
MaxVersion: "TLS12",
},
},
againstVersion: httpConfigV25Allowed,
expect: httpClientConfig{
ProxyURL: "http://proxy.svc.cluster.local:80",
EnableHTTP2: ptr.To(false),
TLSConfig: &tlsConfig{
MinVersion: "TLS12",
MaxVersion: "TLS12",
},
},
expectErr: false,
},
} {
t.Run(tc.name, func(t *testing.T) {
err := tc.in.sanitize(tc.againstVersion, logger)
Expand Down

0 comments on commit fb5dc91

Please sign in to comment.