Repository navigation
Closed
Labels
Description
Describe the bug
I use the nix package manager on macos, and home-manager to manage files deterministically. I just moved my gh cli config.yml into the nix store which is read only. But after I did so, I'm unable to even gh auth login.
$ gh auth login --with-token < ~/.gh-cli-pub
open /Users/me/.config/gh/config.yml: permission denied
zsh: exit 1 gh auth login --with-token < ~/.gh-cli-pub
$ ls -dal ~/.config/gh/config.yml $(readlink -f ~/.config/gh/config.yml)
lrwxr-xr-x 1 me staff 84 Apr 24 09:45 /Users/me/.config/gh/config.yml -> /nix/store/avamd815xg8isrs903r683ik9g9lnqlj-home-manager-files/.config/gh/config.yml
-r--r--r-- 1 root wheel 43 Dec 31 1969 /nix/store/gpqlz3zg8ji69gn2acjyvzky93p15ich-gh-config.yml
$ cat /nix/store/gpqlz3zg8ji69gn2acjyvzky93p15ich-gh-config.yml
aliases: {}
editor: ''
git_protocol: https
$ rg -A20 config.yml
internal/config/stub.go
79: config, err := os.Open(filepath.Join(tempDir, "config.yml"))
80- if err != nil {
81- return
82- }
83- defer config.Close()
84- configData, err := io.ReadAll(config)
85- if err != nil {
86- return
87- }
88- _, err = wc.Write(configData)
89- if err != nil {
90- return
91- }
92-
93- hosts, err := os.Open(filepath.Join(tempDir, "hosts.yml"))
94- if err != nil {
95- return
96- }
97- defer hosts.Close()
98- hostsData, err := io.ReadAll(hosts)
99- if err != nil {I'm presuming right now that that EPERM is coming from the nix store file being owned by root with 444 permissions. Why does the gh cli need to write to its config files at all in the first place?
Steps to reproduce the behavior
- Symlink config.yml to a file owned by a non user, or presumably just make config.yml not writeable by the current user.
- Then try gh auth login via a file, should fail.
- See error above
Expected vs actual behavior
I would expect a cli not to need to write to its config file on each invocation, or ever really. This assumption breaks any sort of deterministic configuration approaches that enforce files being immutable and not changed at runtime.
Logs
n/a
Reacted by Kenichi Kamiya
Activity
mislav commentedon Apr 24, 2023
Thanks for describing your approach!
Commands like
gh auth loginandgh config setdo write to the config file. That is how they are able to persist state between invocations, such as login information (hostname + user + optionally an auth token). Now, one could argue that state information should typically be written to XDG_STATE_HOME instead to XDG_CONFIG_HOME, but the distinction for our own purposes is muddy and we never cared enough to define it more clearly.If you already have an auth token, you can set the GH_TOKEN environment variable and then you can skip
gh auth loginentirely. All gh commands will just work and the config file will never have to be edited (it won't even have to exist at all).Alternatively, you can temporarily change config file permissions when you re-auth or do
gh config set, then change them back to read-only.I'm going to close this now because gh is working as intended and because we haven't anticipated that someone would set readonly permissions to gh's own files under their user directory, nor do we plan to account for such cases—unless there arises a more pressing need to iron this out.
mitchty commentedon Apr 24, 2023
Ah interesting, I guess I wouldn't expect a config file to need to be rewritten but it makes sense if its a legacy situation. I was hoping to avoid having anything in the profile ENV to be honest that any process for my user could read.
I'm curious if there is any plan to migrate the state data that auth login writes out of the config files? Feel free to close, I was unaware of the GH_TOKEN option. I'll brain up some way to set it dynamically off of encrypted data in the nix store.
Thanks for the explanation!
mislav commentedon Apr 24, 2023
gh auth loginwill detect whether the current system is running a Secret Service API (e.g. GNOME keyring implements this) and use that for storing the authentication token, otherwise it will fall back to storing it in a plain text file.I don't know if any Secret Service tools run on nix, but you could always make a shell function like so:
mitchty commentedon Apr 24, 2023
Yeah in this case I'm using age to decrypt encrypted data based off host ssh keys directly from my config checkout which stores it all encrypted, and decrypted files are then on macos in a ram filesystem so they don't persist on disk or get written out to any backing filesystem. This means any encrypted data isn't ever stored in the nix store (think rpm db files maybe) directly and the decrypted data only exists in memory. So when I build a generation that has all my config all that comes along for the ride, just need to figure out how to get at it. direnv tends to be the easiest choice I can have that read the file.
https://github.com/mitchty/nix/blob/master/secrets/secrets.nix
My setups a bit crazy, but its nice to keep macos+nixos in sync with stuff deterministically, which just means I gotta eschew anything not in my git config checkout. Its there or not at all. :)
fix(gh): gh command needs to modify config.yml on every run
fix(gh): gh command needs to modify config.yml on every run
fix(gh): gh command needs to modify config.yml on every run
fix(gh): gh command needs to modify config.yml on every run
fix(gh): gh command needs to modify config.yml on every run
fix(gh): gh command needs to modify config.yml on every run
fix(gh): gh command needs to modify config.yml on every run