Skip to content

Support AzurePipelinesCredential in Azure Event Hubs for Kafka passwordless connection#49108

Merged
rujche merged 14 commits into
mainfrom
rujche/main/try-to-enable-EventHubsKafkaBinderOAuthIT
May 18, 2026
Merged

Support AzurePipelinesCredential in Azure Event Hubs for Kafka passwordless connection#49108
rujche merged 14 commits into
mainfrom
rujche/main/try-to-enable-EventHubsKafkaBinderOAuthIT

Conversation

@rujche
Copy link
Copy Markdown
Member

@rujche rujche commented May 8, 2026

Description

This pull request adds support for using AzurePipelinesCredential to enable passwordless authentication for Azure Event Hubs via Kafka when running in Azure Pipelines. The implementation detects specific Azure DevOps environment variables and, if present, chains the new credential with the existing DefaultAzureCredential. The changes also include a new integration test to verify this behavior and update the changelog accordingly.

Azure Pipelines Credential Support for Kafka Event Hubs

  • Added support for AzurePipelinesCredential in the KafkaOAuth2AuthenticateCallbackHandler to allow passwordless authentication for Azure Event Hubs for Kafka when running in Azure Pipelines. The credential is used only if all required environment variables are present; otherwise, the system falls back to DefaultAzureCredential. The authority host is set based on the current Azure environment for correct cloud targeting. [1] [2] [3] [4]

Testing Enhancements

  • Added a test (testCreateChainedTokenCredentialWhenAzurePipelinesEnvVarsPresent) to verify that a ChainedTokenCredential is created when all Azure Pipelines environment variables are set, ensuring the new credential logic is exercised and isolated per test run. [1] [2] [3]

Documentation Updates

  • Updated the changelog to document the new feature, including the required environment variables and a link to the relevant pull request for more details.

Integration Test Activation

  • Enabled the EventHubsKafkaBinderOAuthIT integration test, which was previously disabled, to allow validation of OAuth scenarios in CI/CD pipelines. [1] [2]

** Related PR** : #47176

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

Copilot AI review requested due to automatic review settings May 8, 2026 05:32
@rujche rujche requested review from a team, Netyyyy, moarychan and saragluna as code owners May 8, 2026 05:32
@github-actions github-actions Bot added the azure-spring All azure-spring related issues label May 8, 2026
@rujche rujche self-assigned this May 8, 2026
@rujche rujche added the azure-spring-eventhubs-kafka Spring event hubs kafka related issues. label May 8, 2026
@rujche rujche added this to the 2026-06 milestone May 8, 2026
@rujche rujche moved this from Todo to In Progress in Spring Cloud Azure May 8, 2026
@rujche
Copy link
Copy Markdown
Member Author

rujche commented May 8, 2026

/azp run java - spring - tests

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request enables the EventHubsKafkaBinderOAuthIT Spring Cloud Azure integration test so it runs as part of the Event Hubs IT suite (when -DskipSpringITs=false is used in CI), aligning with the intent to validate Event Hubs Kafka OAuth scenarios end-to-end.

Changes:

  • Removed the @Disabled annotation from EventHubsKafkaBinderOAuthIT.
  • Removed the now-unused Disabled import.

@rujche
Copy link
Copy Markdown
Member Author

rujche commented May 14, 2026

/azp run java - spring - tests

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@rujche
Copy link
Copy Markdown
Member Author

rujche commented May 14, 2026

/azp run java - spring - tests

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Revert the kafka-clients 3.8.1 override (incompatible with spring-kafka 4.x, caused VerifyError in EventHubsKafkaBinderConnectionStringIT) and instead disable the Spring Cloud Stream Kafka binder's topic auto-creation and admin-based health check. Azure Event Hubs for Kafka does not support the Kafka AdminClient API, so the binder must not create one against the Event Hubs endpoint.
@rujche
Copy link
Copy Markdown
Member Author

rujche commented May 14, 2026

/azp run java - spring - tests

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@rujche
Copy link
Copy Markdown
Member Author

rujche commented May 14, 2026

/azp run java - spring - tests

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@rujche rujche requested a review from Copilot May 14, 2026 09:28
@rujche rujche changed the title Try to enable EventHubsKafkaBinderOAuthIT Enable EventHubsKafkaBinderOAuthIT, update KafkaOAuth2AuthenticateCallbackHandler to make test pass May 14, 2026
@rujche rujche changed the title Enable EventHubsKafkaBinderOAuthIT, update KafkaOAuth2AuthenticateCallbackHandler to make test pass Enable EventHubsKafkaBinderOAuthIT, update KafkaOAuth2AuthenticateCallbackHandler to make test pass May 14, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

Comment thread sdk/spring/CHANGELOG.md Outdated
@rujche rujche changed the title Enable EventHubsKafkaBinderOAuthIT, update KafkaOAuth2AuthenticateCallbackHandler to make test pass Support AzurePipelinesCredential in Azure Event Hubs for Kafka passwordless connection May 15, 2026
rujche added 3 commits May 15, 2026 10:03
In sovereign clouds (Azure China, US Gov) DefaultAzureCredentialBuilderFactory
configures profile.environment.activeDirectoryEndpoint, but the newly added
AzurePipelinesCredentialBuilder was created without it and defaulted to the
public-cloud authority. Since ChainedTokenCredential only falls through on
CredentialUnavailableException, a wrong-authority failure would block the
DefaultAzureCredential fallback. Pass AzureProperties into the builder and
apply authorityHost when available.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

Comments suppressed due to low confidence (1)

sdk/spring/spring-cloud-azure-service/src/main/java/com/azure/spring/cloud/service/implementation/kafka/KafkaOAuth2AuthenticateCallbackHandler.java:185

  • This AzurePipelinesCredentialBuilder is created directly, so unlike the DefaultAzureCredentialBuilderFactory path it does not receive the AzureProperties HTTP client, proxy, logging, retry, or custom pipeline settings. In environments that require those Spring-configured settings (for example an outbound proxy), the Azure Pipelines credential can fail before the configured default credential is usable. Apply the same common credential builder configuration to this builder as the default credential path.
                AzurePipelinesCredentialBuilder builder = new AzurePipelinesCredentialBuilder()
                    .systemAccessToken(systemAccessToken)
                    .clientId(clientId)
                    .tenantId(tenantId)
                    .serviceConnectionId(serviceConnectionId);
                String authorityHost = resolveAuthorityHost(properties);
                if (!isNullOrEmpty(authorityHost)) {
                    builder.authorityHost(authorityHost);

Comment thread sdk/spring/CHANGELOG.md
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@rujche
Copy link
Copy Markdown
Member Author

rujche commented May 15, 2026

/azp run java - spring - tests

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Copy Markdown
Member

@Netyyyy Netyyyy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@rujche rujche merged commit fbd36dc into main May 18, 2026
96 of 97 checks passed
@rujche rujche deleted the rujche/main/try-to-enable-EventHubsKafkaBinderOAuthIT branch May 18, 2026 05:45
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Spring Cloud Azure May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

azure-spring All azure-spring related issues azure-spring-eventhubs-kafka Spring event hubs kafka related issues.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants