Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d13e038
Add options for users to specify guardrails
NickKeller Apr 24, 2023
9b56b8d
Fix lint errors, add to HISTORY.rst
NickKeller Apr 24, 2023
d8a6d8a
Merge branch 'main' into nikelle/aks-guardrails
NickKeller Apr 24, 2023
f9f0438
Fix unit tests again
NickKeller Apr 24, 2023
bf4b704
Fix lint errors
NickKeller Apr 25, 2023
4369974
Mark test as live only
NickKeller Apr 26, 2023
54a2e35
Add additional live_only annotation, fix help
NickKeller Apr 26, 2023
499ad8e
Remove live only annotation, remove exclusions just for running the p…
NickKeller May 1, 2023
3e0f9e1
Add missing ssh key value
NickKeller May 1, 2023
03b0a20
Fixed update command, fixed checks
NickKeller May 2, 2023
57119bf
Update test command to enable policy addon in create
NickKeller May 4, 2023
3f69bbd
Add guardrails create scenario recording
NickKeller May 4, 2023
5c447ba
Add update recordings
NickKeller May 17, 2023
fd1adaa
Merge branch 'main' into nikelle/aks-guardrails
NickKeller May 17, 2023
50b3fd5
Update params, undo some formatting changes
NickKeller May 22, 2023
f736405
Merge branch 'nikelle/aks-guardrails' of github.com:NickKeller/azure-…
NickKeller May 22, 2023
49f77b7
Fixed help message
NickKeller May 22, 2023
6964a53
Fix formatting changes in params.py
NickKeller May 22, 2023
40997d9
Fix formatting changes in custom.py
NickKeller May 22, 2023
75bae92
Fix formatting changes in mc decorator
NickKeller May 22, 2023
ddd86ef
another formatting fix params.py
NickKeller May 22, 2023
1d99c2d
Last mc decorator formatting, fix formatting in test_validators
NickKeller May 22, 2023
4f007e0
another test_validators
NickKeller May 22, 2023
771a34a
Fix whitespace
NickKeller May 22, 2023
8659bf8
use extract_comma_sepatated_string
NickKeller May 22, 2023
dc094ab
Add back guardrails live tests to ignored because they require featur…
NickKeller May 22, 2023
17c670d
Add live_only annotation back
NickKeller May 23, 2023
e8ef7c7
Fix linter errors
NickKeller May 24, 2023
232c5cf
Refactor common code into helper function
NickKeller May 25, 2023
04b848c
Fix lint error
NickKeller May 25, 2023
ab288d7
Remove live_only annotation, move version to proper place
NickKeller May 26, 2023
9a8c719
Added cli flag to pass custom header through
NickKeller May 26, 2023
a6b4c21
Remove tests from exclude
NickKeller May 26, 2023
642eee2
Add httpcustomfeatures recordings
NickKeller May 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/aks-preview/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ Pending
+++++++
* Vendor new SDK and bump API version to 2023-04-02-preview.

0.5.140
+++++++
* Allow options for specifying guardrails profile arguments

0.5.139
* `az aks create` and `az aks nodepool add`: Add warning message when specifying `--os-sku` to `Mariner` or `CBLMariner`.

Expand Down
5 changes: 5 additions & 0 deletions src/aks-preview/azext_aks_preview/_consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@
CONST_AUTOUPGRADE_CONFIGURATION_NAME = "aksManagedAutoUpgradeSchedule"
CONST_NODEOSUPGRADE_CONFIGURATION_NAME = "aksManagedNodeOSUpgradeSchedule"

# Guardrails Level Consts
CONST_GUARDRAILSLEVEL_OFF = "Off"
CONST_GUARDRAILSLEVEL_WARNING = "Warning"
CONST_GUARDRAILSLEVEL_ENFORCEMENT = "Enforcement"

