Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[snap] hugo server fails if ~/.gitconfig includes other gitconfig files #10337

Closed
pandruszkow opened this issue Sep 29, 2022 · 10 comments · Fixed by #10688
Closed

[snap] hugo server fails if ~/.gitconfig includes other gitconfig files #10337

pandruszkow opened this issue Sep 29, 2022 · 10 comments · Fixed by #10688

Comments

@pandruszkow
Copy link

What version of Hugo are you using (hugo version)?

$ hugo version
hugo v0.104.1-8958b8741f552c8024af5194330fbf031544a826+extended linux/amd64 BuildDate=2022-09-26T17:05:45Z VendorInfo=snap:0.104.1

Does this issue reproduce with the latest release?

Yes (on snap, Ubuntu 20.04 LTS)

Steps to reproduce

  1. On Ubuntu 20.04 LTS, install hugo with snap install hugo --channel=extended
  2. Replace ~/.gitconfig with:
[include]
	path = .gitconfig.local
  1. Add the following to ~/.gitconfig.local:
[user]
	name = John Smith
	email = user@example.com
  1. chmod a+r ~/.gitconfig.local ~/.gitconfig
  2. Run hugo server
  3. The following error message appears:
hugo v0.104.1-8958b8741f552c8024af5194330fbf031544a826+extended linux/amd64 BuildDate=2022-09-26T17:05:45Z VendorInfo=snap:0.104.1
ERROR 2022/09/29 12:36:01 Failed to read Git log: warning: unable to access '/home/[REDACTED]/.gitconfig.local': Permission denied
fatal: bad config line 5 in file /home/[REDACTED]/.gitconfig
WARN 2022/09/29 12:36:01 Expand shortcode is deprecated. Use 'details' instead.
Error: Error building site: logged 1 error(s)
Built in 732 ms

Workaround

Follow reproduce steps, but replace hugo server with HUGO_ENABLEGITINFO=false hugo server.

Failure does not occur.

@Et7f3
Copy link

Et7f3 commented Oct 6, 2022

Is it specific to snap ? Can you reproduce in a docker so we have a easily actionnable reproduction?

Can't reproduce on latest so either it is specific to snap or just fixed.

@anthonyfok
Copy link
Member

