-
Notifications
You must be signed in to change notification settings - Fork 1.3k
CSHARP-4255: Automatically create Queryable Encryption keys. #961
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1f05fe2
CSHARP-4255: Automatically create Queryable Encryption keys.
DmitryLukyanov 71e171e
Test fix.
DmitryLukyanov 9318348
Code review,
DmitryLukyanov 2b8e02a
Code review
DmitryLukyanov 8b8705c
Fix typo.
DmitryLukyanov c0b7f6a
Fix rewrapProseTest
DmitryLukyanov c0e4ab1
Removed return type.
DmitryLukyanov 6013fc2
Add positive scenario.
DmitryLukyanov 4e6d6b9
Code review.
DmitryLukyanov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,6 +78,64 @@ public BsonDocument AddAlternateKeyName(Guid id, string alternateKeyName, Cancel | |
public Task<BsonDocument> AddAlternateKeyNameAsync(Guid id, string alternateKeyName, CancellationToken cancellationToken = default) => | ||
_libMongoCryptController.AddAlternateKeyNameAsync(id, alternateKeyName, cancellationToken); | ||
|
||
/// <summary> | ||
/// Create encrypted collection. | ||
/// </summary> | ||
/// <param name="collectionNamespace">The collection namespace.</param> | ||
/// <param name="createCollectionOptions">The create collection options.</param> | ||
/// <param name="kmsProvider">The kms provider.</param> | ||
/// <param name="dataKeyOptions">The datakey options.</param> | ||
/// <param name="cancellationToken">The cancellation token.</param> | ||
public (IMongoCollection<TCollection> Collection, BsonDocument EncryptedFields) CreateEncryptedCollection<TCollection>(CollectionNamespace collectionNamespace, CreateCollectionOptions createCollectionOptions, string kmsProvider, DataKeyOptions dataKeyOptions, CancellationToken cancellationToken = default) | ||
{ | ||
var effectiveEncryptedFields = createCollectionOptions?.EncryptedFields?.DeepClone()?.AsBsonDocument; | ||
|
||
foreach (var fieldDocument in EncryptedCollectionHelper.IterateEmptyKeyIds(collectionNamespace, effectiveEncryptedFields)) | ||
{ | ||
var dataKey = CreateDataKey(kmsProvider, dataKeyOptions, cancellationToken); | ||
EncryptedCollectionHelper.ModifyEndryptedFields(fieldDocument, dataKey); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. true |
||
} | ||
|
||
var database = _libMongoCryptController.KeyVaultClient.GetDatabase(collectionNamespace.DatabaseNamespace.DatabaseName); | ||
|
||
createCollectionOptions.EncryptedFields = effectiveEncryptedFields; | ||
|
||
database.CreateCollection(collectionNamespace.CollectionName, createCollectionOptions, cancellationToken); | ||
|
||
var collection = database.GetCollection<TCollection>(collectionNamespace.CollectionName); | ||
|
||
return (collection, effectiveEncryptedFields); | ||
} | ||
|
||
/// <summary> | ||
/// Create encrypted collection. | ||
/// </summary> | ||
/// <param name="collectionNamespace">The collection namespace.</param> | ||
/// <param name="createCollectionOptions">The create collection options.</param> | ||
/// <param name="kmsProvider">The kms provider.</param> | ||
/// <param name="dataKeyOptions">The datakey options.</param> | ||
/// <param name="cancellationToken">The cancellation token.</param> | ||
public async Task<(IMongoCollection<TCollection> Collection, BsonDocument EncryptedFields)> CreateEncryptedCollectionAsync<TCollection>(CollectionNamespace collectionNamespace, CreateCollectionOptions createCollectionOptions, string kmsProvider, DataKeyOptions dataKeyOptions, CancellationToken cancellationToken = default) | ||
{ | ||
var effectiveEncryptedFields = createCollectionOptions?.EncryptedFields?.DeepClone()?.AsBsonDocument; | ||
|
||
foreach (var fieldDocument in EncryptedCollectionHelper.IterateEmptyKeyIds(collectionNamespace, effectiveEncryptedFields)) | ||
{ | ||
var dataKey = await CreateDataKeyAsync(kmsProvider, dataKeyOptions, cancellationToken).ConfigureAwait(false); | ||
EncryptedCollectionHelper.ModifyEndryptedFields(fieldDocument, dataKey); | ||
} | ||
|
||
var database = _libMongoCryptController.KeyVaultClient.GetDatabase(collectionNamespace.DatabaseNamespace.DatabaseName); | ||
|
||
createCollectionOptions.EncryptedFields = effectiveEncryptedFields; | ||
|
||
await database.CreateCollectionAsync(collectionNamespace.CollectionName, createCollectionOptions, cancellationToken).ConfigureAwait(false); | ||
|
||
var collection = database.GetCollection<TCollection>(collectionNamespace.CollectionName); | ||
|
||
return (collection, effectiveEncryptedFields); | ||
} | ||
|
||
/// <summary> | ||
/// An alias function equivalent to createKey. | ||
/// </summary> | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to discuss whether we can add a different return type than this, so might be not the final form
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've discussed this question with spec author and he's confirmed that we can define public API in the consistent way with previous driver's API methods. So, I consider 2 changes:
I'm not too confident about these changes (as well as about the initial requirement), but I would probably want to avoid returning tuple in public API, thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Tuples are not recommended in public APIs.
Agreed that there is no need to return the
IMongoCollection<TDocument>
.Do we need to return anything?
Also, shouldn't the type parameter be
TDocument
(notTCollection
). But if we don't return theIMongoCollection<TDocument>
I don't think this type parameter is needed any more anyway.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I also think it can be simply
void
methodThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed