Skip to content

Commit ed09990

Browse files
[exporter/azuredataexplorerexporter] add azure default auth (#35835)
#### Description Add the ability to use the default Azure SDK authentication for the kusto client. This enables users to use workload identity. Links: - https://learn.microsoft.com/azure/developer/go/azure-sdk-authentication?tabs=bash#2-authenticate-with-azure - https://github.com/Azure/azure-kusto-go/blob/11658efc9faad4d0300afdc4af9a19c470b0313a/azkustodata/kcsb.go#L294C1-L298C2 - https://learn.microsoft.com/en-us/azure/aks/workload-identity-overview?tabs=go #### Link to tracking issue Fixes #33667 #### Testing - `make` - deploy controller in kind cluster using workload identity, send dummy traces and validate that they reach the ADX cluster #### Documentation Split the authentication docs for each mechanism available.
1 parent 2416e90 commit ed09990

File tree

7 files changed

+88
-8
lines changed

7 files changed

+88
-8
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: azuredataexplorerexporter
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Add new configuration option `use_default_auth` to enable default authentication for Azure Data Explorer. This option allows users to leverage workload identity for authentication.
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [33667]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]

exporter/azuredataexplorerexporter/README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,16 @@ This exporter sends metrics, logs and trace data to
2222
The following settings are required:
2323

