]> rtime.felk.cvut.cz Git - novaboot.git/commitdiff
server: Implement add-key command
authorMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 25 Aug 2017 16:21:27 +0000 (18:21 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 25 Aug 2017 20:17:09 +0000 (22:17 +0200)
server/novaboot-shell
tests/server.wv

index 0c476106ed6767fe9244081542d4acf89cf2aa45..84454c11850dfddb6b32f60d22345669c6f2e8c3 100755 (executable)
@@ -30,9 +30,23 @@ EOF
 
 add_key() {
     local user
+    [ "$NB_ADMIN" ] || return 1
 
+    case $# in
+       0) die "Username argument missing";;
+       1) break;;
+       *) die "User name must not contain spaces: $*";;
+    esac
     user="$1"
-    die "Not implemented"
+    key=$(cat)
+
+    tmp=$(mktemp ~/.ssh/authorized_keys.XXXXXXXX)
+    {
+       cat ~/.ssh/authorized_keys
+       echo "command=\"user $user\" $key"
+    } | sort -u > $tmp
+
+    mv $tmp ~/.ssh/authorized_keys
 }
 
 lock_queue() {
index d589681c1e507a9b9500813eac8783e743148420..aa0381b14c6c6634a753635104d8ef8b11909c70 100755 (executable)
@@ -78,7 +78,12 @@ WVPASS kill $COPROC_PID
 
 SHELLRC="$WV_BASE_DIR/home-novaboot-test/.novaboot-shell"
 TFTPROOT="$WV_BASE_DIR/home-novaboot-test/tftproot"
+AUTH="$WV_BASE_DIR/home-novaboot-test/.ssh/authorized_keys"
 
+WVSTART "Setup SSH server's admin key"
+WVPASS ssh-add -L > keys
+WVPASS test $(wc -l < keys) -gt 0
+WVPASS echo 'command="user test admin"' $(tail -n 1 keys) > $AUTH
 
 WVSTART "Novaboot --ssh option (connect, rsync, reset)"
 WVPASS rm -rf $TFTPROOT
@@ -129,3 +134,19 @@ EOF
 WVFAIL novaboot --ssh novaboot-test@localhost <<EOF
 load file < date
 EOF
+
+WVSTART "add-key subcommand"
+WVPASS ssh-keygen -t ed25519 -N '' -f key
+WVFAIL grep new_user $AUTH
+WVPASS ssh novaboot-test@localhost add-key new_user < key.pub
+WVPASS grep new_user $AUTH
+
+WVSTART "add-key user must not contain spaces"
+WVPASS cp $AUTH auth
+WVFAIL ssh novaboot-test@localhost add-key "new user" < /dev/null
+WVPASS diff -u $AUTH auth
+
+WVSTART "add-key requires username"
+WVPASS cp $AUTH auth
+WVFAIL ssh novaboot-test@localhost add-key < /dev/null
+WVPASS diff -u $AUTH auth