Skip to content

Commit 106c38d

Browse files
authored
Add GNMI client cert cname check support. (#18709)
Add GNMI client cert cname list to yang model. #### Why I did it Allow gnmi service authentication client cert by cname. ### How I did it Add GNMI client cert cname list to yang model. #### How to verify it Pass all UT. ### Description for the changelog Add GNMI client cert cname list to yang model.
1 parent 80e5153 commit 106c38d

File tree

6 files changed

+68
-0
lines changed

6 files changed

+68
-0
lines changed

dockers/docker-sonic-gnmi/gnmi-native.sh

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ if [ -n "$CERTS" ]; then
3333
if [ ! -z $CA_CRT ]; then
3434
TELEMETRY_ARGS+=" --ca_crt $CA_CRT"
3535
fi
36+
37+
TELEMETRY_ARGS+=" --config_table_name GNMI_CLIENT_CERT"
3638
elif [ -n "$X509" ]; then
3739
SERVER_CRT=$(echo $X509 | jq -r '.server_crt')
3840
SERVER_KEY=$(echo $X509 | jq -r '.server_key')

dockers/docker-sonic-telemetry/telemetry.sh

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ if [ -n "$CERTS" ]; then
3434
if [ ! -z $CA_CRT ]; then
3535
TELEMETRY_ARGS+=" --ca_crt $CA_CRT"
3636
fi
37+
38+
# Reuse GNMI_CLIENT_CERT for telemetry service
39+
TELEMETRY_ARGS+=" --config_table_name GNMI_CLIENT_CERT"
3740
elif [ -n "$X509" ]; then
3841
SERVER_CRT=$(echo $X509 | jq -r '.server_crt')
3942
SERVER_KEY=$(echo $X509 | jq -r '.server_key')

src/sonic-yang-models/tests/files/sample_config_db.json

+8
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,14 @@
13291329
"port": "50052"
13301330
}
13311331
},
1332+
"GNMI_CLIENT_CERT": {
1333+
"testcert1": {
1334+
"role": "RW"
1335+
},
1336+
"testcert2": {
1337+
"role": "RO"
1338+
}
1339+
},
13321340
"TUNNEL": {
13331341
"MuxTunnel0": {
13341342
"dscp_mode": "uniform",

src/sonic-yang-models/tests/yang_model_tests/tests/gnmi.json

+7
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,12 @@
1717
},
1818
"GNMI_TABLE_WITH_VALID_CONFIG": {
1919
"desc": "TABLE WITH VALID CONFIG."
20+
},
21+
"GNMI_CLIENT_CERT_LIST_TABLE_WITH_MISSING_ROLE": {
22+
"desc": "CLIENT_CERT_LIST_TABLE_WITH_MISSING_ROLE failure.",
23+
"eStrKey": "Mandatory"
24+
},
25+
"GNMI_CLIENT_CERT_LIST_TABLE_WITH_VALID_CONFIG": {
26+
"desc": "TABLE WITH VALID CONFIG."
2027
}
2128
}

src/sonic-yang-models/tests/yang_model_tests/tests_config/gnmi.json

+27
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,32 @@
8080
}
8181
}
8282
}
83+
},
84+
"GNMI_CLIENT_CERT_LIST_TABLE_WITH_MISSING_ROLE": {
85+
"sonic-gnmi:sonic-gnmi": {
86+
"sonic-gnmi:GNMI_CLIENT_CERT": {
87+
"GNMI_CLIENT_CERT_LIST": [
88+
{
89+
"cert_cname": "testcert1"
90+
}
91+
]
92+
}
93+
}
94+
},
95+
"GNMI_CLIENT_CERT_LIST_TABLE_WITH_VALID_CONFIG": {
96+
"sonic-gnmi:sonic-gnmi": {
97+
"sonic-gnmi:GNMI_CLIENT_CERT": {
98+
"GNMI_CLIENT_CERT_LIST": [
99+
{
100+
"cert_cname": "testcert1",
101+
"role": "RW"
102+
},
103+
{
104+
"cert_cname": "testcert2",
105+
"role": "RO"
106+
}
107+
]
108+
}
109+
}
83110
}
84111
}

src/sonic-yang-models/yang-models/sonic-gnmi.yang

+21
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,28 @@ module sonic-gnmi {
7777
}
7878

7979
}
80+
}
81+
82+
container GNMI_CLIENT_CERT {
83+
description "GNMI client cert list";
8084

85+
list GNMI_CLIENT_CERT_LIST {
86+
max-elements 8;
87+
key "cert_cname";
88+
89+
leaf cert_cname {
90+
type string;
91+
description
92+
"client cert common name";
93+
}
94+
95+
leaf role {
96+
type string;
97+
mandatory true;
98+
description
99+
"role of client cert common name";
100+
}
101+
}
81102
}
82103
}
83104
}

0 commit comments

Comments
 (0)