Skip to content

Commit 39c18af

Browse files
authored
[Container app] az containerapp env create/update: Support peer-to-peer traffic encryption with --enable-peer-to-peer-encryption (Azure#7464)
* Support p2p traffic encryption. * fix style. * fix linter error. * Add param validation. * Add test case.
1 parent 7dcaa84 commit 39c18af

7 files changed

+5496
-10
lines changed

linter_exclusions.yml

+8
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,14 @@ containerapp env create:
377377
platform_reserved_dns_ip:
378378
rule_exclusions:
379379
- option_length_too_long
380+
p2p_encryption_enabled:
381+
rule_exclusions:
382+
- option_length_too_long
383+
containerapp env update:
384+
parameters:
385+
p2p_encryption_enabled:
386+
rule_exclusions:
387+
- option_length_too_long
380388
containerapp github-action add:
381389
parameters:
382390
service_principal_client_id:

src/containerapp/HISTORY.rst

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ upcoming
99
* 'az containerapp env java-component eureka-server-for-spring': Support create/update/show/delete Spring Cloud Eureka; deprecation of 'az containerapp env java-component spring-cloud-eureka'
1010
* 'az containerapp up': Fix InvalidResourceType error when cloud is not AzureCloud
1111
* 'az containerapp create/update': Support enable or disable Java metrics with --runtime and --enable-java-metrics
12+
* 'az containerapp env create/update': Support peer-to-peer traffic encryption with --enable-peer-to-peer-encryption
1213
* 'az containerapp update': Fix --scale-rule-tcp-concurrency for TCP scale rule
1314
* 'az containerapp compose create': Fix an issue where the environment's location is not resolved from --location
1415
* 'az containerapp up': Fix an issue about creating resource group automatically

src/containerapp/azext_containerapp/_params.py

+3
Original file line numberDiff line numberDiff line change
@@ -344,3 +344,6 @@ def load_arguments(self, _):
344344
c.argument('environment_name', options_list=['--environment'], help="The environment name.")
345345
c.argument('resource_group_name', arg_type=resource_group_name_type, id_part=None)
346346
c.argument('configuration', nargs="*", help="Java component configuration. Configuration must be in format \"<propertyName>=<value> <propertyName>=<value> ...\".")
347+
348+
with self.argument_context('containerapp env', arg_group='Peer Traffic Configuration') as c:
349+
c.argument('p2p_encryption_enabled', arg_type=get_three_state_flag(), options_list=['--enable-peer-to-peer-encryption'], is_preview=True, help='Boolean indicating whether the peer-to-peer traffic encryption is enabled for the environment.')

src/containerapp/azext_containerapp/containerapp_env_decorator.py

+47-10
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,9 @@ def construct_payload(self):
3636
# Vnet
3737
self.set_up_vnet_configuration()
3838

39-
if self.get_argument_mtls_enabled() is not None:
40-
safe_set(self.managed_env_def, "properties", "peerAuthentication", "mtls", "enabled", value=self.get_argument_mtls_enabled())
39+
self.set_up_peer_to_peer_encryption()
4140
### copy end
42-
41+
4342
### overwrite custom_domain_configuration
4443
self.set_up_custom_domain_configuration()
4544

@@ -58,13 +57,17 @@ def validate_arguments(self):
5857
if not self.get_argument_enable_workload_profiles():
5958
raise RequiredArgumentMissingError("Cannot use --infrastructure-resource-group/-i without "
6059
"--enable-workload-profiles/-w")
61-
60+
6261
# validate custom domain configuration
6362
if self.get_argument_hostname():
6463
if self.get_argument_certificate_file() and self.get_argument_certificate_key_vault_url():
6564
raise ValidationError("Cannot use --certificate-file with --certificate-akv-url at the same time")
6665
if (not self.get_argument_certificate_file()) and (not self.get_argument_certificate_key_vault_url()):
6766
raise ValidationError("Either --certificate-file or --certificate-akv-url should be set when --dns-suffix is set")
67+
68+
# validate mtls and p2p traffic encryption
69+
if self.get_argument_p2p_encryption_enabled() is False and self.get_argument_mtls_enabled() is True:
70+
raise ValidationError("Cannot use '--enable-mtls' with '--enable-peer-to-peer-encryption False'")
6871

6972
def set_up_dynamic_json_columns(self):
7073
if self.get_argument_logs_destination() == "log-analytics" and self.get_argument_logs_dynamic_json_columns() is not None:
@@ -73,7 +76,7 @@ def set_up_dynamic_json_columns(self):
7376
def set_up_infrastructure_resource_group(self):
7477
if self.get_argument_enable_workload_profiles() and self.get_argument_infrastructure_subnet_resource_id() is not None:
7578
self.managed_env_def["properties"]["infrastructureResourceGroup"] = self.get_argument_infrastructure_resource_group()
76-
79+
7780
def set_up_managed_identity(self):
7881
identity_def = ManagedServiceIdentity
7982
identity_def["type"] = "None"
@@ -149,6 +152,16 @@ def set_up_custom_domain_configuration(self):
149152
}
150153
self.managed_env_def["properties"]["customDomainConfiguration"] = custom_domain
151154