@Et7f3 Yes, it is specific to Snap. We use the home interface which "allows access to non-hidden files owned by the user in the to be user's home ($HOME) directory", and recently added the personal-files interface](https://snapcraft.io/docs/personal-files-interface) to allow access to $HOME/.gitconfig and $HOME/.config/git/config which are both hidden:

hugo/snap/snapcraft.yaml

Lines 22 to 31 in 58b8245

plugs:
etc-gitconfig:
interface: system-files
read:
- /etc/gitconfig
gitconfig:
interface: personal-files
read:
- $HOME/.gitconfig
- $HOME/.config/git/config

$HOME/.gitconfig.local is not in that list, in snapcraft.yaml, thus it is not readable.

@pandruszkow Instead of including an arbitrarily named $HOME/.gitconfig.local file, how about placing its content (e.g. [user] section) into $HOME/.config/git/config instead? From the git config man page:

$XDG_CONFIG_HOME/git/config
           Second user-specific configuration file. If $XDG_CONFIG_HOME is not
           set or empty, $HOME/.config/git/config will be used. Any
           single-valued variable set in this file will be overwritten by
           whatever is in ~/.gitconfig.

Let me know if this works for you or not! Many thanks!

@sivachandran
Copy link

It affected me as well. I end up remove hugo from snap and installed through apt.

@bep bep modified the milestones: v0.105.0, v0.106.0 Oct 26, 2022
@bep bep modified the milestones: v0.106.0, v0.107.0 Nov 18, 2022
@bep bep modified the milestones: v0.107.0, v0.108.0 Dec 3, 2022
@bep bep modified the milestones: v0.108.0, v0.109.0 Dec 14, 2022
@TechWilk
Copy link

Having installed hugo through snap (on PopOS! 22.04 LTS) I experienced the same issue.
@anthonyfok I am using $HOME/.config/git/config which doesn't work either

$ hugo
Start building sites … 
hugo v0.109.0-47b12b83e636224e5e601813ff3e6790c191e371+extended linux/amd64 BuildDate=2022-12-23T10:38:11Z VendorInfo=snap:0.109.0
ERROR 2022/12/26 11:59:17 Failed to read Git log: warning: unable to access '/home/[user]/.config/git/config': Permission denied
warning: unable to access '/home/[user]/.config/git/config': Permission denied
fatal: unknown error occurred while reading the configuration files
Error: Error building site: logged 1 error(s)
Total in 343 ms```

@anthonyfok anthonyfok changed the title hugo server fails if ~/.gitconfig includes other gitconfig files [snap] hugo server fails if ~/.gitconfig includes other gitconfig files Dec 26, 2022
@bep bep modified the milestones: v0.109.0, v0.111.0, v0.110.0 Jan 26, 2023
@pandruszkow
Copy link
Author

@pandruszkow Instead of including an arbitrarily named $HOME/.gitconfig.local file, how about placing its content (e.g. [user] section) into $HOME/.config/git/config instead? From the git config man page:

$HOME/.gitconfig.local is no more more arbitrary than $HOME/.gitconfig or $HOME/.config/git/config. After all, paths under $HOME are just a convention, and there are legitimate reasons why users may wish to allow access to hidden files to confined applications, or use non-default paths for files. Locating config files in specific locations under my own home directory was simply not something that I've ever had to think about up until now. I don't like the way Snap deals with the issue, without even allowing the user to grant a confined application access to additional paths.

I replaced the Snap version with a DEB package. It's working flawlessly now.

@anthonyfok
Copy link
Member

$HOME/.gitconfig.local is no more more arbitrary than $HOME/.gitconfig or $HOME/.config/git/config.

Except that git is programmed to read either $HOME/.gitconfig or $XDG_CONFIG_HOME/git/config (thus usually $HOME/.config/git/config), and these are documented in the git(1) man page.

$HOME/.gitconfig.local, on the other hand, is defined by the end user. In that sense, something like $HOME/.gitconfig.local is no more arbitrary than, for example, $HOME/.gitconfig.anthonyfok. Either of these user-defined paths would require adding a manual include path.

Not that there is anything wrong with that. It is just that Snap's security model seemingly throws us a monkey wrench here.

After all, paths under $HOME are just a convention, and there are legitimate reasons why users may wish to allow access to hidden files to confined applications, or use non-default paths for files.

This I completely agreed. What I meant "arbitrary" above is more in the context of the Snap packaging where snapcraft.yaml currently does not allow us to use a wildcard in the personal-files interface permitted file list if I understand correctly.

I replaced the Snap version with a DEB package. It's working flawlessly now.

I'm glad you came to this conclusion, as the .deb package is what I personally use and what I personally maintain for Debian and derivatives. I should have recommended that you switched to the .deb package in the first place. 😅

@jmooring
Copy link
Member

jmooring commented Feb 2, 2023

@anthonyfok Due to your extensive efforts to resolve #9078, the Hugo snap package works very well for the vast majority of users. Everything is included; it just works. And the fact that it includes Embedded Dart Sass makes it easy for site authors to transition from LibSass (deprecated) to Dart Sass.

I really like the snap package, and wanted to thank you again for your efforts.

@anthonyfok
Copy link
Member

@jmooring Thank you for your kind words and confidence boost! I almost forgot #9078, and I am glad that it is working well for most use cases!

@anthonyfok
Copy link
Member

Let's see how to finally close this issue by making the hugo:gitconfig (personal-files interface) a bit more flexible. Here are some reference documentation and discussions:

Here is a quick summary:

  • personal-files does not support wildcard. This is by design.
  • personal-files does support directory, so adding $HOME/.config/git gives read access to $HOME/.config/git/config and any arbitrary files inside the $HOME/.config/git directory.
  • Top-level $HOME does not work. Again, this is by design, for security reasons. I tried $HOME, $HOME/, '$HOME/.`, and sure enough, none of these works.
  • $HOME/.gitconfig.local seems nicely named, so I'll add this exception too.
  • To test which files or directories are readable or not, simply run snap run --shell hugo.
  • git config -l --show-origin is a great command for testing if git config [include] path is working properly or not.

So, here's what I'm going to do:

  • Allow $HOME/.config/git/* and $HOME/.gitconfig.local to work too
  • Document the above (as well as other quirks of the Hugo Snap package) eventually; when to use Snap and when to use .deb.

anthonyfok added a commit to anthonyfok/hugo that referenced this issue Feb 3, 2023
in hugo:gitconfig plug (personal-files interface) in case end users need
the flexibility of using additional custom git config files.

Fixes gohugoio#10337
@bep bep closed this as completed in #10688 Feb 3, 2023
bep pushed a commit that referenced this issue Feb 3, 2023
in hugo:gitconfig plug (personal-files interface) in case end users need
the flexibility of using additional custom git config files.

Fixes #10337
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants