Skip to content

Commit 64996db

Browse files
committed
Merge pull request gitlabhq#230 from bozaro/git-lfs-authenticate
Add git-lfs-authenticate to command white list
2 parents 4d30c0c + 0bd7699 commit 64996db

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,32 @@ List all keys:
139139
Remove all keys from authorized_keys file:
140140

141141
./bin/gitlab-keys clear
142+
143+
## Git LFS remark
144+
145+
If you want to play with git-lfs (https://git-lfs.github.com/) on GitLab, you should do the following:
146+
147+
* Install LFS-server (no production-ready implementation yet, but you can use https://github.com/github/lfs-test-server) on any host;
148+
* Add some user on LFS-server (for example: user ```foo``` with password ```bar```);
149+
* Add ```git-lfs-authenticate``` script in any PATH-available directory on GIT-server like this:
150+
```
151+
#!/bin/sh
152+
echo "{
153+
\"href\": \"http://lfs.test.local:9999/test/test\",
154+
\"header\": {
155+
\"Authorization\": \"Basic `echo -n foo:bar | base64`\"
156+
}
157+
}"
158+
```
159+
160+
After that you can play with git-lfs (git-lfs feature will be available via ssh protocol).
161+
162+
This design will work without a script git-lfs-authenticate, but with the following limitations:
163+
164+
* You will need to manually configure lfs-server URL for every user working copy;
165+
* SSO don't work and you need to manually add lfs-server credentials for every user working copy (otherwise, git-lfs will ask for the password for each file).
166+
167+
Usefull links:
168+
169+
* https://github.com/github/git-lfs/tree/master/docs/api - Git LFS API, also contains more information about ```git-lfs-authenticate```;
170+
* https://github.com/github/git-lfs/wiki/Implementations - Git LFS-server implementations.

lib/gitlab_shell.rb

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class AccessDeniedError < StandardError; end
77
class DisallowedCommandError < StandardError; end
88
class InvalidRepositoryPathError < StandardError; end
99

10-
GIT_COMMANDS = %w(git-upload-pack git-receive-pack git-upload-archive git-annex-shell).freeze
10+
GIT_COMMANDS = %w(git-upload-pack git-receive-pack git-upload-archive git-annex-shell git-lfs-authenticate).freeze
1111

1212
attr_accessor :key_id, :repo_name, :git_cmd, :repos_path, :repo_name
1313

@@ -56,24 +56,37 @@ def exec
5656
def parse_cmd
5757
args = Shellwords.shellwords(@origin_cmd)
5858
@git_cmd = args.first
59+
@git_access = @git_cmd
5960

6061
raise DisallowedCommandError unless GIT_COMMANDS.include?(@git_cmd)
6162

62-
if @git_cmd == 'git-annex-shell'
63+
case @git_cmd
64+
when 'git-annex-shell'
6365
raise DisallowedCommandError unless @config.git_annex_enabled?
6466

6567
@repo_name = escape_path(args[2].sub(/\A\/~\//, ''))
6668

6769
# Make sure repository has git-annex enabled
6870
init_git_annex(@repo_name)
71+
when 'git-lfs-authenticate'
72+
raise DisallowedCommandError unless args.count >= 2
73+
@repo_name = escape_path(args[1])
74+
case args[2]
75+
when 'download'
76+
@git_access = 'git-upload-pack'
77+
when 'upload'
78+
@git_access = 'git-receive-pack'
79+
else
80+
raise DisallowedCommandError
81+
end
6982
else
7083
raise DisallowedCommandError unless args.count == 2
7184
@repo_name = escape_path(args.last)
7285
end
7386
end
7487

7588
def verify_access
76-
status = api.check_access(@git_cmd, @repo_name, @key_id, '_any')
89+
status = api.check_access(@git_access, @repo_name, @key_id, '_any')
7790

7891
raise AccessDeniedError, status.message unless status.allowed?
7992
end

0 commit comments

Comments
 (0)