-
Couldn't load subscription status.
- Fork 59
Add OAuth2 Support for HTTP Client Configuration in Webhook Receivers #338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
f30d496 to
5bf1217
Compare
77ba656 to
af1d9f8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still looking into it. Comments so far
http/config.go
Outdated
|
|
||
| type ProxyConfig struct { | ||
| // ProxyURL is the HTTP proxy server to use to connect to the targets. | ||
| ProxyURL string `yaml:"proxy_url,omitempty" json:"proxy_url,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it should be masked i.e. overridden .String() so we do not accidentally expose any urls
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly, though it's unclear at a glance where we'd want to redact the information. I can tackle in a followup.
| // ProxyFromEnvironment uses environment HTTP_PROXY, HTTPS_PROXY and NO_PROXY to determine proxies. | ||
| ProxyFromEnvironment bool `yaml:"proxy_from_environment,omitempty" json:"proxy_from_environment,omitempty"` | ||
| // ProxyConnectHeader optionally specifies headers to send to proxies during CONNECT requests. | ||
| ProxyConnectHeader map[string]string `yaml:"proxy_connect_header,omitempty" json:"proxy_connect_header,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WDYT about making all header's values secure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to, but this is tougher than it seems. We don't really have a way to secure arbitrary map[string]string fields in grafana/grafana backend or a way to display that kind of component in the FE right now. I'll see what I can do in a followup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍🏻
…configurations. Mimics upstream configuration so that json config remains similar. - Added proxy settings, including `ProxyURL`, `NoProxy`, and `ProxyConnectHeader`, and ensured validation. - Updated OAuth2 configuration to support proxy usage. - Added tests for HTTP client, proxy configuration, and OAuth2 validation.
85ce077 to
cabc784
Compare
|
Hi Team, Can you please tell the estimate for UI to be released for this feature? In the current Grafana OSS there does not exists an UI for using this contact point. Thanks, |
This PR introduces OAuth2
client_credentialsgrant type support for HTTP client configurations in webhook receivers.Current vs Future Work
This PR introduces
HTTPClientConfigwith a single fieldOAuth2containing the new OAuth2 configuration options. This setup intentionally mimics upstream alertmanager's commonhttp_configas the intention is to bring this change to all relevant integrations and eventually include other common http client configuration options in a standardized way between notifier types.All added configuration fields:
Notable differences from upstream
oauth2: Does not add support for:client_secret_fileclient_secret_refoauth2.tls_config:ca_filecert_filekey_fileca_refcert_refkey_refserver_namemin_versionmax_versionTLSConfigstruct. This means out json fields does not match. Ex:certvsclientCertificate. I'm on the fence here on whether it's worth defining a new struct to keep the field namings the same, thoughts?oauth2.tls_config:proxy_connect_headervalues are not secured in Grafana as secure map values are not supported. We can consider breaking similar with upstream and adding a field specifically forProxy-Authorization, thoughts?Implementation Notes
OAuth2config validation is done during client creation. This is for two reasons:tokenSourceneeds to be stored outsideNotifyas the token is re-used until expiration.BuildReceiverIntegrations: The above change means this function needs to return an error again (it was recently removed).http_config, but this is not done yet. For example, the webhook notifer already hastlsConfigandhmacConfigand it would make sense to move these tohttp_config. This will require a migration though, as the config path will change and the current implementation of these options fail on Send instead of on Create.Copilot Summary 🤖
OAuth2 Integration:
http/client.go, including a newoauth2.TokenSourcefield in theClientstruct and validation for OAuth2 configurations during client initialization. ([[1]](https://github.com/grafana/alerting/pull/338/files#diff-db6dcd51441efbbef50fb4f0e52a2a24d0207a8cf997c2c2d18f1345e0b4b255R28-R39),[[2]](https://github.com/grafana/alerting/pull/338/files#diff-db6dcd51441efbbef50fb4f0e52a2a24d0207a8cf997c2c2d18f1345e0b4b255L50-R71))WithHTTPClientConfigoption to pass HTTP client configurations, including OAuth2 settings. ([http/client.goR88-R95](https://github.com/grafana/alerting/pull/338/files#diff-db6dcd51441efbbef50fb4f0e52a2a24d0207a8cf997c2c2d18f1345e0b4b255R88-R95))SendWebhookmethod to include OAuth2 token handling via an OAuth2 round-tripper. ([http/client.goR149-R153](https://github.com/grafana/alerting/pull/338/files#diff-db6dcd51441efbbef50fb4f0e52a2a24d0207a8cf997c2c2d18f1345e0b4b255R149-R153))Proxy Configuration:
ProxyConfigstruct inhttp/config.goto manage proxy settings, including support for proxy URLs, no-proxy addresses, and headers for CONNECT requests. ([http/config.goR1-R128](https://github.com/grafana/alerting/pull/338/files#diff-9cd5b98b32603671d06faab6568b1be0d3f2790b8ee426270cb20cb91824997aR1-R128))[http/config.goR1-R128](https://github.com/grafana/alerting/pull/338/files#diff-9cd5b98b32603671d06faab6568b1be0d3f2790b8ee426270cb20cb91824997aR1-R128))Test Coverage Enhancements:
http/client_test.goto validate OAuth2 integration, including scenarios for valid and invalid configurations, token reuse, and proxy interactions. ([[1]](https://github.com/grafana/alerting/pull/338/files#diff-0a04f5d21c1d2223648ce05c57de7f0e6b9be9be2da51184c5b441a3602845e6R5-R81),[[2]](https://github.com/grafana/alerting/pull/338/files#diff-0a04f5d21c1d2223648ce05c57de7f0e6b9be9be2da51184c5b441a3602845e6R234-R531))[http/client_test.goR234-R531](https://github.com/grafana/alerting/pull/338/files#diff-0a04f5d21c1d2223648ce05c57de7f0e6b9be9be2da51184c5b441a3602845e6R234-R531))