gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit477d7bdc477d7bdcMerge branch 'p50'mre477d7bdc/docker/sshd/gitoria-shell

2.5 KB

  1. #!/bin/sh
  2. # The forced command of every key: `gitoria-shell <user id>`. What the client asked is in SSH_ORIGINAL_COMMAND and may only be
  3. # git-upload-pack (clone, fetch) or git-receive-pack (push) of ONE repository '<slug>.git'; the app decides who may push.
  4. user=$1
  5. cmd=${SSH_ORIGINAL_COMMAND:-}
  6. refuse() { echo "gitoria: $1" >&2; exit 1; }
  7. case "$cmd" in
  8. "git-upload-pack "*) service=git-upload-pack; write=0 ;;
  9. "git-receive-pack "*) service=git-receive-pack; write=1 ;;
  10. *) refuse "only git clone, fetch and push work over ssh (no shell)" ;;
  11. esac
  12. arg=${cmd#* }
  13. arg=${arg#\'}; arg=${arg%\'}; arg=${arg#/}
  14. slug=${arg%.git}
  15. [ "$arg" = "$slug.git" ] || refuse "no such repository"
  16. # <name> or <org>/<name> (an organization's repo, GO34): each part a-z 0-9 and hyphens, 2-40 characters
  17. case "$slug" in
  18. */*/*) refuse "no such repository" ;;
  19. esac
  20. for part in $(echo "$slug" | tr '/' ' '); do
  21. case "$part" in
  22. ""|*[!a-z0-9-]*|-*|*-) refuse "no such repository" ;;
  23. esac
  24. [ ${#part} -ge 2 ] && [ ${#part} -le 40 ] || refuse "no such repository"
  25. done
  26. status=$(curl -sS --max-time 10 -G -o /tmp/gitoria-access.$$ -w '%{http_code}' -H "X-Gitoria-Secret: $(cat /run/gitoria-secret)" \
  27. --data-urlencode "user=$user" --data-urlencode "slug=$slug" --data-urlencode "write=$write" "$(cat /run/gitoria-url)/__git/access") || status=000
  28. msg=$(cat /tmp/gitoria-access.$$ 2>/dev/null); rm -f /tmp/gitoria-access.$$
  29. [ "$status" = 200 ] || refuse "${msg:-the server did not answer}"
  30. # the app answers "ok <real name>": a moved repo is served from its new place
  31. real=${msg#ok }; real=$(echo "$real" | tr -d '\n')
  32. case "$real" in
  33. ""|*[!a-z0-9/-]*|*..*|/*|*/) real=$slug ;;
  34. esac
  35. # refs/pull/* is gitoria's (pull request heads): the push is refused for it, as over HTTPS (git >= 2.31 reads these variables).
  36. # core.hooksPath: the pre-receive that refuses a direct push to the main branch when the owner switched that on (gitoria#50)
  37. export GIT_CONFIG_COUNT=2 GIT_CONFIG_KEY_0=receive.hideRefs GIT_CONFIG_VALUE_0=refs/pull GIT_CONFIG_KEY_1=core.hooksPath GIT_CONFIG_VALUE_1=/usr/local/share/gitoria-hooks
  38. # a push: the app numbers the repo's pull requests before, and compares them with git after (notifyPush, syncPulls). A failure of that call never fails the push.
  39. pushed() { curl -sS --max-time 10 -G -o /dev/null -H "X-Gitoria-Secret: $(cat /run/gitoria-secret)" \
  40. --data-urlencode "user=$user" --data-urlencode "slug=$real" --data-urlencode "phase=$1" "$(cat /run/gitoria-url)/__git/pushed" >/dev/null 2>&1 || true; }
  41. [ "$write" = 1 ] && pushed before
  42. "$service" "/repos/$real.git"
  43. rc=$?
  44. [ "$write" = 1 ] && [ "$rc" = 0 ] && pushed after
  45. exit $rc

Branches

Latest commits

  • 477d7bdcMerge branch 'p50'mre
  • 00efc06fP50 reportmre
  • e3f85afblog: commit mention slipmre
  • 4d1a4cf4log: #25 numbersmre
  • 1af0a60ddocs: H25 run() correctionmre
  • eefa2dbcRepo setting: refuse direct pushes to the main branch (pre-receive over HTTPS and ssh)mre
  • 8c8ba2f1log: PR flow announcedmre
  • fa00cd35log: Kunibert pings provenmre
  • 3a68cfaclog: components decisionmre
  • 87de8e31log: Kunibert connected to 9 app reposmre
  • c22aff69log: PR-only rollout startedmre
  • 25309981log: STOP and paused workers 2026-11-08mre
  • 5286803alog: worker briefs and reports of 2026-11-08mre
  • 85c86605log: 2026-11-08 Arachne on list shapemre
  • cb634512log: 2026-11-08 keyed lists livemre
  • 07c98d4aLists: keyed rows with @id, remove(id) and one whole-list assignment instead of hand-rebuilt loopsmre
  • 0db0d81elog: 2026-11-08 day52 live, W30 startedmre
  • b05f6d92tests/status: the gate's 3 s app token expired during the restart; it lives 60 s like status-keyedmre
  • 1e8f4f0avendor: Hybriel set-day52 (fault-path leak fix #335, keyed rows #331)mre
  • f5f0fb7blog: 2026-11-08 day50/#29 live, H25 correction, V52 startedmre