@@ -208,7 +208,8 @@ def validate_key_type(ns):
208208 setattr (ns , 'kty' , kty )
209209
210210
211- def _fetch_default_cvm_policy (cli_ctx , vault_url ):
211+ # pylint: disable=line-too-long
212+ def _fetch_default_release_policy (cli_ctx , vault_url , policy_type = 'cvm' ):
212213 try :
213214 # get vault/hsm location
214215 mgmt_client = get_mgmt_service_client (cli_ctx , ResourceType .MGMT_KEYVAULT )
@@ -233,63 +234,99 @@ def _fetch_default_cvm_policy(cli_ctx, vault_url):
233234 _endpoint = cli_ctx .cloud .endpoints .resource_manager
234235 if _endpoint .endswith ('/' ):
235236 _endpoint = _endpoint [:- 1 ]
236- default_cvm_policy_url = f"{ _endpoint } /subscriptions/{ get_subscription_id (cli_ctx )} " \
237- f"/providers/Microsoft.Attestation/Locations/{ location } " \
238- f"/defaultProvider?api-version=2020-10-01"
239- response = send_raw_request (cli_ctx , 'get' , default_cvm_policy_url )
237+ default_release_policy_url = f"{ _endpoint } /subscriptions/{ get_subscription_id (cli_ctx )} /providers/Microsoft.Attestation/Locations/{ location } /defaultProvider?api-version=2020-10-01"
238+ response = send_raw_request (cli_ctx , 'get' , default_release_policy_url )
240239 if response .status_code != 200 :
241- raise AzureInternalError (f"Fail to fetch default cvm policy from { default_cvm_policy_url } " )
240+ raise AzureInternalError (f"Fail to fetch default release policy from { default_release_policy_url } " )
242241
243242 # extract attest uri from response as authority in cvm policy
244243 import json
245244 res_json = json .loads (response .text )
246245 attest_uri = res_json ['properties' ]['attestUri' ]
247- default_cvm_policy = {
248- 'version' : '1.0.0' ,
249- 'anyOf' : [
250- {
251- 'authority' : attest_uri ,
252- 'allOf' : [
253- {
254- 'claim' : 'x-ms-compliance-status' ,
255- 'equals' : 'azure-compliant-cvm'
256- }
257- ]
258- }
259- ]
260- }
261- return default_cvm_policy
246+ if policy_type == 'cvm' :
247+ default_release_policy = {
248+ 'version' : '1.0.0' ,
249+ 'anyOf' : [
250+ {
251+ 'authority' : attest_uri ,
252+ 'allOf' : [
253+ {
254+ 'claim' : 'x-ms-compliance-status' ,
255+ 'equals' : 'azure-compliant-cvm'
256+ }
257+ ]
258+ }
259+ ]
260+ }
261+ else :
262+ default_release_policy = {
263+ 'version' : '1.0.0' ,
264+ 'anyOf' : [
265+ {
266+ 'authority' : attest_uri ,
267+ 'allOf' : [
268+ {
269+ 'anyOf' : [
270+ {
271+ 'claim' : 'x-ms-isolation-tee.x-ms-attestation-type' ,
272+ 'equals' : 'sevsnpvm'
273+ },
274+ {
275+ 'claim' : 'x-ms-isolation-tee.x-ms-attestation-type' ,
276+ 'equals' : 'tdxvm'
277+ }
278+ ]
279+ },
280+ {
281+ 'claim' : 'x-ms-isolation-tee.x-ms-compliance-status' ,
282+ 'equals' : 'azure-compliant-cvm'
283+ }
284+ ]
285+ }
286+ ]
287+ }
288+ return default_release_policy
262289 except Exception as ex : # pylint: disable=broad-except
263- raise AzureInternalError (f"Fail to fetch default cvm policy: { ex } " )
290+ raise AzureInternalError (f"Fail to fetch default release policy: { ex } " )
264291
265292
266293def process_key_release_policy (cmd , ns ):
267294 default_cvm_policy = None
295+ default_data_disk_policy = None
268296 if hasattr (ns , 'default_cvm_policy' ):
269297 default_cvm_policy = ns .default_cvm_policy
270298 del ns .default_cvm_policy
299+ if hasattr (ns , 'default_data_disk_policy' ):
300+ default_data_disk_policy = ns .default_data_disk_policy
301+ del ns .default_data_disk_policy
271302
272303 immutable = None
273304 if hasattr (ns , 'immutable' ):
274305 immutable = ns .immutable
275306 del ns .immutable
276307
277- if not ns .release_policy and not default_cvm_policy :
308+ if not ns .release_policy and not default_cvm_policy and not default_data_disk_policy :
278309 if immutable is not None :
279310 raise InvalidArgumentValueError ('Please provide policy when setting `--immutable`' )
280311 return
281312
282313 if ns .release_policy and default_cvm_policy :
283314 raise InvalidArgumentValueError ('Can not specify both `--policy` and `--default-cvm-policy`' )
315+ if ns .release_policy and default_data_disk_policy :
316+ raise InvalidArgumentValueError ('Can not specify both `--policy` and `--default-data-disk-policy`' )
317+ if default_cvm_policy and default_data_disk_policy :
318+ from azure .cli .core .azclierror import MutuallyExclusiveArgumentError
319+ raise MutuallyExclusiveArgumentError ('`--default-cvm-policy` and `--default-data-disk-policy` '
320+ 'are mutually exclusive' )
284321
285322 import json
286323 KeyReleasePolicy = cmd .loader .get_sdk ('KeyReleasePolicy' , mod = '_models' ,
287324 resource_type = ResourceType .DATA_KEYVAULT_KEYS )
288- if default_cvm_policy :
325+ if default_cvm_policy or default_data_disk_policy :
289326 vault_url = getattr (ns , 'hsm_name' , None ) or getattr (ns , 'vault_base_url' , None )
290327 if not vault_url :
291328 vault_url = getattr (ns , 'identifier' , None )
292- policy = _fetch_default_cvm_policy (cmd .cli_ctx , vault_url )
329+ policy = _fetch_default_release_policy (cmd .cli_ctx , vault_url , 'cvm' if default_cvm_policy else 'data_disk' )
293330 ns .release_policy = KeyReleasePolicy (encoded_policy = json .dumps (policy ).encode ('utf-8' ),
294331 immutable = immutable )
295332 return
0 commit comments