Unable to fork project or create project from group template if application wide `lock_duo_features_enabled` is `true`
<!--- Please read this! Before opening a new issue, make sure to search for keywords in the issues filtered by the "regression" or "type::bug" label: - https://gitlab.com/gitlab-org/gitlab/issues?label_name%5B%5D=regression - https://gitlab.com/gitlab-org/gitlab/issues?label_name%5B%5D=type::bug and verify the issue you're about to submit isn't a duplicate. ---> ### Summary If an instance has Duo disabled then you cannot fork a project. Additionally, creating a project from a group template results in the destination project having no repository. ### Steps to reproduce **Forking a project** 1. Deploy an instance with some level of Duo license (tested with an Ultimate/Duo Core license) 2. In `Admin>GitLab Duo`\>`Change configuration` set `GitLab Duo availability` to `Always off` 3. Visit `/api/v4/application/settings` and check `lock_duo_features_enabled: true` 4. Create a project and fork it 5. Project is half created with no repository **Creating a project from group template** 1. Create a top-level group 2. Create a subgroup within the group called `Templates` 3. Create a project with some content in the `Templates` subgroup 4. [Set the subgroup to be the template source for the group](https://docs.gitlab.com/user/group/custom_project_templates/#set-up-project-templates-for-a-group) 5. Create a new project in the top-level group from the newly created template 6. Notice it imports as expected 7. Now set `lock_duo_features_enabled` to `true` - UI: `Admin -> GitLab Duo -> Change configuration -> select 'Always off'` - API: `curl -X PUT -H "PRIVATE-TOKEN: $PAT" http://gitlab.example.net/api/v4/application/settings?lock_duo_features_enabled=true` 8. Now attempt to create a new project from the template in the top-level group 9. Notice how the import fails and the project is created with no repository ### Example Project n/a ### What is the current _bug_ behavior? Project is created but the import process does not complete so there is no git repo. An error is also logged: ```json {"severity":"ERROR","time":"2025-09-02T12:24:09.100Z","correlation_id":"01K4564X77ZW4EQJN8KAXG7JV4","meta.caller_id":"POST /api/:version/projects/:id/fork","meta.remote_ip":"","meta.feature_category":"source_code_management","meta.user":"root","meta.user_id":1,"meta.project":"test/test","meta.root_namespace":"test","meta.client_id":"user/1","meta.organization_id":1,"message":"Unable to save project. Error: Unable to save #\u003cActiveRecord::RecordInvalid: Validation failed: Duo features enabled cannot be changed because it is locked by an ancestor\u003e: Duo features enabled cannot be changed because it is locked by an ancestor Project ID: 4"} ``` ### What is the expected _correct_ behavior? Project successfully forked. ### Relevant logs and/or screenshots <!--Paste any relevant logs - please use code blocks (```) to format console output, logs, and code as it's tough to read otherwise.--> ### Output of checks <!--If you are reporting a bug on GitLab.com, uncomment below--> <!--This bug happens on GitLab.com--> <!--and uncomment below if you have /label privileges--> <!--/label ~"reproduced on GitLab.com"--> <!--or follow up with an issue comment of `@gitlab-bot label ~"reproduced on GitLab.com"` if you do not--> #### Results of GitLab environment info <!--Input any relevant GitLab environment information if needed.--> <details> <summary>Expand for output related to GitLab environment info</summary> <pre> \# gitlab-rake gitlab:env:info System information System: Proxy: no Current User: git Using RVM: no Ruby Version: 3.2.8 Gem Version: 3.6.9 Bundler Version:2.7.1 Rake Version: 13.0.6 Redis Version: 7.2.10 Sidekiq Version:7.3.9 Go Version: unknown GitLab information Version: 18.3.1-ee Revision: cb15859792b Directory: /opt/gitlab/embedded/service/gitlab-rails DB Adapter: PostgreSQL DB Version: 16.8 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 Elasticsearch: no Geo: no Using LDAP: no Using Omniauth: yes Omniauth Providers: GitLab Shell Version: 14.44.0 Repository storages: - default: unix:/var/opt/gitlab/gitaly/gitaly.socket GitLab Shell path: /opt/gitlab/embedded/service/gitlab-shell Gitaly - default Address: unix:/var/opt/gitlab/gitaly/gitaly.socket - default Version: 18.3.1 - default Git Version: 2.50.1.gl1 </pre> </details> #### Results of GitLab application Check <!--Input any relevant GitLab application check information if needed.--> <details> <summary>Expand for output related to the GitLab application check</summary> <pre> # gitlab-rake gitlab:check SANITIZE=true Checking GitLab subtasks ... Checking GitLab Shell ... GitLab Shell: ... GitLab Shell version \>= 14.44.0 ? ... OK (14.44.0) Running /opt/gitlab/embedded/service/gitlab-shell/bin/gitlab-shell-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 (cluster/worker) ... 1/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: ... LDAP is disabled in config/gitlab.yml Checking LDAP ... Finished Checking GitLab App ... Database config exists? ... yes Tables are truncated? ... skipped All migrations up? ... yes Database contains orphaned GroupMembers? ... no GitLab config exists? ... yes GitLab config up to date? ... yes Cable config exists? ... yes Resque config exists? ... 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? ... skipped (no tmp uploads folder yet) Systemd unit files or init script exist? ... skipped (omnibus-gitlab has neither init script nor systemd units) Systemd unit files or init script up-to-date? ... skipped (omnibus-gitlab has neither init script nor systemd units) Projects have namespace: ... 35/1 ... yes 35/2 ... yes 35/3 ... yes 35/4 ... yes Redis version \>= 6.2.14? ... yes Ruby version \>= 3.0.6 ? ... yes (3.2.8) Git user has default SSH configuration? ... yes Active users: ... 1 Is authorized keys file accessible? ... yes GitLab configured to store new projects in hashed storage? ... yes All projects are in hashed storage? ... yes Elasticsearch version 7.x-9.x or OpenSearch version 1.x-3.x ... skipped (advanced search is disabled) All migrations must be finished before doing a major upgrade ... skipped (Advanced Search is disabled) Checking GitLab App ... Finished Checking GitLab subtasks ... Finished </pre> </details> ### Possible fixes <!--If you can, link to the line of code that might be responsible for the problem.--> ### Patch release information for backports If the bug fix needs to be backported in a [patch release](https://handbook.gitlab.com/handbook/engineering/releases/patch-releases) to a version under [the maintenance policy](https://docs.gitlab.com/policy/maintenance/), please follow the steps on the [patch release runbook for GitLab engineers](https://gitlab.com/gitlab-org/release/docs/-/blob/master/general/patch/engineers.md). Refer to the [internal "Release Information" dashboard](https://dashboards.gitlab.net/d/delivery-release_info/delivery3a-release-information?orgId=1) for information about the next patch release, including the targeted versions, expected release date, and current status. #### High-severity bug remediation To remediate high-severity issues requiring an [internal release](https://handbook.gitlab.com/handbook/engineering/releases/internal-releases/) for single-tenant SaaS instances, refer to the [internal release process for engineers](https://gitlab.com/gitlab-org/release/docs/-/blob/master/general/internal-releases/engineers.md?ref_type=heads). <!--If you don't have /label privileges, follow up with an issue comment of `@gitlab-bot label ~"type::bug"`-->
issue