4

Want to restrict all users in GitHub from deleting an existing tag. Please let us know if there is any way to achieve it. I have found one article where we can protect branches: https://github.com/blog/2051-protected-branches-and-required-status-check

Similarly if there is something through which we can protect tags in GitHub.

Daemon Painter
  • 3,208
  • 3
  • 29
  • 44
SAM
  • 118
  • 1
  • 11
  • Possible duplicate of [Disable tag deletion](https://stackoverflow.com/questions/6390966/disable-tag-deletion) – Dragomir Kolev Aug 21 '17 at 07:06
  • 1
    @DragomirKolev That is not a valid duplicate, because github doesn't allow you to modify the git hooks for the repository – Ferrybig Aug 21 '17 at 07:34
  • Thanks @Ferrybig I was trying to google the same but couldn't find any article for adding git hooks with GitHub to prevent tag deletion. – SAM Aug 21 '17 at 07:41
  • @DragomirKolev if you have achieve this could you please help me with reference article for GitHub. – SAM Aug 21 '17 at 07:42
  • 1
    Set you are only master user. No other one can delete tag. – Vy Do Aug 21 '17 at 09:29
  • There's something called Server-side hooks aswell check https://www.atlassian.com/git/tutorials/git-hooks – Subomi Aug 21 '17 at 12:19

2 Answers2

3

That seems to have been implemented in March 2022, as illustrated by the changelog post:

Tag protection rules

Repository owners can now configure tag protection rules to protect tags in all public repositories and in private repositories on the Pro, Teams or Enterprise plans on GitHub.

Once protected by a tag protection rule, tags matching specified patterns can only be created and deleted by users with "Maintain" or "Admin" permissions to the repository.

For more information, see our documentation.

And, now in public beta:

Protected tags

Our beta tag protection feature gives repo admins the option to protect tags on their repo.
If they choose to do so, only maintainers and admins will be able to create these tags, and only admins will be able to modify or delete these tags.

Tags are protected by patterns - you could protect all tags by using the "*" pattern, but you don’t have to.

To set up and manage these tag protections, we’ve introduced three endpoints, which any repo admin should be able to use:

GET /repos/{owner/{repo}/tags/protection

Returns a list of tag protection rules.

POST /repos/{owner}/{repo}/tags/protection

Creates a new tag protection rule. Payload must include a pattern - example:

curl -" "Authorization: token $GITHUB_TOK"N" -XPOST -d '{"pattern": "*"}' https://api.github.com/repos/JasonEtco/testing/tags/protection

{
"id": 123456,
"pattern": "*",
"created_at": "2022-01-12T12:01:47.094-05:00",
"updated_at": "2022-01-12T12:01:47.094-05:00"
}
DELETE /repos/{owner}/{repo}/tags/protection/{tag_protection_id}

Deletes a tag protection rule.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
2

GitHub currently does not support protecting tags. This means anyone with write access to a repository can push any tag and delete any existing tag. (Unfortunately, I could not find references for this. Thus, I today did an experiment from an account with Collaborator access to a repository owned by a different account, and the Collaborator could push any tag and delete any existing tag. Repository settings only allow protecting branches, not tags.)

There is an open feature request in the GitHub support community, where a GitHub staff member commented in February 2019 that they "are tracking an internal issue about this".

As a workaround, GitHub support suggests to "set up a webhook to be notified if a tag is deleted using [their] API: https://developer.github.com/v3/activity/events/types/#deleteevent ". You could create a GitHub Actions workflow triggered by the delete event, where you could check whether a user (sender field) is allowed to delete a given tag. If deletion is not allowed, you could restore the tag.

Competing products, such as GitLab and Bitbucket Server, apparently do support tag protection.

akku
  • 76
  • 1
  • 7