gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit220a80e0220a80e0|||PR Remove temporary /__heap route and heap helper; logmre220a80e0/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

  • 220a80e0|||PR Remove temporary /__heap route and heap helper; logmre
  • 13f0c342Merge branch 'hl25-records' into mainGitoria
  • a002ecb7|||PR records: HL25 report, heap helper, logmre
  • 2492a55cTemporary keyed /__heap route for the live memory snapshotmre
  • fefaedd2log: tracker PR-only, HL25 startedmre
  • 21aa57calog: parkmre
  • e9f950a8reports: G25c soakmre
  • a7783686log: deploy 9f41ffcmre
  • 9f41ffc1log: W30b mergedmre
  • bef635c1Merge branch 'w30b'mre
  • 15b996a5Org list: keyed rows by @id, newest first, concat instead of hand loopmre
  • c4f6d9e3reports: G25c growth huntmre
  • b88e39f1log: privacy cleanup donemre
  • bfd7826ddocs: neutral example organisation namemre
  • 01b71c2edocs: neutral wording in missions, reports and logmre
  • 3eeea733log: 2026-11-09 PR flow plan and membersmre
  • e7c2ff1fdocs: neutral name for the apps-api reviewmre
  • 120b7abdlog: step 3 queuedmre
  • 358474bflog: P50 livemre
  • 477d7bdcMerge branch 'p50'mre