Download raw body.
gotd: fix reference protection for creations sent with empty pack files
gotd: fix reference protection for creations sent with empty pack files
On Wed, Dec 02, 2026 at 07:15:50PM +0300, Anton Kasimov wrote:
> Hello,
>
> I was investigating why pushing tags created with jujutsu to gotd
> failed with:
>
> fatal: remote error: refs/tags/: reference namespace is protected
>
> whenever "protect tag namespace refs/tags/" is configured. I searched
> for the cause together with an AI agent (Crush with Z.AI GLM), and
> asked it to prepare tests once the problems were confirmed; I reviewed
> the resulting code and diffs as much as I could.
There are plans to improve the reference protection feature soon,
in order to treat the creation and deletion of references as explictly
allowed or denied operations. I will have to extend our test suite
while working on this and will also try to check for the problems
you have pointed out since they all very much relate to this feature.
In any case, I won't commit LLM-generated contributions. While the tests
in your patches could be useful as local reproducers they won't make it
into our test suite for this reason.
FYI, a draft of the new proposed syntax is below.
If you see anything horribly wrong about this, please let me know.
I've been considering changing the allow/deny precedence to first-match
win or last-match wins behaviour. This draft was written under the
assumption that "allow" will always override "deny", but that might change.
# New syntax for allow / deny rules:
# allow [ (overwrite | creation | deletion) [ by (user | :group) ] ]
# deny [ (overwrite | creation | deletion) [ by (user | :group) ] ]
# Overwrite means moving an existing reference: Changing where
# a tag points to, or changing the history a branch tip points to.
# Creation and deletion have their obvious meanings.
# New syntax for setting global reference protection rules.
# Global rules apply to all references in all repositories, unless
# overridden by the repository- and reference-specific rules.
protect references {
deny overwrite # "by everyone" is implied
deny creation # "by everyone" is implied
deny deletion # "by everyone" is implied
# We have a shortcut to do the above:
deny
}
# This allows us to set rules for any names, even outside "refs/".
# Which is needed because, for example, "HEAD" is a reference name
# outside of "refs/".
# If "protect references" is not used in gotd.conf, the default is to
# allow everything, which is equivalent to:
protect references {
allow overwrite
allow creation
allow deletion
# We have a shortcut to do the above:
allow
}
# Here, the global defaults are changed. Nobody can overwrite, only
# admins can create, and only robert can delete.
protect references {
allow creation by :admins
allow deletion by robert
# The implicit default still applies to everyone else:
# deny
}
# New allow/deny syntax also works in repository-specific protection rules:
repository "foo" {
protect {
# These two rules are equivalent:
branch "main" # 1
branch "main" { # 2
# During parsing, every new branch/tag protection
# rule gets initialized with these values, making
# these 3 lines the implicit default:
deny overwrite
deny deletion
deny creation
}
# With the new syntax we can scope reference protection rules
# to specific users and groups:
# In this example, anyone can create the "main" branch if it
# is missing, but only admins may delete it:
branch "main" {
allow creation
allow deletion by :admins
# These implicit defaults still apply to anyone who
# is not allowed above:
# deny overwrite
# deny deletion
}
# Reject attempts by developers to push arbitrary branches
# to the server:
branch namespace "refs/heads" {
allow creation by :admins
# These implicit defaults still apply:
# deny overwrite
# deny deletion
# deny creation
}
# This is not a syntax error but the "deny" rule has no effect
# because of precedence rules:
branch "main" {
allow creation by :developers
deny creation by :developers
}
# This is equivalent to the above, the order does not matter:
branch "main" {
deny creation by :developers
allow creation by :developers
}
# Allow only :taggers to create new tags:
tag namespace "refs/tags" {
# This example allows creation and deletion by taggers
# but not overwrite (deny changing tag objects in one
# push operation which could be a force-push mistake).
allow creation by :taggers
# These implicit defaults still apply:
# deny overwrite
# deny deletion
# deny creation
}
}
}
repository "bar" {
# This repository does not protect references by default,
# no matter what the global default says:
protect allow overwrite
protect allow creation
protect allow deletion
# Same as above:
protect allow
# Also same as above:
protect {
`allow
}
}
gotd: fix reference protection for creations sent with empty pack files
gotd: fix reference protection for creations sent with empty pack files