Skip to content

Commit 5b22f40

Browse files
authored
ctrmgrd: default Kubernetes join to secure TLS verification (#28051)
Why I did it The default value of CFG_SER_INSECURE in dflt_cfg_ser was set to "true", causing kube_commands.py to skip TLS certificate verification when downloading the Kubernetes CA certificate during cluster join. Additionally, the insecure flag comparison used bare Python truthiness (if insecure:), which evaluates the string "false" as truthy — making the flag ineffective regardless of its value. Work item tracking Microsoft ADO: How I did it Changed CFG_SER_INSECURE default in dflt_cfg_ser from "true" to "false" in ctrmgrd.py Fixed kube_commands.py to compare the flag as a string: insecure.lower() == "true" instead of bare truthiness Updated sonic-kubernetes_master.yang default to "false" to align with runtime behavior How to verify it Set up a SONiC device configured to join a Kubernetes master with no explicit insecure field in ConfigDB KUBERNETES_MASTER|SERVER. Confirm that kube_join_master uses verified TLS by default. Confirm that setting insecure=true in ConfigDB restores the previous behavior.
1 parent 0169cfe commit 5b22f40

5 files changed

Lines changed: 9 additions & 9 deletions

File tree

src/sonic-ctrmgrd/ctrmgr/ctrmgrd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
CFG_SER_IP: "",
7474
CFG_SER_PORT: "6443",
7575
CFG_SER_DISABLE: "false",
76-
CFG_SER_INSECURE: "true"
76+
CFG_SER_INSECURE: "false"
7777
}
7878

7979
dflt_st_ser = {

src/sonic-ctrmgrd/ctrmgr/kube_commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def _gen_cli_kubeconf(server, port, insecure):
249249
client-certificate-data: {{ ame_crt }}
250250
client-key-data: {{ ame_key }}
251251
"""
252-
if insecure:
252+
if insecure.lower() == "true":
253253
r = requests.get(K8S_CA_URL.format(server, port), cert=(AME_CRT, AME_KEY), verify=False)
254254
else:
255255
r = requests.get(K8S_CA_URL.format(server, port), cert=(AME_CRT, AME_KEY))

src/sonic-ctrmgrd/tests/ctrmgrd_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
common_test.KUBE_JOIN: {
107107
"ip": "10.10.10.10",
108108
"port": "6443",
109-
"insecure": "true"
109+
"insecure": "false"
110110
}
111111
}
112112
},
@@ -151,7 +151,7 @@
151151
common_test.KUBE_JOIN: {
152152
"ip": "10.10.10.10",
153153
"port": "6443",
154-
"insecure": "true"
154+
"insecure": "false"
155155
},
156156
common_test.KUBE_RESET: {
157157
"flag": "true"

src/sonic-ctrmgrd/tests/kube_commands_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
0: {
106106
common_test.DESCR: "Regular insecure join",
107107
common_test.RETVAL: 0,
108-
common_test.ARGS: ["10.3.157.24", 6443, True, False],
108+
common_test.ARGS: ["10.3.157.24", 6443, "true", False],
109109
common_test.PROC_CMD: [
110110
"kubectl --kubeconfig {} --request-timeout 20s drain none \
111111
--ignore-daemonsets".format(KUBE_ADMIN_CONF),
@@ -129,7 +129,7 @@
129129
1: {
130130
common_test.DESCR: "Regular secure join",
131131
common_test.RETVAL: 0,
132-
common_test.ARGS: ["10.3.157.24", 6443, False, False],
132+
common_test.ARGS: ["10.3.157.24", 6443, "false", False],
133133
common_test.PROC_CMD: [
134134
"kubectl --kubeconfig {} --request-timeout 20s drain none \
135135
--ignore-daemonsets".format(KUBE_ADMIN_CONF),
@@ -153,7 +153,7 @@
153153
2: {
154154
common_test.DESCR: "Skip join as already connected",
155155
common_test.RETVAL: 0,
156-
common_test.ARGS: ["10.3.157.24", 6443, True, False],
156+
common_test.ARGS: ["10.3.157.24", 6443, "true", False],
157157
common_test.NO_INIT: True,
158158
common_test.PROC_CMD: [
159159
"systemctl start kubelet"
@@ -162,7 +162,7 @@
162162
3: {
163163
common_test.DESCR: "Regular join: fail due to unable to lock",
164164
common_test.RETVAL: -1,
165-
common_test.ARGS: ["10.3.157.24", 6443, False, False],
165+
common_test.ARGS: ["10.3.157.24", 6443, "false", False],
166166
common_test.FAIL_LOCK: True
167167
}
168168
}

src/sonic-yang-models/yang-models/sonic-kubernetes_master.yang

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ module sonic-kubernetes_master {
5050
leaf insecure {
5151
description "Whether to use HTTP instead of HTTPS for downloading Kubernetes CA certificate";
5252
type stypes:boolean_type;
53-
default "true";
53+
default "false";
5454
}
5555

5656
}

0 commit comments

Comments
 (0)