Skip to content

Commit a677e8c

Browse files
committed
Azure: Allow ignoring security type via config
This commit adds a new property for `AzurePublishingMetadata` named `unsupported_security_type_arches` which aims to map the list of unsupported arches which shouldn't receive a value for security_type on SKU building. When not set this value defaults to `x64Gen1`. It also changes the `_build_skus` and `update_skus` functions to receive the list of unsupported arches and use the default when not set. Signed-off-by: Jonathan Gangi <[email protected]> Assisted-by: Cursor/Gemini
1 parent 6277899 commit a677e8c

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed

cloudpub/ms_azure/service.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,7 @@ def publish(self, metadata: AzurePublishingMetadata) -> None:
884884
generation=metadata.generation,
885885
plan_name=plan_name,
886886
old_skus=tech_config.skus,
887+
unsupported_security_type_arches=metadata.unsupported_security_type_arches,
887888
)
888889
log.info(
889890
"Updating the technical configuration for \"%s\" on \"%s\".",

cloudpub/ms_azure/utils.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
log = logging.getLogger(__name__)
2222

2323

24+
DEFAULT_UNSUPPORTED_SECURITY_TYPE_ARCHES = ["x64Gen1"]
25+
"""The default list of arches that don't support security type."""
26+
27+
2428
class AzurePublishingMetadata(PublishingMetadata):
2529
"""A collection of metadata necessary for publishing a VHD Image into a product."""
2630

@@ -34,6 +38,7 @@ def __init__(
3438
generation: str = "V2",
3539
support_legacy: bool = False,
3640
recommended_sizes: Optional[List[str]] = None,
41+
unsupported_security_type_arches: Optional[List[str]] = None,
3742
**kwargs,
3843
) -> None:
3944
"""
@@ -61,6 +66,9 @@ def __init__(
6166
The modular push causes the effect to only publish
6267
the changed plan instead of the whole offer to preview/live.
6368
Default to ``False``.
69+
unsupported_security_type_arches (list, optional):
70+
The list of arches that don't support security type.
71+
Default to ``["x64Gen1"]``.
6472
**kwargs
6573
Arguments for :class:`~cloudpub.common.PublishingMetadata`.
6674
"""
@@ -72,7 +80,9 @@ def __init__(
7280
self.legacy_sku_id = kwargs.pop("legacy_sku_id", None)
7381
self.check_base_sas_only = kwargs.pop("check_base_sas_only", False)
7482
self.modular_push = kwargs.pop("modular_push", None) or False
75-
83+
self.unsupported_security_type_arches = (
84+
unsupported_security_type_arches or DEFAULT_UNSUPPORTED_SECURITY_TYPE_ARCHES
85+
)
7686
if generation == "V1" or not support_legacy:
7787
self.legacy_sku_id = None
7888
else:
@@ -309,15 +319,19 @@ def _build_skus(
309319
alt_gen: str,
310320
plan_name: str,
311321
security_type: Optional[List[str]] = None,
322+
unsupported_security_type_arches: Optional[List[str]] = None,
312323
) -> List[VMISku]:
313324
def get_skuid(arch):
314325
if arch == "x64":
315326
return plan_name
316327
return f"{plan_name}-{arch.lower()}"
317328

318329
def get_safe_security_type(image_type):
319-
# Arches which aren't x86Gen2 (like ARM64) doesn't work well with security type
320-
if image_type != "x64Gen2":
330+
unsupported_arches = (
331+
unsupported_security_type_arches or DEFAULT_UNSUPPORTED_SECURITY_TYPE_ARCHES
332+
)
333+
# Some arches (like x86 Gen1) doesn't support security type, so we need to skip them.
334+
if image_type in unsupported_arches:
321335
return None
322336
return security_type
323337

@@ -348,8 +362,8 @@ def get_safe_security_type(image_type):
348362

349363

350364
def _get_security_type(old_skus: List[VMISku]) -> Optional[List[str]]:
351-
# The security type may exist only for x64 Gen2, so it iterates over all gens to find it
352-
# Get the security type for all gens
365+
# The security type may not be applied for certain arches, like x64 Gen1.
366+
# This function will return the proper security type for the arches that has it set.
353367
for osku in old_skus:
354368
if osku.security_type is not None:
355369
return osku.security_type
@@ -361,6 +375,7 @@ def update_skus(
361375
generation: str,
362376
plan_name: str,
363377
old_skus: Optional[List[VMISku]] = None,
378+
unsupported_security_type_arches: Optional[List[str]] = None,
364379
) -> List[VMISku]:
365380
"""
366381
Return the expected VMISku list based on given DiskVersion.
@@ -375,13 +390,20 @@ def update_skus(
375390
old_skus (list, optional)
376391
A list of the existing SKUs to extract the security_type value
377392
when set.
393+
unsupported_security_type_arches (list, optional)
394+
The list of arches that don't support security type.
395+
Default to ``["x64Gen1"]``.
378396
Returns:
379397
The updated list with VMISkus.
380398
"""
381399
if not old_skus:
382400
alt_gen = "V2" if generation == "V1" else "V1"
383401
return _build_skus(
384-
disk_versions, default_gen=generation, alt_gen=alt_gen, plan_name=plan_name
402+
disk_versions,
403+
default_gen=generation,
404+
alt_gen=alt_gen,
405+
plan_name=plan_name,
406+
unsupported_security_type_arches=unsupported_security_type_arches,
385407
)
386408

387409
# If we have SKUs for each image we don't need to update them as they're already
@@ -419,6 +441,7 @@ def update_skus(
419441
alt_gen=alt_gen,
420442
plan_name=plan_name,
421443
security_type=security_type,
444+
unsupported_security_type_arches=unsupported_security_type_arches,
422445
)
423446

424447

tests/ms_azure/test_service.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,7 @@ def test_publish_overwrite(
10881088
generation=metadata_azure_obj.generation,
10891089
plan_name="plan-1",
10901090
old_skus=expected_tech_config.skus,
1091+
unsupported_security_type_arches=metadata_azure_obj.unsupported_security_type_arches,
10911092
)
10921093
mock_configure.assert_called_once_with(resources=[technical_config_obj])
10931094
mock_submit.assert_not_called()
@@ -1171,6 +1172,7 @@ def test_publish_nodiskversion(
11711172
generation=metadata_azure_obj.generation,
11721173
plan_name="plan-1",
11731174
old_skus=expected_tech_config.skus,
1175+
unsupported_security_type_arches=metadata_azure_obj.unsupported_security_type_arches,
11741176
)
11751177
mock_disk_scratch.assert_called_once_with(metadata_azure_obj, expected_source)
11761178
mock_configure.assert_called_once_with(resources=[expected_tech_config])

tests/ms_azure/test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ def test_update_existing_skus_mixed_arches(
489489
VMISku.from_json(x)
490490
for x in [
491491
{"imageType": "x64Gen2", "skuId": "plan1", "securityType": ["trusted"]},
492-
{"imageType": "arm64Gen2", "skuId": "plan1-arm64"},
492+
{"imageType": "arm64Gen2", "skuId": "plan1-arm64", "securityType": ["trusted"]},
493493
{"imageType": "x64Gen1", "skuId": "plan1-gen1"},
494494
]
495495
]

0 commit comments

Comments
 (0)