-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script to generate fingerprints for existing keys in api-db
- Loading branch information
1 parent
9fedd48
commit b3997e3
Showing
1 changed file
with
18 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
|
||
set -eu -o pipefail | ||
|
||
# disable globbing | ||
set -f; | ||
# set field separator to NL (only) | ||
IFS=$'\n'; | ||
# get all ssh keys from api-db into a bash array | ||
SSHKEY_RECORDS=( $(mysql -u$MARIADB_USER -p$MARIADB_PASSWORD -h$HOSTNAME $MARIADB_DATABASE --batch -sse "select id, key_type, key_value from ssh_key") ); | ||
|
||
for SSHKEY_RECORD in "${SSHKEY_RECORDS[@]}"; | ||
do | ||
RECORD_ID=$(awk '{print $1}' <<< "$SSHKEY_RECORD"); | ||
SSHKEY=$(awk '{print $2, $3}' <<< "$SSHKEY_RECORD"); | ||
FINGERPRINT=$(ssh-keygen -lE sha256 -f - <<< "$SSHKEY" | awk '{print $2}'); | ||
mysql -u$MARIADB_USER -p$MARIADB_PASSWORD -h$HOSTNAME $MARIADB_DATABASE -e "UPDATE ssh_key SET key_fingerprint = '$FINGERPRINT' WHERE id = $RECORD_ID"; | ||
done; |