Allow downloading release assets without authentication by BagToad · Pull Request #13723 · cli/cli · GitHub
Skip to content

Allow downloading release assets without authentication#13723

Draft
BagToad wants to merge 3 commits into
trunkfrom
bagtoad/disable-auth-check-release-clone
Draft

Allow downloading release assets without authentication#13723
BagToad wants to merge 3 commits into
trunkfrom
bagtoad/disable-auth-check-release-clone

Conversation

@BagToad

@BagToad BagToad commented Jun 24, 2026

Copy link
Copy Markdown
Member

Fixes #2680

Description

gh release download now works without authentication against public repositories, matching gh extension install. A token is still used when one is present.

Key Points

This change has three parts, from simplest to subtlest:

  • Why drop the auth gate - the login requirement is unnecessary for public downloads.
  • Fixing the by-tag race to be success oriented - an anonymous draft-lookup 403 no longer masks a release the REST lookup found.
  • Honoring the gate under repo override - the cobra plumbing fix that makes the dropped gate apply to download.

Why drop the auth gate

Release endpoints for public repositories are readable anonymously over REST, so the login gate is unnecessary. Removing it is the same one-line cmdutil.DisableAuthCheck change that #13176 made for gh extension install.

The same logic here applies as with gh extension install:

What this says is that extension installation is going to happen unauthenticated whether we make it easier or not. We might as well make it easier and keep people installing through our core commands.

In gh release download - people are going to just curl the endpoint directly, and that degrades their experience since we provide a lot of abstractions over the API that make gh much more than a curl/gh api call.

But I'll broaden the conversation - we got feedback that folks are using gh release download more in CI and they want to secure their CI by not providing gh a token unless it's necessary. If you're downloading a public asset, that's not necessary and we force you to use a larger than necessary token scope.

Fixing the by-tag race to be success oriented

The by-tag path creates problems that make this deviate a bit from gh ext install - that's one reason why this diff is a bit bigger. FetchRelease races a published-release REST lookup against a draft-release GraphQL lookup. GraphQL rejects anonymous requests, so the draft lookup returns a 403. The old selector returned the first result unless it was exactly ErrReleaseNotFound, so that 403 could win the race and mask a release the REST lookup found.

The selector now prefers a found release and only errors when both lookups fail. We used to return whichever result arrived first, treating only a not-found error as a reason to wait for the second:

// Before - a non-not-found error from either lookup wins
res := <-results
if errors.Is(res.error, ErrReleaseNotFound) {
    res = <-results
    cancel()
} else {
    cancel()
    <-results // drain the channel
}
return res.release, res.error

Now we take a success from either lookup, and only surface an error when both fail:

// Now - a found release wins; an error needs both lookups to fail
first := <-results
if first.error == nil {
    cancel()
    <-results // drain the channel
    return first.release, nil
}

second := <-results
cancel()
if second.error == nil {
    return second.release, nil
}
if errors.Is(second.error, ErrReleaseNotFound) {
    return nil, second.error
}
return nil, first.error

This also stops a transient draft-lookup failure from masking a real release for authenticated users.

Honoring the gate under repo override

Removing the gate did not take effect on its own. release enables the -R/--repo override, and that installs a PersistentPreRunE on the release command. cobra runs only the nearest such hook walking up from the command you invoked, so the override hook shadows the root auth gate. The override re-runs the nearest ancestor hook to make up for that, but it handed the ancestor to the hook as the command, so the auth gate judged release instead of download and never saw download's DisableAuthCheck.

The fix keeps the invoked command and passes that leaf up, the node cobra would have judged if the repo override didn't muck with it:

// Before - climbs by reassigning cmd, so the gate is judged against the ancestor
for cmd.HasParent() {
    cmd = cmd.Parent()
    if cmd.PersistentPreRunE != nil {
        return cmd.PersistentPreRunE(cmd, args)
    }
}

// Now - keep the invoked leaf and pass it up
for p := overrideCmd.Parent(); p != nil; p = p.Parent() {
    if p.PersistentPreRunE != nil {
        return p.PersistentPreRunE(cmd, args)
    }
}

This mirrors cobra's own execute loop, which walks the parents but always hands them the leaf command. cobra's EnableTraverseRunHooks global would run the whole chain for us and maybe is a better long term fix, but it is process-wide and would change pre-run behavior for every command, so I'm not touching it here.

I guarded this with an integration test, since the bug only surfaces with the pieces wired together. Test_EnableRepoOverride_authCheckIntegration builds a root gate, a repo-override parent, and a leaf, then asserts the gate judged the leaf: opting out with DisableAuthCheck skips the check, otherwise the gate still runs. It lives in cmdutil beside the helper, since the coupling is the helper's, not any one command's.

Notes for reviewers

Three atomic commits:

  • fix(release): don't let a failed draft lookup mask a found release changes the selector in FetchRelease and adds a regression case to the existing Test_downloadRun table.
  • feat(release): allow download without authentication removes the gate in the download command.
  • fix(cmdutil): honor DisableAuthCheck under repo-override parents fixes the repo-override helper so the gate removal actually takes effect, and adds an integration test that pins the coupling between repo override and the root auth gate.

Additional Context

BagToad and others added 2 commits June 24, 2026 17:38
FetchRelease races a published-release REST lookup against a draft-release
GraphQL lookup, and returned the first result unless it was ErrReleaseNotFound.
A failing draft lookup, such as a 403 when unauthenticated, could mask a release
the published lookup found. Prefer a found release and only error when both fail.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Downloading assets from a public repository's release works unauthenticated
over REST, so drop the login gate. A token is still used when present.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 24, 2026 23:39
@BagToad BagToad requested review from a team as code owners June 24, 2026 23:39
@BagToad BagToad requested a review from babakks June 24, 2026 23:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request updates gh release download to work without requiring authentication for public repositories, and adjusts release lookup behavior to avoid a failed draft (GraphQL) lookup masking a successful published (REST) lookup.

Changes:

  • Bypass the pre-execution login gate for gh release download.
  • Update shared.FetchRelease selection logic to prefer a successful lookup result over an error from the other concurrent lookup.
  • Add a regression test ensuring an unauthorized draft lookup does not prevent downloading a published release by tag.
Show a summary per file
File Description
pkg/cmd/release/shared/fetch.go Changes concurrent published/draft selection logic for by-tag release lookup.
pkg/cmd/release/download/download.go Disables the auth check gate so downloads can proceed unauthenticated.
pkg/cmd/release/download/download_test.go Adds coverage for the “draft lookup unauthorized” regression scenario.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 3/3 changed files
  • Comments generated: 1

Comment thread pkg/cmd/release/shared/fetch.go
@BagToad

BagToad commented Jun 25, 2026

Copy link
Copy Markdown
Member Author

@BagToad BagToad marked this pull request as draft June 25, 2026 05:37

@andyfeller andyfeller left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only suggestion I'd like to offer is making this abundantly clear in the command description with very huge warning about the potential impact of using unauthenticated release assets with a link to GH docs page + section on unauthentiated rate limits

EnableRepoOverride's hook shadows the root auth gate, then re-runs the nearest ancestor hook to restore it. That re-run passed the ancestor as the command, so the gate judged the wrong node and ignored a leaf's DisableAuthCheck. Pass the invoked leaf instead, as cobra does for every persistent hook.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow certain requests to be unauthenticated.

3 participants