Skip to content

feat(eventhubs): restore connection string authentication - #7293

Closed
Sagar Patel (sagar0207) wants to merge 4 commits into
Azure:mainfrom
sagar0207:feature/eventhubs-connection-string-auth
Closed

Sagar Patel (sagar0207) wants to merge 4 commits into
Azure:mainfrom
sagar0207:feature/eventhubs-connection-string-auth

Conversation

@sagar0207

@sagar0207 Sagar Patel (sagar0207) commented Aug 5, 2026 •

Copy link
Copy Markdown
Member

Summary

Restore connection-string authentication for the Event Hubs ProducerClient and ConsumerClient.

The constructors were available through 1.0.0-beta.10 and were removed in 1.0.0-beta.11 during the Rust AMQP merge. The connection-string parser and SAS credential remained, but the Rust backend's token generation and CBS SAS-token handling were incomplete.

Fixes #7250 and #7295.

Azure DevOps work item: 39045651

Related earlier draft: #7251.

Changes

  • Restored the previous public constructor signatures:

    ProducerClient(
        std::string const& connectionString,
        std::string const& eventHub,
        ProducerClientOptions options = {});
    
    ConsumerClient(
        std::string const& connectionString,
        std::string const& eventHub = {},
        std::string const& consumerGroup = DefaultConsumerGroup,
        ConsumerClientOptions const& options = {});
  • Reused ServiceBusSasConnectionStringCredential and the existing uAMQP CBS SAS-token path.

  • Added SAS support to the default Rust AMQP backend:

    • Generates HMAC-SHA256 SAS tokens through the Rust wrapper.
    • Matches the existing uAMQP token bytes and URL encoding.
    • Sends servicebus.windows.net:sastoken through the Rust CBS path.
    • Preserves JWT behavior for Microsoft Entra ID credentials.
  • Restored EntityPath behavior:

    • An empty Event Hub argument uses the connection string EntityPath.
    • A matching Event Hub argument is accepted.
    • A different Event Hub argument throws std::invalid_argument.
    • An Event Hub name is required when the connection string has no EntityPath.
  • Restored Event Hubs emulator support:

    • Uses AMQP without TLS.
    • Defaults to port 5672 when the emulator endpoint has no port.
    • Preserves an explicitly configured non-TLS port.
    • Rejects emulator port 5671 because the current AMQP transport maps that port to TLS.
  • Added focused offline tests, a shared fixed-vector token test, and an opt-in live round-trip test.

  • Restored and updated four connection-string samples:

    • create_producer.cpp
    • create_consumer.cpp
    • produce_events.cpp
    • consume_events.cpp
  • Kept those samples in compile coverage but excluded them from automatic live sample execution because the standard live resources do not expose a connection string.

  • Updated the package README with:

    • An inline Microsoft Entra ID example.
    • Connection-string formats with and without EntityPath.
    • Support on both AMQP backends.
    • Current send and receive APIs.
  • Updated the samples README and changelog.

Validation

The branch was rebased onto current main at 5270d5ae7.

uAMQP

  • Event Hubs library built successfully.
  • Azure Core AMQP connection-string tests built successfully.
  • Event Hubs test executable built successfully.
  • All four restored samples compiled and linked successfully.
  • The fixed-vector SAS token test passed.
  • 13 focused offline connection-string tests passed.
  • The live-only test correctly skipped in playback mode.

Event Hubs emulator

The focused round-trip test passed on both uAMQP and Rust AMQP against the Docker Event Hubs emulator using the official connection-string shape without an explicit port.

The test opened the receiver, sent one event, received it, and compared the event body.

Azure Event Hubs

The focused round-trip test passed on both uAMQP and Rust AMQP against:

  • Namespace: cpp-connscale-ns
  • Event Hub: eh-connscale-testing
  • Consumer group: $Default

The connection string was held only in process memory and removed after the test.

Rust AMQP

  • Rust SAS token unit tests passed.
  • Azure Core AMQP and Event Hubs C++ tests built successfully.
  • The fixed-vector test produced the same literal SAS token on both backends.
  • 13 focused Event Hubs connection-string tests passed.
  • Live Azure Event Hubs and emulator round trips passed.

Scope

This PR does not:

  • Change CBS token refresh behavior.
  • Change retry or link recovery behavior.
  • Change the standard live-test resources to enable local authentication.
  • Add a new BlobCheckpointStore constructor.
  • Fix the separate Event Hubs performance-test connection-string configuration issue.

Security

  • No real connection strings, shared keys, or SAS tokens are stored in the repository.
  • Connection-string samples are not automatically executed by the standard live sample job.
  • Live SAS validation requires an explicitly supplied SAS-enabled resource.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
7 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@sagar0207
Sagar Patel (sagar0207) force-pushed the feature/eventhubs-connection-string-auth branch from ea1825b to 5bb10d2 Compare August 5, 2026 20:51
@sagar0207

Copy link
Copy Markdown
Member Author

@microsoft-github-policy-service agree company="Microsoft"

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
7 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Restores the previously-available connection-string authentication entry points for Azure Event Hubs ProducerClient and ConsumerClient, bringing the C++ SDK back in line with earlier betas and enabling local/emulator scenarios that require SAS/connection strings.

Changes:

  • Reintroduced public connection-string constructors (with uAMQP support; Rust AMQP throws an unsupported-backend error).
  • Restored emulator-specific behavior (non-TLS AMQP, defaulting to port 5672, rejecting 5671).
  • Added focused unit tests and restored/updated connection-string samples and documentation.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
