Skip to content

fix: avoid /etc/gitconfig under strict snap confinement#3007

Open
arimu1 wants to merge 1 commit into
gitui-org:masterfrom
arimu1:fix/2984-snap-gitconfig
Open

fix: avoid /etc/gitconfig under strict snap confinement#3007
arimu1 wants to merge 1 commit into
gitui-org:masterfrom
arimu1:fix/2984-snap-gitconfig

Conversation

@arimu1

@arimu1 arimu1 commented Jul 23, 2026

Copy link
Copy Markdown

Fixes #2984.

Under strict snap confinement, /etc/gitconfig is not accessible, so libgit2 fails to even open a non-bare repo:

Error: invalid repo path: failed open - '/etc/gitconfig' is locked: Permission denied; class=Os (2); code=Locked (-14)

This happens because opening a repo always loads the merged git config, including the system level, and the strict snap sandbox blocks that path.

This detects strict confinement via the SNAP/SNAP_CONFINEMENT environment variables snapd sets, and only in that case redirects libgit2's system-level config search path away from /etc to the snap's own install directory (which never contains a gitconfig file, so libgit2 simply finds no system config instead of failing to reach /etc). Classic/devmode confinement and non-snap runs are left untouched.

This follows the precedent already linked from the issue: the test suite does the exact same set_search_path trick (see sandbox_config_files in asyncgit/src/sync/mod.rs) to avoid touching real system config files during tests; this PR applies the same idea at runtime, gated on the snap-confinement check.

Added unit tests for the pure decision function (snap_system_config_override) covering: no snap, strict confinement, classic confinement, devmode confinement, and unknown/old-snapd confinement (defaults to the safe/strict behavior). No real snap sandbox is required to run these tests.

Strict snap confinement blocks access to /etc/gitconfig, which makes
libgit2 fail to even open a non-bare repo with an error like
'/etc/gitconfig' is locked: Permission denied, since opening a repo
always loads the merged config including the system level.

Detect strict confinement via the SNAP/SNAP_CONFINEMENT environment
variables snapd sets and, in that case only, redirect libgit2's
system-level config search path to the snap's own install directory
(which never contains a gitconfig file), mirroring the approach the
test suite already uses to avoid touching real system config files.

Fixes gitui-org#2984
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.

Snap strict confinement: inaccessible search path for git config

1 participant