155+
def set_up_peer_to_peer_encryption(self):
156+
is_p2p_encryption_enabled = self.get_argument_p2p_encryption_enabled()
157+
is_mtls_enabled = self.get_argument_mtls_enabled()
158+
159+
if is_p2p_encryption_enabled is not None:
160+
safe_set(self.managed_env_def, "properties", "peerTrafficConfiguration", "encryption", "enabled", value=is_p2p_encryption_enabled)
161+
162+
if is_mtls_enabled is not None:
163+
safe_set(self.managed_env_def, "properties", "peerAuthentication", "mtls", "enabled", value=is_mtls_enabled)
164+
152165
def get_argument_enable_workload_profiles(self):
153166
return self.get_param("enable_workload_profiles")
154167

@@ -163,13 +176,16 @@ def get_argument_system_assigned(self):
163176

164177
def get_argument_user_assigned(self):
165178
return self.get_param("user_assigned")
166-
179+
167180
def get_argument_certificate_identity(self):
168181
return self.get_param("certificate_identity")
169-
182+
170183
def get_argument_certificate_key_vault_url(self):
171184
return self.get_param("certificate_key_vault_url")
172185

186+
def get_argument_p2p_encryption_enabled(self):
187+
return self.get_param("p2p_encryption_enabled")
188+
173189

174190
class ContainerappEnvPreviewUpdateDecorator(ContainerAppEnvUpdateDecorator):
175191
def validate_arguments(self):
@@ -178,6 +194,15 @@ def validate_arguments(self):
178194
# validate custom domain configuration
179195
if self.get_argument_certificate_file() and self.get_argument_certificate_key_vault_url():
180196
raise ValidationError("Cannot use certificate --certificate-file with --certificate-akv-url at the same time")
197+
198+
# validate mtls and p2p traffic encryption
199+
if self.get_argument_p2p_encryption_enabled() is False and self.get_argument_mtls_enabled() is True:
200+
raise ValidationError("Cannot use '--enable-mtls' with '--enable-peer-to-peer-encryption False'")
201+
202+
def construct_payload(self):
203+
super().construct_payload()
204+
205+
self.set_up_peer_to_peer_encryption()
181206

182207
def set_up_app_log_configuration(self):
183208
logs_destination = self.get_argument_logs_destination()
@@ -217,12 +242,24 @@ def set_up_custom_domain_configuration(self):
217242
safe_set(self.managed_env_def, "properties", "customDomainConfiguration", "certificateValue", value="")
218243
safe_set(self.managed_env_def, "properties", "customDomainConfiguration", "certificatePassword", value="")
219244

245+
def set_up_peer_to_peer_encryption(self):
246+
is_p2p_encryption_enabled = self.get_argument_p2p_encryption_enabled()
247+
is_mtls_enabled = self.get_argument_mtls_enabled()
248+
249+
if is_p2p_encryption_enabled is not None:
250+
safe_set(self.managed_env_def, "properties", "peerTrafficConfiguration", "encryption", "enabled", value=is_p2p_encryption_enabled)
251+
252+
if is_mtls_enabled is not None:
253+
safe_set(self.managed_env_def, "properties", "peerAuthentication", "mtls", "enabled", value=is_mtls_enabled)
254+
220255
def get_argument_logs_dynamic_json_columns(self):
221256
return self.get_param("logs_dynamic_json_columns")
222-
257+
223258
def get_argument_certificate_identity(self):
224259
return self.get_param("certificate_identity")
225-
260+
226261
def get_argument_certificate_key_vault_url(self):
227262
return self.get_param("certificate_key_vault_url")
228-
263+
264+
def get_argument_p2p_encryption_enabled(self):
265+
return self.get_param("p2p_encryption_enabled")

src/containerapp/azext_containerapp/custom.py

+2
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,7 @@ def create_managed_environment(cmd,
717717
certificate_key_vault_url=None,
718718
enable_workload_profiles=True,
719719
mtls_enabled=None,
720+
p2p_encryption_enabled=None,
720721
enable_dedicated_gpu=False,
721722
no_wait=False,
722723
logs_dynamic_json_columns=False,
@@ -757,6 +758,7 @@ def update_managed_environment(cmd,
757758
min_nodes=None,
758759
max_nodes=None,
759760
mtls_enabled=None,
761+
p2p_encryption_enabled=None,
760762
no_wait=False,
761763
logs_dynamic_json_columns=None):
762764
raw_parameters = locals()

0 commit comments

Comments
 (0)