sdk/eventhubs/azure-messaging-eventhubs/test/ut/connection_string_test.cpp Adds offline constructor behavior tests plus an opt-in live round-trip test for connection-string auth.
sdk/eventhubs/azure-messaging-eventhubs/test/ut/CMakeLists.txt Includes the new connection-string unit test source in the test target.
sdk/eventhubs/azure-messaging-eventhubs/src/producer_client.cpp Implements the connection-string constructor and emulator port/scheme selection for ProducerClient.
sdk/eventhubs/azure-messaging-eventhubs/src/consumer_client.cpp Implements the connection-string constructor and emulator port/scheme selection for ConsumerClient.
sdk/eventhubs/azure-messaging-eventhubs/samples/README.md Updates sample environment variables and sample list to reflect restored connection-string samples.
sdk/eventhubs/azure-messaging-eventhubs/samples/produce-events/produce_events.cpp Restores a connection-string-based “produce events” sample.
sdk/eventhubs/azure-messaging-eventhubs/samples/produce-events/CMakeLists.txt Adds the restored sample and disables automatic run for connection-string sample execution.
sdk/eventhubs/azure-messaging-eventhubs/samples/consume-events/consume_events.cpp Restores a connection-string-based “consume events” sample.
sdk/eventhubs/azure-messaging-eventhubs/samples/consume-events/CMakeLists.txt Adds the restored sample and disables automatic run for connection-string sample execution.
sdk/eventhubs/azure-messaging-eventhubs/samples/basic-operations/create_producer.cpp Restores a connection-string-based “create producer” sample.
sdk/eventhubs/azure-messaging-eventhubs/samples/basic-operations/create_consumer.cpp Restores a connection-string-based “create consumer” sample.
sdk/eventhubs/azure-messaging-eventhubs/samples/basic-operations/CMakeLists.txt Adds restored basic-operation samples and disables automatic run for connection-string samples.
sdk/eventhubs/azure-messaging-eventhubs/README.md Updates README examples and guidance for Entra ID and connection-string auth, matching the restored API surface.
sdk/eventhubs/azure-messaging-eventhubs/inc/azure/messaging/eventhubs/producer_client.hpp Restores the public connection-string constructor signature and Doxygen contract for ProducerClient.
sdk/eventhubs/azure-messaging-eventhubs/inc/azure/messaging/eventhubs/consumer_client.hpp Restores the public connection-string constructor signature and Doxygen contract for ConsumerClient.
sdk/eventhubs/azure-messaging-eventhubs/CHANGELOG.md Records the restoration as a new feature under the next unreleased version.

@j7nw4r

Copy link
Copy Markdown
Member

I filed #7295 to track the Rust AMQP side, so the unsupported-backend guard in this PR has a follow-up that removes it.

The gap is narrower than the note in this PR suggests. Three things block it, and the surrounding machinery already works. GenerateSasToken is a stub for the Rust backend and returns an empty string, so GetToken hands back an empty token and reports success. PutToken throws for every token type except JWT. The FFI function amqpclaimsbasedsecurity_authorize_path takes no token type and passes None, which the Rust crate reads as jwt.

The parts that already work: src/amqp/connection.cpp:208 picks CbsTokenType::Sas for a SAS credential, the Rust crate already accepts token_type: Option<String> and documents servicebus.windows.net:sastoken, and the Rust connection already opens with SASL ANONYMOUS.

The one open decision in #7295 is where the HMAC-SHA256 lives. The root Cargo.toml already declares hmac, sha2, and base64, so Rust looks like the smaller change. A C++ implementation needs a new crypto primitive in azure-core-amqp and a macOS path, because the Rust backend links only the Security framework there.

@j7nw4r

Copy link
Copy Markdown
Member

Sagar Patel (@sagar0207) the Rust AMQP side is now ready for review at sagar0207#1, which targets this branch. Merging it removes the unsupported-backend guard here, and it turns on ten of the connection-string tests that currently run only under uAMQP.

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// cspell: words amqpclaimsbasedsecurity
// cspell: words amqpclaimsbasedsecurity sastoken servicebus

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These changes should go into the AMQP library in the azure-sdk-for-rust SDK and we should get rid of this client.

Originally the plan was for the C++ code to depend on the Rust azure_core_amqp package directly via cargo but I ran out of time to fix that.

This seems like an incredible opportunity to break this private fork of the azure_core_amqp package and use just the primary package.

The primary package already has a cplusplus feature intended for this use.

@j7nw4r Johnathan W (j7nw4r) Aug 6, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Larry Osterman (@LarryOsterman) One of the concerns that our managers had was that given the timeframe of the changes (we want to get all of the producer and auth changes out in the next month for Billing), we didn't want to rock the boat with depending on the rust implementation.

I'll check with the team. Maybe we should break like you said.

cc Sagar Patel (@sagar0207) Eric Lam (MSFT) (@hmlam) SJ (@sjkwak)

Sagar Patel (sagar0207) and others added 4 commits August 6, 2026 14:37
Copilot-Session: f65b70a0-d52e-48a7-84f7-826ff4b091c5
Copilot-Session: f65b70a0-d52e-48a7-84f7-826ff4b091c5
Copilot-Session: f65b70a0-d52e-48a7-84f7-826ff4b091c5
@sagar0207

Copy link
Copy Markdown
Member Author

Superseded by #7296, which uses the same rebased commit history from an internal Azure repository branch so protected Cargo-feed CI can authenticate. Please continue review on #7296.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Restore connection string authentication for the Event Hubs clients

4 participants