Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
357e6ce
Add custom ca certs to CLI
Nov 18, 2022
ac01260
Try with json string instead...
Nov 18, 2022
ce4faad
Revert "Try with json string instead..."
Nov 18, 2022
6e7dcfa
Try running correctly encoded certs
Nov 22, 2022
41453dc
Use normal cert
Nov 22, 2022
1ead95c
handle multiple CAs getting passed
Nov 23, 2022
08faaa2
try different encoding for read certs
Nov 24, 2022
7870b71
use correct test certs in decorator tests
Nov 28, 2022
9ec9e4f
add missing test
Nov 29, 2022
2f5a449
add registered feature
Nov 29, 2022
4302cff
add missing trailing space
Nov 29, 2022
edb55f9
add short option
Nov 29, 2022
279ec50
update help instructions
Nov 30, 2022
be320e5
Update src/aks-preview/azext_aks_preview/_params.py
FumingZhang Dec 1, 2022
d3bc6d4
Update src/aks-preview/azext_aks_preview/_params.py
FumingZhang Dec 1, 2022
cb488c2
remove unneeded new line indicator
Dec 6, 2022
418232d
use correct value for expected certs in create CMD
Dec 6, 2022
1e86430
Add live test recording
Dec 6, 2022
2345a40
Add new version information
Dec 8, 2022
1aba5f4
add new recording, change validation order
Dec 8, 2022
4c00614
fix lint error
Dec 8, 2022
ff0f839
add missing short names in help
Dec 8, 2022
053360c
lint fix blank line
Dec 9, 2022
1d83fc8
add missing help, update version
Dec 9, 2022
5fcbe99
Add exclusion for custom ca certs option
Dec 9, 2022
943a90c
Change ordering in help prompt
Dec 9, 2022
430f8e4
update history
Dec 9, 2022
cda029c
extract reused cert to const
Dec 9, 2022
9ddb578
Fix import path
Dec 9, 2022
7003ab6
lint fix
Dec 9, 2022
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
6 changes: 6 additions & 0 deletions linter_exclusions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ aks create:
node_public_ip_tags:
rule_exclusions:
- option_length_too_long
custom_ca_trust_certificates:
rule_exclusions:
- option_length_too_long
aks addon enable:
parameters:
appgw_watch_namespace:
Expand Down Expand Up @@ -218,6 +221,9 @@ aks update:
ksm_metric_labels_allow_list:
rule_exclusions:
- option_length_too_long
custom_ca_trust_certificates:
rule_exclusions:
- option_length_too_long
arcdata dc create:
parameters:
logs_ui_private_key_file:
Expand Down
6 changes: 6 additions & 0 deletions src/aks-preview/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ Pending

* Update the minimum required cli core version to `2.43.0`.
Comment thread
FumingZhang marked this conversation as resolved.

0.5.119
+++++++

* Add `--custom-ca-trust-certificates` option for custom CA in aks create and aks update
* Bumped dependency on azure-cli-core

0.5.118
+++++++

Expand Down
17 changes: 17 additions & 0 deletions src/aks-preview/azext_aks_preview/_consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,20 @@
# tag_name gives latest version released.
# Moving away from 1:n release to avoid unwanted breaking changes with auto upgrades.
CONST_DRAFT_CLI_VERSION = "v0.0.22"

