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 theCreateService
. -
destroy_release
permission should be declared inProjectPolicy
, so we've moved to there. This effectively fixes some false-positive tests. -
Releases::LinkPolicy
should delegate toReleasePolicy
. This allows asset-links to use the same authorization model. - The GraphQL mutation for link creation should call
update_release
instead ofcreate_release
because it's creating an asset for an existing release i.e. updating an existing release. This root issue is being tracked separately.
- Since release creation action can't be authorized with
- 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:
A project developer can't edit an existing release:
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
-
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