Skip to content

[Event Hubs Client] Shared Key Credential + Connection String Parser#16044

Merged
jsquire merged 1 commit intoAzure:masterfrom
jsquire:eventhubs/sharedkeycredential
Oct 23, 2020
Merged

[Event Hubs Client] Shared Key Credential + Connection String Parser#16044
jsquire merged 1 commit intoAzure:masterfrom
jsquire:eventhubs/sharedkeycredential

Conversation

@jsquire
Copy link
Copy Markdown
Member

@jsquire jsquire commented Oct 16, 2020

Summary

The focus of these changes is to expose the shared key credential and connection string parser as part of the API surface. Adjustments to the
internal representation were made to support SAS rotation and refining the API surface.

Note: These changes have been reviewed and approved by the architecture board and the .NET language architect. Marking with the corresponding tag for tracking purposes.

Last Upstream Rebase

Monday, October 19, 2:29pm (EDT)

References

The focus of these changes is to expose the shared key credential and
connection string parser as part of the API surface.  Adjustments to the
internal representation were made to support SAS rotation and refining the
API surface.
@jsquire jsquire force-pushed the eventhubs/sharedkeycredential branch from e927f73 to b77628a Compare October 19, 2020 19:04
Copy link
Copy Markdown
Member

@christothes christothes left a comment

Choose a reason for hiding this comment

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

LGTM - just some minor comments / questions

string fullyQualifiedNamespace,
string eventHubName,
EventHubsSharedAccessKeyCredential credential,
EventProcessorClientOptions clientOptions = default) : base((clientOptions ?? DefaultClientOptions).CacheEventCount, consumerGroup, fullyQualifiedNamespace, eventHubName, credential, CreateOptions(clientOptions))
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.

Is it ok that the first arg to the base ctor conditionally passes DefaultClientOptions but the last arg doesn't?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Scared me there. The first argument sets the batch size using either the specified option or the default size. The latter translates the derived options into the base type and passes it as the options set.

The CacheEventCount used for the batch size in the first argument does not exist as part of the base options, due to it being batch-driven natively and expecting that callers will need to specify the size of batches that they want to process.

Comment on lines +119 to +120
SharedAccessKeyName = null;
SharedAccessKey = null;
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.

Just curious - why is setting the key name and key to null a side effect of this method?

Copy link
Copy Markdown
Member Author

@jsquire jsquire Oct 23, 2020

Choose a reason for hiding this comment

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

The intent expressed is to update the credential with the sharedAccessSignature passed to the method, which invalidates and replaces any key/value that may have been there. This is an effect of the credential supporting both key/value and SAS.

This is all very likely to change after next week's arch board meeting; there's a push to split the concept and standardize the credential types in Core.

Comment thread sdk/eventhub/Azure.Messaging.EventHubs/src/EventHubConnection.cs
Comment on lines +217 to +218
var hasSharedKey = ((!string.IsNullOrEmpty(SharedAccessKeyName)) && (!string.IsNullOrEmpty(SharedAccessKey)));
var hasSharedSignature = (!string.IsNullOrEmpty(SharedAccessSignature));
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.

nit: if this block moves above the previous one, the previous validation can be simplified to
if(!hasSharedKey && !hasSharedSignature)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not.... quite. The above says: "if I have a signature and I have either a key or value, then my intent was not clear because I specified all or parts of both." Using hasSharedKey would change the semantics to "If I have a signature and I have BOTH a key and value..."

The reason that I used this form was to ensure that we don't assume that having a SAS alone is a clear statement of intent. If I give you a SAS and some part of a key/value pair, then I'm giving you two forms of authorization, though one is not in a valid form.


if (string.IsNullOrEmpty(Endpoint?.Host)
|| ((string.IsNullOrEmpty(explicitEventHubName)) && (string.IsNullOrEmpty(EventHubName)))
|| ((!hasSharedKey) && (!hasSharedSignature)))
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.

Is this additional validation needed? It looks like we'd have thrown OnlyOneSharedAccessAuthorizationMayBeSpecified above if this were true.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The block above that I think you're referring to validates that "only one of these is present" but doesn't cover the case where both are missing. Line 222 validates that at least one of them was present.

@jsquire jsquire merged commit d846c82 into Azure:master Oct 23, 2020
jsquire added a commit that referenced this pull request Oct 23, 2020
@jsquire
Copy link
Copy Markdown
Member Author

jsquire commented Oct 23, 2020

.... and I just inadvertently merged before pushing changes. I'll address the feedback in a follow-up PR.

@jsquire jsquire deleted the eventhubs/sharedkeycredential branch October 23, 2020 16:41
jsquire added a commit to jsquire/azure-sdk-for-net that referenced this pull request Oct 23, 2020
The focus of these changes is to incorporate feedback that was inadvertently
missed before merging Azure#16044.
jsquire added a commit that referenced this pull request Oct 23, 2020
The focus of these changes is to incorporate feedback that was inadvertently
missed before merging #16044.
annelo-msft pushed a commit to annelo-msft/azure-sdk-for-net that referenced this pull request Feb 17, 2021
…zure#16044)

The focus of these changes is to expose the shared key credential and
connection string parser as part of the API surface.  Adjustments to the
internal representation were made to support SAS rotation and refining the
API surface.
annelo-msft pushed a commit to annelo-msft/azure-sdk-for-net that referenced this pull request Feb 17, 2021
The focus of these changes is to incorporate feedback that was inadvertently
missed before merging Azure#16044.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Client This issue is related to a non-management package Event Hubs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants