fix: avoid /etc/gitconfig under strict snap confinement#3007
Open
arimu1 wants to merge 1 commit into
Open
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2984.
Under strict snap confinement,
/etc/gitconfigis not accessible, so libgit2 fails to even open a non-bare repo: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_CONFINEMENTenvironment variables snapd sets, and only in that case redirects libgit2's system-level config search path away from/etcto the snap's own install directory (which never contains agitconfigfile, 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_pathtrick (seesandbox_config_filesinasyncgit/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.