CONST_AZURE_SERVICE_MESH_MODE_DISABLED = "Disabled"
CONST_AZURE_SERVICE_MESH_MODE_ISTIO = "Istio"
CONST_AZURE_SERVICE_MESH_INGRESS_MODE_EXTERNAL = "External"
Expand Down
30 changes: 29 additions & 1 deletion src/aks-preview/azext_aks_preview/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
If monitoring addon is enabled --no-wait argument will have no effect
virtual-node - enable AKS Virtual Node. Requires --aci-subnet-name to provide the name of an existing subnet for the Virtual Node to use.
aci-subnet-name must be in the same vnet which is specified by --vnet-subnet-id (required as well).
azure-policy - enable Azure policy. The Azure Policy add-on for AKS enables at-scale enforcements and safeguards on your clusters in a centralized, consistent manner.
azure-policy - enable Azure policy. The Azure Policy add-on for AKS enables at-scale enforcements and safeguards on your clusters in a centralized, consistent manner. Required if enabling Guardrails
Learn more at aka.ms/aks/policy.
ingress-appgw - enable Application Gateway Ingress Controller addon (PREVIEW).
confcom - enable confcom addon, this will enable SGX device plugin by default(PREVIEW).
Expand Down Expand Up @@ -525,6 +525,15 @@
- name: --node-public-ip-tags
type: string
short-summary: The ipTags of the node public IPs.
- name: --guardrails-level
type: string
short-summary: The Guardrails Level. Accepted Values are [Off, Warning]. Requires azure policy addon to be enabled
- name: --guardrails-version
type: string
short-summary: The version of Guardrails to use. Default "v1.0.0" Use the ListGuardrailsVersions API to discover available versions
- name: --guardrails-excluded-ns
type: string
short-summary: Comma-separated list of Kubernetes namespaces to exclude from Guardrails
- name: --enable-asm --enable-azure-service-mesh
type: bool
short-summary: Enable Azure Service Mesh.
Expand Down Expand Up @@ -611,6 +620,10 @@
text: az aks create -g MyResourceGroup -n MyManagedCluster --network-plugin none
- name: Create a kubernetes cluster with Custom CA Trust enabled.
text: az aks create -g MyResourceGroup -n MyManagedCluster --enable-custom-ca-trust
- name: Create a kubernetes cluster with guardrails set to "Warning"
text: az aks create -g MyResourceGroup -n MyManagedCluster --guardrails-level Warning --enable-addons azure-policy
- name: Create a kubernetes cluster with guardrails set to "Warning" and some namespaces excluded
text: az aks create -g MyResourceGroup -n MyManagedCluster --guardrails-level Warning --guardrails-excluded-ns ns1,ns2 --enable-addons azure-policy
- name: Create a kubernetes cluster with Azure Service Mesh enabled.
text: az aks create -g MyResourceGroup -n MyManagedCluster --enable-azure-service-mesh
- name: Create a kubernetes cluster with Azure Monitor Metrics enabled.
Expand Down Expand Up @@ -1000,6 +1013,15 @@
type: string
short-summary: Path to a file containing up to 10 blank line separated certificates. Only valid for linux nodes.
long-summary: These certificates are used by Custom CA Trust features and will be added to trust stores of nodes. Requires Custom CA Trust to be enabled on the node.
- name: --guardrails-level
type: string
short-summary: The Guardrails Level. Accepted Values are [Off, Warning]. Requires azure policy addon to be enabled
- name: --guardrails-version
type: string
short-summary: The version of Guardrails to use. Default "v1.0.0" Use the ListGuardrailsVersions API to discover available versions
- name: --guardrails-excluded-ns
type: string
short-summary: Comma-separated list of Kubernetes namespaces to exclude from Guardrails. Use "" to clear a previously non-empty list
examples:
- name: Reconcile the cluster back to its current state.
text: az aks update -g MyResourceGroup -n MyManagedCluster
Expand Down Expand Up @@ -1059,6 +1081,12 @@
text: az aks update -g MyResourceGroup -n MyManagedCluster --enable-windows-gmsa --gmsa-dns-server "10.240.0.4" --gmsa-root-domain-name "contoso.com"
- name: Update a existing managed cluster to a managed cluster snapshot.
text: az aks update -g MyResourceGroup -n MyManagedCluster --cluster-snapshot-id "/subscriptions/00000/resourceGroups/AnotherResourceGroup/providers/Microsoft.ContainerService/managedclustersnapshots/mysnapshot1"
- name: Update a kubernetes cluster with guardrails set to "Warning". Assumes azure policy addon is already enabled
text: az aks update -g MyResourceGroup -n MyManagedCluster --guardrails-level Warning
- name: Update a kubernetes cluster with guardrails set to "Warning" and some namespaces excluded. Assumes azure policy addon is already enabled
text: az aks update -g MyResourceGroup -n MyManagedCluster --guardrails-level Warning --guardrails-excluded-ns ns1,ns2
- name: Update a kubernetes cluster to clear any namespaces excluded from guardrails. Assumes azure policy addon is already enabled
text: az aks update -g MyResourceGroup -n MyManagedCluster --guardrails-excluded-ns ""
"""

helps['aks kollect'] = """
Expand Down
18 changes: 18 additions & 0 deletions src/aks-preview/azext_aks_preview/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