CONST_CUSTOM_CA_TEST_CERT = '-----BEGIN CERTIFICATE-----\n' \
'MIICljCCAX4CCQC9zUAgqqqrWzANBgkqhkiG9w0BAQsFADANMQswCQYDVQQGEwJQ\n' \
'TDAeFw0yMjA5MTQwNjIzMjdaFw0yMjA5MTUwNjIzMjdaMA0xCzAJBgNVBAYTAlBM\n' \
'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAopKNIIbvvcPCw9fc4KLX\n' \
'KDtRZobp5L+/1hCN+3OGhk5NvSTpSUrFifxqc0o3IF7YkO3K1n2jAvCMXO16Bf9b\n' \
'OAR7VkCrwGFVkXNjM4wvXAX8CNNvjqd1zDPXSKdE7Wd8k3fTzx6nGUM0UgljIPhH\n' \
'yh4a4Zujd5Ig2P/ZSX0pGJm47JTtMu7MDFHVM5wRWcCrN/H0TCYPIvEOs0B8AZxc\n' \
'p3TF7A6veT5U9pVhQ3Xl9JN6LvvLqPxG3ea10rdv9DYzaiXmSY3ujI3Ri1Q11uWC\n' \
'dtrFIpFu5cHW2OBW+jBXxL0v8xQmkxTLik4BR/PLCl30wxKQNsq3pjDgu0mutKuu\n' \
'5wIDAQABMA0GCSqGSIb3DQEBCwUAA4IBAQAVEAIs/hLwTVCwpEXdoXR24LelNNuB\n' \
'/8ptK6lyjE11XwfMN3yy7F2oB1lrA4rI3j9obpDsHDJBNB13bi/lKgvAcbIn/Tyu\n' \
'RKThtUdPgxNnqDUyxnb3OofMF3gB8ePTu+jZpd3zrlEuxdl40ByATCSyOgR6DHMt\n' \
'SDd+joypnOHFAeSM+V0AaTelXSCK9OAWSAp5e6S76a6lRx+D5Xl3hBedBI0tX59h\n' \
'tEYNEGZaRElFU79WcEF0cH+ZW0+jJ95xE3thZffRz6QI6yF63m8aC9l9bbdJS2zg\n' \
'Yv8W+lCZi//ODeOBUugr++z9uj+vGk47JDSpV0n4JOun3ALUDJ0gqmcS\n' \
'-----END CERTIFICATE-----'
8 changes: 8 additions & 0 deletions src/aks-preview/azext_aks_preview/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,10 @@
- name: --enable-custom-ca-trust
type: bool
short-summary: Enable Custom CA Trust on agent node pool.
- name: --ca-certs --custom-ca-trust-certificates
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: --enable-keda
type: bool
short-summary: Enable KEDA workload auto-scaler.
Expand Down Expand Up @@ -914,6 +918,10 @@
type: string
short-summary: Public key path or key contents to install on node VMs for SSH access. For example,
'ssh-rsa AAAAB...snip...UcyupgH azureuser@linuxvm'.
- name: --ca-certs --custom-ca-trust-certificates
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.
examples:
- name: Reconcile the cluster back to its current state.
text: az aks update -g MyResourceGroup -n MyManagedCluster
Expand Down
3 changes: 3 additions & 0 deletions src/aks-preview/azext_aks_preview/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
validate_vm_set_type,
validate_vnet_subnet_id,
validate_enable_custom_ca_trust,
validate_custom_ca_trust_certificates,
validate_defender_config_parameter,
validate_defender_disable_and_enable_parameters,
validate_azuremonitorworkspaceresourceid,
Expand Down Expand Up @@ -348,6 +349,7 @@ def load_arguments(self, _):
c.argument('workload_runtime', arg_type=get_enum_type(workload_runtimes), default=CONST_WORKLOAD_RUNTIME_OCI_CONTAINER)
# no validation for aks create because it already only supports Linux.
c.argument('enable_custom_ca_trust', action='store_true')
c.argument('custom_ca_trust_certificates', options_list=["--custom-ca-trust-certificates", "--ca-certs"], is_preview=True, help="path to file containing list of new line separated CAs")
Comment thread
FumingZhang marked this conversation as resolved.
c.argument('enable_vpa', action='store_true', is_preview=True, help="enable vertical pod autoscaler for cluster")
c.argument('nodepool_allowed_host_ports', validator=validate_allowed_host_ports, is_preview=True, help="allowed host ports for agentpool")
c.argument('nodepool_asg_ids', validator=validate_application_security_groups, is_preview=True, help="application security groups for agentpool")
Expand Down Expand Up @@ -459,6 +461,7 @@ def load_arguments(self, _):
c.argument('enable_vpa', action='store_true', is_preview=True, help="enable vertical pod autoscaler for cluster")
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")

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/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,14 @@ def validate_enable_custom_ca_trust(namespace):
'--enable_custom_ca_trust can only be set for Linux nodepools')


def validate_custom_ca_trust_certificates(namespace):
"""Validates Custom CA Trust Certificates can only be used on Linux."""
if namespace.custom_ca_trust_certificates is not None and namespace.custom_ca_trust_certificates != "":
if hasattr(namespace, 'os_type') and namespace.os_type != "Linux":
raise ArgumentUsageError(
'--custom-ca-trust-certificates can only be set for linux nodepools')


def validate_disable_windows_outbound_nat(namespace):
"""Validates disable_windows_outbound_nat can only be used on Windows."""
if namespace.disable_windows_outbound_nat:
Expand Down
2 changes: 2 additions & 0 deletions src/aks-preview/azext_aks_preview/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ def aks_create(
enable_node_restriction=False,
enable_vpa=False,
enable_cilium_dataplane=False,
custom_ca_trust_certificates=None,
# nodepool
host_group_id=None,
crg_id=None,
Expand Down Expand Up @@ -819,6 +820,7 @@ def aks_update(
disable_vpa=False,
cluster_snapshot_id=None,
ssh_key_value=None,
custom_ca_trust_certificates=None
):
# DO NOT MOVE: get all the original parameters and save them as a dictionary
raw_parameters = locals()
Expand Down
63 changes: 63 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 @@ -4,6 +4,7 @@
# --------------------------------------------------------------------------------------------

import os
from base64 import b64encode
from types import SimpleNamespace
from typing import Dict, List, Optional, Tuple, TypeVar, Union

Expand Down Expand Up @@ -41,6 +42,7 @@
from azure.cli.core.commands import AzCliCommand
from azure.cli.core.profiles import ResourceType
from azure.cli.core.util import get_file_json
from azure.cli.core.util import read_file_content
from knack.log import get_logger
from knack.prompting import prompt_y_n

Expand Down Expand Up @@ -1979,6 +1981,31 @@ def get_disable_keda(self) -> bool:
"""
return self._get_disable_keda(enable_validation=True)

def get_custom_ca_trust_certificates(self) -> Union[List[bytes], None]:
"""Obtain the value of custom ca trust certificates.

:return: List[str] or None
"""
custom_ca_certs_file_path = self.raw_param.get("custom_ca_trust_certificates")
if not custom_ca_certs_file_path:
return None
if not os.path.isfile(custom_ca_certs_file_path):
raise InvalidArgumentValueError(
"{} is not valid file, or not accessible.".format(
custom_ca_certs_file_path
)
)
# CAs are supposed to be separated with a new line, we filter out empty strings (e.g. some stray new line). We only allow up to 10 CAs
file_content = read_file_content(custom_ca_certs_file_path).split(os.linesep + os.linesep)
certs = [str.encode(x) for x in file_content if len(x) > 1]
if len(certs) > 10:
raise InvalidArgumentValueError(
"Only up to 10 new-line separated CAs can be passed, got {} instead.".format(
len(certs)
)
)
return certs

def get_defender_config(self) -> Union[ManagedClusterSecurityProfileDefender, None]:
"""Obtain the value of defender.

Expand Down Expand Up @@ -2559,6 +2586,22 @@ def set_up_defender(self, mc: ManagedCluster) -> ManagedCluster:

return mc

def set_up_custom_ca_trust_certificates(self, mc: ManagedCluster) -> ManagedCluster:
"""Set up Custom CA Trust Certificates for the ManagedCluster object.

:return: the ManagedCluster object
"""
self._ensure_mc(mc)

ca_certs = self.context.get_custom_ca_trust_certificates()
if ca_certs:
if mc.security_profile is None:
mc.security_profile = self.models.ManagedClusterSecurityProfile()

mc.security_profile.custom_ca_trust_certificates = ca_certs

return mc

def set_up_node_restriction(self, mc: ManagedCluster) -> ManagedCluster:
"""Set up security profile nodeRestriction for the ManagedCluster object.

Expand Down Expand Up @@ -2645,6 +2688,8 @@ def construct_mc_profile_preview(self, bypass_restore_defaults: bool = False) ->
mc = self.set_up_vpa(mc)
# set up kube-proxy config
mc = self.set_up_kube_proxy_config(mc)
# set up custom ca trust certificates
mc = self.set_up_custom_ca_trust_certificates(mc)

# DO NOT MOVE: keep this at the bottom, restore defaults
mc = self._restore_defaults_in_mc(mc)
Expand Down Expand Up @@ -3069,6 +3114,22 @@ def update_defender(self, mc: ManagedCluster) -> ManagedCluster:

return mc

def update_custom_ca_trust_certificates(self, mc: ManagedCluster) -> ManagedCluster:
"""Update Custom CA Trust Certificates for the ManagedCluster object.

:return: the ManagedCluster object
"""
self._ensure_mc(mc)

ca_certs = self.context.get_custom_ca_trust_certificates()
if ca_certs:
if mc.security_profile is None:
mc.security_profile = self.models.ManagedClusterSecurityProfile()

mc.security_profile.custom_ca_trust_certificates = ca_certs

return mc

def update_azure_monitor_profile(self, mc: ManagedCluster) -> ManagedCluster:
"""Update azure monitor profile for the ManagedCluster object.
:return: the ManagedCluster object
Expand Down Expand Up @@ -3246,5 +3307,7 @@ def update_mc_profile_preview(self) -> ManagedCluster:
mc = self.update_outbound_type_in_network_profile(mc)
# update kube proxy config
mc = self.update_kube_proxy_config(mc)
# update custom ca trust certificates
mc = self.update_custom_ca_trust_certificates(mc)

return mc
33 changes: 33 additions & 0 deletions src/aks-preview/azext_aks_preview/tests/latest/data/certs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
-----BEGIN CERTIFICATE-----
MIICljCCAX4CCQC9zUAgqqqrWzANBgkqhkiG9w0BAQsFADANMQswCQYDVQQGEwJQ
TDAeFw0yMjA5MTQwNjIzMjdaFw0yMjA5MTUwNjIzMjdaMA0xCzAJBgNVBAYTAlBM
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAopKNIIbvvcPCw9fc4KLX
KDtRZobp5L+/1hCN+3OGhk5NvSTpSUrFifxqc0o3IF7YkO3K1n2jAvCMXO16Bf9b
OAR7VkCrwGFVkXNjM4wvXAX8CNNvjqd1zDPXSKdE7Wd8k3fTzx6nGUM0UgljIPhH
yh4a4Zujd5Ig2P/ZSX0pGJm47JTtMu7MDFHVM5wRWcCrN/H0TCYPIvEOs0B8AZxc
p3TF7A6veT5U9pVhQ3Xl9JN6LvvLqPxG3ea10rdv9DYzaiXmSY3ujI3Ri1Q11uWC
dtrFIpFu5cHW2OBW+jBXxL0v8xQmkxTLik4BR/PLCl30wxKQNsq3pjDgu0mutKuu
5wIDAQABMA0GCSqGSIb3DQEBCwUAA4IBAQAVEAIs/hLwTVCwpEXdoXR24LelNNuB
/8ptK6lyjE11XwfMN3yy7F2oB1lrA4rI3j9obpDsHDJBNB13bi/lKgvAcb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