Skip to content

Commit 9ec260c

Browse files
authored
[AKS] az aks create/update: Add support for ACNS transit encryption (#32988)
1 parent 9428bc2 commit 9ec260c

File tree

10 files changed

+2619
-4
lines changed

10 files changed

+2619
-4
lines changed

src/azure-cli/azure/cli/command_modules/acs/_consts.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,10 @@
267267
# consts for workloadruntime
268268
CONST_WORKLOAD_RUNTIME_KATA_VM_ISOLATION = "KataVmIsolation"
269269

270+
# consts for acns transit encryption
271+
CONST_TRANSIT_ENCRYPTION_WIREGUARD = "WireGuard"
272+
CONST_TRANSIT_ENCRYPTION_NONE = "None"
273+
270274

271275
# consts for decorator pattern
272276
class DecoratorMode(Enum):

src/azure-cli/azure/cli/command_modules/acs/_help.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,10 @@
591591
- name: --enable-container-network-logs
592592
type: bool
593593
short-summary: Enable container network log collection functionalities on a cluster. Automatically enables --enable-high-log-scale-mode.
594+
- name: --acns-transit-encryption-type
595+
type: string
596+
short-summary: Set transit encryption type for ACNS security.
597+
long-summary: Configures pod-to-pod encryption for Cilium-based clusters. Once enabled, all traffic between Cilium managed pods will be encrypted when it leaves the node boundary. Valid values are "WireGuard" and "None". On cluster creation, this must be used together with "--enable-acns".
594598
- name: --nrg-lockdown-restriction-level
595599
type: string
596600
short-summary: Restriction level on the managed node resource group.
@@ -1098,6 +1102,10 @@
10981102
- name: --disable-container-network-logs
10991103
type: bool
11001104
short-summary: Disable container network log collection functionalities on a cluster.
1105+
- name: --acns-transit-encryption-type
1106+
type: string
1107+
short-summary: Set transit encryption type for ACNS security.
1108+
long-summary: Configures pod-to-pod encryption for Cilium-based clusters. Once enabled, all traffic between Cilium managed pods will be encrypted when it leaves the node boundary. Valid values are "WireGuard" and "None". When creating a cluster, this option must be used together with "--enable-acns"; when updating a cluster, it can be used on its own to modify the transit encryption type for an existing ACNS-enabled cluster.
11011109
- name: --nrg-lockdown-restriction-level
11021110
type: string
11031111
short-summary: Restriction level on the managed node resource group.

src/azure-cli/azure/cli/command_modules/acs/_params.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@
7575
CONST_NODE_PROVISIONING_MODE_AUTO,
7676
CONST_NODE_PROVISIONING_DEFAULT_POOLS_NONE,
7777
CONST_NODE_PROVISIONING_DEFAULT_POOLS_AUTO,
78-
CONST_WORKLOAD_RUNTIME_KATA_VM_ISOLATION)
78+
CONST_WORKLOAD_RUNTIME_KATA_VM_ISOLATION,
79+
CONST_TRANSIT_ENCRYPTION_WIREGUARD,
80+
CONST_TRANSIT_ENCRYPTION_NONE)
7981
from azure.cli.command_modules.acs.azurecontainerstorage._consts import (
8082
CONST_ACSTOR_ALL,
8183
CONST_DISK_TYPE_EPHEMERAL_VOLUME_ONLY,
@@ -228,6 +230,11 @@
228230
CONST_NODE_PROVISIONING_DEFAULT_POOLS_AUTO,
229231
]
230232

233+
transit_encryption_types = [
234+
CONST_TRANSIT_ENCRYPTION_WIREGUARD,
235+
CONST_TRANSIT_ENCRYPTION_NONE,
236+
]
237+
231238
dev_space_endpoint_types = ['Public', 'Private', 'None']
232239