2424
- `cluster_uri` (no default): The cluster name of the provisioned ADX cluster to ingest the data.
25-
- `application_id` (no default): The client id to connect to the cluster and ingest data.
26-
- `application_key` (no default): The cluster secret corresponding to the client id.
27-
- `tenant_id` (no default): The tenant id where the application_id is referenced from.
25+
26+
One authentication method is required:
27+
- Service principal:
28+
- `application_id` (no default): The client id to connect to the cluster and ingest data.
29+
- `application_key` (no default): The cluster secret corresponding to the client id.
30+
- `tenant_id` (no default): The tenant id where the application_id is referenced from.
31+
- Managed identity:
32+
- `managed_identity_id` (no default): The managed identity id to authenticate with. Set to "system" for system-assigned managed identity. Set the MI client Id (GUID) for user-assigned managed identity.
33+
- Default authentication:
34+
- `use_azure_auth` (default: false): Set to true to use the Azure [default authentication](https://learn.microsoft.com/en-us/azure/developer/go/azure-sdk-authentication?tabs=bash#2-authenticate-with-azure).
2835

2936
The following settings can be optionally configured and have default values:
3037
> Note that the database tables are expected to be created upfront before the exporter is in operation , the definition of these are in the section [Database and Table definition scripts](#database-and-table-definition-scripts)

exporter/azuredataexplorerexporter/adx_exporter.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ func createKcsb(config *Config, version string) *kusto.ConnectionStringBuilder {
218218
isSystemManagedIdentity := strings.EqualFold(strings.TrimSpace(config.ManagedIdentityID), "SYSTEM")
219219
// If the user has managed identity done, use it. For System managed identity use the MI as system
220220
switch {
221+
case config.UseAzureAuth:
222+
kcsb = kusto.NewConnectionStringBuilder(config.ClusterURI).WithDefaultAzureCredential()
221223
case !isManagedIdentity:
222224
kcsb = kusto.NewConnectionStringBuilder(config.ClusterURI).WithAadAppKey(config.ApplicationID, string(config.ApplicationKey), config.TenantID)
223225
case isManagedIdentity && isSystemManagedIdentity:

exporter/azuredataexplorerexporter/adx_exporter_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ func TestCreateKcsb(t *testing.T) {
178178
name string // name of the test
179179
config Config // config for the test
180180
isMsi bool // is MSI enabled
181+
isAzureAuth bool // is azure authentication enabled
181182
applicationID string // application id
182183
managedIdentityID string // managed identity id
183184
}{
@@ -216,6 +217,15 @@ func TestCreateKcsb(t *testing.T) {
216217
managedIdentityID: "636d798f-b005-41c9-9809-81a5e5a12b2e",
217218
applicationID: "",
218219
},
220+
{
221+
name: "azure auth",
222+
config: Config{
223+
ClusterURI: "https://CLUSTER.kusto.windows.net",
224+
Database: "tests",
225+
UseAzureAuth: true,
226+
},
227+
isAzureAuth: true,
228+
},
219229
}
220230
for i := range tests {
221231
tt := tests[i]
@@ -229,6 +239,8 @@ func TestCreateKcsb(t *testing.T) {
229239
wantManagedID := tt.managedIdentityID
230240
assert.Equal(t, wantManagedID, gotKcsb.ManagedServiceIdentity)
231241
assert.Equal(t, "https://CLUSTER.kusto.windows.net", gotKcsb.DataSource)
242+
wantIsAzure := tt.isAzureAuth
243+
assert.Equal(t, wantIsAzure, gotKcsb.DefaultAuth)
232244
})
233245
}
234246
}

exporter/azuredataexplorerexporter/config.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type Config struct {
2424
ApplicationKey configopaque.String `mapstructure:"application_key"`
2525
TenantID string `mapstructure:"tenant_id"`
2626
ManagedIdentityID string `mapstructure:"managed_identity_id"`
27+
UseAzureAuth bool `mapstructure:"use_azure_auth"`
2728
Database string `mapstructure:"db_name"`
2829
MetricTable string `mapstructure:"metrics_table_name"`
2930
LogTable string `mapstructure:"logs_table_name"`
@@ -46,9 +47,23 @@ func (adxCfg *Config) Validate() error {
4647
if isClusterURIEmpty {
4748
return errors.New(`clusterURI config is mandatory`)
4849
}
49-
// Parameters for AD App Auth or Managed Identity Auth are mandatory
50-
if isAppAuthEmpty && isManagedAuthEmpty {
51-
return errors.New(`either ["application_id" , "application_key" , "tenant_id"] or ["managed_identity_id"] are needed for auth`)
50+
// Parameters for AD App Auth or Managed Identity Auth or Default Auth are mandatory
51+
authMethods := 0
52+
53+
if !isAppAuthEmpty {
54+
authMethods++
55+
}
56+
57+
if !isManagedAuthEmpty {
58+
authMethods++
59+
}
60+
61+
if adxCfg.UseAzureAuth {
62+
authMethods++
63+
}
64+
65+
if authMethods != 1 {
66+
return errors.New(`either ["application_id" , "application_key" , "tenant_id"] or ["managed_identity_id"] or ["use_azure_auth"] must be provided for auth`)
5267
}
5368

5469
if !(adxCfg.IngestionType == managedIngestType || adxCfg.IngestionType == queuedIngestTest || isEmpty(adxCfg.IngestionType)) {

exporter/azuredataexplorerexporter/config_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestLoadConfig(t *testing.T) {
4545
},
4646
{
4747
id: component.NewIDWithName(metadata.Type, "2"),
48-
errorMessage: `either ["application_id" , "application_key" , "tenant_id"] or ["managed_identity_id"] are needed for auth`,
48+
errorMessage: `either ["application_id" , "application_key" , "tenant_id"] or ["managed_identity_id"] or ["use_azure_auth"] must be provided for auth`,
4949
},
5050
{
5151
id: component.NewIDWithName(metadata.Type, "3"),
@@ -111,6 +111,18 @@ func TestLoadConfig(t *testing.T) {
111111
},
112112
},
113113
},
114+
{
115+
id: component.NewIDWithName(metadata.Type, "9"),
116+
expected: &Config{
117+
ClusterURI: "https://CLUSTER.kusto.windows.net",
118+
Database: "oteldb",
119+
MetricTable: "OTELMetrics",
120+
LogTable: "OTELLogs",
121+
TraceTable: "OTELTraces",
122+
UseAzureAuth: true,
123+
IngestionType: queuedIngestTest,
124+
},
125+
},
114126
}
115127

116128
for _, tt := range tests {

exporter/azuredataexplorerexporter/testdata/config.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,9 @@ azuredataexplorer/8:
145145
enabled: true
146146
initial_interval: 10s
147147
max_interval: 60s
148-
max_elapsed_time: 10m
148+
max_elapsed_time: 10m
149+
azuredataexplorer/9:
150+
# Kusto cluster uri
151+
cluster_uri: "https://CLUSTER.kusto.windows.net"
152+
# weather to use the default azure auth
153+
use_azure_auth: true

0 commit comments

Comments
 (0)