az cosmosdb sql container create command with a client Encryption Policy attached does NOT actually create the policy
See original GitHub issueDescribe the bug
When running az cosmosdb sql container create -g "<resource-group>" -a "<account>" -d "<database>" -n "<container>" --partition-key-path "/partitionKey" --cep @policy-file.json
, the Encryption Policy is not applied.
Command Name
az cosmosdb sql container create
Errors:
None
To Reproduce:
Steps to reproduce the behavior.
- create a cosmosdb database - done via the azure portal
- create a ClientEncryptionKey (created via Powershell as I have not found a Azure CLI native command to do this)
$myKeyWrapMetadataObject = [Microsoft.Azure.Commands.CosmosDB.Models.PSSqlKeyWrapMetadata]::new([Microsoft.Azure.Management.CosmosDB.Models.KeyWrapMetadata]::new("key1","AZURE_KEY_VAULT", "url-to-key-vault-key", "RSA-OAEP")) New-AzCosmosDbClientEncryptionKey -AccountName $accountName -DatabaseName $databaseName -ResourceGroupName "d-weu-shrd-rg" -Name $keyName -EncryptionAlgorithmName "AEAD_AES_256_CBC_HMAC_SHA256" -KeyWrapMetadata $myKeyWrapMetadataObject
- create a container with an encryption policy via Azure CLI
az cosmosdb sql container create -g "<resource-group>" -a "<account>" -d "<database>" -n "<container>" --partition-key-path "/partitionKey" --cep @policy-file.json
Content of the policy-file.json{ "includedPaths": [ { "path": "/password", "clientEncryptionKeyId": "key1", "encryptionAlgorithm": "AEAD_AES_256_CBC_HMAC_SHA256", "encryptionType": "Deterministic" } ], "policyFormatVersion": 2 }
Current Behavior
Below is the output from the az cosmosdb sql container create
command
Expected Behavior
This is the output of the az cosmosdb sql container show
command run against a container created via the .Net CosmosSDK. Code is located in the azure-cosmos-dotnet-v3 repo in the samples .sln, encryption project.
It shows the encryption policies.
Environment Summary tried locally on my Windows 10 Enterprise 20H2, as well as in the Azure Devops pipeline CLI task
azure-cli 2.42.0
Issue Analytics
- State:
- Created 10 months ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
New-AzCosmosDBSqlContainer (Az.CosmosDB)
Example 2: Create a new CosmosDB Sql Container with Client Encryption Policy. PowerShell. Copy. Try It. $includedPath1 = [Microsoft.Azure.Management.
Read more >Getting started with Azure Cosmos DB Serverless - SQLShack
In this article, we will learn how to create a serverless instance of Azure Cosmos DB as well as understand its applicability in...
Read more >container create --unique-keys-policy string-arg example does ...
I just ran the example from the command prompt with CLI 2.0.77 and it worked. It looks like Powershell likely parses input JSON...
Read more >azure-cli 2.23.0 - PyPI
New command az network vnet-gateway vpn-client ipsec-policy show . ... az cosmosdb sql container create/update : Add –analytical-storage-ttl parameter ...
Read more >Kubernetes Microservices on Azure with Cosmos DB
The generator creates four applications. They are designed to be built and run as docker containers, which makes it easy for them to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Solution worked. Thanks a lot.
@pavelplesca If you want to use the old cli, use bash task to install old CLI:
Please Note:
Since the Keys used in the policy should be created upfront. Azure CLI does not support creating Client Encryption Keys. We do have Powershell support that you can leverage which provides support to create Client Encryption Keys and containers with Client Encryption Policy. Please refer to the below documentations -