Skip to content

Add validation to Conan recipe that conforms with Conan.io

What does this MR do?

Description

The GitLab Conan registry does not have the same validation in the package recipe that the Conan client is checking as reported in #214471 (closed). This can lead to problems when working with the GitLab registry.

Proposed solution

All four parts of the recipe: <pkg-name>/<version>@<user>/<channel> are validated by modifying the current regex Gitlab::Regex.conan_recipe_component_regex to use the one in Conan.io - (^[a-zA-Z0-9_][a-zA-Z0-9_\+\.-]{1,50}$). Which is used in the following files:

  • Validates all four of the component parameters in the incoming request on https://gitlab.com/gitlab-org/gitlab/blob/master/ee/lib/api/conan_packages.rb#L86 as PACKAGE_COMPONENT_REGEX
  • Validates both :name and version: in the Packages::Package model as <pkg-name> and <version> resp.
  • Validates both :package_username and :package_channel in the Packages::ConanMetadatum model as <user> and <channel> resp.

TODO

I am not sure if the :name should be validated again with format: { with: Gitlab::Regex.package_name_regex } as in https://gitlab.com/gitlab-org/gitlab/blob/master/ee/app/models/packages/package.rb#L26. I am thinking of adding unless: :conan? Also, am not sure if tests should be added to ee/spec/models/packages/package_spec.rb, ee/spec/requests/api/conan_packages_spec.rb and ee/spec/services/packages/conan

Update

  • Separate :name format validations for all other packages from Conan package using :unless conan?
  • Add test for Gitlab::Regex.conan_recipe_component_regex to check for the format rules as follows:
    • minimum of two characters
    • maximum of fifty characters
    • starts with only alphanumeric or underscore
    • includes only alphanumeric, _, +, . and -

Screenshots

Regex format from conan.io

image

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • 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

Closes #214471 (closed)

Edited by Nick Thomas

Merge request reports

Loading