Expand description
Forge-qualified trust-tuple resources.
A resource names the forge first, then the path on it:
resource = forge-host "/" segment *( "/" segment )
forge-host = lowercased DNS host of the forge: github.com, a GHES host,
codeberg.org, a self-hosted git.example.org, or localhost
segment = lowercased [a-z0-9._-]+, never "." or ".."github.com/acme and github.com/acme/widgets are resources;
acme/widgets is not. The forge is explicit because github.com/acme and
codeberg.org/acme may belong to different people, and a grant that
silently assumed one of them would be a grant to whoever holds the other.
Normalisation is deliberately narrow: ASCII case is folded (GitHub and
Forgejo owners and repo names are case-insensitive, so Acme/Widgets and
acme/widgets are one repository and must be one resource), and nothing
else is repaired. A scheme, a trailing slash, a .git suffix or an empty
segment is refused with a message that says what to write instead, rather
than quietly rewritten — resource is what scopes a signer, and an input
that needed guessing at is one to show back to the operator.
How many path segments a forge allows is the forge’s rule, not the
grammar’s: GitHub and Forgejo have exactly an owner and optionally a repo,
while a forge with nested groups keeps its full path. Callers that know
their forge pass that bound to normalize_resource_with_depth.
Structs§
- Resource
Error - Why a string is not a valid forge-qualified resource.
Enums§
- Resource
Error Kind - The specific rule a resource broke.
Constants§
- MAX_
PATH_ SEGMENTS - Most path segments (after the host)
normalize_resourceaccepts when the caller states no forge-specific bound. GitLab allows 20 levels of subgroup under a top-level group, so this is that plus the project. - MAX_
RESOURCE_ LEN - Longest resource accepted, in bytes. Far above any real forge path (GitHub: 39-byte owners, 100-byte repo names) while keeping a hostile input from turning into an unbounded registry key.
Functions§
- normalize_
resource - Normalise a forge-qualified resource, allowing up to
MAX_PATH_SEGMENTSpath segments after the host. - normalize_
resource_ with_ depth - Normalise a forge-qualified resource with at most
max_path_segmentssegments after the host —2for GitHub and Forgejo (owner/repo). - resource_
contains - Segment-prefix containment of two normalised resources:
scopecontainsresourcewhen it is equal to it or a whole-segment prefix of it.