Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[generate_dump] Improve generate_dump script to remove secrets from golden_config_db.json and old_config files #3390

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No actual work here?

Copy link
Contributor Author

@liuh-80 liuh-80 Jul 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this comments is for next 3 lines of code:

Remove snmp community string from old_config/snmp.yml
Remove secret from /etc/sonic/config_db.json
Remove secret from /etc/sonic/golden_config_db.json


# 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
Loading