@@ -42,7 +42,6 @@ SAVE_STDERR=true
42
42
RETURN_CODE=0
43
43
DEBUG_DUMP=false
44
44
45
-
46
45
handle_signal ()
47
46
{
48
47
echo " Generate Dump received interrupt" >&2
@@ -155,6 +154,7 @@ save_bcmcmd_all_ns() {
155
154
# cmd: The command to run. Make sure that arguments with spaces have quotes
156
155
# filename: the filename to save the output as in $BASE/dump
157
156
# do_gzip: (OPTIONAL) true or false. Should the output be gzipped
157
+ # cleanup_method: (OPTIONAL) the cleanup method to procress dump file after it generated.
158
158
# Returns:
159
159
# None
160
160
# ##############################################################################
@@ -168,6 +168,7 @@ save_cmd() {
168
168
local do_gzip=${3:- false}
169
169
local tarpath=" ${BASE} /dump/$filename "
170
170
local timeout_cmd=" timeout --foreground ${TIMEOUT_MIN} m"
171
+ local cleanup_method=${4:- dummy_cleanup_method}
171
172
local redirect=' &>'
172
173
local redirect_eval=' 2>&1'
173
174
if [ ! -d $LOGDIR ]; then
@@ -187,7 +188,9 @@ save_cmd() {
187
188
if $do_gzip ; then
188
189
tarpath=" ${tarpath} .gz"
189
190
filepath=" ${filepath} .gz"
190
- local cmds=" $cmd $redirect_eval | gzip -c > '${filepath} '"
191
+ # cleanup_method will run in a sub-shell, need declare it first
192
+ local cleanup_method_declration=$( declare -f $cleanup_method )
193
+ local cmds=" $cleanup_method_declration ; $cmd $redirect_eval | $cleanup_method | gzip -c > '${filepath} '"
191
194
if $NOOP ; then
192
195
echo " ${timeout_cmd} bash -c \" ${cmds} \" "
193
196
else
@@ -199,22 +202,36 @@ save_cmd() {
199
202
fi
200
203
else
201
204
if $NOOP ; then
202
- echo " ${timeout_cmd} $cmd $redirect '$filepath '"
205
+ echo " ${timeout_cmd} $cmd | $cleanup_method $redirect '$filepath '"
203
206
else
204
207
RC=0
205
- eval " ${timeout_cmd} $cmd " " $redirect " " $filepath " || RC=$?
208
+ eval " ${timeout_cmd} $cmd | $cleanup_method " " $redirect " " $filepath " || RC=$?
206
209
if [ $RC -ne 0 ]; then
207
210
echo " Command: $cmd timedout after ${TIMEOUT_MIN} minutes."
208
211
fi
209
212
fi
210
213
fi
214
+
211
215
($TAR $V -rhf $TARFILE -C $DUMPDIR " $tarpath " \
212
216
|| abort " ${ERROR_TAR_FAILED} " " tar append operation failed. Aborting to prevent data loss." ) \
213
217
&& $RM $V -rf " $filepath "
214
218
end_t=$( date +%s%3N)
215
219
echo " [ save_cmd:$cmd ] : $(( $end_t - $start_t )) msec" >> $TECHSUPPORT_TIME_INFO
216
220
}
217
221
222
+ # ##############################################################################
223
+ # Dummy cleanup method.
224
+ # Globals:
225
+ # None
226
+ # Arguments:
227
+ # None
228
+ # Returns:
229
+ # None
230
+ # ##############################################################################
231
+ dummy_cleanup_method () {
232
+ cat
233
+ }
234
+
218
235
# ##############################################################################
219
236
# Runs a given command in all namesapces in case of multi ASIC platform, in
220
237
# default (host) namespace in single ASIC platform
@@ -224,22 +241,24 @@ save_cmd() {
224
241
# cmd: The command to run. Make sure that arguments with spaces have quotes
225
242
# filename: the filename to save the output as in $BASE/dump
226
243
# do_gzip: (OPTIONAL) true or false. Should the output be gzipped
244
+ # cleanup_method: (OPTIONAL) the cleanup method to procress dump file after it generated.
227
245
# Returns:
228
246
# None
229
247
# ##############################################################################
230
248
save_cmd_all_ns () {
231
249
trap ' handle_error $? $LINENO' ERR
232
250
local do_zip=${3:- false}
251
+ local cleanup_method=${4:- dummy_cleanup_method}
233
252
234
253
# host or default namespace
235
- save_cmd " $1 " " $2 " " $do_zip "
254
+ save_cmd " $1 " " $2 " " $do_zip " $cleanup_method
236
255
237
256
if [[ ( " $NUM_ASICS " > 1 ) ]] ; then
238
257
for (( i= 0 ; i< $NUM_ASICS ; i++ ))
239
258
do
240
259
local cmd=" sonic-netns-exec asic$i $1 "
241
260
local file=" $2 .$i "
242
- save_cmd " $cmd " " $file " " $do_zip "
261
+ save_cmd " $cmd " " $file " " $do_zip " $cleanup_method
243
262
done
244
263
fi
245
264
}
@@ -591,7 +610,8 @@ save_redis_info() {
591
610
save_redis " APPL_DB"
592
611
save_redis " ASIC_DB"
593
612
save_redis " COUNTERS_DB"
594
- save_redis " CONFIG_DB"
613
+ # There are secrets in CONFIG_DB need to be cleanup.
614
+ save_redis " CONFIG_DB" " CONFIG_DB" remove_secret_from_config_db_dump
595
615
save_redis " FLEX_COUNTER_DB"
596
616
save_redis " STATE_DB"
597
617
}
@@ -637,18 +657,20 @@ save_proc() {
637
657
# Arguments:
638
658
# DB name: DB name
639
659
# Filename: Destination filename, if not given then filename would be DB name
660
+ # cleanup_method: (OPTIONAL) the cleanup method to procress dump file after it generated.
640
661
# Returns:
641
662
# None
642
663
# ##############################################################################
643
664
save_redis () {
665
+ local cleanup_method=${3:- dummy_cleanup_method}
644
666
trap ' handle_error $? $LINENO' ERR
645
667
local db_name=$1
646
668
if [ $# -ge 2 ] && [ -n " $2 " ]; then
647
669
local dest_file_name=$2
648
670
else
649
671
local dest_file_name=" $db_name "
650
672
fi
651
- save_cmd_all_ns " sonic-db-dump -n '$db_name ' -y" " $dest_file_name .json"
673
+ save_cmd_all_ns " sonic-db-dump -n '$db_name ' -y" " $dest_file_name .json" false $cleanup_method
652
674
}
653
675
654
676
# ##############################################################################
@@ -1259,6 +1281,9 @@ main() {
1259
1281
rm $rm_list
1260
1282
fi
1261
1283
1284
+ # Remove secret from /etc files before tar
1285
+ remove_secret_from_etc_files $TARDIR
1286
+
1262
1287
start_t=$( date +%s%3N)
1263
1288
($TAR $V --warning=no-file-removed -rhf $TARFILE -C $DUMPDIR --mode=+rw \
1264
1289
--exclude=" etc/alternatives" \
@@ -1271,6 +1296,13 @@ main() {
1271
1296
--exclude=" *snmpd.conf*" \
1272
1297
--exclude=" /etc/mlnx" \
1273
1298
--exclude=" /etc/mft" \
1299
+ --exclude=" */etc/sonic/*.cer" \
1300
+ --exclude=" */etc/sonic/*.crt" \
1301
+ --exclude=" */etc/sonic/*.pem" \
1302
+ --exclude=" */etc/sonic/*.key" \
1303
+ --exclude=" */etc/ssl/*.pem" \
1304
+ --exclude=" */etc/ssl/certs/*" \
1305
+ --exclude=" */etc/ssl/private/*" \
1274
1306
$BASE /etc \
1275
1307
|| abort " ${ERROR_TAR_FAILED} " " Tar append operation failed. Aborting for safety." ) \
1276
1308
&& $RM $V -rf $TARDIR
@@ -1310,6 +1342,57 @@ main() {
1310
1342
exit $RETURN_CODE
1311
1343
}
1312
1344
1345
+ # ##############################################################################
1346
+ # Remove secret from pipeline inout and output result to pipeline.
1347
+ # Globals:
1348
+ # None
1349
+ # Arguments:
1350
+ # None
1351
+ # Returns:
1352
+ # None
1353
+ # ##############################################################################
1354
+ remove_secret_from_config_db_dump () {
1355
+ # Remove tacacs & radius passkey and snmp community from config DB
1356
+ sed -E ' s/\"passkey\"\s*:\s*\"([^\"]*)\"/\"passkey\":\"****\"/g; /SNMP_COMMUNITY/,/\s{2,4}\},/d'
1357
+ }
1358
+
1359
+ # ##############################################################################
1360
+ # Remove secret from dump files.
1361
+ # Globals:
1362
+ # Arguments:
1363
+ # dumppath: the dump file path.
1364
+ # Returns:
1365
+ # None
1366
+ # ##############################################################################
1367
+ remove_secret_from_etc_files () {
1368
+ local dumppath=$1
1369
+ echo " Remove secret from etc files."
1370
+ # Remove tacacs passkey from tacplus_nss.conf
1371
+ local secret_regex=' s/(secret=)([^,|\S]*)(.*)/\1****\3/g'
1372
+ sed -i -E $secret_regex $dumppath /etc/tacplus_nss.conf
1373
+
1374
+ # Remove radius passkey from radius_nss.conf
1375
+ sed -i -E $secret_regex $dumppath /etc/radius_nss.conf
1376
+
1377
+ # Remove tacacs passkey from common-auth-sonic
1378
+ sed -i -E ' s/(secret=)(\S*)/\1****/g' $dumppath /etc/pam.d/common-auth-sonic
1379
+
1380
+ # Remove tacacs passkey from pam_radius_auth.conf
1381
+ sed -i -E ' s/^([^#]\S*\s*)(\S*)/\1****/g' $dumppath /etc/pam_radius_auth.conf
1382
+
1383
+ # Remove radius passkey from per-server conf file /etc/pam_radius_auth.d/{ip}_{port}.conf
1384
+ for filename in $dumppath /etc/pam_radius_auth.d/* .conf; do
1385
+ sed -i -E ' s/^([^#]\S*\s*)(\S*)/\1****/g' $filename
1386
+ done
1387
+
1388
+ # Remove snmp community string from snmp.yml
1389
+ sed -i -E ' s/(\s*snmp_\S*community\s*:\s*)(\S*)/\1****/g' $dumppath /etc/sonic/snmp.yml
1390
+
1391
+ # Remove secret from /etc/sonic/config_db.json
1392
+ cat $dumppath /etc/sonic/config_db.json | remove_secret_from_config_db_dump > $dumppath /etc/sonic/config_db.json.temp
1393
+ mv $dumppath /etc/sonic/config_db.json.temp $dumppath /etc/sonic/config_db.json
1394
+ }
1395
+
1313
1396
# ##############################################################################
1314
1397
# Terminates generate_dump early just in case we have issues.
1315
1398
# Globals:
0 commit comments