from azext_aks_preview._client_factory import get_nodepool_snapshots_client, get_mc_snapshots_client

from azure.cli.command_modules.acs._validators import (
extract_comma_separated_string,
)

logger = get_logger(__name__)

# type variables
Expand Down Expand Up @@ -282,3 +286,17 @@ def check_is_apiserver_vnet_integration_cluster(mc: ManagedCluster) -> bool:
if mc and mc.api_server_access_profile:
return bool(mc.api_server_access_profile.enable_vnet_integration)
return False


def setup_common_guardrails_profile(level, version, excludedNamespaces, mc: ManagedCluster, models) -> ManagedCluster:
if (level is not None or version is not None or excludedNamespaces is not None) and mc.guardrails_profile is None:
mc.guardrails_profile = models.GuardrailsProfile(
level=level,
version=version
)
# replace values with provided values
if excludedNamespaces is not None:
mc.guardrails_profile.excluded_namespaces = extract_comma_separated_string(
excludedNamespaces, enable_strip=True, keep_none=True, default_value=[])

return mc
19 changes: 19 additions & 0 deletions src/aks-preview/azext_aks_preview/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@
CONST_WEEKINDEX_FIRST,
CONST_WEEKINDEX_FOURTH,
CONST_WEEKINDEX_LAST,
CONST_GUARDRAILSLEVEL_OFF,
CONST_GUARDRAILSLEVEL_WARNING,
CONST_GUARDRAILSLEVEL_ENFORCEMENT,
CONST_AZURE_SERVICE_MESH_INGRESS_MODE_EXTERNAL,
CONST_AZURE_SERVICE_MESH_INGRESS_MODE_INTERNAL,
CONST_WEEKINDEX_SECOND,
CONST_WEEKINDEX_THIRD,
CONST_WEEKLY_MAINTENANCE_SCHEDULE,
Expand Down Expand Up @@ -230,6 +235,13 @@

keyvault_network_access_types = [CONST_AZURE_KEYVAULT_NETWORK_ACCESS_PUBLIC, CONST_AZURE_KEYVAULT_NETWORK_ACCESS_PRIVATE]

# consts for guardrails level
guardrails_levels = [
CONST_GUARDRAILSLEVEL_OFF,
CONST_GUARDRAILSLEVEL_WARNING,
CONST_GUARDRAILSLEVEL_ENFORCEMENT
]

