gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitb554cd5fb554cd5flogmreb554cd5f/docker/sshd/gitoria-shell

2.3 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. export GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=receive.hideRefs GIT_CONFIG_VALUE_0=refs/pull
  37. # 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.
  38. pushed() { curl -sS --max-time 10 -G -o /dev/null -H "X-Gitoria-Secret: $(cat /run/gitoria-secret)" \
  39. --data-urlencode "user=$user" --data-urlencode "slug=$real" --data-urlencode "phase=$1" "$(cat /run/gitoria-url)/__git/pushed" >/dev/null 2>&1 || true; }
  40. [ "$write" = 1 ] && pushed before
  41. "$service" "/repos/$real.git"
  42. rc=$?
  43. [ "$write" = 1 ] && [ "$rc" = 0 ] && pushed after
  44. exit $rc

Branches

Latest commits

  • b554cd5flogmre
  • f4c9440ddeploy.sh: tar --hard-dereference for the live data backupmre
  • 1a687b15Merge branch 'w48-member-merge'mre
  • 166c775fW48 report, logmre
  • 1b4623f0Members merge pull requests: API route, button on /pulls and /pulls/N, one shared merge pathmre
  • 1075c38cW48 mission, logmre
  • 17bdd0d6V37/V39 missions, logmre
  • 146de5f8Re-vendor gitoria to Hybriel set-day39 (51e921d7)mre
  • e874e44dtests/status-keyed: app token lives 60 s so it outlives the gate's two restartsmre
  • 270b8d61deploy.sh: DEPLOY_STOP_START=1 stops, waits for the old pid, then starts (mpackdb freeze, replaces the standby swap)mre
  • 3f9235b8project.hl: drop the dummy /pulls/:n component route (hybriel#294 is fixed in day37)mre
  • c90daf19Re-vendor gitoria to Hybriel set-day37 (f6b3d45b)mre
  • 03b5bb08W39 report to reports/, drop scratch repro, mission + logmre
  • 154d333fMerge w39-create-api: POST /api/repos with a user token (#39)mre
  • 149dd512Rewrite W39 reportmre
  • e5385075Expect 401 for POST /api/repos without a tokenmre
  • 1a76055cDocument repository creation APImre
  • 4d779b3bAdd create-api gatemre
  • 88563122Add POST /api/repos for user tokensmre
  • b00860e3Create repositories with member checks in createRepoInmre