Skip to content

Commit

Permalink
[AKS] az aks create/update: Add --nrg-lockdown-restriction-level
Browse files Browse the repository at this point in the history
…parameter to support specifying restriction level on the managed node resource group (#30391)
  • Loading branch information
y1hao authored Nov 29, 2024
1 parent 9c16b21 commit a4eb750
Show file tree
Hide file tree
Showing 8 changed files with 1,866 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/azure-cli/azure/cli/command_modules/acs/_consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@
CONST_NODE_OS_CHANNEL_UNMANAGED = "Unmanaged"
CONST_NODE_OS_CHANNEL_SECURITY_PATCH = "SecurityPatch"

# consts for nrg-lockdown restriction level
CONST_NRG_LOCKDOWN_RESTRICTION_LEVEL_READONLY = "ReadOnly"
CONST_NRG_LOCKDOWN_RESTRICTION_LEVEL_UNRESTRICTED = "Unrestricted"

# network plugin
CONST_NETWORK_PLUGIN_KUBENET = "kubenet"
CONST_NETWORK_PLUGIN_AZURE = "azure"
Expand Down
8 changes: 8 additions & 0 deletions src/azure-cli/azure/cli/command_modules/acs/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,10 @@
- name: --disable-acns-security
type: bool
short-summary: Used to disable advanced networking security features on a clusters when enabling advanced networking features with "--enable-acns".
- name: --nrg-lockdown-restriction-level
type: string
short-summary: Restriction level on the managed node resource group.
long-summary: The restriction level of permissions allowed on the cluster's managed node resource group, supported values are Unrestricted, and ReadOnly (recommended ReadOnly).
examples:
- name: Create a Kubernetes cluster with an existing SSH public key.
Expand Down Expand Up @@ -968,6 +972,10 @@
- name: --disable-acns-security
type: bool
short-summary: Used to disable advanced networking security features on a clusters when enabling advanced networking features with "--enable-acns".
- name: --nrg-lockdown-restriction-level
type: string
short-summary: Restriction level on the managed node resource group.
long-summary: The restriction level of permissions allowed on the cluster's managed node resource group, supported values are Unrestricted, and ReadOnly (recommended ReadOnly).
examples:
- name: Reconcile the cluster back to its current state.
Expand Down
11 changes: 10 additions & 1 deletion src/azure-cli/azure/cli/command_modules/acs/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@
CONST_LOAD_BALANCER_BACKEND_POOL_TYPE_NODE_IP,
CONST_LOAD_BALANCER_BACKEND_POOL_TYPE_NODE_IP_CONFIGURATION,
CONST_AZURE_SERVICE_MESH_INGRESS_MODE_EXTERNAL,
CONST_AZURE_SERVICE_MESH_INGRESS_MODE_INTERNAL)
CONST_AZURE_SERVICE_MESH_INGRESS_MODE_INTERNAL,
CONST_NRG_LOCKDOWN_RESTRICTION_LEVEL_READONLY,
CONST_NRG_LOCKDOWN_RESTRICTION_LEVEL_UNRESTRICTED)
from azure.cli.command_modules.acs.azurecontainerstorage._consts import (
CONST_ACSTOR_ALL,
CONST_DISK_TYPE_EPHEMERAL_VOLUME_ONLY,
Expand Down Expand Up @@ -186,6 +188,11 @@
CONST_GPU_INSTANCE_PROFILE_MIG7_G,
]

nrg_lockdown_restriction_levels = [
CONST_NRG_LOCKDOWN_RESTRICTION_LEVEL_READONLY,
CONST_NRG_LOCKDOWN_RESTRICTION_LEVEL_UNRESTRICTED,
]

# consts for maintenance configuration
schedule_types = [
CONST_DAILY_MAINTENANCE_SCHEDULE,
Expand Down Expand Up @@ -306,6 +313,7 @@ def load_arguments(self, _):
c.argument('load_balancer_outbound_ports', type=int, validator=validate_load_balancer_outbound_ports)
c.argument('load_balancer_idle_timeout', type=int, validator=validate_load_balancer_idle_timeout)
c.argument('load_balancer_backend_pool_type', arg_type=get_enum_type(backend_pool_types))
c.argument('nrg_lockdown_restriction_level', arg_type=get_enum_type(nrg_lockdown_restriction_levels))
c.argument('nat_gateway_managed_outbound_ip_count', type=int, validator=validate_nat_gateway_managed_outbound_ip_count)
c.argument('nat_gateway_idle_timeout', type=int, validator=validate_nat_gateway_idle_timeout)
c.argument('outbound_type', arg_type=get_enum_type(outbound_types))
Expand Down Expand Up @@ -481,6 +489,7 @@ def load_arguments(self, _):
c.argument('load_balancer_outbound_ports', type=int, validator=validate_load_balancer_outbound_ports)
c.argument('load_balancer_idle_timeout', type=int, validator=validate_load_balancer_idle_timeout)
c.argument('load_balancer_backend_pool_type', arg_type=get_enum_type(backend_pool_types))
c.argument('nrg_lockdown_restriction_level', arg_type=get_enum_type(nrg_lockdown_restriction_levels))
c.argument('nat_gateway_managed_outbound_ip_count', type=int, validator=validate_nat_gateway_managed_outbound_ip_count)
c.argument('nat_gateway_idle_timeout', type=int, validator=validate_nat_gateway_idle_timeout)
c.argument('network_dataplane', arg_type=get_enum_type(network_dataplanes))
Expand Down
2 changes: 2 additions & 0 deletions src/azure-cli/azure/cli/command_modules/acs/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ def aks_create(
attach_acr=None,
skip_subnet_role_assignment=False,
node_resource_group=None,
nrg_lockdown_restriction_level=None,
k8s_support_plan=None,
enable_defender=False,
defender_config=None,
Expand Down Expand Up @@ -732,6 +733,7 @@ def aks_update(
disable_windows_gmsa=False,
attach_acr=None,
detach_acr=None,
nrg_lockdown_restriction_level=None,
enable_defender=False,
disable_defender=False,
defender_config=None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ aks create:
disable_acns_observability:
rule_exclusions:
- option_length_too_long
nrg_lockdown_restriction_level:
rule_exclusions:
- option_length_too_long

aks enable-addons:
parameters:
Expand Down Expand Up @@ -168,6 +171,9 @@ aks update:
disable_acns_observability:
rule_exclusions:
- option_length_too_long
nrg_lockdown_restriction_level:
rule_exclusions:
- option_length_too_long
aks nodepool add:
parameters:
disable_windows_outbound_nat:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2022,6 +2022,27 @@ def get_load_balancer_backend_pool_type(self) -> Union[str, None]:
# this parameter does not need validation
return load_balancer_backend_pool_type

def get_nrg_lockdown_restriction_level(self) -> Union[str, None]:
"""Obtain the value of nrg_lockdown_restriction_level.
:return: string or None
"""
# read the original value passed by the command
nrg_lockdown_restriction_level = self.raw_param.get("nrg_lockdown_restriction_level")

# In create mode, try to read the property value corresponding to the parameter from the `mc` object.
if self.decorator_mode == DecoratorMode.CREATE:
if (
self.mc and
hasattr(self.mc, "nrg_lockdown_restriction_level") and # for backward compatibility
self.mc.node_resource_group_profile and
self.mc.node_resource_group_profile.restriction_level is not None
):
nrg_lockdown_restriction_level = self.mc.node_resource_group_profile.restriction_level

# this parameter does not need dynamic completion
# this parameter does not need validation
return nrg_lockdown_restriction_level

def get_nat_gateway_managed_outbound_ip_count(self) -> Union[int, None]:
"""Obtain the value of nat_gateway_managed_outbound_ip_count.
Expand Down Expand Up @@ -6482,6 +6503,19 @@ def set_up_metrics_profile(self, mc: ManagedCluster) -> ManagedCluster:

return mc

def set_up_node_resource_group_profile(self, mc: ManagedCluster) -> ManagedCluster:
"""Set up node resource group profile for the ManagedCluster object.
:return: the ManagedCluster object
"""
self._ensure_mc(mc)

node_resource_group_profile = None
nrg_lockdown_restriction_level = self.context.get_nrg_lockdown_restriction_level()
if nrg_lockdown_restriction_level:
node_resource_group_profile = self.models.ManagedClusterNodeResourceGroupProfile(restriction_level=nrg_lockdown_restriction_level)
mc.node_resource_group_profile = node_resource_group_profile
return mc

def construct_mc_profile_default(self, bypass_restore_defaults: bool = False) -> ManagedCluster:
"""The overall controller used to construct the default ManagedCluster profile.
Expand Down Expand Up @@ -6560,6 +6594,9 @@ def construct_mc_profile_default(self, bypass_restore_defaults: bool = False) ->
mc = self.set_up_azure_container_storage(mc)
# set up metrics profile
mc = self.set_up_metrics_profile(mc)
# set up node resource group profile
mc = self.set_up_node_resource_group_profile(mc)

# DO NOT MOVE: keep this at the bottom, restore defaults
if not bypass_restore_defaults:
mc = self._restore_defaults_in_mc(mc)
Expand Down Expand Up @@ -7825,6 +7862,21 @@ def update_app_routing_profile(self, mc: ManagedCluster) -> ManagedCluster:

return mc

def update_node_resource_group_profile(self, mc: ManagedCluster) -> ManagedCluster:
"""Update node resource group profile for the ManagedCluster object.
:return: the ManagedCluster object
"""
self._ensure_mc(mc)

nrg_lockdown_restriction_level = self.context.get_nrg_lockdown_restriction_level()
if nrg_lockdown_restriction_level is not None:
if mc.node_resource_group_profile is None:
mc.node_resource_group_profile = (
self.models.ManagedClusterNodeResourceGroupProfile() # pylint: disable=no-member
)
mc.node_resource_group_profile.restriction_level = nrg_lockdown_restriction_level
return mc

def _enable_keyvault_secret_provider_addon(self, mc: ManagedCluster) -> None:
"""Helper function to enable keyvault secret provider addon for the ManagedCluster object.
Expand Down Expand Up @@ -8389,6 +8441,8 @@ def update_mc_profile_default(self) -> ManagedCluster:
mc = self.update_upgrade_settings(mc)
# update metrics profile
mc = self.update_metrics_profile(mc)
# update node resource group profile
mc = self.update_node_resource_group_profile(mc)
return mc

def check_is_postprocessing_required(self, mc: ManagedCluster) -> bool:
Expand Down
Loading

0 comments on commit a4eb750

Please sign in to comment.