Skip to content

Commit b91c00e

Browse files
committed
read authorized_keys from user_config if exists
1 parent bd14fd0 commit b91c00e

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

phala-cloud-prelaunch-script/prelaunch.sh

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
echo "----------------------------------------------"
3-
echo "Running Phala Cloud Pre-Launch Script v0.0.10"
3+
echo "Running Phala Cloud Pre-Launch Script v0.0.11"
44
echo "----------------------------------------------"
55
set -e
66

@@ -160,19 +160,29 @@ else
160160
echo "Root password already set; no changes."
161161
fi
162162

163+
mkdir -p /home/root/.ssh
163164
if [[ -n "$DSTACK_ROOT_PUBLIC_KEY" ]]; then
164-
mkdir -p /home/root/.ssh
165165
echo "$DSTACK_ROOT_PUBLIC_KEY" > /home/root/.ssh/authorized_keys
166166
unset $DSTACK_ROOT_PUBLIC_KEY
167167
echo "Root public key set"
168168
fi
169169
if [[ -n "$DSTACK_AUTHORIZED_KEYS" ]]; then
170-
mkdir -p /home/root/.ssh
171170
echo "$DSTACK_AUTHORIZED_KEYS" > /home/root/.ssh/authorized_keys
172171
unset $DSTACK_AUTHORIZED_KEYS
173172
echo "Root authorized_keys set"
174173
fi
175174

175+
if [[ -f /dstack/user_config ]] && jq empty /dstack/user_config 2>/dev/null; then
176+
if [[ $(jq 'has("ssh_authorized_keys")' /dstack/user_config 2>/dev/null) == "true" ]]; then
177+
jq -j '.ssh_authorized_keys' /dstack/user_config >> /home/root/.ssh/authorized_keys
178+
# Remove duplicates if there are multiple keys
179+
if [[ $(cat /home/root/.ssh/authorized_keys | wc -l) -gt 1 ]]; then
180+
sort -u /home/root/.ssh/authorized_keys > /home/root/.ssh/authorized_keys.tmp
181+
mv /home/root/.ssh/authorized_keys.tmp /home/root/.ssh/authorized_keys
182+
fi
183+
echo "Set root authorized_keys from user preferences, total" $(cat /home/root/.ssh/authorized_keys | wc -l) "keys"
184+
fi
185+
fi
176186

177187
if [[ -S /var/run/dstack.sock ]]; then
178188
export DSTACK_APP_ID=$(curl -s --unix-socket /var/run/dstack.sock http://dstack/Info | jq -j .app_id)

0 commit comments

Comments
 (0)