Просмотр исходного кода

keypair verification before container startup

Paolo Asperti лет назад: 3
Родитель
Сommit
fab70ce8e7
2 измененных файлов с 30 добавлено и 5 удалено
  1. 2 0
      README.md
  2. 28 5
      docker/rootfs/etc/s6-overlay/s6-rc.d/key-secret/up.real

+ 2 - 0
README.md

@@ -185,6 +185,8 @@ We use these environment variables:
185 185
 You can obviously keep the key pair in a docker volume, but the best practices tells you to not write the keys on the filesystem; so we provide a couple of options.
186 186
 
187 187
 On container startup, the presence of the keypair is checked (`/data/id_ed25519.pub` and `/data/id_ed25519`) and if one of these keys doesn't exist, it's recreated from ENV variables or docker secrets.
188
+Then the validity of the keypair is checked: if public and private keys doesn't match, the container will stop.
189
+If you provide no keys, `hbbs` will generate one for you, and it'll place it in the default location.
188 190
 
189 191
 #### Use ENV to store the key pair
190 192
 

+ 28 - 5
docker/rootfs/etc/s6-overlay/s6-rc.d/key-secret/up.real

@@ -26,10 +26,33 @@ if [ ! -f /data/id_ed25519 ] && [ ! "$KEY_PRIV" = "" ] ; then
26 26
   echo "Private key created from ENV variable"
27 27
 fi
28 28
 
29
-# fix perms
30
-if [ -f /data/id_ed25519.pub ] ; then
31
-  chmod 600 /data/id_ed25519.pub 
29
+# check if both keys provided
30
+if [ -f /data/id_ed25519.pub ] && [ ! -f /data/id_ed25519 ] ; then
31
+  echo "Private key missing."
32
+  echo "You must provide BOTH the private and the public key."
33
+  /run/s6/basedir/bin/halt
34
+  exit 1
32 35
 fi
33
-if [ -f /data/id_ed25519 ] ; then
34
-  chmod 600 /data/id_ed25519
36
+
37
+if [ ! -f /data/id_ed25519.pub ] && [ -f /data/id_ed25519 ] ; then
38
+  echo "Public key missing."
39
+  echo "You must provide BOTH the private and the public key."
40
+  /run/s6/basedir/bin/halt
41
+  exit 1
35 42
 fi
43
+
44
+# here we have either no keys or both
45
+
46
+# if we have both keys, we fix permissions and ownership
47
+# and check for keypair validation
48
+if [ -f /data/id_ed25519.pub ] && [ -f /data/id_ed25519 ] ; then
49
+  chmod 0600 /data/id_ed25519.pub /data/id_ed25519
50
+  chown root:root /data/id_ed25519.pub /data/id_ed25519
51
+  /usr/bin/rustdesk-utils validatekeypair "$(cat /data/id_ed25519.pub)" "$(cat /data/id_ed25519)" || {
52
+    echo "Key pair not valid"
53
+    /run/s6/basedir/bin/halt
54
+    exit 1
55
+  }
56
+fi
57
+
58
+# if we have no keypair, hbbs will generate one