Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-workhorse
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-workhorse
Commits
b8c0fedd
Commit
b8c0fedd
authored
Nov 26, 2015
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
X draft auth cache
parent
921cdfef
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
4 deletions
+24
-4
blob.go
blob.go
+24
-4
No files found.
blob.go
View file @
b8c0fedd
...
@@ -31,30 +31,50 @@ func blobPreAuthorizeHandler(handleFunc serviceHandleFunc) serviceHandleFunc {
...
@@ -31,30 +31,50 @@ func blobPreAuthorizeHandler(handleFunc serviceHandleFunc) serviceHandleFunc {
}
}
}
}
type
authInfo
struct
{
authResponse
authorizationResponse
timestamp
int64
// in seconds
}
// project -> authInfo
// FIXME it have to be not only project (privateToken etc...)
var
authCache
=
make
(
map
[
string
]
authInfo
)
// verify that download access is authorized by auth backend
// verify that download access is authorized by auth backend
func
verifyDownloadAccess
(
w
http
.
ResponseWriter
,
r
*
gitRequest
,
project
string
)
(
downloadOk
bool
)
{
func
verifyDownloadAccess
(
w
http
.
ResponseWriter
,
r
*
gitRequest
,
project
string
)
bool
{
downloadOk
=
false
// XXX do we need mutex to lock authCache ?
auth
,
ok
:=
authCache
[
project
]
if
ok
{
log
.
Printf
(
"downloadOk cached %v ago: %v"
,
time
.
Since
(
time
.
Unix
(
auth
.
timestamp
,
0
)),
auth
.
authResponse
)
r
.
authorizationResponse
=
auth
.
authResponse
return
(
auth
.
authResponse
.
RepoPath
!=
""
)
// XXX ok?
}
// request to verify whether download is possible via asking as git fetch would do
// request to verify whether download is possible via asking as git fetch would do
// XXX privateToken not propagated, etc ...
// XXX privateToken not propagated, etc ...
reqDownloadAccess
,
err
:=
http
.
NewRequest
(
"GET"
,
project
+
".git/info/refs?service=git-upload-pack"
,
nil
)
reqDownloadAccess
,
err
:=
http
.
NewRequest
(
"GET"
,
project
+
".git/info/refs?service=git-upload-pack"
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
fail500
(
w
,
"GET git-upload-pack"
,
err
)
fail500
(
w
,
"GET git-upload-pack"
,
err
)
return
return
false
// XXX not cache as it is just we cannot create request
}
}
// swap original request to 'verify-download' one
// swap original request to 'verify-download' one
//requestBlob := r.Request
//requestBlob := r.Request
r
.
Request
=
reqDownloadAccess
r
.
Request
=
reqDownloadAccess
downloadOk
:=
false
preAuthorizeHandler
(
preAuthorizeHandler
(
func
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
func
(
w
http
.
ResponseWriter
,
r
*
gitRequest
)
{
// if we ever get to this point - auth handler approved
// if we ever get to this point - auth handler approved
// access and thus it is ok to download
// access and thus it is ok to download
downloadOk
=
true
downloadOk
=
true
},
""
)
(
w
,
r
)
},
""
)
(
w
,
r
)
return
// XXX do we need to lock authCache ?
authCache
[
project
]
=
authInfo
{
r
.
authorizationResponse
,
time
.
Now
()
.
Unix
()}
return
downloadOk
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment