Skip to content

Commit f5b0046

Browse files
authored
[AKS] az aks update: Add --disable-http-proxy and --enable-http-proxy options (#32996)
1 parent d443a13 commit f5b0046

File tree

10 files changed

+283
-26
lines changed

10 files changed

+283
-26
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,12 @@
10151015
- name: --http-proxy-config
10161016
type: string
10171017
short-summary: HTTP Proxy configuration for this cluster.
1018+
- name: --disable-http-proxy
1019+
type: bool
1020+
short-summary: Disable HTTP Proxy Configuration on the cluster.
1021+
- name: --enable-http-proxy
1022+
type: bool
1023+
short-summary: Enable HTTP Proxy Configuration on the cluster.
10181024
- name: --enable-oidc-issuer
10191025
type: bool
10201026
short-summary: Enable OIDC issuer.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,8 @@ def load_arguments(self, _):
743743
c.argument('disable_image_cleaner', action='store_true', validator=validate_image_cleaner_enable_disable_mutually_exclusive)
744744
c.argument('image_cleaner_interval_hours', type=int)
745745
c.argument('http_proxy_config')
746+
c.argument('disable_http_proxy', action='store_true')
747+
c.argument('enable_http_proxy', action='store_true')
746748
c.argument('custom_ca_trust_certificates', options_list=["--custom-ca-trust-certificates", "--ca-certs"], validator=validate_custom_ca_trust_certificates, help="path to file containing list of new line separated CAs")
747749
c.argument('enable_run_command', action='store_true')
748750
c.argument('disable_run_command', action='store_true')

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,8 @@ def aks_update(
11481148
disable_image_cleaner=False,
11491149
image_cleaner_interval_hours=None,
11501150
http_proxy_config=None,
1151+
disable_http_proxy=False,
1152+
enable_http_proxy=False,
11511153
enable_keda=False,
11521154
disable_keda=False,
11531155
enable_vpa=False,

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,12 @@ aks update:
230230
disable_container_network_logs:
231231
rule_exclusions:
232232
- option_length_too_long
233+
disable_http_proxy:
234+
rule_exclusions:
235+
- option_length_too_long
236+
enable_http_proxy:
237+
rule_exclusions:
238+
- option_length_too_long
233239
aks nodepool add:
234240
parameters:
235241
disable_windows_outbound_nat:

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

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2021,6 +2021,64 @@ def get_http_proxy_config(self) -> Union[Dict, ManagedClusterHTTPProxyConfig, No
20212021
# this parameter does not need validation
20222022
return http_proxy_config
20232023

2024+
def get_disable_http_proxy(self) -> bool:
2025+
"""Obtain the value of disable_http_proxy.
2026+
2027+
This function will verify the parameter by default. If both enable_http_proxy and disable_http_proxy are
2028+
specified, raise a MutuallyExclusiveArgumentError.
2029+
2030+
:return: bool
2031+
"""
2032+
return self._get_disable_http_proxy(enable_validation=True)
2033+
2034+
def _get_disable_http_proxy(self, enable_validation: bool = False) -> bool:
2035+
"""Internal function to obtain the value of disable_http_proxy.
2036+
2037+
This function supports the option of enable_validation. When enabled, if both enable_http_proxy and
2038+
disable_http_proxy are specified, raise a MutuallyExclusiveArgumentError.
2039+
2040+
:return: bool
2041+
"""
2042+
# read the original value passed by the command
2043+
disable_http_proxy = self.raw_param.get("disable_http_proxy")
2044+
2045+
if enable_validation:
2046+
if disable_http_proxy and self._get_enable_http_proxy(enable_validation=False):
2047+
raise MutuallyExclusiveArgumentError(
2048+
"Cannot specify --enable-http-proxy and --disable-http-proxy at the same time."
2049+
)
2050+
2051+
return disable_http_proxy
2052+
2053+
def get_enable_http_proxy(self) -> bool:
2054+
"""Obtain the value of enable_http_proxy.
2055+
2056+
This function will verify the parameter by default. If both enable_http_proxy and disable_http_proxy are
2057+
specified, raise a MutuallyExclusiveArgumentError.
2058+
2059+
:return: bool
2060+
"""
2061+
return self._get_enable_http_proxy(enable_validation=True)
2062+
2063+
def _get_enable_http_proxy(self, enable_validation: bool = False) -> bool:
2064+
"""Internal function to obtain the value of enable_http_proxy.
2065+
2066+
This function supports the option of enable_validation. When enabled, if both enable_http_proxy and
2067+
disable_http_proxy are specified, raise a MutuallyExclusiveArgumentError.
2068+
2069+
:return: bool
2070+
"""
2071+
# read the original value passed by the command
2072+
enable_http_proxy = self.raw_param.get("enable_http_proxy")
2073+
2074+
if enable_validation:
2075+
if enable_http_proxy and self._get_disable_http_proxy(enable_validation=False):
2076+
raise MutuallyExclusiveArgumentError(
2077+
"Cannot specify --enable-http-proxy and --disable-http-proxy at the same time."
2078+
)
2079+
2080+
return enable_http_proxy
2081+
20242082
def get_assignee_from_identity_or_sp_profile(self) -> Tuple[str, bool]:
20252083
"""Helper function to obtain the value of assignee from identity_profile or service_principal_profile.
20262084
@@ -8490,11 +8548,38 @@ def update_monitoring_profile_flow_logs(self, mc: ManagedCluster) -> ManagedClus
84908548
def update_http_proxy_config(self, mc: ManagedCluster) -> ManagedCluster:
84918549
"""Set up http proxy config for the ManagedCluster object.
84928550
8551+
Only updates if --http-proxy-config was explicitly provided, to avoid wiping existing config.
8552+
84938553
:return: the ManagedCluster object
84948554
"""
84958555
self._ensure_mc(mc)
84968556

8497-
mc.http_proxy_config = self.context.get_http_proxy_config()
8557+
http_proxy_config = self.context.get_http_proxy_config()
8558+
if http_proxy_config is not None:
8559+
mc.http_proxy_config = http_proxy_config
8560+
return mc
8561+
8562+
def update_http_proxy_enabled(self, mc: ManagedCluster) -> ManagedCluster:
8563+
"""Update http proxy enabled/disabled state for the ManagedCluster object.
8564+
8565+
:return: the ManagedCluster object
8566+
"""
8567+
self._ensure_mc(mc)
8568+
8569+
if self.context.get_disable_http_proxy():
8570+
if mc.http_proxy_config is None:
8571+
mc.http_proxy_config = (
8572+
self.models.ManagedClusterHTTPProxyConfig() # pylint: disable=no-member
8573+
)
8574+
mc.http_proxy_config.enabled = False
8575+
8576+
if self.context.get_enable_http_proxy():
8577+
if mc.http_proxy_config is None:
8578+
mc.http_proxy_config = (
8579+
self.models.ManagedClusterHTTPProxyConfig() # pylint: disable=no-member
8580+
)
8581+
mc.http_proxy_config.enabled = True
8582+
84988583
return mc
84998584

85008585
def update_identity(self, mc: ManagedCluster) -> ManagedCluster:
@@ -9800,6 +9885,8 @@ def update_mc_profile_default(self) -> ManagedCluster:
98009885
mc = self.update_identity_profile(mc)
98019886
# set up http proxy config
98029887
mc = self.update_http_proxy_config(mc)
9888+
# update http proxy enabled/disabled state
9889+
mc = self.update_http_proxy_enabled(mc)
98039890
# update workload autoscaler profile
98049891
mc = self.update_workload_auto_scaler_profile(mc)
98059892
# update kubernetes support plan

src/azure-cli/azure/cli/command_modules/acs/tests/latest/data/httpproxyconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"httpProxy": "http://cli-proxy-vm:3128/",
3-
"httpsProxy": "https://cli-proxy-vm:3129/",
3+
"httpsProxy": "http://cli-proxy-vm:3128/",
44
"noProxy": [
55
"localhost",
66
"127.0.0.1"

src/azure-cli/azure/cli/command_modules/acs/tests/latest/data/httpproxyconfig_update.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"httpProxy": "http://cli-proxy-vm:3128/",
3-
"httpsProxy": "https://cli-proxy-vm:3129/",
3+
"httpsProxy": "http://cli-proxy-vm:3128/",
44
"noProxy": [
55
"localhost",
66
"127.0.0.1"

src/azure-cli/azure/cli/command_modules/acs/tests/latest/data/setup_proxy.sh

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,12 @@ echo "setting up ${WORKDIR}"
77

88
pushd "$WORKDIR"
99

10-
apt update -y && apt install -y apt-transport-https curl gnupg make gcc < /dev/null
11-
12-
# add diladele apt key
13-
wget -qO - https://packages.diladele.com/diladele_pub.asc | apt-key add -
14-
15-
# add new repo
16-
tee /etc/apt/sources.list.d/squid413-ubuntu20.diladele.com.list <<EOF
17-
deb https://squid413-ubuntu20.diladele.com/ubuntu/ focal main
18-
EOF
19-
20-
# and install
21-
apt-get update && apt-get install -y squid-common squid-openssl squidclient libecap3 libecap3-dev < /dev/null
10+
apt-get update -y && apt-get install -y curl squid < /dev/null
2211

2312
mkdir -p /var/lib/squid
2413

25-
/usr/lib/squid/security_file_certgen -c -s /var/lib/squid/ssl_db -M 4MB || true
14+
/usr/lib/squid/security_file_certgen -c -s /var/lib/squid/ssl_db -M 4MB 2>/dev/null || \
15+
/usr/libexec/squid/security_file_certgen -c -s /var/lib/squid/ssl_db -M 4MB 2>/dev/null || true
2616

2717
chown -R proxy:proxy /var/lib/squid
2818

@@ -127,13 +117,11 @@ cp squidc.pem /usr/local/share/ca-certificates/squidc.crt
127117
update-ca-certificates
128118

129119
sed -i 's~http_access deny all~http_access allow all~' /etc/squid/squid.conf
130-
sed -i "s~http_port 3128~http_port $HOST:3128\nhttps_port $HOST:3129 tls-cert=/etc/squid/squidc.pem tls-key=/etc/squid/squidk.pem~" /etc/squid/squid.conf
120+
sed -i "s~http_port 3128~http_port $HOST:3128~" /etc/squid/squid.conf
131121

132122
systemctl restart squid
133123
systemctl status squid
134124

135125
# validation, fails VM creation if commands fail
136126
curl -fsSl -o /dev/null -w '%{http_code}\n' -x http://${HOST}:3128/ -I http://www.google.com
137127
curl -fsSl -o /dev/null -w '%{http_code}\n' -x http://${HOST}:3128/ -I https://www.google.com
138-
curl -fsSl -o /dev/null -w '%{http_code}\n' -x https://${HOST}:3129/ -I http://www.google.com
139-
curl -fsSl -o /dev/null -w '%{http_code}\n' -x https://${HOST}:3129/ -I https://www.google.com

0 commit comments

Comments
 (0)