-
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.
Merge pull request #959 from amazeeio/577-api-disallow-duplicate-ssh-…
…keys API: Disallow duplicate ssh keys
- Loading branch information
Showing
9 changed files
with
100 additions
and
17 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
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
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
38 changes: 38 additions & 0 deletions
38
services/api-db/docker-entrypoint-initdb.d/04-generate-ssh-key-fingerprints.sh
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,38 @@ | ||
#!/bin/bash | ||
|
||
set -eu -o pipefail | ||
|
||
# disable globbing | ||
set -f; | ||
# set field separator to NL (only) | ||
IFS=$'\n'; | ||
|
||
DUPLICATE_SSHKEY_RECORDS=( $(mysql infrastructure --batch -sse "SELECT count(*) count, key_value FROM ssh_key GROUP BY key_value HAVING count > 1") ); | ||
|
||
if [ ${#DUPLICATE_SSHKEY_RECORDS[@]} -ne 0 ]; then | ||
echo "====== FOUND DUPLICATE SSH KEYS IN LAGOON API DATABASE!" | ||
for DUPLICATE_SSHKEY_RECORD in "${DUPLICATE_SSHKEY_RECORDS[@]}"; | ||
do | ||
echo "" | ||
echo $(awk '{print $2}' <<< "$DUPLICATE_SSHKEY_RECORD"); | ||
done; | ||
echo "" | ||
echo "====== PLEASE REMOVE DUPLICATED SSH KEYS AND RUN INITIALIZATION OF DB AGAIN" | ||
#exit 1 | ||
fi | ||
|
||
echo "=== Starting SSH KEY Fingerprint generation" | ||
|
||
# get all ssh keys which have no fingerprint yet from api-db into a bash array | ||
SSHKEY_RECORDS=( $(mysql infrastructure --batch -sse "SELECT id, key_type, key_value FROM ssh_key WHERE key_fingerprint is NULL") ); | ||
|
||
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}'); | ||
echo "Adding SSH Key Fingerprint for SSH KEY '$RECORD_ID': $FINGERPRINT" | ||
mysql infrastructure -e "UPDATE ssh_key SET key_fingerprint = '$FINGERPRINT' WHERE id = $RECORD_ID"; | ||
done; | ||
|
||
echo "=== Finished SSH KEY Fingerprint generation" |
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 |
---|---|---|
@@ -1,5 +1,10 @@ | ||
#!/bin/sh | ||
#!/bin/bash | ||
|
||
INITDB_DIR="/docker-entrypoint-initdb.d" | ||
|
||
for sql_file in `ls $INITDB_DIR`; do mysql --verbose < "$INITDB_DIR/$sql_file" ; done | ||
for f in `ls /docker-entrypoint-initdb.d/*`; do | ||
case "$f" in | ||
*.sh) echo "$0: running $f"; . "$f" ;; | ||
*.sql) echo "$0: running $f"; cat $f| tee | mysql --verbose; echo ;; | ||
*) echo "$0: ignoring $f" ;; | ||
esac | ||
echo | ||
done |
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
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
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
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