@matheusbsbs / matheus-bagliano / commits / 8b2bd7cdac
Fork 0

Smart-http: check if repository is OK to export before serving it

Similar to how git-daemon checks whether a repository is OK to be exported, smart-http should also check. This check can be satisfied in two different ways: the environmental variable GIT_HTTP_EXPORT_ALL may be set to export all repositories, or the individual repository may have the file git-daemon-export-ok. Acked-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Tarmigan Casebolt <tarmigan+git@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Tarmigan Casebolt committed Dec 28, 2009 at 16:49 UTC 8b2bd7cdacf71260dbc954316af2bed8e076c182
4 files changed +55 -2
Documentation/git-http-backend.txt
+10
@@ -18,6 +18,11 @@ The program supports clients fetching using both the smart HTTP protcol
18 and the backwards-compatible dumb HTTP protocol, as well as clients
19 pushing using the smart HTTP protocol.
20
21 +It verifies that the directory has the magic file
22 +"git-daemon-export-ok", and it will refuse to export any git directory
23 +that hasn't explicitly been marked for export this way (unless the
24 +GIT_HTTP_EXPORT_ALL environmental variable is set).
25 +
26 By default, only the `upload-pack` service is enabled, which serves
27 'git-fetch-pack' and 'git-ls-remote' clients, which are invoked from
28 'git-fetch', 'git-pull', and 'git-clone'. If the client is authenticated,
@@ -70,6 +75,7 @@ Apache 2.x::
75 +
76 ----------------------------------------------------------------
77 SetEnv GIT_PROJECT_ROOT /var/www/git
78 +SetEnv GIT_HTTP_EXPORT_ALL
79 ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/
80 ----------------------------------------------------------------
81 +
@@ -157,6 +163,10 @@ by the invoking web server, including:
163 * QUERY_STRING
164 * REQUEST_METHOD
165
166 +The GIT_HTTP_EXPORT_ALL environmental variable may be passed to
167 +'git-http-backend' to bypass the check for the "git-daemon-export-ok"
168 +file in each repository before allowing export of that repository.
169 +
170 The backend process sets GIT_COMMITTER_NAME to '$REMOTE_USER' and
171 GIT_COMMITTER_EMAIL to '$\{REMOTE_USER}@http.$\{REMOTE_ADDR\}',
172 ensuring that any reflogs created by 'git-receive-pack' contain some
http-backend.c
+3
@@ -648,6 +648,9 @@ int main(int argc, char **argv)
648 setup_path();
649 if (!enter_repo(dir, 0))
650 not_found("Not a git repository: '%s'", dir);
651 + if (!getenv("GIT_HTTP_EXPORT_ALL") &&
652 + access("git-daemon-export-ok", F_OK) )
653 + not_found("Repository not exported: '%s'", dir);
654
655 git_config(http_config, NULL);
656 cmd->imp(cmd_arg);
t/lib-httpd/apache.conf
+5
@@ -22,8 +22,13 @@ Alias /dumb/ www/
22
23 <Location /smart/>
24 SetEnv GIT_EXEC_PATH ${GIT_EXEC_PATH}
25 + SetEnv GIT_HTTP_EXPORT_ALL
26 +</Location>
27 +<Location /smart_noexport/>
28 + SetEnv GIT_EXEC_PATH ${GIT_EXEC_PATH}
29 </Location>
30 ScriptAlias /smart/ ${GIT_EXEC_PATH}/git-http-backend/
31 +ScriptAlias /smart_noexport/ ${GIT_EXEC_PATH}/git-http-backend/
32 <Directory ${GIT_EXEC_PATH}>
33 Options None
34 </Directory>
t/t5560-http-backend.sh
+37 -2
@@ -23,7 +23,7 @@ config() {
23 }
24
25 GET() {
26 - curl --include "$HTTPD_URL/smart/repo.git/$1" >out 2>/dev/null &&
26 + curl --include "$HTTPD_URL/$SMART/repo.git/$1" >out 2>/dev/null &&
27 tr '\015' Q <out |
28 sed '
29 s/Q$//
@@ -91,6 +91,7 @@ get_static_files() {
91 GET $IDX_URL "$1"
92 }
93
94 +SMART=smart
95 test_expect_success 'direct refs/heads/master not found' '
96 log_div "refs/heads/master"
97 GET refs/heads/master "404 Not Found"
@@ -99,6 +100,19 @@ test_expect_success 'static file is ok' '
100 log_div "getanyfile default"
101 get_static_files "200 OK"
102 '
103 +SMART=smart_noexport
104 +test_expect_success 'no export by default' '
105 + log_div "no git-daemon-export-ok"
106 + get_static_files "404 Not Found"
107 +'
108 +test_expect_success 'export if git-daemon-export-ok' '
109 + log_div "git-daemon-export-ok"
110 + (cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
111 + touch git-daemon-export-ok
112 + ) &&
113 + get_static_files "200 OK"
114 +'
115 +SMART=smart
116 test_expect_success 'static file if http.getanyfile true is ok' '
117 log_div "getanyfile true"
118 config http.getanyfile true &&
@@ -145,7 +159,6 @@ test_expect_success 'http.receivepack false' '
159 GET info/refs?service=git-receive-pack "403 Forbidden" &&
160 POST git-receive-pack 0000 "403 Forbidden"
161 '
148 -
162 run_backend() {
163 REQUEST_METHOD=GET \
164 GIT_PROJECT_ROOT="$HTTPD_DOCUMENT_ROOT_PATH" \
@@ -194,6 +207,28 @@ GET /smart/repo.git/$LOOSE_URL HTTP/1.1 200
207 GET /smart/repo.git/$PACK_URL HTTP/1.1 200
208 GET /smart/repo.git/$IDX_URL HTTP/1.1 200
209
210 +### no git-daemon-export-ok
211 +###
212 +GET /smart_noexport/repo.git/HEAD HTTP/1.1 404 -
213 +GET /smart_noexport/repo.git/info/refs HTTP/1.1 404 -
214 +GET /smart_noexport/repo.git/objects/info/packs HTTP/1.1 404 -
215 +GET /smart_noexport/repo.git/objects/info/alternates HTTP/1.1 404 -
216 +GET /smart_noexport/repo.git/objects/info/http-alternates HTTP/1.1 404 -
217 +GET /smart_noexport/repo.git/$LOOSE_URL HTTP/1.1 404 -
218 +GET /smart_noexport/repo.git/$PACK_URL HTTP/1.1 404 -
219 +GET /smart_noexport/repo.git/$IDX_URL HTTP/1.1 404 -
220 +
221 +### git-daemon-export-ok
222 +###
223 +GET /smart_noexport/repo.git/HEAD HTTP/1.1 200
224 +GET /smart_noexport/repo.git/info/refs HTTP/1.1 200
225 +GET /smart_noexport/repo.git/objects/info/packs HTTP/1.1 200
226 +GET /smart_noexport/repo.git/objects/info/alternates HTTP/1.1 200 -
227 +GET /smart_noexport/repo.git/objects/info/http-alternates HTTP/1.1 200 -
228 +GET /smart_noexport/repo.git/$LOOSE_URL HTTP/1.1 200
229 +GET /smart_noexport/repo.git/$PACK_URL HTTP/1.1 200
230 +GET /smart_noexport/repo.git/$IDX_URL HTTP/1.1 200
231 +
232 ### getanyfile true
233 ###
234 GET /smart/repo.git/HEAD HTTP/1.1 200