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

Adding type in EncryptionKeyWrapMetadata and performing validation on partition key #21407

Merged

Conversation

simplynaveen20
Copy link
Member

@simplynaveen20 simplynaveen20 commented May 13, 2021

This PR contains 3 parts

  1. Adding type in EncryptionKeyWrapMetadata constructor and doing validation of store provider name during CEK creation
  2. Validation of partition key to avoid having it as encrypted field
  3. Exposing policyFormatVersion in ClientEncryptionPolicy

closes #20376

@ghost ghost added the Cosmos label May 13, 2021
@simplynaveen20 simplynaveen20 changed the title Adding type in EncryptionKeyWrapMetadata and doing validation on partition key Adding type in EncryptionKeyWrapMetadata and performing validation on partition key May 13, 2021
Copy link
Contributor

@moderakh moderakh left a comment

Choose a reason for hiding this comment

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

@simplynaveen20 in similar scenario, does non Cosmos Exception type reach public surface area in the DotNet SDK?

void validatePartitionKeyPathsAreNotEncrypted(List<List<String>> partitionKeyPathTokens) {
checkNotNull(partitionKeyPathTokens, "partitionKeyPathTokens cannot be null");
List<String> propertiesToEncrypt =
this.includedPaths.stream().map(clientEncryptionIncludedPath -> clientEncryptionIncludedPath.getPath().substring(1)).collect(Collectors.toList());
Copy link
Contributor

Choose a reason for hiding this comment

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

nice usage of java8 stream API. :-)

@@ -82,6 +82,13 @@ public CosmosAsyncClientEncryptionKey getClientEncryptionKey(String id) {

EncryptionKeyStoreProvider encryptionKeyStoreProvider =
this.cosmosEncryptionAsyncClient.getEncryptionKeyStoreProvider();

if (!encryptionKeyStoreProvider.getProviderName().equals(encryptionKeyWrapMetadata.getType())) {
throw new IllegalArgumentException("The EncryptionKeyWrapMetadata Type value does not match with the " +
Copy link
Contributor

Choose a reason for hiding this comment

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

in similar scenario, does non Cosmos Exception type reach public surface area in the DotNet SDK?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes .NET has ArgumentException as well. To me this is correct and it should be non cosmos as it is validation on argument passed by user.

Copy link
Contributor

Choose a reason for hiding this comment

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

how would it work on the async API? do we do validation upfront? or do we return a Mono.of(IllegalArgException)

Copy link
Member Author

@simplynaveen20 simplynaveen20 May 19, 2021

Choose a reason for hiding this comment

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

This validation is on async API itself which is doing validation upfront .

@simplynaveen20 simplynaveen20 requested a review from moderakh May 18, 2021 18:28
Copy link
Member

@kushagraThapar kushagraThapar left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @simplynaveen20

Copy link
Contributor

@moderakh moderakh 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 the question on the async API and how validation and throwing IllegalArgException from async api works.

@@ -82,6 +82,13 @@ public CosmosAsyncClientEncryptionKey getClientEncryptionKey(String id) {

EncryptionKeyStoreProvider encryptionKeyStoreProvider =
this.cosmosEncryptionAsyncClient.getEncryptionKeyStoreProvider();

if (!encryptionKeyStoreProvider.getProviderName().equals(encryptionKeyWrapMetadata.getType())) {
throw new IllegalArgumentException("The EncryptionKeyWrapMetadata Type value does not match with the " +
Copy link
Contributor

Choose a reason for hiding this comment

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

how would it work on the async API? do we do validation upfront? or do we return a Mono.of(IllegalArgException)

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

Successfully merging this pull request may close these issues.

Azure Cosmos Client Encryption : Adds support to expose Type in EncryptionKeyWrapMetadata constructor
3 participants