Skip to content

Commit 6d514d6

Browse files
committed
Managed Identity support for Azure Event Hubs. Changes include -
- If authentication token is not specified in provider, attempt to get the token using workload identity. = Add new field .spec.serviceAccountName to support multi-tenant workload identity as defined in RFC-0010 to use an identity with a service account other than the notification-controller. - Use proxy to get the token if specified in provider spec. - Cache the tokens if enabled in the notification controller options. - If address has SAS connection string, use that for authentication, this takes priority over token-authentication - If static JWT token is specified in the secret reference, use it for authentication, this takes priority over workload identity-acquired token. - Add unit tests for the 3 authentication mechanisms (SAS, JWT, managed identity). - Add documentation for using single-tenant and multi-tenant approaches of workload identity with azureeventhub provider. - Add operation post to github helpers and provider controller for cache event metrics Signed-off-by: Dipti Pai <[email protected]>
1 parent 5dfaa1a commit 6d514d6

File tree

13 files changed

+368
-65
lines changed

13 files changed

+368
-65
lines changed

api/v1beta3/provider_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ type ProviderSpec struct {
108108
// +optional
109109
SecretRef *meta.LocalObjectReference `json:"secretRef,omitempty"`
110110

111+
// ServiceAccountName is the name of the service account used to
112+
// authenticate with services from cloud providers.
113+
// +optional
114+
ServiceAccountName string `json:"serviceAccountName,omitempty"`
115+
111116
// CertSecretRef specifies the Secret containing
112117
// a PEM-encoded CA certificate (in the `ca.crt` key).
113118
// +optional

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,11 @@ spec:
490490
required:
491491
- name
492492
type: object
493+
serviceAccountName:
494+
description: |-
495+
ServiceAccountName is the name of the service account used to
496+
authenticate with services from cloud providers.
497+
type: string
493498
suspend:
494499
description: |-
495500
Suspend tells the controller to suspend subsequent

docs/api/v1beta3/notification.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,19 @@ credentials for this Provider.</p>
350350
</tr>
351351
<tr>
352352
<td>
353+
<code>serviceAccountName</code><br>
354+
<em>
355+
string
356+
</em>
357+
</td>
358+
<td>
359+
<em>(Optional)</em>
360+
<p>ServiceAccountName is the name of the service account used to
361+
authenticate with services from cloud providers.</p>
362+
</td>
363+
</tr>
364+
<tr>
365+
<td>
353366
<code>certSecretRef</code><br>
354367
<em>
355368
<a href="https://pkg.go.dev/github.com/fluxcd/pkg/apis/meta#LocalObjectReference">
@@ -655,6 +668,19 @@ credentials for this Provider.</p>
655668
</tr>
656669
<tr>
657670
<td>
671+
<code>serviceAccountName</code><br>
672+
<em>
673+
string
674+
</em>
675+
</td>
676+
<td>
677+
<em>(Optional)</em>
678+
<p>ServiceAccountName is the name of the service account used to
679+
authenticate with services from cloud providers.</p>
680+
</td>
681+
</tr>
682+
<tr>
683+
<td>
658684
<code>certSecretRef</code><br>
659685
<em>
660686
<a href="https://pkg.go.dev/github.com/fluxcd/pkg/apis/meta#LocalObjectReference">

docs/spec/v1beta3/providers.md

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,13 +1414,59 @@ jobs:
14141414

14151415
### Azure Event Hub
14161416

1417-
The Azure Event Hub supports two authentication methods, [JWT](https://docs.microsoft.com/en-us/azure/event-hubs/authenticate-application)
1418-
and [SAS](https://docs.microsoft.com/en-us/azure/event-hubs/authorize-access-shared-access-signature) based.
1417+
The Azure Event Hub provider supports the following authentication methods,
1418+
- [Managed
1419+
Identity](https://learn.microsoft.com/en-us/azure/event-hubs/authenticate-managed-identity)
1420+
- [JWT](https://docs.microsoft.com/en-us/azure/event-hubs/authenticate-application)
1421+
- [SAS](https://docs.microsoft.com/en-us/azure/event-hubs/authorize-access-shared-access-signature)
1422+
based.
1423+
1424+
#### Managed Identity
1425+
1426+
Managed identity authentication can be setup using Azure Workload identity.
1427+
1428+
##### Pre-requisites
1429+
1430+
- Ensure Workload Identity is properly [set up on your
1431+
cluster](https://learn.microsoft.com/en-us/azure/aks/workload-identity-deploy-cluster#create-an-aks-cluster).
1432+
1433+
##### Configure workload identity
1434+
1435+
- Create a managed identity to access Azure Event Hub.
1436+
- Grant the managed identity the necessary permissions to send events to Azure
1437+
Event hub as described
1438+
[here](https://learn.microsoft.com/en-us/azure/event-hubs/authenticate-managed-identity#to-assign-azure-roles-using-the-azure-portal).
1439+
1440+
- Establish a federated identity credential between the managed identity and the
1441+
service account to be used for authentication. Ensure the federated credential
1442+
uses the correct namespace and name of the service account. For more details,
1443+
please refer to this
1444+
[guide](https://azure.github.io/azure-workload-identity/docs/quick-start.html#6-establish-federated-identity-credential-between-the-identity-and-the-service-account-issuer--subject).
1445+
1446+
##### Single tenant approach
1447+
1448+
This approach uses the notification-controller service account for setting up
1449+
authentication.
1450+
1451+
- In the default installation, the notification-controller service account is
1452+
located in the `flux-system` namespace with name `notification-controller`.
1453+
1454+
- Configure workload identity with notification-controller as described in the
1455+
docs [here](/flux/installation/configuration/workload-identity/).
1456+
1457+
##### Multi-tenant approach
1458+
1459+
For multi-tenant clusters, set `.spec.serviceAccountName` of the provider to
1460+
the service account to be used for authentication. Ensure that the service
1461+
account has the
1462+
[annotations](https://learn.microsoft.com/en-us/azure/aks/workload-identity-overview?tabs=dotnet#service-account-annotations)
1463+
for the client-id and tenant-id of the managed identity.
14191464

14201465
#### JWT based auth
14211466

1422-
In JWT we use 3 input values. Channel, token and address.
1423-
We perform the following translation to match we the data we need to communicate with Azure Event Hub.
1467+
In JWT we use 3 input values. Channel, token and address. We perform the
1468+
following translation to match we the data we need to communicate with Azure
1469+
Event Hub.
14241470

14251471
- channel = Azure Event Hub namespace
14261472
- address = Azure Event Hub name
@@ -1450,11 +1496,13 @@ stringData:
14501496
```
14511497

14521498
The controller doesn't take any responsibility for the JWT token to be updated.
1453-
You need to use a secondary tool to make sure that the token in the secret is renewed.
1499+
You need to use a secondary tool to make sure that the token in the secret is
1500+
renewed.
14541501

1455-
If you want to make a easy test assuming that you have setup a Azure Enterprise application and you called it
1456-
event-hub you can follow most of the bellow commands. You will need to provide the `client_secret` that you got
1457-
when generating the Azure Enterprise Application.
1502+
If you want to make a easy test assuming that you have setup a Azure Enterprise
1503+
application and you called it event-hub you can follow most of the bellow
1504+
commands. You will need to provide the `client_secret` that you got when
1505+
generating the Azure Enterprise Application.
14581506

14591507
```shell
14601508
export AZURE_CLIENT=$(az ad app list --filter "startswith(displayName,'event-hub')" --query '[].appId' |jq -r '.[0]')
@@ -1497,8 +1545,8 @@ stringData:
14971545
```
14981546

14991547
Assuming that you have created the Azure event hub and namespace you should be
1500-
able to use a similar command to get your connection string. This will give
1501-
you the default Root SAS, which is NOT supposed to be used in production.
1548+
able to use a similar command to get your connection string. This will give you
1549+
the default Root SAS, which is NOT supposed to be used in production.
15021550

15031551
```shell
15041552
az eventhubs namespace authorization-rule keys list --resource-group <rg-name> --namespace-name <namespace-name> --name RootManageSharedAccessKey -o tsv --query primaryConnectionString

go.mod

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6
1111
github.com/Azure/azure-amqp-common-go/v4 v4.2.0
1212
github.com/Azure/azure-event-hubs-go/v3 v3.6.2
13-
github.com/DataDog/datadog-api-client-go/v2 v2.37.1
13+
github.com/DataDog/datadog-api-client-go/v2 v2.35.0
1414
github.com/PagerDuty/go-pagerduty v1.8.0
1515
github.com/cdevents/sdk-go v0.4.1
1616
github.com/chainguard-dev/git-urls v1.0.2
@@ -20,8 +20,9 @@ require (
2020
github.com/fluxcd/notification-controller/api v1.5.0
2121
github.com/fluxcd/pkg/apis/event v0.17.0
2222
github.com/fluxcd/pkg/apis/meta v1.11.0
23-
github.com/fluxcd/pkg/cache v0.8.0
24-
github.com/fluxcd/pkg/git v0.27.0
23+
github.com/fluxcd/pkg/auth v0.10.1-0.20250502123105-182841a21cfa
24+
github.com/fluxcd/pkg/cache v0.8.1-0.20250502123105-182841a21cfa
25+
github.com/fluxcd/pkg/git v0.27.1-0.20250502123105-182841a21cfa
2526
github.com/fluxcd/pkg/masktoken v0.7.0
2627
github.com/fluxcd/pkg/runtime v0.59.0
2728
github.com/fluxcd/pkg/ssa v0.46.0
@@ -63,15 +64,15 @@ require (
6364
cloud.google.com/go/compute/metadata v0.6.0 // indirect
6465
cloud.google.com/go/iam v1.3.1 // indirect
6566
github.com/42wim/httpsig v1.2.2 // indirect
66-
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible // indirect
67+
github.com/Azure/azure-sdk-for-go v65.0.0+incompatible // indirect
6768
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.18.0 // indirect
6869
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.9.0 // indirect
6970
github.com/Azure/azure-sdk-for-go/sdk/internal v1.11.1 // indirect
70-
github.com/Azure/go-amqp v1.0.0 // indirect
71+
github.com/Azure/go-amqp v1.3.0 // indirect
7172
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
7273
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
73-
github.com/Azure/go-autorest/autorest v0.11.29 // indirect
74-
github.com/Azure/go-autorest/autorest/adal v0.9.23 // indirect
74+
github.com/Azure/go-autorest/autorest v0.11.28 // indirect
75+
github.com/Azure/go-autorest/autorest/adal v0.9.21 // indirect
7576
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
7677
github.com/Azure/go-autorest/autorest/to v0.4.0 // indirect
7778
github.com/Azure/go-autorest/autorest/validation v0.3.1 // indirect
@@ -100,7 +101,6 @@ require (
100101
github.com/felixge/httpsnoop v1.0.4 // indirect
101102
github.com/fluxcd/pkg/apis/acl v0.7.0 // indirect
102103
github.com/fluxcd/pkg/apis/kustomize v1.10.0 // indirect
103-
github.com/fluxcd/pkg/auth v0.10.0 // indirect
104104
github.com/fsnotify/fsnotify v1.8.0 // indirect
105105
github.com/fxamacker/cbor/v2 v2.8.0 // indirect
106106
github.com/gabriel-vasile/mimetype v1.4.5 // indirect
@@ -132,6 +132,7 @@ require (
132132
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
133133
github.com/hashicorp/go-version v1.7.0 // indirect
134134
github.com/inconshreveable/mousetrap v1.1.0 // indirect
135+
github.com/joho/godotenv v1.5.1 // indirect
135136
github.com/josharian/intern v1.0.0 // indirect
136137
github.com/jpillora/backoff v1.0.0 // indirect
137138
github.com/json-iterator/go v1.1.12 // indirect

0 commit comments

Comments
 (0)