Skip to content

Fix authorization callers for the Release write actions

What does this MR do?

Previously, we fixed the declarative policy for Releases to take protected tags into account. This MR makes sure if the callers, especially APIs, are correctly calling the declarative policy for Release model.

This MR contains three changes:

  • Adding tests in both Rest and GraphQL APIs if each endpoint is correctly authorizing with protected tags.
  • Fixing some callers to correctly evaluate the protected tags.
    • Since release creation action can't be authorized with ReleasePolicy (technically possible but require some process flow change, that could cause a sideffect), we add the protected tag check in the CreateService.
    • destroy_release permission should be declared in ProjectPolicy, so we've moved to there. This effectively fixes some false-positive tests.
    • Releases::LinkPolicy should delegate to ReleasePolicy. This allows asset-links to use the same authorization model.
    • The GraphQL mutation for link creation should call update_release instead of create_release because it's creating an asset for an existing release i.e. updating an existing release. This root issue is being tracked separately.
  • Adding documentation about the Release permission fix with protected tags.

This fix is still behind evalute_protected_tag_for_release_permissions feature flag.

Related #327505 (closed)

Manual QA

Before the tags are protected:

A project developer can create a release and delete it via API.

shinya@shinya-B550-VISION-D:~/workspace/thin-gdk/services/rails/src$ curl --request DELETE --header "PRIVATE-TOKEN: rUpEqgtcUwxzp9YRKY2x" "http://local.gitlab.test:8181/api/v4/projects/72/releases/v0.2"
{"name":"Awesome ap v0.2","tag_name":"v0.2","description":"","created_at":"2021-07-05T07:03:57.528Z","released_at":"2021-07-05T07:03:57.528Z","author":{"id":100,"name":"shinya Maeda","username":"shinya","state":"active","avatar_url":"https://www.gravatar.com/avatar/d99019d49e480c8654156065b29eeb6f?s=80\u0026d=identicon","web_url":"http://local.gitlab.test:8181/shinya"},"commit":{"id":"0a270645ea6261ca60c711c73b06ba7bcfaf6b5a","short_id":"0a270645","created_at":"2021-07-05T07:00:48.000+00:00","parent_ids":[],"title":"Initial commit","message":"Initial commit","author_name":"Administrator","author_email":"admin@example.com","authored_date":"2021-07-05T07:00:48.000+00:00","committer_name":"Administrator","committer_email":"admin@example.com","committed_date":"2021-07-05T07:00:48.000+00:00","trailers":{},"web_url":"http://local.gitlab.test:8181/root/releases-with-protected-tags/-/commit/0a270645ea6261ca60c711c73b06ba7bcfaf6b5a"},"upcoming_release":false,"commit_path":"/root/releases-with-protected-tags/-/commit/0a270645ea6261ca60c711c73b06ba7bcfaf6b5a","tag_path":"/root/releases-with-protected-tags/-/tags/v0.2","assets":{"count":4,"sources":[{"format":"zip","url":"http://local.gitlab.test:8181/root/releases-with-protected-tags/-/archive/v0.2/releases-with-protected-tags-v0.2.zip"},{"format":"tar.gz","url":"http://local.gitlab.test:8181/root/releases-with-protected-tags/-/archive/v0.2/releases-with-protected-tags-v0.2.tar.gz"},{"format":"tar.bz2","url":"http://local.gitlab.test:8181/root/releases-with-protected-tags/-/archive/v0.2/releases-with-protected-tags-v0.2.tar.bz2"},{"format":"tar","url":"http://local.gitlab.test:8181/root/releases-with-protected-tags/-/archive/v0.2/releases-with-protected-tags-v0.2.tar"}],"links":[]},"evidences":[],"_links":{"self":"http://local.gitlab.test:8181/root/releases-with-protected-tags/-/releases/v0.2","edit_url":"http://local.gitlab.test:8181/root/releases-with-protected-tags/-/releases/v0.2/edit"

After the tags are protected:

A project developer can't create a new release:

2021-07-05_14-08

A project developer can't edit an existing release:

2021-07-05_14-09

A project developer can't delete an existing release:

shinya@shinya-B550-VISION-D:~/workspace/thin-gdk/services/rails/src$ curl --request DELETE --header "PRIVATE-TOKEN: rUpEqgtcUwxzp9YRKY2x" "http://local.gitlab.test:8181/api/v4/projects/72/releases/v0.1"
{"message":"403 Forbidden"}

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

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 Shinya Maeda

Merge request reports