Prevent hidden projects to be cloned or pulled via git actions
What does this MR do and why?
- This MR disables downloading a project (
git cloneorgit pull) if it is marked for delayed deletion (soft-deleted) and is a free project (i.e. it hashiddenset totrue) - Pushing to such projects (
git push) is already blocked.
Screenshots or screen recordings
How to set up and validate locally
- Ensure that your GDK/local setup has ultimate license.
- Enable the
check_namespace_planvia the application settings API so that even if the instance is on an ultimate plan, we can still create users without plans or free plans. - Follow this doc so that your setup behaves as SaaS and therefore even if the instance is on an ultimate plan, we can still create users without plans or free plans OR Enable the
check_namespace_planvia the application settings API so that even if the instance is on an ultimate plan, we can still create groups without plans. - Enable delayed deletion feature at the instance level by navigating to Admin > Settings > General and enable "Default delayed project deletion" and set "Default deletion delay" to a value greater than 0.
- Create a user or use an existing user. Make sure that the user is on free/default plan from the admin panel (
https://gdk.test:3000/admin/usesrs/user-name/edit). - Log in to as the above user and create a new project.
- Clone the project locally using
git clone <git url>. You should be able to clone the repo.
➜ tmp git clone https://gdk.test:3000/root/project1.git
Cloning into 'project1'...
remote: Enumerating objects: 6, done.
remote: Total 6 (delta 0), reused 0 (delta 0), pack-reused 6
Receiving objects: 100% (6/6), done.
- Delete the above project from GitLab (GDK) UI by navigating to the project settings and delete this project.
- Run
git pulllocally from inside the project's directory. You shouldn't be able to pull and see the following error.
➜ project1 git:(main) git pull
remote: You are not allowed to download code from this project.
fatal: unable to access 'https://gdk.test:3000/root/project1.git/': The requested URL returned error: 403
- Remove the cloned project locally by running
rm -rf <project_name>and then clone the project again usinggit clone <git url>. You should get the following error.
git clone https://gdk.test:3000/root/project1.git
Cloning into 'project1'...
remote: You are not allowed to download code from this project.
fatal: unable to access 'https://gdk.test:3000/root/project1.git/': The requested URL returned error: 403
- Login via an admin user and visit the pending deletion dashboard. Restore the above project.
- Clone the repo locally again and this time you should be able to clone it successfully.
➜ tmp git clone https://gdk.test:3000/root/project1.git
Cloning into 'project1'...
remote: Enumerating objects: 6, done.
remote: Total 6 (delta 0), reused 0 (delta 0), pack-reused 6
Receiving objects: 100% (6/6), done.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Relates to https://gitlab.com/gitlab-org/gitlab/-/issues/366568
Edited by Huzaifa Iftikhar
