Skip to content

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

Merged
Sagar Patel (sagar0207) merged 5 commits into
mainfrom
sagar0207/eventhubs-connection-string-auth
Aug 8, 2026
Merged

feat(eventhubs): restore connection string authentication#7296
Sagar Patel (sagar0207) merged 5 commits into
mainfrom
sagar0207/eventhubs-connection-string-auth

Conversation

@sagar0207

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

Supersedes #7293. That PR came from a personal fork, so its CI jobs could not access the internal Azure Rust Cargo feed.

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 847ae28b6.

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.

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
@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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Restores connection-string authentication for Event Hubs ProducerClient and ConsumerClient, including SAS token support on the Rust AMQP backend and emulator-specific behavior.

Changes:

  • Reintroduced connection-string constructors and EntityPath validation/selection in both clients.
  • Implemented SAS token generation + CBS SAS token-type support for the Rust AMQP backend.
  • Added offline/live tests and refreshed samples + README/changelog documentation.

Reviewed changes

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

Show a summary per file
File Description
sdk/eventhubs/azure-messaging-eventhubs/test/ut/connection_string_test.cpp Adds focused unit + opt-in live round-trip tests for connection-string behavior.
sdk/eventhubs/azure-messaging-eventhubs/test/ut/CMakeLists.txt Includes the new connection-string unit tests in the test target.
sdk/eventhubs/azure-messaging-eventhubs/src/producer_client.cpp Restores connection-string constructor logic (EntityPath + emulator port handling).
sdk/eventhubs/azure-messaging-eventhubs/src/consumer_client.cpp Restores connection-string constructor logic (EntityPath + emulator port handling).
sdk/eventhubs/azure-messaging-eventhubs/samples/produce-events/produce_events.cpp Adds a connection-string “produce events” sample.
sdk/eventhubs/azure-messaging-eventhubs/samples/produce-events/CMakeLists.txt Adjusts sample build macro usage; disables automatic run for conn-string sample.
sdk/eventhubs/azure-messaging-eventhubs/samples/consume-events/consume_events.cpp Adds a connection-string “consume events” sample.
sdk/eventhubs/azure-messaging-eventhubs/samples/consume-events/CMakeLists.txt Adjusts sample build macro usage; disables automatic run for conn-string sample.
sdk/eventhubs/azure-messaging-eventhubs/samples/basic-operations/create_producer.cpp Restores a basic connection-string producer sample.
sdk/eventhubs/azure-messaging-eventhubs/samples/basic-operations/create_consumer.cpp Restores a basic connection-string consumer sample.
sdk/eventhubs/azure-messaging-eventhubs/samples/basic-operations/CMakeLists.txt Adjusts sample build macro usage; disables automatic run for conn-string samples.
sdk/eventhubs/azure-messaging-eventhubs/samples/README.md Updates environment variables and sample list naming/descriptions.
sdk/eventhubs/azure-messaging-eventhubs/inc/azure/messaging/eventhubs/producer_client.hpp Adds public connection-string constructor + docs.
sdk/eventhubs/azure-messaging-eventhubs/inc/azure/messaging/eventhubs/consumer_client.hpp Adds public connection-string constructor + docs.
sdk/eventhubs/azure-messaging-eventhubs/README.md Updates auth guidance + modern send/receive examples and conn-string formats.
sdk/eventhubs/azure-messaging-eventhubs/CHANGELOG.md Records restored connection-string auth + Rust backend support.
sdk/core/azure-core-amqp/test/ut/connection_string_tests.cpp Adds a fixed-vector SAS token test shared across backends; refactors existing tests.
sdk/core/azure-core-amqp/src/impl/rust_amqp/rust_amqp/rust_wrapper/src/amqp/sas.rs Implements Rust SAS token generation + percent-encoding compatible with uAMQP.
sdk/core/azure-core-amqp/src/impl/rust_amqp/rust_amqp/rust_wrapper/src/amqp/mod.rs Exposes the new Rust sas module.
sdk/core/azure-core-amqp/src/impl/rust_amqp/rust_amqp/rust_wrapper/src/amqp/cbs.rs Extends Rust CBS authorize API to accept token type (JWT vs SAS).
sdk/core/azure-core-amqp/src/impl/rust_amqp/rust_amqp/rust_wrapper/Cargo.toml Adds Rust crypto dependencies for SAS (base64/hmac/sha2).
sdk/core/azure-core-amqp/src/impl/rust_amqp/amqp/connection_string_credential.cpp Implements Rust-backend SAS token generation via Rust interop.
sdk/core/azure-core-amqp/src/impl/rust_amqp/amqp/claim_based_security.cpp Adds SAS token type support for Rust-backend CBS authorize calls.
sdk/core/azure-core-amqp/inc/azure/core/amqp/internal/connection_string_credential.hpp Adds test-only friend access for fixed-vector SAS token testing.
sdk/core/azure-core-amqp/CHANGELOG.md Notes Rust backend SAS token generation + CBS token-type behavior.

Comment thread sdk/core/azure-core-amqp/test/ut/connection_string_tests.cpp
Comment thread sdk/eventhubs/azure-messaging-eventhubs/src/producer_client.cpp Outdated
Centralize connection string handling and harden Rust CBS FFI validation.

Copilot-Session: f65b70a0-d52e-48a7-84f7-826ff4b091c5
@sagar0207
Sagar Patel (sagar0207) enabled auto-merge (squash) August 7, 2026 20:20
@sagar0207
Sagar Patel (sagar0207) merged commit 66ad7bf into main Aug 8, 2026
127 checks passed
@sagar0207
Sagar Patel (sagar0207) deleted the sagar0207/eventhubs-connection-string-auth branch August 8, 2026 20:17
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

5 participants