gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commite7af3ecee7af3eceMerge branch 'w52b-approval-followup' into mainGitoriae7af3ece/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

  • e7af3eceMerge branch 'w52b-approval-followup' into mainGitoria
  • c01e66c6|||PR approvals follow-up: live Merge after status writes, helpers (#52)mre
  • 841da497Merge branch 'w53-pulls-speed-pr' into mainGitoria
  • 80307ae2|||PR pulls page cache: live PR numbers, complete scans onlymre
  • 69141f65|||PR pulls page: cache the git part per repo by branch tipsmre
  • 155861f6Merge branch 'w52-person-approval' into mainGitoria
  • b5435de8|||PR person approvals: second Kunibert round (#52)mre
  • 3a8b2fb8|||PR person approvals: Kunibert review fixes (#52)mre
  • 2a89d8d0|||PR person approvals: Approve button for people; merge needs the required checks or a listed person's approval (#52)mre
  • 83f0c953Report person approval verificationmre
  • 3ae94b86Record browser failures and verify owned tab cleanupmre
  • 54eec687Gate person approvals and merge alternativesmre
  • 12b08829Add person approvals for pull request headsmre
  • 55c84779Merge branch 'gp-gate-ports' into mainGitoria
  • 57af42bbREADME: point to deploy.sh for the port listmre
  • d63375d2README: gate commands with explicit portsmre
  • feeaa701|||PR gates: explicit ports only, deploy.sh passes themmre
  • 6cc1f943Merge branch 'records-1112' into mainGitoria
  • 9448c438|||PR records: LOG, missions and reports since 11-09mre
  • 6dc08a8eMerge branch 'p51-public-pr-reads' into mainGitoria