push using deploy key with write permission fails for old deploy keys
Summary
hi, We have had this self hosted gitlab instance for a few years now and have been constantly updating/migrating the database.
Today I tried to enable an old deploy key for pushs in a repo, but this didn't work when I actually tried to push.
remote: GitLab: You are not allowed to push code to this project.
Turns out, old deploy keys don't have user_id set.
gitlab_development=# select id,user_id,public,created_at from keys where public='t';
id | user_id | public | created_at
-----+---------+--------+----------------------------
96 | 21 | t | 2017-06-13 13:43:41.880239
127 | 21 | t | 2018-09-18 13:57:32.379519
7 | | t | 2015-08-10 11:22:56.500186
30 | | t | 2016-05-19 15:28:29.725857
199 | 21 | t | 2021-06-09 10:20:52.220525
For the database this is not an issue, user_id is nullable, but the code in gitlab doesn't handle this case properly.
Also at no point is the owner of a public deploy key shown in the UI.
Steps to reproduce
- create a project
- create a public deploy key
- enable the deploy key for read/write in the project
- test with a push
- null the user_id field for the key to simulate it being an old migrated key
- test again
What is the current bug behavior?
old migrated deploy keys can't be used for pushing.
What is the expected correct behavior?
I think public keys shouldn't care about their owner, or at the very least the owner should be visible in the UI/be settable.
Results of GitLab environment info
Currently running 13.12.2, but the keys are from 2015/2016.