Skip to content

Instantly share code, notes, and snippets.

@coopernetes
Last active October 23, 2023 18:17
Show Gist options
  • Save coopernetes/bf79e7b2df4d2c66804fc13cb2f57dc7 to your computer and use it in GitHub Desktop.
Save coopernetes/bf79e7b2df4d2c66804fc13cb2f57dc7 to your computer and use it in GitHub Desktop.
git-proxy manual authorization steps

Authorize git pushes through git-proxy using the API

Git-proxy includes a REST-based API for managing certain aspects of repositories & git operations (pushes, pulls). This API is fronted by a web UI. The web interface is under active development and is missing some key features to allow Git Proxy to push commits through it.

The below procedure will allow you to "authorize" a push through git-proxy using the included API. The following assumptions are made and must be modified to match your deployment of git-proxy:

Procedure

  1. Attempted to push a new commit or branch through git-proxy. Expect to receive an error message similar to the output below. Note the "tracking id" value, which is the last part of the URL:

    $ git remote -v
    origin	https://github.com/finos/git-proxy.git (fetch)
    origin	https://github.com/finos/git-proxy.git (push)
    proxy	http://localhost:8000/RBC/git-proxy.git (fetch)
    proxy	http://localhost:8000/RBC/git-proxy.git (push)
    $ git push proxy chore/test-branch
    Enumerating objects: 5, done.
    Counting objects: 100% (5/5), done.
    Delta compression using up to 10 threads
    Compressing objects: 100% (3/3), done.
    Writing objects: 100% (3/3), 470 bytes | 470.00 KiB/s, done.
    Total 3 (delta 2), reused 0 (delta 0), pack-reused 0
    remote: ERR	Your push request is waiting authorisation, tracking id http://localhost:8080/requests/0000000000000000000000000000000000000000__79b4d8953cbc324bcc1eb53d6412ff89666c241f
    fatal: the remote end hung up unexpectedly
    fatal: the remote end hung up unexpectedly
    error: failed to push some refs to 'http://localhost:8000/RBC/git-proxy.git'
    $ _request_id="0000000000000000000000000000000000000000__79b4d8953cbc324bcc1eb53d6412ff89666c241f"
  2. Authenticate to the API using the default admin/admin credentials and obtain a cookie. The cookie value is saved to a file called git-proxy-cookie.

    curl -H "Content-Type: application/json" -c git-proxy-cookie -X POST \
      -d '{"username":"admin","password":"admin"}' http://localhost:8080/auth/login
  3. Validate that the request is received and exists in the database. This request should succeed and you should get back a JSON blob returned in the response. Note that we are reusing the cookie generated from step 2:

    curl -b ./git-proxy-cookie http://localhost:8080/api/v1/push/${_request_id}
  4. Send a POST to authorise the push:

    curl -b ./git-proxy-cookie \
      -X POST http://localhost:8080/api/v1/push/${_request_id}/authorise
  5. Push the new code again. It should be now successfully push through git-proxy:

    $ git push proxy chore/test-branch
    Enumerating objects: 5, done.
    Counting objects: 100% (5/5), done.
    Delta compression using up to 10 threads
    Compressing objects: 100% (3/3), done.
    Writing objects: 100% (3/3), 470 bytes | 470.00 KiB/s, done.
    Total 3 (delta 2), reused 0 (delta 0), pack-reused 0
    remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
    remote:
    remote: Create a pull request for 'chore/test-branch' on GitHub by visiting:
    remote:      https://github.com/RBC/git-proxy/pull/new/chore/test-branch
    remote:
    To http://localhost:8000/RBC/git-proxy.git
    * [new branch]      chore/test-branch -> chore/test-branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment