Edwin Kempin | 6b2a18c | 2020-09-22 17:04:56 +0200 | [diff] [blame] | 1 | # Validation |
| 2 | |
| 3 | The code owners functionality relies on the validity of the following: |
| 4 | |
| 5 | * [code owner config files](user-guide.html#codeOwnerConfigFiles) that define |
| 6 | the code owners |
| 7 | * [code-owner.config](config.html#projectLevelConfigFile) files in the |
| 8 | 'refs/meta/config' branches of the projects that contain the project-level |
| 9 | configuration of the `@PLUGIN@` plugin |
| 10 | |
| 11 | To reduce the risk that these files become invalid, they are validated when |
Edwin Kempin | 3d489e2 | 2020-09-30 12:57:08 +0200 | [diff] [blame] | 12 | they are modified and invalid modifications are rejected. In addition code owner |
| 13 | config files in a repository can be validated on demand by the [Check code |
| 14 | owners files REST endpoint](rest-api.html#check-code-owner-config-files). |
Edwin Kempin | 6b2a18c | 2020-09-22 17:04:56 +0200 | [diff] [blame] | 15 | |
| 16 | **NOTE:** Most configuration issues are gracefully handled and do not break the |
| 17 | code owners functionality (e.g. non-resolveable code owners or non-resolveable |
| 18 | imports are silently ignored), however some configuration issue (non-parseable |
| 19 | configuration files, configuration of a non-existing [backend](backends.html) |
| 20 | etc.) are severe errors and block the submission of all changes for which the |
| 21 | affected configuration files are relevant. |
| 22 | |
Edwin Kempin | 205285a | 2020-12-01 09:53:04 +0100 | [diff] [blame] | 23 | **NOTE:** It's possible to disable the validation of code owner config files on |
| 24 | push and setup an [external |
| 25 | validation](config-guide.html#externalValidationOfCodeOwnerConfigs) by a CI bot |
| 26 | instead. In this case findings would be posted on the change. |
| 27 | |
Edwin Kempin | 6b2a18c | 2020-09-22 17:04:56 +0200 | [diff] [blame] | 28 | All validations are best effort to prevent invalid configurations from |
| 29 | entering the repository, but not all possible issues can be prevented. Doing the |
| 30 | validation is useful since it prevents most issues and also gives quick feedback |
| 31 | to uploaders about typos (e.g. if an email is misspelled it's not breaking |
| 32 | anything, but the intended change of the uploader is not working). |
| 33 | |
| 34 | No validation is done when: |
| 35 | |
| 36 | * the `@PLUGIN@` plugin is not installed/enabled (this means when the `@PLUGIN@` |
| 37 | plugin gets installed/enabled, it is possible that invalid configuration files |
| 38 | already exist in the repository) |
| 39 | * updates happen behind Gerrit's back (e.g. pushes that bypass Gerrit) |
Edwin Kempin | b05f24f | 2020-12-11 13:03:29 +0100 | [diff] [blame] | 40 | * the validation is disabled via the |
| 41 | [enableValidationOnCommitReceived](config.html#codeOwnersEnableValidationOnCommitReceived) |
| 42 | or [enableValidationOnSubmit](config.html#codeOwnersEnableValidationOnSubmit) |
| 43 | config options |
Edwin Kempin | ea5f832 | 2021-03-12 15:37:48 +0100 | [diff] [blame] | 44 | * the [--code-owners~skip-validation](#skipCodeOwnerConfigValidationOnDemand) |
| 45 | push option was specified on push |
Edwin Kempin | 6b2a18c | 2020-09-22 17:04:56 +0200 | [diff] [blame] | 46 | |
| 47 | In addition for [code owner config files](user-guide.html#codeOwnerConfigFiles) |
| 48 | no validation is done when: |
| 49 | |
| 50 | * the code owners functionality is disabled for the repository or branch (this |
| 51 | means when the code owners functionality gets enabled, it is possible that |
| 52 | invalid code owner configs already exist in the repository) |
| 53 | * the `@PLUGIN@` plugin configuration is invalid (in this case we don't know |
| 54 | which files are code owner config files, so we allow all uploads rather than |
| 55 | blocking all uploads, to reduce the risk of breaking the plugin configuration |
| 56 | `code-owner.config` files are validated too) |
| 57 | |
Edwin Kempin | 29b692c | 2021-01-19 11:45:22 +0100 | [diff] [blame] | 58 | ## <a id="howCodeOwnerConfigsCanGetIssuesAfterSubmit"> |
Edwin Kempin | 6b2a18c | 2020-09-22 17:04:56 +0200 | [diff] [blame] | 59 | In addition it is possible that [code owner config |
| 60 | files](user-guide.hmtl#codeOwnerConfigFiles) get issues after they have been |
| 61 | submitted: |
| 62 | |
| 63 | * configuration parameters that are relevant for the validation are changed |
| 64 | (e.g. the [accounts.visibility](../../../Documentation/config-gerrit.html#accounts.visibility) |
| 65 | setting is changed, [another code owners backend is |
| 66 | configured](setup-guide.html#configureCodeOwnersBackend) which now uses a |
Edwin Kempin | c85684a | 2021-01-19 12:01:01 +0100 | [diff] [blame] | 67 | different syntax or different names for code owner config files, the [file |
| 68 | extension for code owner config file is set/changed](config.html#codeOwnersFileExtension), |
Edwin Kempin | 3ded05a | 2021-06-09 15:09:37 +0200 | [diff] [blame] | 69 | [arbitrary file extensions for code owner config files](config.html#codeOwnersEnableCodeOwnerConfigFilesWithFileExtensions) |
| 70 | get enabled/disabled or the [allowed email domains are |
| 71 | changed](config.html#pluginCodeOwnersAllowedEmailDomain)) |
Edwin Kempin | 6b2a18c | 2020-09-22 17:04:56 +0200 | [diff] [blame] | 72 | * emails of users may change so that emails in code owner configs can no longer |
| 73 | be resolved |
| 74 | * imported code owner config files may get deleted or renamed so that import |
| 75 | references can no longer be resolved |
| 76 | |
| 77 | When updating [code owner config files](user-guide.html#codeOwnerConfigFiles) |
| 78 | the validation only rejects the update if it introduces **new** issues. This |
| 79 | means the update is allowed if: |
| 80 | |
| 81 | * there are issues that are still present after the update, but the update |
| 82 | doesn't introduce any new issues |
| 83 | * the file was non-parseable and the update makes it parseable, but issues are |
| 84 | present (since a parseable file with issues is better than a non-parseable |
| 85 | file) |
| 86 | * the file was non-parseable and with the update it is still non-parseable |
| 87 | |
| 88 | For [code owner config files](user-guide.html#codeOwnerConfigFiles) the |
Edwin Kempin | 1914db5 | 2021-03-24 15:31:23 +0100 | [diff] [blame] | 89 | validation may also be performed on submit (in addition to the validation that |
| 90 | is performed on upload of the change, see |
| 91 | [enableValidationOnSubmit](config.html#codeOwnersEnableValidationOnSubmit) |
| 92 | config setting). Repeating the validation on submit can make sense because |
| 93 | relevant configuration can change between the time a change is uploaded and the |
| 94 | time a change is submitted. If enabled, on submit we repeat the exact same |
| 95 | validation that was done on upload. This means, all visibility checks will be |
| 96 | done from the perspective of the uploader. |
Edwin Kempin | 6b2a18c | 2020-09-22 17:04:56 +0200 | [diff] [blame] | 97 | |
Edwin Kempin | 515aec0 | 2022-02-11 15:26:27 +0100 | [diff] [blame] | 98 | ## <a id="codeOwnerConfigValidationOnBranchCreation">Code owner config validation on branch creation |
| 99 | |
| 100 | It's possible to [enable validation of code owner config files on branch |
| 101 | creation](config.html#pluginCodeOwnersEnableValidationOnBranchCreation) (off by |
| 102 | default). |
| 103 | |
| 104 | If the validation is enabled and a new branch is created, all code owner config |
| 105 | files that are contained in the initial commit are newly validated, even if the |
| 106 | branch is created for a commit that already exists in the repository. |
| 107 | |
| 108 | Validating code owner config files newly when a branch is created makes sense |
| 109 | because: |
| 110 | |
| 111 | * the validation configuration of the new branch may differ from the validation |
| 112 | configuration of the branch that already contains the commit |
| 113 | * [imports from other projects](backend-find-owners.html#referenceCodeOwnerConfigFilesFromOtherProjects) |
| 114 | that do not specify a branch may not be resolvable: If a branch is not |
| 115 | specified it's assumed that the code owner config file from the other project |
| 116 | should be imported from the same branch that contains the importing code owner |
| 117 | config. This means when a new branch `foo` is being created a code owner |
| 118 | config file that is referenced by such an import is expected to be found in |
| 119 | the branch `foo` of the other project, but this branch may not exist there so |
| 120 | that the import is unresolvable. By validating the code owner config files on |
| 121 | branch creation such unresolvable imports are detected and flagged. |
| 122 | |
| 123 | What should be done if the creation of a branch fails due to invalid code owner |
| 124 | config files is explained in the |
| 125 | [config FAQs](config-faqs.html#branchCreationFailsDueInvalidCodeOwnerConfigFiles). |
| 126 | |
Edwin Kempin | 2fd84e0 | 2021-05-17 09:02:53 +0000 | [diff] [blame] | 127 | ## <a id="skipCodeOwnerConfigValidationOnDemand">Skip code owner config validation on demand |
| 128 | |
Edwin Kempin | 65181c4 | 2021-06-15 14:32:12 +0200 | [diff] [blame] | 129 | By setting the `code-owners~skip-validation` push option it is possible to skip |
| 130 | the code owner config validation on push: |
| 131 | `git push -o code-owners~skip-validation origin HEAD:refs/for/master` |
Edwin Kempin | 2fd84e0 | 2021-05-17 09:02:53 +0000 | [diff] [blame] | 132 | |
Edwin Kempin | 56df6ea | 2022-02-11 13:47:55 +0100 | [diff] [blame] | 133 | For the [Create |
Edwin Kempin | 515aec0 | 2022-02-11 15:26:27 +0100 | [diff] [blame] | 134 | Branch](../../../Documentation/rest-api-projects.html#create-branch), [Create |
Edwin Kempin | 56df6ea | 2022-02-11 13:47:55 +0100 | [diff] [blame] | 135 | Change](../../../Documentation/rest-api-changes.html#create-change), the [Cherry |
| 136 | Pick Revision](../../../Documentation/rest-api-changes.html#cherry-pick) and the |
| 137 | [Rebase](../../../Documentation/rest-api-changes.html#rebase-change) REST |
| 138 | endpoints skipping the code owner config validation is possible by setting |
Edwin Kempin | 0be9119 | 2021-06-15 14:28:41 +0200 | [diff] [blame] | 139 | `code-owners~skip-validation` with the value `true` as a validation option in |
Edwin Kempin | 56df6ea | 2022-02-11 13:47:55 +0100 | [diff] [blame] | 140 | the input (see field `validation_options`). |
Edwin Kempin | ec23f6e | 2022-02-10 09:20:31 +0100 | [diff] [blame] | 141 | |
Edwin Kempin | 0be9119 | 2021-06-15 14:28:41 +0200 | [diff] [blame] | 142 | Using the push option or the validation option requires the calling user to |
| 143 | have the `Can Skip Code Owner Config Validation` global capability. Host |
| 144 | administrators have this capability implicitly assigned via the `Administrate |
| 145 | Server` global capability. |
Edwin Kempin | 2fd84e0 | 2021-05-17 09:02:53 +0000 | [diff] [blame] | 146 | |
| 147 | **NOTE:** Using this option only makes sense if the [code owner config validation |
| 148 | on submit](config.html#pluginCodeOwnersEnableValidationOnSubmit) is disabled, as |
| 149 | otherwise it's not possible to submit the created change (using the push option |
| 150 | only skips the validation for the push, but not for the submission of the |
| 151 | change). |
| 152 | |
Edwin Kempin | 6b2a18c | 2020-09-22 17:04:56 +0200 | [diff] [blame] | 153 | ### <a id="codeOwnerConfigFileChecks">Validation checks for code owner config files |
| 154 | |
| 155 | For [code owner config files](user-guide.html#codeOwnerConfigFiles) the |
| 156 | following checks are performed: |
| 157 | |
| 158 | * the code owner config files are parseable |
Edwin Kempin | 91664dd | 2021-03-24 14:12:50 +0100 | [diff] [blame] | 159 | * the code owner emails are resolveable (unless this check is |
| 160 | [disabled](config.html#codeOwnersRejectNonResolvableCodeOwners)):\ |
Edwin Kempin | 6b2a18c | 2020-09-22 17:04:56 +0200 | [diff] [blame] | 161 | a code owners email is not resolveable if: |
| 162 | * the account that owns it is inactive |
| 163 | * the account that owns it is not visible to the uploader (according to |
| 164 | [accounts.visibility](../../../Documentation/config-gerrit.html#accounts.visibility) |
| 165 | setting) |
| 166 | * it is a non-visible secondary email |
| 167 | * there is no account that has this email assigned |
Edwin Kempin | ba6cd40 | 2021-02-24 10:11:35 +0100 | [diff] [blame] | 168 | * it is ambiguous (the same email is assigned to multiple active accounts) |
Edwin Kempin | 6b2a18c | 2020-09-22 17:04:56 +0200 | [diff] [blame] | 169 | * it has an email domain that is disallowed (see |
| 170 | [allowedEmailDomain](config.html#pluginCodeOwnersAllowedEmailDomain)) |
| 171 | configuration |
Edwin Kempin | 91664dd | 2021-03-24 14:12:50 +0100 | [diff] [blame] | 172 | * the imports are resolveable (unless this check is |
| 173 | [disabled](config.html#codeOwnersRejectNonResolvableImports)):\ |
Edwin Kempin | 6b2a18c | 2020-09-22 17:04:56 +0200 | [diff] [blame] | 174 | an import is not resolveable if: |
| 175 | * the imported file is not a code owner config file |
| 176 | * the imported file is not parseable |
| 177 | * the imported file doesn't exists |
| 178 | * the branch from which the file should be imported doesn't exist or is not |
| 179 | visible to the uploader |
| 180 | * the project from which the file should be imported doesn't exist or is not |
| 181 | visible to the uploader |
| 182 | * the project from which the file should be imported doesn't permit reads |
| 183 | (e.g. has the state `HIDDEN`) |
| 184 | |
Edwin Kempin | 9bb9014 | 2022-06-09 13:44:56 +0200 | [diff] [blame] | 185 | **NOTE:** Non-resolvable code owner emails are rejected with a generic message, |
| 186 | rather than informing about the exact reason why a code owner email is not |
| 187 | resolvable. This is intentional and prevents that uploaders can probe the |
| 188 | existence of emails/accounts (if specific reasons would be returned an uploader |
| 189 | could create a code owner config file with arbitrary emails and then deduce from |
| 190 | the messages which emails/accounts exist, which would a privacy issue). |
| 191 | |
Edwin Kempin | 2166004 | 2020-12-11 15:42:54 +0100 | [diff] [blame] | 192 | **NOTE:** Whether commits that newly add non-resolvable code owners and |
| 193 | non-resolvable imports are rejected on commit received and on submit is |
| 194 | controlled by the |
| 195 | [rejectNonResolvableCodeOwners](config.html#pluginCodeOwnersRejectNonResolvableCodeOwners) |
| 196 | and [rejectNonResolvableImports](config.html#pluginCodeOwnersRejectNonResolvableImports) |
| 197 | config settings. |
| 198 | |
Edwin Kempin | 6b2a18c | 2020-09-22 17:04:56 +0200 | [diff] [blame] | 199 | The following things are **not** checked (not an exhaustive list): |
| 200 | |
| 201 | * Cycles in imports of owner config files:\ |
| 202 | Detecting cycles in imports can be expensive and they are not seen as a |
| 203 | problem. When imports are resolved we keep track of the imported code owner |
| 204 | config files and stop if we see a code owner config file that we’ve imported |
| 205 | already. This behaviour is consistent with how Gerrit handles cycles in group |
| 206 | includes. |
| 207 | * Impossible code owner configurations:\ |
| 208 | It is possible to create a code owner configuration where some folders/files |
| 209 | have no code owners. In this case nobody can give a code owner approval for |
| 210 | these folders/files, and submitting changes to them requires a |
| 211 | [code owner override](user-guide.html#codeOwnerOverride). |
| 212 | |
| 213 | |
Edwin Kempin | bdb3282 | 2020-12-11 14:05:24 +0100 | [diff] [blame] | 214 | ### <a id="codeOwnersConfigFileChecks">Validation checks for code-owners.config files |
Edwin Kempin | 6b2a18c | 2020-09-22 17:04:56 +0200 | [diff] [blame] | 215 | |
| 216 | For the [code-owner.config](config.html#projectLevelConfigFile) in the |
| 217 | `refs/meta/config` branch the following checks are performed: |
| 218 | |
| 219 | * `code-owner.config` file is parseable |
| 220 | * the [codeOwners.backend](config.html#codeOwnersBackend) and |
| 221 | [codeOwners.\<branch\>.backend](config.html#codeOwnersBranchBackend) |
| 222 | configurations are valid (that they reference an existing [code owner |
| 223 | backend](backends.html)) |
| 224 | * the [codeOwners.disabled](config.html#codeOwnersDisabled) and |
| 225 | [codeOwners.disabledBranch](config.html#codeOwnersDisabledBranch) |
| 226 | configurations are valid (that they have parseable value) |
| 227 | * the [codeOwners.requiredApproval](config.html#codeOwnersRequiredApproval) |
| 228 | and [codeOwners.overrideApproval](config.html#codeOwnersOverrideApproval) |
| 229 | configurations are valid (that they reference an existing label that has a |
| 230 | range that covers the specified voting value, it's currently not possible to |
| 231 | add the definition of this label in the same commit but it must be present |
| 232 | before) |
Edwin Kempin | 748b63a | 2020-09-24 09:13:50 +0200 | [diff] [blame] | 233 | * the [codeOwners.mergeCommitStrategy](config.html#codeOwnersMergeCommitStrategy) |
| 234 | configuration is valid |
Edwin Kempin | e184988 | 2020-11-26 13:19:13 +0100 | [diff] [blame] | 235 | * the [codeOwners.fallbackCodeOwners](config.html#codeOwnersFallbackCodeOwners) |
| 236 | configuration is valid |
Edwin Kempin | aa2c255 | 2020-12-14 09:29:29 +0100 | [diff] [blame] | 237 | * the [codeOwners.maxPathsInChangeMessages](config.html#codeOwnersMaxPathsInChangeMessages) |
| 238 | configuration is valid |
Edwin Kempin | 6b2a18c | 2020-09-22 17:04:56 +0200 | [diff] [blame] | 239 | |
| 240 | --- |
| 241 | |
| 242 | Back to [@PLUGIN@ documentation index](index.html) |
| 243 | |
| 244 | Part of [Gerrit Code Review](../../../Documentation/index.html) |