# azure service mesh
ingress_gateway_types = [
CONST_AZURE_SERVICE_MESH_INGRESS_MODE_EXTERNAL,
Expand Down Expand Up @@ -417,6 +429,10 @@ def load_arguments(self, _):
c.argument('nodepool_asg_ids', validator=validate_application_security_groups, is_preview=True, help="application security groups for agentpool")
c.argument('node_public_ip_tags', arg_type=tags_type, validator=validate_node_public_ip_tags,
help='space-separated tags: key[=value] [key[=value] ...].')
c.argument('guardrails_level', arg_type=get_enum_type(guardrails_levels), is_preview=True)
c.argument('guardrails_version', type=str,
help='The guardrails version', is_preview=True)
c.argument('guardrails_excluded_ns', type=str, is_preview=True)
# azure monitor profile
c.argument('enable_azuremonitormetrics', action='store_true')
c.argument('azure_monitor_workspace_resource_id', validator=validate_azuremonitorworkspaceresourceid)
Expand Down Expand Up @@ -538,6 +554,9 @@ def load_arguments(self, _):
c.argument('disable_vpa', action='store_true', is_preview=True, help="disable vertical pod autoscaler for cluster")
c.argument('cluster_snapshot_id', validator=validate_cluster_snapshot_id, is_preview=True)
c.argument('custom_ca_trust_certificates', options_list=["--custom-ca-trust-certificates", "--ca-certs"], validator=validate_custom_ca_trust_certificates, is_preview=True, help="path to file containing list of new line separated CAs")
c.argument('guardrails_level', arg_type=get_enum_type(guardrails_levels), is_preview=True)
c.argument('guardrails_version', help='The guardrails version', is_preview=True)
c.argument('guardrails_excluded_ns', is_preview=True)

with self.argument_context('aks upgrade') as c:
c.argument('kubernetes_version', completer=get_k8s_upgrades_completion_list)
Expand Down
8 changes: 8 additions & 0 deletions src/aks-preview/azext_aks_preview/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,10 @@ def aks_create(
nodepool_allowed_host_ports=None,
nodepool_asg_ids=None,
node_public_ip_tags=None,
# guardrails parameters
guardrails_level=None,
guardrails_version=None,
guardrails_excluded_ns=None,
# azure service mesh
enable_azure_service_mesh=None,
# azure monitor profile
Expand Down Expand Up @@ -736,6 +740,10 @@ def aks_update(
disable_vpa=False,
cluster_snapshot_id=None,
custom_ca_trust_certificates=None,
# guardrails parameters
guardrails_level=None,
guardrails_version=None,
guardrails_excluded_ns=None,
):
# DO NOT MOVE: get all the original parameters and save them as a dictionary
raw_parameters = locals()
Expand Down
42 changes: 42 additions & 0 deletions src/aks-preview/azext_aks_preview/managed_cluster_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
check_is_private_cluster,
check_is_apiserver_vnet_integration_cluster,
get_cluster_snapshot_by_snapshot_id,
setup_common_guardrails_profile
)
from azext_aks_preview._loadbalancer import create_load_balancer_profile
from azext_aks_preview._loadbalancer import (
Expand Down Expand Up @@ -162,6 +163,15 @@ def external_functions(self) -> SimpleNamespace:
self.__external_functions = SimpleNamespace(**external_functions)
return self.__external_functions

def get_guardrails_level(self) -> Union[str, None]:
return self.raw_param.get("guardrails_level")

def get_guardrails_excluded_namespaces(self) -> Union[str, None]:
return self.raw_param.get("guardrails_excluded_ns")

def get_guardrails_version(self) -> Union[str, None]:
return self.raw_param.get("guardrails_version")

# pylint: disable=no-self-use
def __validate_pod_identity_with_kubenet(self, mc, enable_pod_identity, enable_pod_identity_with_kubenet):
"""Helper function to check the validity of serveral pod identity related parameters.
Expand Down Expand Up @@ -2654,6 +2664,14 @@ def set_up_auto_upgrade_profile(self, mc: ManagedCluster) -> ManagedCluster:
mc.auto_upgrade_profile.node_os_upgrade_channel = node_os_upgrade_channel
return mc

def set_up_guardrails_profile(self, mc: ManagedCluster) -> ManagedCluster:
excludedNamespaces = self.context.get_guardrails_excluded_namespaces()
version = self.context.get_guardrails_version()
level = self.context.get_guardrails_level()
# provided any value?
mc = setup_common_guardrails_profile(level, version, excludedNamespaces, mc, self.models)
return mc

def set_up_azure_service_mesh_profile(self, mc: ManagedCluster) -> ManagedCluster:
"""Set up azure service mesh for the ManagedCluster object.

Expand Down Expand Up @@ -2720,6 +2738,8 @@ def construct_mc_profile_preview(self, bypass_restore_defaults: bool = False) ->
mc = self.set_up_node_resource_group_profile(mc)
# set up auto upgrade profile
mc = self.set_up_auto_upgrade_profile(mc)
# set up guardrails profile
mc = self.set_up_guardrails_profile(mc)
# set up azure service mesh profile
mc = self.set_up_azure_service_mesh_profile(mc)
# set up azure monitor profile
Expand Down Expand Up @@ -3436,6 +3456,26 @@ def update_auto_upgrade_profile(self, mc: ManagedCluster) -> ManagedCluster:
mc.auto_upgrade_profile.node_os_upgrade_channel = node_os_upgrade_channel
return mc

def update_guardrails_profile(self, mc: ManagedCluster) -> ManagedCluster:
"""Update guardrails profile for the ManagedCluster object
:return: the ManagedCluster object
"""

self._ensure_mc(mc)

excludedNamespaces = self.context.get_guardrails_excluded_namespaces()
version = self.context.get_guardrails_version()
level = self.context.get_guardrails_level()

mc = setup_common_guardrails_profile(level, version, excludedNamespaces, mc, self.models)

if level is not None:
mc.guardrails_profile.level = level
if version is not None:
mc.guardrails_profile.version = version

return mc

def update_azure_service_mesh_profile(self, mc: ManagedCluster) -> ManagedCluster:
"""Update azure service mesh profile for the ManagedCluster object.
"""
Expand Down Expand Up @@ -3561,6 +3601,8 @@ def update_mc_profile_preview(self) -> ManagedCluster:
mc = self.update_node_resource_group_profile(mc)
# update auto upgrade profile
mc = self.update_auto_upgrade_profile(mc)
# update guardrails_profile
mc = self.update_guardrails_profile(mc)
# update auto upgrade profile
mc = self.update_upgrade_settings(mc)

Expand Down
Loading