Skip to content

Commit 3f4e962

Browse files
authored
Merge pull request #1137 from cappyzawa/feat/mtls-postmessage-notifiers
Add mTLS support for postMessage-based notifiers
2 parents a3e6dd6 + 98ecf2d commit 3f4e962

31 files changed

+490
-313
lines changed

api/v1beta3/provider_types.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,17 @@ type ProviderSpec struct {
123123
// +optional
124124
ServiceAccountName string `json:"serviceAccountName,omitempty"`
125125

126-
// CertSecretRef specifies the Secret containing
127-
// a PEM-encoded CA certificate (in the `ca.crt` key).
128-
// +optional
126+
// CertSecretRef specifies the Secret containing TLS certificates
127+
// for secure communication.
128+
//
129+
// Supported configurations:
130+
// - CA-only: Server authentication (provide ca.crt only)
131+
// - mTLS: Mutual authentication (provide ca.crt + tls.crt + tls.key)
132+
// - Client-only: Client authentication with system CA (provide tls.crt + tls.key only)
129133
//
130-
// Note: Support for the `caFile` key has
131-
// been deprecated.
134+
// Legacy keys "caFile", "certFile", "keyFile" are supported but deprecated. Use "ca.crt", "tls.crt", "tls.key" instead.
135+
//
136+
// +optional
132137
CertSecretRef *meta.LocalObjectReference `json:"certSecretRef,omitempty"`
133138

134139
// Suspend tells the controller to suspend subsequent

config/crd/bases/notification.toolkit.fluxcd.io_providers.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,11 +443,15 @@ spec:
443443
type: string
444444
certSecretRef:
445445
description: |-
446-
CertSecretRef specifies the Secret containing
447-
a PEM-encoded CA certificate (in the `ca.crt` key).
446+
CertSecretRef specifies the Secret containing TLS certificates
447+
for secure communication.
448448
449-
Note: Support for the `caFile` key has
450-
been deprecated.
449+
Supported configurations:
450+
- CA-only: Server authentication (provide ca.crt only)
451+
- mTLS: Mutual authentication (provide ca.crt + tls.crt + tls.key)
452+
- Client-only: Client authentication with system CA (provide tls.crt + tls.key only)
453+
454+
Legacy keys "caFile", "certFile", "keyFile" are supported but deprecated. Use "ca.crt", "tls.crt", "tls.key" instead.
451455
properties:
452456
name:
453457
description: Name of the referent.

docs/api/v1beta3/notification.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -392,10 +392,13 @@ github.com/fluxcd/pkg/apis/meta.LocalObjectReference
392392
</td>
393393
<td>
394394
<em>(Optional)</em>
395-
<p>CertSecretRef specifies the Secret containing
396-
a PEM-encoded CA certificate (in the <code>ca.crt</code> key).</p>
397-
<p>Note: Support for the <code>caFile</code> key has
398-
been deprecated.</p>
395+
<p>CertSecretRef specifies the Secret containing TLS certificates
396+
for secure communication.</p>
397+
<p>Supported configurations:
398+
- CA-only: Server authentication (provide ca.crt only)
399+
- mTLS: Mutual authentication (provide ca.crt + tls.crt + tls.key)
400+
- Client-only: Client authentication with system CA (provide tls.crt + tls.key only)</p>
401+
<p>Legacy keys &ldquo;caFile&rdquo;, &ldquo;certFile&rdquo;, &ldquo;keyFile&rdquo; are supported but deprecated. Use &ldquo;ca.crt&rdquo;, &ldquo;tls.crt&rdquo;, &ldquo;tls.key&rdquo; instead.</p>
399402
</td>
400403
</tr>
401404
<tr>
@@ -730,10 +733,13 @@ github.com/fluxcd/pkg/apis/meta.LocalObjectReference
730733
</td>
731734
<td>
732735
<em>(Optional)</em>
733-
<p>CertSecretRef specifies the Secret containing
734-
a PEM-encoded CA certificate (in the <code>ca.crt</code> key).</p>
735-
<p>Note: Support for the <code>caFile</code> key has
736-
been deprecated.</p>
736+
<p>CertSecretRef specifies the Secret containing TLS certificates
737+
for secure communication.</p>
738+
<p>Supported configurations:
739+
- CA-only: Server authentication (provide ca.crt only)
740+
- mTLS: Mutual authentication (provide ca.crt + tls.crt + tls.key)
741+
- Client-only: Client authentication with system CA (provide tls.crt + tls.key only)</p>
742+
<p>Legacy keys &ldquo;caFile&rdquo;, &ldquo;certFile&rdquo;, &ldquo;keyFile&rdquo; are supported but deprecated. Use &ldquo;ca.crt&rdquo;, &ldquo;tls.crt&rdquo;, &ldquo;tls.key&rdquo; instead.</p>
737743
</td>
738744
</tr>
739745
<tr>

docs/spec/v1beta3/providers.md

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ field](https://api.slack.com/methods/chat.postMessage#arg_username) to the
284284
payload, defaulting to the name of the reporting controller.
285285

286286
This Provider type supports the configuration of a [proxy URL](#https-proxy)
287-
and/or [TLS certificates](#tls-certificates).
287+
and/or [certificate secret reference](#certificate-secret-reference).
288288

289289
###### Slack example
290290

@@ -363,7 +363,7 @@ In both cases the Event metadata is attached as facts, and the involved object a
363363
The severity of the Event is used to set the color of the message.
364364

365365
This Provider type supports the configuration of a [proxy URL](#https-proxy)
366-
and/or [TLS certificates](#tls-certificates), but lacks support for
366+
and/or [certificate secret reference](#certificate-secret-reference), but lacks support for
367367
configuring a [Channel](#channel). This can be configured during the
368368
creation of the Incoming Webhook Workflow in Microsoft Teams.
369369

@@ -403,7 +403,7 @@ The Event will be formatted into a [DataDog Event](https://docs.datadoghq.com/ap
403403
API endpoint of the provided DataDog [Address](#address).
404404

405405
This Provider type supports the configuration of a [proxy URL](#https-proxy)
406-
and/or [TLS certificates](#tls-certificates).
406+
and/or [certificate secret reference](#certificate-secret-reference).
407407

408408
The metadata of the Event is included in the DataDog event as extra tags.
409409

@@ -459,7 +459,7 @@ The Event will be formatted into a [Slack message](#slack) and send to the
459459
`/slack` endpoint of the provided Discord [Address](#address).
460460

461461
This Provider type supports the configuration of a [proxy URL](#https-proxy)
462-
and/or [TLS certificates](#tls-certificates), but lacks support for
462+
and/or [certificate secret reference](#certificate-secret-reference), but lacks support for
463463
configuring a [Channel](#channel). This can be configured [during the creation
464464
of the address](https://discord.com/developers/docs/resources/webhook#create-webhook)
465465

@@ -507,7 +507,7 @@ The Provider's [Channel](#channel) is used to set the `environment` on the
507507
Sentry client.
508508

509509
This Provider type supports the configuration of
510-
[TLS certificates](#tls-certificates).
510+
[certificate secret reference](#certificate-secret-reference).
511511

512512
###### Sentry example
513513

@@ -555,7 +555,7 @@ a unique identifier with the topic identifier (`-1234567890:1`) for the forum ch
555555
or the username (`@username`) of the target channel.
556556

557557
This Provider type does not support the configuration of a [proxy URL](#https-proxy)
558-
or [TLS certificates](#tls-certificates).
558+
or [certificate secret reference](#certificate-secret-reference).
559559

560560
###### Telegram example
561561

@@ -623,7 +623,7 @@ The Event will be formatted into a [Lark Message card](https://open.larksuite.co
623623
with the metadata written to the message string.
624624

625625
This Provider type does not support the configuration of a [proxy URL](#https-proxy)
626-
or [TLS certificates](#tls-certificates).
626+
or [certificate secret reference](#certificate-secret-reference).
627627

628628
###### Lark example
629629

@@ -660,7 +660,7 @@ The Event will be formatted into a [Slack message](#slack) and send as a
660660
payload the provided Rocket [Address](#address).
661661

662662
This Provider type does support the configuration of a [proxy URL](#https-proxy)
663-
and [TLS certificates](#tls-certificates).
663+
and [certificate secret reference](#certificate-secret-reference).
664664

665665
###### Rocket example
666666

@@ -742,7 +742,7 @@ You can optionally add [attributes](https://cloud.google.com/pubsub/docs/samples
742742
to the Pub/Sub message using a [`headers` key in the referenced Secret](#http-headers-example).
743743

744744
This Provider type does not support the configuration of a [proxy URL](#https-proxy)
745-
or [TLS certificates](#tls-certificates).
745+
or [certificate secret reference](#certificate-secret-reference).
746746

747747
###### Google Pub/Sub with JSON Credentials and Custom Headers Example
748748

@@ -788,7 +788,7 @@ with the metadata added to the [`details` field](https://docs.opsgenie.com/docs/
788788
as a list of key-value pairs.
789789

790790
This Provider type does support the configuration of a [proxy URL](#https-proxy)
791-
and [TLS certificates](#tls-certificates).
791+
and [certificate secret reference](#certificate-secret-reference).
792792

793793
###### Opsgenie example
794794

@@ -831,7 +831,7 @@ The provider will also send [Change Events](https://developer.pagerduty.com/api-
831831
for `info` level `Severity`, which will be displayed in the PagerDuty service's timeline to track changes.
832832

833833
This Provider type supports the configuration of a [proxy URL](#https-proxy)
834-
and [TLS certificates](#tls-certificates).
834+
and [certificate secret reference](#certificate-secret-reference).
835835

836836
The [Channel](#channel) is used to set the routing key to send the event to the appropriate integration.
837837

@@ -916,7 +916,7 @@ global:
916916
```
917917

918918
This Provider type does support the configuration of a [proxy URL](#https-proxy)
919-
and [TLS certificates](#tls-certificates).
919+
and [certificate secret reference](#certificate-secret-reference).
920920

921921
###### Prometheus Alertmanager example
922922

@@ -988,7 +988,7 @@ The [Channel](#channel) is used to set the ID of the room to send the message
988988
to.
989989

990990
This Provider type does support the configuration of a [proxy URL](#https-proxy)
991-
and [TLS certificates](#tls-certificates).
991+
and [certificate secret reference](#certificate-secret-reference).
992992

993993
###### Webex example
994994

@@ -1184,11 +1184,36 @@ stringData:
11841184
proxy: "http://username:password@proxy_url:proxy_port"
11851185
```
11861186

1187-
### TLS certificates
1187+
### Certificate secret reference
11881188

11891189
`.spec.certSecretRef` is an optional field to specify a name reference to a
1190-
Secret in the same namespace as the Provider, containing the TLS CA certificate.
1191-
The secret must be of type `kubernetes.io/tls` or `Opaque`.
1190+
Secret in the same namespace as the Provider, containing TLS certificates for
1191+
secure communication. The secret must be of type `kubernetes.io/tls` or `Opaque`.
1192+
1193+
#### Supported configurations
1194+
1195+
- **CA-only**: Server authentication (provide `ca.crt` only)
1196+
- **mTLS**: Client certificate authentication (provide `tls.crt` + `tls.key`, optionally with `ca.crt`)
1197+
1198+
#### Providers supporting client certificate authentication
1199+
1200+
The following webhook-based providers support client certificate authentication:
1201+
1202+
| Provider Type | Description |
1203+
|---------------------|--------------------------------|
1204+
| `alertmanager` | Prometheus Alertmanager |
1205+
| `discord` | Discord webhooks |
1206+
| `forwarder` | Generic forwarder |
1207+
| `grafana` | Grafana annotations API |
1208+
| `matrix` | Matrix rooms |
1209+
| `msteams` | Microsoft Teams |
1210+
| `opsgenie` | Opsgenie alerts |
1211+
| `pagerduty` | PagerDuty events |
1212+
| `rocket` | Rocket.Chat |
1213+
| `slack` | Slack API |
1214+
| `webex` | Webex messages |
1215+
1216+
Support for client certificate authentication is being expanded to additional providers over time.
11921217

11931218
#### Example
11941219

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ require (
2424
github.com/fluxcd/pkg/cache v0.9.0
2525
github.com/fluxcd/pkg/git v0.31.0
2626
github.com/fluxcd/pkg/masktoken v0.7.0
27-
github.com/fluxcd/pkg/runtime v0.61.0
27+
github.com/fluxcd/pkg/runtime v0.63.0
2828
github.com/fluxcd/pkg/ssa v0.48.0
2929
github.com/fluxcd/pkg/ssh v0.18.0
3030
github.com/getsentry/sentry-go v0.32.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ github.com/fluxcd/pkg/git v0.31.0 h1:hVUJcRujNa+GA5zrjrMpuVcgHbCBjfq0CZIZJqJl22I
168168
github.com/fluxcd/pkg/git v0.31.0/go.mod h1:rUgLXVQGBkBggHOLVMhHMHaweQ8Oc6HwZiN2Zm08Zxs=
169169
github.com/fluxcd/pkg/masktoken v0.7.0 h1:pitmyOg2pUVdW+nn2Lk/xqm2TaA08uxvOC0ns3sz6bM=
170170
github.com/fluxcd/pkg/masktoken v0.7.0/go.mod h1:Lc1uoDjO1GY6+YdkK+ZqqBIBWquyV58nlSJ5S1N1IYU=
171-
github.com/fluxcd/pkg/runtime v0.61.0 h1:63OCvVoJd3RbmAl7UBUzOeNtaY5V1iVL+SaaqiNMM74=
172-
github.com/fluxcd/pkg/runtime v0.61.0/go.mod h1:UeU0/eZLErYC/1bTmgzBfNXhiHy9fuQzjfLK0HxRgxY=
171+
github.com/fluxcd/pkg/runtime v0.63.0 h1:55J7ascGmXyTXWGwhD21N9fU7jC1l5rhdzjgNXs6aZg=
172+
github.com/fluxcd/pkg/runtime v0.63.0/go.mod h1:7pxGvaU0Yy1cDIUhiHAHhCx2yCLnkcVsplbYZG6j4JY=
173173
github.com/fluxcd/pkg/ssa v0.48.0 h1:DW+4DG8L/yZEi30UltOEXPB1d/ZFn4HfVhpJQp5oc2o=
174174
github.com/fluxcd/pkg/ssa v0.48.0/go.mod h1:T50TO0U2obLodZnrFgOrxollfBEy4V673OkM2aTUF1c=
175175
github.com/fluxcd/pkg/ssh v0.18.0 h1:SB0RrZ/YZIla3chTUulsfVmiCzJv5pEWfHM3dHMC8AU=

internal/notifier/alertmanager.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package notifier
1818

1919
import (
2020
"context"
21-
"crypto/x509"
21+
"crypto/tls"
2222
"encoding/json"
2323
"fmt"
2424
"net/url"
@@ -32,10 +32,10 @@ import (
3232
)
3333

3434
type Alertmanager struct {
35-
URL string
36-
ProxyURL string
37-
CertPool *x509.CertPool
38-
Token string
35+
URL string
36+
ProxyURL string
37+
TLSConfig *tls.Config
38+
Token string
3939
}
4040

4141
type AlertManagerAlert struct {
@@ -74,17 +74,17 @@ func (a *AlertManagerTime) UnmarshalJSON(jsonRepr []byte) error {
7474
return nil
7575
}
7676

77-
func NewAlertmanager(hookURL string, proxyURL string, certPool *x509.CertPool, token string) (*Alertmanager, error) {
77+
func NewAlertmanager(hookURL string, proxyURL string, tlsConfig *tls.Config, token string) (*Alertmanager, error) {
7878
_, err := url.ParseRequestURI(hookURL)
7979
if err != nil {
8080
return nil, fmt.Errorf("invalid Alertmanager URL %s: '%w'", hookURL, err)
8181
}
8282

8383
return &Alertmanager{
84-
URL: hookURL,
85-
ProxyURL: proxyURL,
86-
CertPool: certPool,
87-
Token: token,
84+
URL: hookURL,
85+
ProxyURL: proxyURL,
86+
Token: token,
87+
TLSConfig: tlsConfig,
8888
}, nil
8989
}
9090

@@ -141,8 +141,8 @@ func (s *Alertmanager) Post(ctx context.Context, event eventv1.Event) error {
141141
if s.ProxyURL != "" {
142142
opts = append(opts, withProxy(s.ProxyURL))
143143
}
144-
if s.CertPool != nil {
145-
opts = append(opts, withCertPool(s.CertPool))
144+
if s.TLSConfig != nil {
145+
opts = append(opts, withTLSConfig(s.TLSConfig))
146146
}
147147
if s.Token != "" {
148148
opts = append(opts, withRequestModifier(func(request *retryablehttp.Request) {

internal/notifier/alertmanager_fuzz_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package notifier
1818

1919
import (
2020
"context"
21-
"crypto/x509"
21+
"crypto/tls"
2222
"fmt"
2323
"io"
2424
"net/http"
@@ -43,10 +43,10 @@ func Fuzz_AlertManager(f *testing.F) {
4343
}))
4444
defer ts.Close()
4545

46-
var cert x509.CertPool
47-
_ = fuzz.NewConsumer(seed).GenerateStruct(&cert)
46+
var tlsConfig tls.Config
47+
_ = fuzz.NewConsumer(seed).GenerateStruct(&tlsConfig)
4848

49-
alertmanager, err := NewAlertmanager(fmt.Sprintf("%s/%s", ts.URL, urlSuffix), "", &cert, "")
49+
alertmanager, err := NewAlertmanager(fmt.Sprintf("%s/%s", ts.URL, urlSuffix), "", &tlsConfig, "")
5050
if err != nil {
5151
return
5252
}

0 commit comments

Comments
 (0)