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

Authentication required when git isn't present #2649

Closed
mkasberg opened this issue Dec 29, 2022 · 2 comments · Fixed by #2650
Closed

Authentication required when git isn't present #2649

mkasberg opened this issue Dec 29, 2022 · 2 comments · Fixed by #2650
Labels
bug Something isn't working

Comments

@mkasberg
Copy link

Describe the bug

When git is not installed, Chezmoi prompts for authentication to clone a public GitHub repository. Authentication should not be required.

To reproduce

This one-liner will reproduce the bug in a new, minimal Ubuntu Docker container:

docker run --rm -it ubuntu:latest /bin/bash -c 'apt-get update && apt-get install curl && sh -c "$(curl -fsLS git.io/chezmoi)" -- -b "$HOME/bin" init --apply -S ~/dotfiles mkasberg'

This is initializing config on a new machine using a slightly modified version of the init command from the https://chezmoi.io homepage.

Note that this works fine (does not prompt for auth) when git is installed:

docker run --rm -it ubuntu:latest /bin/bash -c 'apt-get update && apt-get install curl git && sh -c "$(curl -fsLS git.io/chezmoi)" -- -b "$HOME/bin" init --apply -S ~/dotfiles mkasberg'

Feel free to try that exact command with my dotfiles (since they're public anyway), but I expect it's reproducible with any GitHub username.

Expected behavior

Auth should not be required to clone a public repository over https. (In particular, since this is a bootstrapping step on a new machine, we might not yet have ssh keys, password vaults, etc.)

Output of command with the --verbose flag

 docker run --rm -it ubuntu:latest /bin/bash -c 'apt-get update && apt-get install curl && sh -c "$(curl -fsLS git.io/chezmoi)" -- -b "$HOME/bin" init --verbose --apply -S ~/dotfiles mkasberg'
[...]
info found version 2.28.0 for latest/linux/amd64
info installed /root/bin/chezmoi
chezmoi: https://mkasberg@github.com/mkasberg/dotfiles.git: authentication required
Username? ?

Output of chezmoi doctor

N/A - chezmoi is not yet installed.

Additional context

I'm 90% sure this is a bug with Chezmoi - apologies if I'm misunderstanding something here and this is from some other component or is expected behavior.

@twpayne twpayne added the bug Something isn't working label Dec 29, 2022
@twpayne
Copy link
Owner

twpayne commented Dec 29, 2022

Thanks for the report and the perfect reproduction case!

This is definitely a bug in chezmoi, and comes as an unwanted side effect of #2562. tl;dr including the username in the guessed repo URL causes chezmoi to prompt for authentication.

When you run chezmoi init mkasberg, chezmoi guesses the repo URL as https://mkasberg@github.com/mkasberg/dotfiles.git, which triggers the authentication prompt when git is not installed.

On the same machine without git installed, running chezmoi init --guess-repo-url=false https://github.com/mkasberg/dotfiles.git disables the repo URL guessing and does not prompt for authentication.

@halostatue
Copy link
Collaborator

I wonder if it might not be worthwhile to have a --public-repo flag that can be used for this situation? That is, chezmoi init --public-repo mkasberg would guess the repo URL as https://github.com/mkasberg/dotfiles.git. It would be good for cases where one has a dotfile configuration that is read-only from clients but read-write from a primary system.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants