summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2023-05-27 22:11:22 -0400
committerAndrew Cady <d@jerkface.net>2023-05-27 22:11:22 -0400
commite6f31e56797cf45b13c0d98499d647125521feeb (patch)
tree70184d78e9588d933c69aec46d2f42c0e031840f
parentf2ac2fe76e6d8fcad24daa1f8c16e207e95465f1 (diff)
endoforge proof of concept
-rw-r--r--.gitignore3
-rw-r--r--src/endofossil37
2 files changed, 36 insertions, 4 deletions
diff --git a/.gitignore b/.gitignore
index a7db9aa..372cbed 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
1work/ 1/work/
2/remotes/
2/db 3/db
diff --git a/src/endofossil b/src/endofossil
index 401806f..c4ae60d 100644
--- a/src/endofossil
+++ b/src/endofossil
@@ -1,15 +1,18 @@
1#!/bin/bash 1#!/bin/bash
2set -e 2set -e -o pipefail
3
4 3
5IFS=/ read n pid uid <<< "$1" 4IFS=/ read n pid uid <<< "$1"
6[ "$pid" ] 5[ "$pid" ]
7 6
7[ "$uid" -gt 0 ]
8IFS=: read username realname _ _ gecos homedir shell < <(getent passwd "$uid")
9
8authtype= 10authtype=
9while read -d '' 11while read -d ''
10do 12do
11 case "${REPLY%%=*}" in 13 case "${REPLY%%=*}" in
12 'SSH_USER_AUTH' ) read authtype keytype keyvalue < "${REPLY#*=}" ;; 14 'SSH_USER_AUTH' ) read authtype keytype keyvalue < "${REPLY#*=}" ;;
15 'SSH_ORIGINAL_COMMAND' ) SSH_ORIGINAL_COMMAND=${REPLY#*=} ;;
13 esac 16 esac
14done < /proc/$pid/environ 17done < /proc/$pid/environ
15[ "$authtype" = publickey ] 18[ "$authtype" = publickey ]
@@ -26,4 +29,32 @@ do
26done < <(ssh-keygen -f <(printf '%s\n' "$keytype $keyvalue") -r .) 29done < <(ssh-keygen -f <(printf '%s\n' "$keytype $keyvalue") -r .)
27[ "$keyhash" ] 30[ "$keyhash" ]
28 31
29printf '%s\n' "$keyhash" 32case "$SSH_ORIGINAL_COMMAND" in
33 *\"* ) exit 1 ;;
34 fossil\ test-http\ * ) ;;
35 *) exit 1 ;;
36esac
37
38# This is no way to do it.
39# Let's just share /home/*/src and /srv/src and /usr/src.
40fossil_dir=$homedir/src/fossil
41upstreamDatabase=$fossil_dir/db
42readWriteDbName=db.fossil # Must end in .fossil for 'fossil test-http' to find it.
43readWriteDir=$fossil_dir/remotes/$keyhash
44
45as_user()
46{
47 setpriv --reuid="$username" --init-groups --inh-caps=-all "$@"
48}
49if ! [ -d "$readWriteDir" ]
50then
51 as_user mkdir "$readWriteDir"
52fi
53as_user cp -n --reflink -- "$upstreamDatabase" "$readWriteDir"/"$readWriteDbName"
54
55exec systemd-run -P \
56 --property=User="$username" \
57 --property=ReadOnlyPaths=/ \
58 --property=ReadWritePaths="$readWriteDir" \
59 --property=WorkingDirectory="$readWriteDir" \
60 -- fossil test-http "$readWriteDbName"