Skip to content

Commit 67c049d

Browse files
committed
Add mTLS support for DataDog and Sentry notifiers
These notifiers were using x509.CertPool which only supports CA certificates for server authentication. By migrating to tls.Config, they now support mutual TLS authentication with client certificates. This enables secure communication in enterprise environments that require client certificate authentication, completing the runtime/secrets migration for these remaining notifiers. Signed-off-by: cappyzawa <[email protected]>
1 parent 326c6bc commit 67c049d

File tree

5 files changed

+14
-16
lines changed

5 files changed

+14
-16
lines changed

docs/spec/v1beta3/providers.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,6 +1205,7 @@ The following providers support client certificate authentication:
12051205
| `azuredevops` | Azure DevOps |
12061206
| `bitbucket` | Bitbucket |
12071207
| `bitbucketserver` | BitBucket Server/Data Center |
1208+
| `datadog` | DataDog |
12081209
| `discord` | Discord webhooks |
12091210
| `forwarder` | Generic forwarder |
12101211
| `gitea` | Gitea |
@@ -1217,6 +1218,7 @@ The following providers support client certificate authentication:
12171218
| `opsgenie` | Opsgenie alerts |
12181219
| `pagerduty` | PagerDuty events |
12191220
| `rocket` | Rocket.Chat |
1221+
| `sentry` | Sentry |
12201222
| `slack` | Slack API |
12211223
| `webex` | Webex messages |
12221224

internal/notifier/datadog.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package notifier
1919
import (
2020
"context"
2121
"crypto/tls"
22-
"crypto/x509"
2322
"fmt"
2423
"net/http"
2524
"net/url"
@@ -41,7 +40,7 @@ type DataDog struct {
4140
// url: The DataDog API endpoint to use. Examples: https://api.datadoghq.com, https://api.datadoghq.eu, etc.
4241
// token: The DataDog API key (not the application key).
4342
// headers: A map of extra tags to add to the event
44-
func NewDataDog(address string, proxyUrl string, certPool *x509.CertPool, token string) (*DataDog, error) {
43+
func NewDataDog(address string, proxyUrl string, tlsConfig *tls.Config, token string) (*DataDog, error) {
4544
conf := datadog.NewConfiguration()
4645

4746
if token == "" {
@@ -56,7 +55,7 @@ func NewDataDog(address string, proxyUrl string, certPool *x509.CertPool, token
5655
conf.Host = baseUrl.Host
5756
conf.Scheme = baseUrl.Scheme
5857

59-
if proxyUrl != "" || certPool != nil {
58+
if proxyUrl != "" || tlsConfig != nil {
6059
transport := &http.Transport{}
6160

6261
if proxyUrl != "" {
@@ -68,10 +67,8 @@ func NewDataDog(address string, proxyUrl string, certPool *x509.CertPool, token
6867
transport.Proxy = http.ProxyURL(proxy)
6968
}
7069

71-
if certPool != nil {
72-
transport.TLSClientConfig = &tls.Config{
73-
RootCAs: certPool,
74-
}
70+
if tlsConfig != nil {
71+
transport.TLSClientConfig = tlsConfig
7572
}
7673

7774
conf.HTTPClient = &http.Client{

internal/notifier/datadog_fuzz_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package notifier
22

33
import (
44
"context"
5+
"crypto/tls"
56
"crypto/x509"
67
"io"
78
"net/http"
@@ -33,7 +34,8 @@ func Fuzz_DataDog(f *testing.F) {
3334
var cert x509.CertPool
3435
_ = fuzz.NewConsumer(seed).GenerateStruct(&cert)
3536

36-
dd, err := NewDataDog(ts.URL, "", &cert, apiKey)
37+
tlsConfig := &tls.Config{RootCAs: &cert}
38+
dd, err := NewDataDog(ts.URL, "", tlsConfig, apiKey)
3739
if err != nil {
3840
return
3941
}

internal/notifier/factory.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ func webexNotifierFunc(opts notifierOptions) (Interface, error) {
271271
}
272272

273273
func sentryNotifierFunc(opts notifierOptions) (Interface, error) {
274-
return NewSentry(opts.CertPool, opts.URL, opts.Channel)
274+
return NewSentry(opts.TLSConfig, opts.URL, opts.Channel)
275275
}
276276

277277
func azureEventHubNotifierFunc(opts notifierOptions) (Interface, error) {
@@ -307,7 +307,7 @@ func pagerDutyNotifierFunc(opts notifierOptions) (Interface, error) {
307307
}
308308

309309
func dataDogNotifierFunc(opts notifierOptions) (Interface, error) {
310-
return NewDataDog(opts.URL, opts.ProxyURL, opts.CertPool, opts.Token)
310+
return NewDataDog(opts.URL, opts.ProxyURL, opts.TLSConfig, opts.Token)
311311
}
312312

313313
func natsNotifierFunc(opts notifierOptions) (Interface, error) {

internal/notifier/sentry.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package notifier
1919
import (
2020
"context"
2121
"crypto/tls"
22-
"crypto/x509"
2322
"fmt"
2423
"net/http"
2524

@@ -33,17 +32,15 @@ type Sentry struct {
3332
}
3433

3534
// NewSentry creates a Sentry client from the provided Data Source Name (DSN)
36-
func NewSentry(certPool *x509.CertPool, dsn string, environment string) (*Sentry, error) {
35+
func NewSentry(tlsConfig *tls.Config, dsn string, environment string) (*Sentry, error) {
3736
if dsn == "" {
3837
return nil, fmt.Errorf("DSN cannot be empty")
3938
}
4039

4140
tr := &http.Transport{}
42-
if certPool != nil {
41+
if tlsConfig != nil {
4342
tr = &http.Transport{
44-
TLSClientConfig: &tls.Config{
45-
RootCAs: certPool,
46-
},
43+
TLSClientConfig: tlsConfig,
4744
}
4845
}
4946
client, err := sentry.NewClient(sentry.ClientOptions{

0 commit comments

Comments
 (0)