deploy keys blocked when user that added deploy key deleted from LDAP

Summary

We recently upgraded to GitLab 12.4.2 and experienced issues where deploy keys are getting the following error

Your account has been blocked

It appears this is occurring because GitLab associates deploy keys with the user that added the deploy key. When the user that added the deploy key is 'LDAP blocked' or deleted from LDAP the deploy key becomes blocked because the user it is associated to is no longer available.

GitLab should ideally not associate deploy keys to the user that added the deploy key, since user churn is expected for projects. Pretty sure this is the same thing that happened in gitlab-foss#26923 (closed) however it was glossed over since the reporter re-added the key and it resolved the symptoms.

Steps to reproduce

  1. Create user in LDAP
  2. Use user to log in to GitLab
  3. Add deploy key to repository
  4. Clone the repository you added the deploy key to WITH the deploy key
git clone git@gitlab.com:semuuN4o/example-path-repo.git
  1. Run SSH test command https://docs.gitlab.com/ee/ssh/#testing-that-everything-is-set-up-correctly
Welcome to GitLab, @<user that added deploy key>!
  1. Delete user in LDAP
  2. Upgrade gitlab and perform a gitlab-ctl reconfigure/restart
  3. Run SSH test command
Welcome to GitLab, @<user that added deploy key>!
  1. Perform a git pull with deploy key
Your account has been blocked

Example Project

N/A

What is the current bug behavior?

GitLab denies the deploy key access because the deploy key is linked to the deleted user

Your account has been blocked

What is the expected correct behavior?

GitLab allows the deploy key to continue functioning after the user that added the deploy key is deleted.

Relevant logs and/or screenshots

Did not find anything relevant in the logs

Output of checks

(If you are reporting a bug on GitLab.com, write: This bug happens on GitLab.com)

Results of GitLab environment info

Expand for output related to GitLab environment info

(For installations with omnibus-gitlab package run and paste the output of: sudo gitlab-rake gitlab:env:info)

System information
System:         
Current User:   git
Using RVM:      no
Ruby Version:   2.6.3p62
Gem Version:    2.7.9
Bundler Version:1.17.3
Rake Version:   12.3.3
Redis Version:  3.2.12
Git Version:    2.22.0
Sidekiq Version:5.2.7
Go Version:     unknown

GitLab information
Version:        12.4.2
Revision:       393a5bdafa2
Directory:      /opt/gitlab/embedded/service/gitlab-rails
DB Adapter:     PostgreSQL
DB Version:     10.9
URL:            https://gitlab.example.com
HTTP Clone URL: https://gitlab.example.com/some-group/some-project.git
SSH Clone URL:  git@gitlab.example.com:some-group/some-project.git
Using LDAP:     yes
Using Omniauth: yes
Omniauth Providers: 

GitLab Shell
Version:        10.2.0
Repository storage paths:
- default:      /var/opt/gitlab/git-data/repositories
GitLab Shell path:              /opt/gitlab/embedded/service/gitlab-shell
Git:            /opt/gitlab/embedded/bin/git

Results of GitLab application Check

Expand for output related to the GitLab application check

(For installations with omnibus-gitlab package run and paste the output of: sudo gitlab-rake gitlab:check SANITIZE=true)

`Checking GitLab subtasks ...

Checking GitLab Shell ...

GitLab Shell: ... GitLab Shell version >= 10.2.0 ? ... OK (10.2.0)
Running /opt/gitlab/embedded/service/gitlab-shell/bin/check
Internal API available: OK
Redis available via internal API: OK
gitlab-shell self-check successful

Checking GitLab Shell ... Finished

Checking Gitaly ...

Gitaly: ... default ... OK

Checking Gitaly ... Finished

Checking Sidekiq ...

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

Checking Sidekiq ... Finished

Checking Incoming Email ...

Incoming Email: ... Reply by email is disabled in config/gitlab.yml

Checking Incoming Email ... Finished

Checking LDAP ...

LDAP: ... Server: ldapmain
LDAP authentication... Failed. Check `bind_dn` and `password` configuration values
LDAP users with access to your GitLab server (only showing the first 100 results)
	User output sanitized. Found 100 users of 100 limit.

Checking LDAP ... Finished

Checking GitLab App ...

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: ... 
5/4 ... yes
5/19 ... yes
5/20 ... yes
5/21 ... yes
5/22 ... yes
5/23 ... yes
5/24 ... yes
5/25 ... yes
5/26 ... yes
5/27 ... yes
5/30 ... yes
5/31 ... yes
5/34 ... yes
5/36 ... yes
5/37 ... yes
5/39 ... yes
45/40 ... yes
97/41 ... yes
5/42 ... yes
106/43 ... yes
107/44 ... yes
5/45 ... yes
5/51 ... yes
5/52 ... yes
5/53 ... yes
Redis version >= 2.8.0? ... yes
Ruby version >= 2.5.3 ? ... yes (2.6.3)
Git version >= 2.22.0 ? ... yes (2.22.0)
Git user has default SSH configuration? ... yes
Active users: ... 112
Is authorized keys file accessible? ... yes

Checking GitLab App ... Finished


Checking GitLab subtasks ... Finished``

Possible fixes

Not sure, seems like associating deploy keys to a user in general is a bad idea since deploy keys are not suppose to be associated to users https://docs.gitlab.com/ee/ssh/#deploy-keys

Edited Nov 16, 2019 by Nick
Assignee Loading
Time tracking Loading