Skip to content
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

KeyRefresh: Adds AzureKeyCredential support to enable key refresh scenarios #3276

Merged

Conversation

kirankumarkolli
Copy link
Member

@kirankumarkolli kirankumarkolli commented Jun 17, 2022

Type of change

Please delete options that are not relevant.

  • [] New feature (non-breaking change which adds functionality)

Description

CosmosClient supporting Azure.AzureKeyCredential
This capability enables applications to

  • Leverage AzureKeyCredential type with Azure CosmosDB
  • Leverage AzureKeyCredential.Update API to dynamically change credentials in-flight (with-out client re-creation)

New scenarios

  • ResourceToken hot-swap: ResourceTokens are time-bound (max 24Hours). Token can now be hot-swapped with-out ComsosClient re-creation
  • Hot swapping master key credentials (Primary <-> Secondary): For scenarios of keys recycle, clients can be refreshed with new credentials with-out re-creation

Sample usage

    AzureKeyCredential keyCredential = new AzureKeyCredential(<account-key/resource-token>);
    CosmosClient client = new CosmosClient(
            <Account Endpoint>,
            keyCredential);
    ....

    // Update key-credentials
    keyCredential.Update(<Refreshed account-key/resource-token>);

    ....

⚠️ Key changes are posible only through the AzureKeyCredential instance used during the CosmosClient creation

API changes

namespace Microsoft.Azure.Cosmos
{
    public class CosmosClient : IDisposable
    {
        public CosmosClient(
            string accountEndpoint,
            AzureKeyCredential authKeyOrResourceTokenCredential,
            CosmosClientOptions clientOptions = null);

         public Task<CosmosClient> CreateAndInitializeAsync(string accountEndpoint,
            AzureKeyCredential authKeyOrResourceTokenCredential,
            IReadOnlyList<(string databaseId, string containerId)> containers,
            CosmosClientOptions cosmosClientOptions = null,
            CancellationToken cancellationToken = default)
    }
}

namespace Microsoft.Azure.Cosmos.Fluent
{
    public class CosmosClientBuilder
    {
        public CosmosClientBuilder(
            string accountEndpoint,
            AzureKeyCredential authKeyOrResourceTokenCredential)
    }
}

Micro benchmark result

image

Closing issues

To automatically close an issue: closes #IssueNumber

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Please follow the required format: "[Internal] Category: (Adds|Fixes|Refactors|Removes) Description"

Internal should be used for PRs that have no customer impact. This flag is used to help generate the changelog to know which PRs should be included. Examples:
Diagnostics: Adds GetElapsedClientLatency to CosmosDiagnostics
PartitionKey: Fixes null reference when using default(PartitionKey)
[v4] Client Encryption: Refactors code to external project
[Internal] Query: Adds code generator for CosmosNumbers for easy additions in the future.

Copy link
Member

@FabianMeiswinkel FabianMeiswinkel left a comment

Choose a reason for hiding this comment

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

LGTM except for few NITs

@kirankumarkolli kirankumarkolli changed the title AzureKeyCredential support (for key refresh scenario's) KeyRefresh: AzureKeyCredential support o enable key refresh scenario's Jun 21, 2022
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Please follow the required format: "[Internal] Category: (Adds|Fixes|Refactors|Removes) Description"

Internal should be used for PRs that have no customer impact. This flag is used to help generate the changelog to know which PRs should be included. Examples:
Diagnostics: Adds GetElapsedClientLatency to CosmosDiagnostics
PartitionKey: Fixes null reference when using default(PartitionKey)
[v4] Client Encryption: Refactors code to external project
[Internal] Query: Adds code generator for CosmosNumbers for easy additions in the future.

@kirankumarkolli kirankumarkolli changed the title KeyRefresh: AzureKeyCredential support o enable key refresh scenario's KeyRefresh: Adds AzureKeyCredential support o enable key refresh scenario's Jun 21, 2022
@kirankumarkolli
Copy link
Member Author

TODO: Needs to re-work the merge strategy (Other changes are showing up) :-(

Copy link
Member

@FabianMeiswinkel FabianMeiswinkel left a comment

Choose a reason for hiding this comment

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

LGTM

kirankumarkolli and others added 4 commits June 23, 2022 10:07
Co-authored-by: Matias Quaranta <ealsur@users.noreply.github.com>
Co-authored-by: Matias Quaranta <ealsur@users.noreply.github.com>
Co-authored-by: Matias Quaranta <ealsur@users.noreply.github.com>
@kirankumarkolli kirankumarkolli self-assigned this Jun 23, 2022
@j82w j82w dismissed github-actions’s stale review July 1, 2022 18:32

Valid title, bad bot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants