comparison mercurial/hgweb/common.py @ 37147:a2566597acb5

lfs: add basic routing for the server side wire protocol processing The recent hgweb refactoring yielded a clean point to wrap a function that could handle this, so I moved the routing for this out of the core. While not an hg wire protocol, this seems logically close enough. For now, these handlers do nothing other than check permissions. The protocol requires support for PUT requests, so that has been added to the core, and funnels into the same handler as GET and POST. The permission checking code was assuming that anything not checking 'pull' or None ops should be using POST. But that breaks the upload check if it checks 'push'. So I invented a new 'upload' permission, and used it to avoid the mandate to POST. A function wrap point could be added, but security code should probably stay grouped together. Given that anything not 'pull' or None was requiring POST, the comment on hgweb.common.permhooks is probably wrong- there is no 'read'. The rationale for the URIs is that the spec for the Batch API[1] defines the URL as the LFS server url + '/objects/batch'. The default git URLs are: Git remote: https://git-server.com/foo/bar LFS server: https://git-server.com/foo/bar.git/info/lfs Batch API: https://git-server.com/foo/bar.git/info/lfs/objects/batch '.git/' seems like it's not something a user would normally track. If we adhere to how git defines the URLs, then the hg-git extension should be able to talk to a git based server without any additional work. The URI for the transfer requests starts with '.hg/' to ensure that there are no conflicts with tracked files. Since these are handed out by the Batch API, we can change this at any point in the future. (Specifically, it might be a good idea to use something under the proposed /api/ namespace.) In any case, no files are stored at these locations in the repository directory. I started a new module for this because it seems like a good idea to keep all of the security sensitive server side code together. There's also an issue with `hg verify` in that it will want to download *all* blobs in order to run. Sadly, there's no way in the protocol to ask the server to verify the content of a blob it may have. (The verify action is for storing files on a 3rd party server, and then informing the LFS server when that completes.) So we may end up implementing a custom transfer adapter that simply indicates if the blobs are valid, and fall back to basic transfers for non-hg servers. In other words, this code is likely to get bigger before this is made non-experimental. [1] https://github.com/git-lfs/git-lfs/blob/master/docs/api/batch.md
author Matt Harbison <matt_harbison@yahoo.com>
date Sat, 17 Mar 2018 01:23:01 -0400
parents 02bea04b4c54
children cc0a6ea95d98
comparison
equal deleted inserted replaced
37146:c37c47e47a95 37147:a2566597acb5
59 if op == 'pull' and not hgweb.allowpull: 59 if op == 'pull' and not hgweb.allowpull:
60 raise ErrorResponse(HTTP_UNAUTHORIZED, 'pull not authorized') 60 raise ErrorResponse(HTTP_UNAUTHORIZED, 'pull not authorized')
61 elif op == 'pull' or op is None: # op is None for interface requests 61 elif op == 'pull' or op is None: # op is None for interface requests
62 return 62 return
63 63
64 # Allow LFS uploading via PUT requests
65 if op == 'upload':
66 if req.method != 'PUT':
67 msg = 'upload requires PUT request'
68 raise ErrorResponse(HTTP_METHOD_NOT_ALLOWED, msg)
64 # enforce that you can only push using POST requests 69 # enforce that you can only push using POST requests
65 if req.method != 'POST': 70 elif req.method != 'POST':
66 msg = 'push requires POST request' 71 msg = 'push requires POST request'
67 raise ErrorResponse(HTTP_METHOD_NOT_ALLOWED, msg) 72 raise ErrorResponse(HTTP_METHOD_NOT_ALLOWED, msg)
68 73
69 # require ssl by default for pushing, auth info cannot be sniffed 74 # require ssl by default for pushing, auth info cannot be sniffed
70 # and replayed 75 # and replayed
79 if not (allow and ismember(hgweb.repo.ui, user, allow)): 84 if not (allow and ismember(hgweb.repo.ui, user, allow)):
80 raise ErrorResponse(HTTP_UNAUTHORIZED, 'push not authorized') 85 raise ErrorResponse(HTTP_UNAUTHORIZED, 'push not authorized')
81 86
82 # Hooks for hgweb permission checks; extensions can add hooks here. 87 # Hooks for hgweb permission checks; extensions can add hooks here.
83 # Each hook is invoked like this: hook(hgweb, request, operation), 88 # Each hook is invoked like this: hook(hgweb, request, operation),
84 # where operation is either read, pull or push. Hooks should either 89 # where operation is either read, pull, push or upload. Hooks should either
85 # raise an ErrorResponse exception, or just return. 90 # raise an ErrorResponse exception, or just return.
86 # 91 #
87 # It is possible to do both authentication and authorization through 92 # It is possible to do both authentication and authorization through
88 # this. 93 # this.
89 permhooks = [checkauthz] 94 permhooks = [checkauthz]