- 
                Notifications
    
You must be signed in to change notification settings  - Fork 5k
 
[Azure] Add client secret (Oauth2) support for eventhub filebeat input #47256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
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 | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.  | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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   | 
    
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:
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: