Skip to content

Commit

Permalink
Remove secret from golden_config_db.json and old_config files (#3390)
Browse files Browse the repository at this point in the history
  • Loading branch information
liuh-80 authored Jul 4, 2024
1 parent 414cf3b commit fb2e5cd
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions scripts/generate_dump
Original file line number Diff line number Diff line change
Expand Up @@ -2155,7 +2155,7 @@ finalize() {


###############################################################################
# Remove secret from pipeline inout and output result to pipeline.
# Remove secret from pipeline input and output result to pipeline.
# Globals:
# None
# Arguments:
Expand All @@ -2168,6 +2168,18 @@ remove_secret_from_config_db_dump() {
sed -E 's/\"passkey\"\s*:\s*\"([^\"]*)\"/\"passkey\":\"****\"/g; /SNMP_COMMUNITY/,/\s{2,4}\},/d'
}


###############################################################################
# Remove secret from file.
###############################################################################
remove_secret_from_config_db_dump_file() {
local dumpfile=$1
if [ -e ${dumpfile} ]; then
cat $dumpfile | remove_secret_from_config_db_dump > $dumpfile.temp
mv $dumpfile.temp $dumpfile
fi
}

###############################################################################
# Remove secret from dump files.
# Globals:
Expand Down Expand Up @@ -2201,8 +2213,24 @@ remove_secret_from_etc_files() {
sed -i -E 's/(\s*snmp_\S*community\s*:\s*)(\S*)/\1****/g' $dumppath/etc/sonic/snmp.yml

# Remove secret from /etc/sonic/config_db.json
cat $dumppath/etc/sonic/config_db.json | remove_secret_from_config_db_dump > $dumppath/etc/sonic/config_db.json.temp
mv $dumppath/etc/sonic/config_db.json.temp $dumppath/etc/sonic/config_db.json
remove_secret_from_config_db_dump_file $dumppath/etc/sonic/config_db.json

# Remove secret from /etc/sonic/golden_config_db.json
remove_secret_from_config_db_dump_file $dumppath/etc/sonic/golden_config_db.json

# Remove secret from /etc/sonic/old_config/

# Remove snmp community string from old_config/snmp.yml
local oldsnmp=${dumppath}/etc/sonic/old_config/snmp.yml
if [ -e ${oldsnmp} ]; then
sed -i -E 's/(\s*snmp_\S*community\s*:\s*)(\S*)/\1****/g' $oldsnmp
fi

# Remove secret from /etc/sonic/config_db.json
remove_secret_from_config_db_dump_file ${dumppath}/etc/sonic/old_config/config_db.json

# Remove secret from /etc/sonic/golden_config_db.json
remove_secret_from_config_db_dump_file ${dumppath}/etc/sonic/old_config/golden_config_db.json
}

###############################################################################
Expand Down

0 comments on commit fb2e5cd

Please sign in to comment.