[Azure] Add client secret (Oauth2) support for eventhub filebeat input#47256
[Azure] Add client secret (Oauth2) support for eventhub filebeat input#47256kaiyan-sheng merged 25 commits intomainfrom
Conversation
🤖 GitHub commentsExpand to view the GitHub comments
Just comment with:
|
|
This pull request does not have a backport label.
To fixup this pull request, you need to add the backport labels for the needed
|
🔍 Preview links for changed docs |
colleenmcginnis
left a comment
There was a problem hiding this comment.
Starting with v9.0, there is no longer a new documentation set published with every minor release: the same page stays valid over time and shows version-related evolutions. Read more in Write cumulative documentation.
Based on the backport labels, it looks like these changes are likely targeting 9.3.0. If that's the case, you can use my suggestions below. If not, feel free to adjust my suggestions as needed.
changelog/fragments/1761678237-feat-add-oauth2-for-azure-eventhub.yaml
Outdated
Show resolved
Hide resolved
|
Pinging @elastic/obs-ds-hosted-services (Team:obs-ds-hosted-services) |
|
@colleenmcginnis Thank you so much for the comments! Yes this change will likely to go in for 9.3.0. Definitely no backports since it is a feature. |
zmoog
left a comment
There was a problem hiding this comment.
I've reviewed the changes in the oauth2_azure branch. This is a solid first PR for adding OAuth2 authentication to the Azure Event Hub input.
Here are my observations.
I would move the authentication-related code into dedicated files, with helper function(s) that takes the config and returns a azcore.TokenCredential — or a client, since the current legacy authentication methods are not included in azidentity.
// Just a high-level example
func createAzureCredential(config azureInputConfig, log *logp.Logger) (azcore.TokenCredential, error) {
credentialOptions := &azidentity.ClientSecretCredentialOptions{
ClientOptions: azcore.ClientOptions{
Cloud: getAzureCloud(config.AuthorityHost),
},
}
return azidentity.NewClientSecretCredential(
config.TenantID,
config.ClientID,
config.ClientSecret,
credentialOptions,
)
}I'm usually against premature optimizations, but in this case we have a list of authentication methods we're going to implement very soon.
The azidentity supports many credential types https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity#readme-credential-types, but I guess our list will probably be:
- Client secret (oauth2) — this PR!
- Workload identity
- Managed Identity (?)
- Client certificate (?)
I would adopt the azidentity naming convention and use "client secret" insted of "OAuth2".
Since we'll soon have 3+ authentication types, we should probably consider adding an "auth type" configuration setting for explicit selection. Inferring the authentication type from the option values can become tricky pretty quickly—also considering that we'll have event hub and storage account.
Having an auth_type option to check can probably simplify config validation and setup logic.
To wrap things up I suggest:
- Move the authentication-related code into dedicated files, with a single entry point that takes the config and returns a client.
- Add
auth_type(for example,client_credentials,workload_identity, etc.) - Adopt the
azidentitynaming convention for credential types. - We probably need to list the permissions needed to read from the Event Hubs and write to the Storage Account. Ideally also add at least a link to some Microsoft docs that explains how to set up the service principal / app regististration—so we don't have to maintain it.
@zmoog I totally forgot we talked about this in our meeting. Yes I will add the |
|
@zmoog While making the changes, I realize we also have storage account auth type to consider. Should we allow customers to have different auth types for storage account and eventhub? Will the customer in any use case perfers that? |
|
@zmoog and I talked offline and decided to only have one |
zmoog
left a comment
There was a problem hiding this comment.
We need to remove calls to the legacy SDKs from the processor v2 code path.
I have ideas to streamline the Validate() function in the config. It has become overly complex, but I'm also fine in dealing with this in a follow up PR.
|
Hello! @kaiyan-sheng @zmoog With respect to the integration between Azure Event Hub and Elasticsearch using Azure Active Directory authentication (Client ID and Client Secret), it is understood that this capability will be introduced in version 9.3. Could you please confirm the expected availability timeline for the upgraded version for customers? Thanks, |
|
@Mergifyio backport 8.19 9.1 9.2 9.3 |
❌ No backport have been createdDetails
GitHub error: |
… eventhub filebeat input (#48144)
… eventhub filebeat input (#48143)
Proposed commit message
This PR is to enhance Azure Event Hub input plugin for Elastic Agent with RBAC authorization (OAuth2) due to security requirements. Previously we only support shared access key (with connection string) for authentication.
The implementation added a new config parameter called
auth_typefor users to specify authentication method:When
auth_typeis set toconnection_string, or leave it blank:connection_string is required. Whenauth_typeis set toclient_secret`, oauth2 is used.Note: We do expect users to use the same auth type for both eventhub and storage account.
OAuth2 specific Configuration Parameters (
auth_type=client_secret)When using OAuth2 authentication, the following parameters are required:
eventhub_namespace: Fully qualified namespace (e.g.,namespace.servicebus.windows.net)tenant_id: Azure AD tenant IDclient_id: Azure AD application (client) IDclient_secret: Azure AD application client secretauthority_host: Azure AD authority host (optional, defaults to Azure Public Cloud)https://login.microsoftonline.comis the default.Checklist
./changelog/fragmentsusing the changelog tool.Disruptive User Impact
N/A
How to test this PR locally
Setups on Azure side
OR
Instead of getting storage account connection string, assign storage account role:
When no
connection_stringis specified and noauth_typeis specified:We get error log when starting Filebeat:
testing backwards compatibility:
Without
auth_typespecified, by default we are usingconnection_stringto keep backwards compatible. This config still works.testing with oauth2 for both eventhub and SA:
Screenshots
I can see logs getting ingested from Eventhub to elasticsearch with Filebeat:

Logs
I see this in the filebeat log when testing: