Skip to content

Sandboxed git fetch cannot use the gh auth git-credential helper: ~/Library/Keychains stays denied #24077

Description

@dgtjn

What happened

Since c9bfdc3 ("Extend sandboxing to package processing"), upgrading a formula whose url is a private GitHub repository (url "https://github.com/<owner>/<private-repo>.git", tag:, revision:) fails when the new tag has to be fetched:

fatal: could not read Username for 'https://github.com': terminal prompts disabled

git is configured with the GitHub CLI as its credential helper (credential.https://github.com.helper=!/opt/homebrew/bin/gh auth git-credential, as written by gh auth setup-git), and gh auth status reports the token is stored in the (keyring), which is the default on macOS.

Why

GitDownloadStrategy#allow_fetch_credentials recognises the gh auth git-credential helper and opens GH_CONFIG_DIR / ~/.config/gh to the sandbox. That is not enough when gh keeps its token in the macOS Keychain: the sandbox's home deny list in sandbox.rb still includes Library/Keychains, so gh auth git-credential get returns nothing and git falls back to a prompt it cannot show.

Reproduced outside brew with a profile containing only (deny file-read* (subpath "<home>/Library/Keychains")): under sandbox-exec, gh auth git-credential get returns no credential; without the profile it returns one.

Workaround

brew skips the fetch when the tag is already in the cached clone, so fetching it from a normal shell first lets the upgrade through:

git -C "$(brew --cache)/<name>--git" fetch origin tag <tag>

A first install (no cached clone yet) has no such workaround.

Environment

  • Homebrew 7.0.6-21-g3f12c3e (on main because homebrew.devcmdrun is set; 7.0.6 itself is not affected)
  • macOS 27.0, Apple Silicon
  • gh with the token in the keyring, git credential helper set by gh auth setup-git
  • Seen on two Macs

Suggestion

When the gh helper is detected and gh stores its token in the keyring, allow the sandboxed git process to reach the Keychain (read access to the login keychain, plus whatever mach lookup securityd needs). Or document that the helper is only supported with gh auth login --insecure-storage.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions