Skip to content

Commit 9fd5867

Browse files
authored
[CosmosDB] Adds support to create containers with Client Encryption Policy (#18034)
* Support client encryption policy during container creation * Update SqlOperationsTests.ps1 * Update New-AzCosmosDBSqlContainer.md * Update PSClientEncryptionPolicy.cs * Update NewAzCosmosDBSqlContainer.cs * Update ChangeLog.md * Updated package. * Update CosmosDB.Test.csproj * Updated example, session records. * updated session records.
1 parent ee78012 commit 9fd5867

File tree

47 files changed

+24980
-95050
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+24980
-95050
lines changed

src/CosmosDB/CosmosDB.Test/CosmosDB.Test.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<Import Project="$(MSBuildThisFileDirectory)..\..\Az.Test.props" />
66
<ItemGroup>
77
<PackageReference Include="Microsoft.Azure.KeyVault" Version="3.0.1" />
8-
<PackageReference Include="Microsoft.Azure.Management.CosmosDB" Version="3.5.0-preview" />
8+
<PackageReference Include="Microsoft.Azure.Management.CosmosDB" Version="3.7.0-preview" />
99
<PackageReference Include="Microsoft.Azure.Management.Network" Version="22.0.0" />
1010
</ItemGroup>
11-
</Project>
11+
</Project>

src/CosmosDB/CosmosDB.Test/ScenarioTests/SqlOperationsTests.ps1

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,8 @@ function Test-ClientEncryptionKeyCmdlets
896896
$DatabaseName = "dbNameCdbAE"
897897
$ClientEncryptionKeyName = "cek1"
898898
$EncryptionAlgorithm = "AEAD_AES_256_CBC_HMAC_SHA256"
899+
$EncryptionType_1 = "Deterministic"
900+
$EncryptionType_2 = "Randomized"
899901
$keywrapmetadataName = "cmk1v1"
900902
$keywrapmetadataName2 = "cmk1v2"
901903
$keywrapmetadataType = "AZURE_KEY_VAULT"
@@ -932,6 +934,7 @@ function Test-ClientEncryptionKeyCmdlets
932934
Remove-AzKeyVault -VaultName $vaultName -InRemovedState -Force -Location $location
933935
}
934936
catch{}
937+
935938
$encryptionKeyVault=New-AzKeyVault -VaultName $vaultName -ResourceGroupName $rgName -Location $location
936939

937940
# add access police for key-vault
@@ -985,6 +988,37 @@ function Test-ClientEncryptionKeyCmdlets
985988
Assert-AreEqual $UpdatedClientEncryptionKey.Resource.keyWrapMetadata.type $keywrapmetadataType
986989
Assert-AreEqual $UpdatedClientEncryptionKey.Resource.keyWrapMetadata.value $encryptionKey2
987990
Assert-AreEqual $UpdatedClientEncryptionKey.Resource.keyWrapMetadata.algorithm $keywrapmetadataAlgo
991+
992+
#Test - validate client encryption policy creation.
993+
$includedPath_1 = [Microsoft.Azure.Management.CosmosDB.Models.ClientEncryptionIncludedPath]::new("/path1",$ClientEncryptionKeyName,$EncryptionType_1,$EncryptionAlgorithm);
994+
$includedPath_2 = [Microsoft.Azure.Management.CosmosDB.Models.ClientEncryptionIncludedPath]::new("/path2",$ClientEncryptionKeyName,$EncryptionType_2,$EncryptionAlgorithm);
995+
$listofIncludedPaths = New-Object Collections.Generic.List[Microsoft.Azure.Management.CosmosDB.Models.ClientEncryptionIncludedPath]
996+
$listofIncludedPaths.Add($includedPath_1)
997+
$listofIncludedPaths.Add($includedPath_2)
998+
$newClientEncryptionPolicy = New-Object Microsoft.Azure.Management.CosmosDB.Models.ClientEncryptionPolicy
999+
$newClientEncryptionPolicy.IncludedPaths = $listofIncludedPaths
1000+
#verify the default policy version 1 is picked up
1001+
$newClientEncryptionPolicy.PolicyFormatVersion = 187
1002+
$newPSSqlClientEncryptionPolicy = [Microsoft.Azure.Commands.CosmosDB.Models.PSSqlClientEncryptionPolicy]::new($newClientEncryptionPolicy)
1003+
1004+
$ContainerWithEncryptionPolicy = "containerWithEncryptionPolicy"
1005+
#create a container with the above policy
1006+
New-AzCosmosDBSqlContainer -AccountName $AccountName -ResourceGroupName $rgName -DatabaseName $DatabaseName -Name $ContainerWithEncryptionPolicy -PartitionKeyPath "/pk" -PartitionKeyKind Hash -ClientEncryptionPolicy $newPSSqlClientEncryptionPolicy
1007+
1008+
$ContainerWithEncryptionPolicy = Get-AzCosmosDBSqlContainer -AccountName $AccountName -ResourceGroupName $rgName -DatabaseName $DatabaseName -Name $ContainerWithEncryptionPolicy
1009+
1010+
Assert-AreEqual $ContainerWithEncryptionPolicy.Resource.ClientEncryptionPolicy.IncludedPaths[0].Path "/path1"
1011+
Assert-AreEqual $ContainerWithEncryptionPolicy.Resource.ClientEncryptionPolicy.IncludedPaths[0].ClientEncryptionKeyId $ClientEncryptionKeyName
1012+
Assert-AreEqual $ContainerWithEncryptionPolicy.Resource.ClientEncryptionPolicy.IncludedPaths[0].EncryptionAlgorithm $EncryptionAlgorithm
1013+
Assert-AreEqual $ContainerWithEncryptionPolicy.Resource.ClientEncryptionPolicy.IncludedPaths[0].EncryptionType $EncryptionType_1
1014+
Assert-AreEqual $ContainerWithEncryptionPolicy.Resource.ClientEncryptionPolicy.PolicyFormatVersion 1
1015+
1016+
Assert-AreEqual $ContainerWithEncryptionPolicy.Resource.ClientEncryptionPolicy.IncludedPaths[1].Path "/path2"
1017+
Assert-AreEqual $ContainerWithEncryptionPolicy.Resource.ClientEncryptionPolicy.IncludedPaths[1].ClientEncryptionKeyId $ClientEncryptionKeyName
1018+
Assert-AreEqual $ContainerWithEncryptionPolicy.Resource.ClientEncryptionPolicy.IncludedPaths[1].EncryptionAlgorithm $EncryptionAlgorithm
1019+
Assert-AreEqual $ContainerWithEncryptionPolicy.Resource.ClientEncryptionPolicy.IncludedPaths[1].EncryptionType $EncryptionType_2
1020+
Assert-AreEqual $ContainerWithEncryptionPolicy.Resource.ClientEncryptionPolicy.PolicyFormatVersion 1
1021+
9881022
}
9891023
Finally {
9901024
Remove-AzCosmosDBSqlDatabase -AccountName $AccountName -ResourceGroupName $rgName -Name $DatabaseName

src/CosmosDB/CosmosDB.Test/ScenarioTests/TableOperationsTests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ Test Table throughput cmdlets using all parameter sets
150150
#>
151151
function Test-TableThroughputCmdlets
152152
{
153-
$AccountName = "table-db2530"
153+
$AccountName = "table-db2527"
154154
$rgName = "CosmosDBResourceGroup34"
155155
$TableName = "tableName3"
156156
$apiKind = "Table"

0 commit comments

Comments
 (0)