233240
keyvault_network_access_types = [CONST_AZURE_KEYVAULT_NETWORK_ACCESS_PUBLIC, CONST_AZURE_KEYVAULT_NETWORK_ACCESS_PRIVATE]
@@ -605,6 +612,7 @@ def load_arguments(self, _):
605612
c.argument('disable_acns_security', action='store_true')
606613
c.argument("acns_advanced_networkpolicies", arg_type=get_enum_type(advanced_networkpolicies))
607614
c.argument('enable_container_network_logs', action='store_true')
615+
c.argument('acns_transit_encryption_type', arg_type=get_enum_type(transit_encryption_types))
608616
c.argument("if_match")
609617
c.argument("if_none_match")
610618
# node provisioning
@@ -664,6 +672,7 @@ def load_arguments(self, _):
664672
c.argument("acns_advanced_networkpolicies", arg_type=get_enum_type(advanced_networkpolicies))
665673
c.argument('enable_container_network_logs', action='store_true')
666674
c.argument('disable_container_network_logs', action='store_true')
675+
c.argument('acns_transit_encryption_type', arg_type=get_enum_type(transit_encryption_types))
667676
# private cluster parameters
668677
c.argument('enable_apiserver_vnet_integration', action='store_true')
669678
c.argument('apiserver_subnet_id', validator=validate_apiserver_subnet_id)

