Pushing to git LFS repository using deploy key fails

Summary

When pushing git LFS objects to a GitLab hosted repository using a deploy key with write access enabled, the server encounters a 500 error.

Steps to reproduce

  • Create an LFS enabled repo
  • Add a deploy key to the repo and enable write access
  • Push some LFS files to the repo with only the deploy key

What is the current bug behavior?

The git LFS client dies with a fatal error and the objects are not pushed to the remote.

What is the expected correct behavior?

The objects should be pushed to the remote.

Relevant logs and/or screenshots

Git LFS on the client responds with:

Fatal error: Server error: http://<redacted>/group/repo.git/info/lfs/objects/batch

The following is from production_json.log (repo name stripped) :

{"method":"POST","path":"/group/repo.git/info/lfs/objects/batch","format":"json","controller":"Projects::LfsApiController","action":"batch","st
atus":500,"error":"NoMethodError: undefined method `admin?' for #<DeployKey:0x00007f7880ec4b90>","duration":195.55,"view":0.0,"db":1.43,"time":"2017-10
-24T19:22:52.971Z","params":{"operation":"upload","objects":[{"oid":"72b6971eb4b3e728b8f42da124a7fec7033edc4b2fb19d62fe52ea4f358cd7db","size":8225672},
{"oid":"cb647713c88cc15c923c27a205c76c378834feed207a13df56f8ecce971dae47","size":1032330},{"oid":"24eb8e00cf9646200453200b7234d0564ad2e072dbab71b948ce3
662a343c486","size":10888},{"oid":"49cd0e4d57e925ebbe2a2a0ce6561b59a3cc6a6640fe79dc18daa0a520f05925","size":9462}],"namespace_id":"group","project_id":
"repo.git","lfs_api":{"operation":"upload","objects":[{"oid":"72b6971eb4b3e728b8f42da124a7fec7033edc4b2fb19d62fe52ea4f358cd7db","size":8225672}
,{"oid":"cb647713c88cc15c923c27a205c76c378834feed207a13df56f8ecce971dae47","size":1032330},{"oid":"24eb8e00cf9646200453200b7234d0564ad2e072dbab71b948ce
3662a343c486","size":10888},{"oid":"49cd0e4d57e925ebbe2a2a0ce6561b59a3cc6a6640fe79dc18daa0a520f05925","size":9462}]}},"remote_ip":"192.168.202.65","use
r_id":75,"username":null}

Results of GitLab environment info

Expand for output related to GitLab environment info
System information
System:		Ubuntu 16.04
Current User:	git
Using RVM:	no
Ruby Version:	2.3.5p376
Gem Version:	2.6.13
Bundler Version:1.13.7
Rake Version:	12.1.0
Redis Version:	3.2.5
Git Version:	2.13.5
Sidekiq Version:5.0.4
Go Version:	unknown

GitLab information Version: 10.1.0 Revision: 5a695c4 Directory: /opt/gitlab/embedded/service/gitlab-rails DB Adapter: postgresql URL: http:// HTTP Clone URL: http:///some-group/some-project.git SSH Clone URL: git@:some-group/some-project.git Using LDAP: no Using Omniauth: no

GitLab Shell Version: 5.9.3 Repository storage paths:

  • default: /var/opt/gitlab/git-data/repositories Hooks: /opt/gitlab/embedded/service/gitlab-shell/hooks Git: /opt/gitlab/embedded/bin/git

Results of GitLab application Check

Checking GitLab Shell ...

GitLab Shell version >= 5.9.3 ? ... OK (5.9.3) Repo base directory exists? default... yes Repo storage directories are symlinks? default... no Repo paths owned by git:root, or git:git? default... yes Repo paths access is drwxrws---? default... yes hooks directories in repos are links: ... 3/1 ... ok 3/3 ... ok 3/4 ... ok 10/6 ... ok 3/7 ... ok 2/8 ... ok 3/11 ... ok 3/18 ... ok 10/20 ... ok 14/24 ... ok 14/25 ... ok 14/26 ... ok 14/27 ... ok 14/28 ... ok 14/29 ... ok 4/31 ... ok 4/32 ... ok 2/33 ... ok 2/34 ... ok 10/36 ... ok 3/37 ... ok 3/38 ... ok 26/39 ... ok 26/40 ... ok 26/41 ... ok 27/42 ... ok 27/43 ... repository is empty 3/44 ... ok 3/45 ... ok 3/46 ... ok 14/47 ... ok 14/48 ... ok 14/49 ... ok 33/50 ... ok Running /opt/gitlab/embedded/service/gitlab-shell/bin/check Check GitLab API access: OK Redis available via internal API: OK

Access to /var/opt/gitlab/.ssh/authorized_keys: OK gitlab-shell self-check successful

Checking GitLab Shell ... Finished

Checking Sidekiq ...

Running? ... yes Number of Sidekiq processes ... 1

Checking Sidekiq ... Finished

Reply by email is disabled in config/gitlab.yml Checking LDAP ...

LDAP is disabled in config/gitlab.yml

Checking LDAP ... Finished

Checking GitLab ...

Git configured correctly? ... yes Database config exists? ... yes All migrations up? ... yes Database contains orphaned GroupMembers? ... no GitLab config exists? ... yes GitLab config up to date? ... yes Log directory writable? ... yes Tmp directory writable? ... yes Uploads directory exists? ... yes Uploads directory has correct permissions? ... yes Uploads directory tmp has correct permissions? ... yes Init script exists? ... skipped (omnibus-gitlab has no init script) Init script up-to-date? ... skipped (omnibus-gitlab has no init script) Projects have namespace: ... 3/1 ... yes 3/3 ... yes 3/4 ... yes 10/6 ... yes 3/7 ... yes 2/8 ... yes 3/11 ... yes 3/18 ... yes 10/20 ... yes 14/24 ... yes 14/25 ... yes 14/26 ... yes 14/27 ... yes 14/28 ... yes 14/29 ... yes 4/31 ... yes 4/32 ... yes 2/33 ... yes 2/34 ... yes 10/36 ... yes 3/37 ... yes 3/38 ... yes 26/39 ... yes 26/40 ... yes 26/41 ... yes 27/42 ... yes 27/43 ... yes 3/44 ... yes 3/45 ... yes 3/46 ... yes 14/47 ... yes 14/48 ... yes 14/49 ... yes 33/50 ... yes Redis version >= 2.8.0? ... yes Ruby version >= 2.3.3 ? ... yes (2.3.5) Git version >= 2.7.3 ? ... yes (2.13.5) Git user has default SSH configuration? ... yes Active users: ... 22

Checking GitLab ... Finished