Draft: Never select storages that are weighted zero
What does this MR do?
Fixes #36175
When creating a new project, the storage that the project repository is put in should be decided by a weighted random configuration in the admin https://docs.gitlab.com/ee/administration/repository_storage_paths.html#configure-where-new-repositories-are-stored. Ideally it wouldn't matter if we had a "default" storage or not, as long as someone has configured the weights.
There are a couple of problems that prevent this from working intuitively:
- When a new storage is setup, by default it is assumed to have a weight of zero, unless it is called "default" then it is assumed to be 100. So if you have no storage called "default" then by default all weights are assumed to be zero. If all weights are zero, then they act like all weights are 100. This means new projects will be randomly assigned even when the admin doesn't want them to be. This does not follow our docs which say:
(storage weight) / (sum of all weights) * 100 = chance %
i.e. zero weight = zero chance. - If the weighted random finds no candidates, the projects column default will select 'default' regardless of configuration.
To make this work how we might expect this MR:
- Explicitly filter out any storages that are set to zero. This makes sure when everything is zero on first bootup (because we have no "default") we wont accidentally put projects in unexpected storages.
- Removes the column default for repository_storage. This makes sure that there's no chance of default being used when it is weighted zero. This column has a presence validation that will prevent projects being created in this case.
Does this MR meet the acceptance criteria?
Conformity
-
I have included changelog trailers, or none are needed. (Does this MR need a changelog?) -
I have added/updated documentation, or it's not needed. (Is documentation required?) -
I have properly separated EE content from FOSS, or this MR is FOSS only. (Where should EE code go?) -
I have added information for database reviewers in the MR description, or it's not needed. (Does this MR have database related changes?) -
I have self-reviewed this MR per code review guidelines. -
This MR does not harm performance, or I have asked a reviewer to help assess the performance impact. (Merge request performance guidelines) -
I have followed the style guides. -
This change is backwards compatible across updates, or this does not apply.
Availability and Testing
-
I have added/updated tests following the Testing Guide, or it's not needed. (Consider all test levels. See the Test Planning Process.) -
I have tested this MR in all supported browsers, or it's not needed. -
I have informed the Infrastructure department of a default or new setting change per definition of done, or it's not needed.
Security
Does this MR contain changes to processing or storing of credentials or tokens, authorization and authentication methods or other items described in the security review guidelines? If not, then delete this Security section.
-
Label as security and @ mention @gitlab-com/gl-security/appsec
-
The MR includes necessary changes to maintain consistency between UI, API, email, or other methods -
Security reports checked/validated by a reviewer from the AppSec team
Edited by James Fargher