src/azure-cli/azure/cli/command_modules/acs/custom.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,7 @@ def aks_create(
935935
disable_acns_security=None,
936936
acns_advanced_networkpolicies=None,
937937
enable_container_network_logs=None,
938+
acns_transit_encryption_type=None,
938939
# network isoalted cluster
939940
bootstrap_artifact_source=CONST_ARTIFACT_SOURCE_DIRECT,
940941
bootstrap_container_registry_resource_id=None,
@@ -1164,6 +1165,7 @@ def aks_update(
11641165
acns_advanced_networkpolicies=None,
11651166
enable_container_network_logs=None,
11661167
disable_container_network_logs=None,
1168+
acns_transit_encryption_type=None,
11671169
# network isoalted cluster
11681170
bootstrap_artifact_source=None,
11691171
bootstrap_container_registry_resource_id=None,

src/azure-cli/azure/cli/command_modules/acs/linter_exclusions.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ aks create:
7676
acns_advanced_networkpolicies:
7777
rule_exclusions:
7878
- option_length_too_long
79+
acns_transit_encryption_type:
80+
rule_exclusions:
81+
- option_length_too_long
7982
nrg_lockdown_restriction_level:
8083
rule_exclusions:
8184
- option_length_too_long
@@ -191,6 +194,9 @@ aks update:
191194
acns_advanced_networkpolicies:
192195
rule_exclusions:
193196
- option_length_too_long
197+
acns_transit_encryption_type:
198+
rule_exclusions:
199+
- option_length_too_long
194200
nrg_lockdown_restriction_level:
195201
rule_exclusions:
196202
- option_length_too_long
@@ -205,7 +211,7 @@ aks update:
205211
- option_length_too_long
206212
disable_private_cluster:
207213
rule_exclusions:
208-
- option_length_too_long
214+
- option_length_too_long
209215
enable_static_egress_gateway:
210216
rule_exclusions:
211217
- option_length_too_long

src/azure-cli/azure/cli/command_modules/acs/managed_cluster_decorator.py

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2676,6 +2676,32 @@ def get_enable_high_log_scale_mode(self) -> Union[bool, None]:
26762676
# If container network logs are not being enabled, return the original value
26772677
return enable_high_log_scale_mode
26782678

2679+
def get_acns_transit_encryption_type(self) -> Union[str, None]:
2680+
"""Get the transit encryption type for acns security.
2681+
2682+
:return: str or None
2683+
"""
2684+
acns_transit_encryption = self.raw_param.get("acns_transit_encryption_type")
2685+
if acns_transit_encryption is not None:
2686+
enable_acns = self.raw_param.get("enable_acns")
2687+
disable_acns = self.raw_param.get("disable_acns")
2688+
disable_acns_security = self.raw_param.get("disable_acns_security")
2689+
if disable_acns_security:
2690+
raise MutuallyExclusiveArgumentError(
2691+
"Cannot specify --acns-transit-encryption-type and "
2692+
"--disable-acns-security at the same time."
2693+
)
2694+
if disable_acns:
2695+
raise MutuallyExclusiveArgumentError(
2696+
"Cannot specify --acns-transit-encryption-type and "
2697+
"--disable-acns at the same time."
2698+
)
2699+
if self.decorator_mode == DecoratorMode.CREATE and not enable_acns:
2700+
raise MutuallyExclusiveArgumentError(
2701+
"--acns-transit-encryption-type requires --enable-acns."
2702+
)
2703+
return acns_transit_encryption
2704+
26792705
def _get_pod_cidr_and_service_cidr_and_dns_service_ip_and_docker_bridge_address_and_network_policy(
26802706
self, enable_validation: bool = False
26812707
) -> Tuple[
@@ -6356,6 +6382,7 @@ def set_up_network_profile(self, mc: ManagedCluster) -> ManagedCluster:
63566382

63576383
(acns_enabled, acns_observability, acns_security) = self.context.get_acns_enablement()
63586384
acns_advanced_networkpolicies = self.context.get_acns_advanced_networkpolicies()
6385+
acns_transit_encryption = self.context.get_acns_transit_encryption_type()
63596386
if acns_enabled is not None:
63606387
acns = self.models.AdvancedNetworking(
63616388
enabled=acns_enabled,
@@ -6375,6 +6402,12 @@ def set_up_network_profile(self, mc: ManagedCluster) -> ManagedCluster:
63756402
)
63766403
else:
63776404
acns.security.advanced_network_policies = acns_advanced_networkpolicies
6405+
if acns_transit_encryption is not None:
6406+
if acns.security is None:
6407+
acns.security = self.models.AdvancedNetworkingSecurity()
6408+
acns.security.transit_encryption = self.models.AdvancedNetworkingSecurityTransitEncryption(
6409+
type=acns_transit_encryption,
6410+
)
63786411

63796412
if any(
63806413
[
@@ -8281,6 +8314,7 @@ def update_network_profile_advanced_networking(self, mc: ManagedCluster) -> Mana
82818314
self._ensure_mc(mc)
82828315
(acns_enabled, acns_observability, acns_security) = self.context.get_acns_enablement()
82838316
acns_advanced_networkpolicies = self.context.get_acns_advanced_networkpolicies()
8317+
acns_transit_encryption = self.context.get_acns_transit_encryption_type()
82848318
if acns_enabled is not None:
82858319
acns = self.models.AdvancedNetworking(
82868320
enabled=acns_enabled,
@@ -8300,8 +8334,27 @@ def update_network_profile_advanced_networking(self, mc: ManagedCluster) -> Mana
83008334
)
83018335
else:
83028336
acns.security.advanced_network_policies = acns_advanced_networkpolicies
8303-
if acns_enabled is not None:
8337+
if acns_transit_encryption is not None:
8338+
if acns.security is None:
8339+
acns.security = self.models.AdvancedNetworkingSecurity()
8340+
acns.security.transit_encryption = self.models.AdvancedNetworkingSecurityTransitEncryption(
8341+
type=acns_transit_encryption,
8342+
)
83048343
mc.network_profile.advanced_networking = acns
8344+
elif acns_transit_encryption is not None:
8345+
if (mc.network_profile.advanced_networking is None or
8346+
not mc.network_profile.advanced_networking.enabled):
8347+
raise MutuallyExclusiveArgumentError(
8348+
"--acns-transit-encryption-type requires ACNS to be enabled on the cluster. "
8349+
"Use --enable-acns together with --acns-transit-encryption-type."
8350+
)
8351+
if mc.network_profile.advanced_networking.security is None:
8352+
mc.network_profile.advanced_networking.security = self.models.AdvancedNetworkingSecurity()
8353+
mc.network_profile.advanced_networking.security.transit_encryption = (
8354+
self.models.AdvancedNetworkingSecurityTransitEncryption(
8355+
type=acns_transit_encryption,
8356+
)
8357+
)
83058358
return mc
83068359

83078360
def update_monitoring_profile_flow_logs(self, mc: ManagedCluster) -> ManagedCluster:

0 commit comments

Comments
 (0)