Skip to content
Open
Show file tree
Hide file tree
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
21 changes: 7 additions & 14 deletions scripts/new-vm/template-user-data
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,18 @@ users:
ssh_authorized_keys:
- <USER_PUBKEY>

ssh_keys:
#Don't change the next line, we use it as anchor to append the server private key
#We can't use the <VAR> the private key spans multiple lines an replacing a variable with
#multiple lines is hard. If you add a key by hand, make sure that all lines of the
#key are indented with 4 whitespaces
ecdsa_private: |

ecdsa_public: <SERVER_PUBKEY>

ssh:
emit_keys_to_console: false

#After converting to VM for our tool, we only want to use the root partition
#This change does not affect the initial boot (in which the config is applied)
write_files:
- path: /etc/fstab
content: |
# <file system> <mount point> <type> <options> <dump> <pass>
/dev/sda2 / ext4 defaults 0 1
- path: /etc/ssh/sshd_config.d/only_use_ecdsa.conf
- path: /etc/netplan/00-installer-config.yaml
permissions: '0644'
content: |
HostKey /etc/ssh/ssh_host_ecdsa_key
network:
version: 2
ethernets:
enp0s2:
dhcp4: true
6 changes: 5 additions & 1 deletion scripts/new-vm/tyche-convert-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ DST_FOLDER=$(mktemp -d)
SRC_IMAGE=
DST_IMAGE=

NON_INTERACTIVE=""
NON_INTERACTIVE=


SCRIPT_PATH=$(realpath "$(dirname "$0")")
Expand All @@ -24,6 +24,7 @@ usage() {
echo ""
echo "-in PATH.qcow2 [Mandatory] Path to unencrypted input qcow2 disk image"
echo "-out PATH.qcow2 [Optional] Path where the encrypted qcow2 disk is created. Defaults to the directory of the input file with -encrypted suffix"
echo "-q [Optional] Don not ask for user intearaction"
echo ""
exit
}
Expand All @@ -40,6 +41,9 @@ while [ -n "$1" ]; do
-out) DST_IMAGE="$2"
shift
;;
-q) NON_INTERACTIVE="1"
shift
;;
*)
usage
;;
Expand Down
31 changes: 0 additions & 31 deletions scripts/new-vm/tyche-create-new-vm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ NEW_VM=
#size of the qcow2 disk image in GB
SIZE=20
OWNER_PUBKEY_PATH=""
#Path to private key. public key is expected to be in the same directory, using the .pub extension
SERVER_PRIVKEY_PATH=""
SERVER_PUBKEY_PATH=""

usage() {
echo "Usage:"
Expand Down Expand Up @@ -47,11 +44,6 @@ while [ -n "$1" ]; do
-owner-pubkey) OWNER_PUBKEY_PATH="$2"
shift
;;
-server-privkey)
SERVER_PRIVKEY_PATH="$2"
SERVER_PRIVKEY_PATH="${2}.pub"
shift
;;
-size)
SIZE="$2"
shift
Expand Down Expand Up @@ -101,14 +93,6 @@ if [ -z "$OWNER_PUBKEY_PATH" ]; then
OWNER_PUBKEY_PATH="${DEFAULT_PATH}.pub"
fi

if [ -z "$SERVER_PRIVKEY_PATH" ]; then
mkdir -p "$KEYS_PATH"
DEFAULT_PATH="$KEYS_PATH/ssh-server-key-vm"
echo "No server ssh key provided. Generating a new keypair at $DEFAULT_PATH"
ssh-keygen -t ecdsa -N "" -f "$DEFAULT_PATH"
SERVER_PRIVKEY_PATH="$DEFAULT_PATH"
SERVER_PUBKEY_PATH="${DEFAULT_PATH}.pub"
fi

#Query Username and password
echo "Enter username"
Expand All @@ -131,21 +115,6 @@ sed -i "s#<USER>#$USERNAME#g" "$USER_DATA"
sed -i "s#<PWDHASH>#$PWHASH#g" "$USER_DATA"
USER_PUBKEY=$(cat "$OWNER_PUBKEY_PATH")
sed -i "s#<USER_PUBKEY>#$USER_PUBKEY#g" "$USER_DATA"
# SERVER_PRIVKEY=$(cat "$SERVER_PRIVKEY_PATH")
# sed -i "s#<SERVER_PRIVKEY>#$SERVER_PRIVKEY#g" user-data

#Dirty hack to get all lines of our private key to be indented by 4 whitespaces
#1) copy to file
#2) replace each linestart with 4 whitespaces
#3) append key after the "ecda_private: |" line in the config template
TMP=$(mktemp)
cp "$SERVER_PRIVKEY_PATH" "$TMP"
sed -i 's#^# #' "$TMP"
sed -i "/^ *ecdsa_private: |/r $TMP" "$USER_DATA"
rm "$TMP"
# awk -v r="$SERVER_PRIVKEY" '{gsub(/<SERVER_PRIVKEY>/,r)}1'
SERVER_PUBKEY=$(cat "$SERVER_PUBKEY_PATH")
sed -i "s#<SERVER_PUBKEY>#$SERVER_PUBKEY#g" "$USER_DATA"

OUT_CFG_BLOB="$BUILD_DIR/config-blob.img"
echo "Writing config blow to $OUT_CFG_BLOB"
Expand Down
Loading