GitHub API 401 when running `flox activate`

Version: 0.0.7-r92

After a new install on MacOS (arm64), output of flox activate:

error: unable to download 'https://api.github.com/repos/flox/floxpkgs/commits/master': HTTP error 401

       response body:

       {
         "message": "Bad credentials",
         "documentation_url": "https://docs.github.com/rest"
       }
(use '--show-trace' to show detailed location information)

ERROR: could not verify defaultFlake URL: "github:flox/floxpkgs/master"

But if I just curl https://api.github.com/repos/flox/floxpkgs/commits/master, the requested resource is returned. Any ideas how to proceed?

Solved this myself: It turns out the GitHub CLI is required. After installing it and running gh auth login, I was able to run flox activate without issues

2 Likes

This seems like something that should probably be included in the “Install flox” documentation :sunglasses:

Thank you for your feedback and subsequent updates! Looking into this further, is it possible you were logged into the gh client with an invalid token when you first started using flox? I ask as we support running with no github token, and hence running flox activate shouldn’t have given you that error message. Would you be able to help us reproduce the problem so we can find/address the bug?

Hi Robin! :wave: No, I actually had never used the gh client and had to install it to do this! (I was on the old third-party hub cli for a while.)

How can I help reproduce?

Hi there! I tried to reproduce with a fresh install on a Mac VM, but I didn’t get the error:

floxfan@floxfans-Virtual-Machine ~ % flox --version
Version: 0.0.7-r92
floxfan@floxfans-Virtual-Machine ~ % flox activate
Updating /Users/floxfan/.config/flox/nix.conf
Updating /Users/floxfan/.config/flox/gitconfig

flox collects basic usage metrics in order to improve the user experience,
including a record of the subcommand invoked along with a unique token.
It does not collect any personal information.

Do you consent to the collection of basic usage metrics? (Y/n) n

Understood. If you change your mind you can change your election
at any time with the following command: flox config --reset

flox [default] floxfan@floxfans-Virtual-Machine ~ % flox install hello
created generation 1
flox [default] floxfan@floxfans-Virtual-Machine ~ % which hello
/Users/floxfan/.local/share/flox/environments/local/default/bin/hello

Any chance you have some other pre-existing git config that might be messing with authentication?

It is entirely possible! I’m not sure what it would be, though. I don’t do anything super-weird, but I do authenticate to GitHub with SSH instead of HTTPS, so maybe it’s related to that? Here’s the output of git config --list:

credential.helper=osxkeychain
user.name=Ryan Elainska
user.email=<REDACTED>
push.default=current
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
rerere.enabled=true
remote.pushdefault=origin
merge.ff=true
pull.rebase=false
init.defaultbranch=main
url.ssh://git@github.com/.insteadof=https://github.com/

hmmmm, as we cannot recreate the issue and this is the only time this issue has been reported so far, I think it best to wrap up this thread but definitely keep it in mind in the event we get a similar report. Would that be ok with you @glassblowerscat ?

That seems reasonable! There’s a pretty decent probability that it’s an edge case. M1 Macs have lots of those, especially for developers :smirk:

We use insteadof to inject credentials, so there’s a chance those could be conflicting. It looks like longest match is respected though, so I’m not sure why the one you have would be taking precedence. I am curious though if removing that from your git config would be another workaround

@mkenigs Just to be clear about what you’re suggesting, you think maybe removing the credential.helper value would be something to try?

No sorry I meant the url.ssh://git@github.com/.insteadof=https://github.com/

I had the same problem, and it was likely due to expired gh cli credentials - i.e. running gh auth loginsolved it for me).

2 Likes

ah, another data point - thank you for letting us know! :slight_smile:

Hei, I’m running into the same issue when trying to install on a NixOS system:

$ nix --accept-flake-config --access-tokens "github.com=ghp_im
enAOv7CRIu5DWSaU6LguNfhyfQwU3J3qpp" profile install --impure github:flox/floxpkgs#eval
Catalog.$(nix eval --raw --expr builtins.currentSystem --impure).stable.flox

gives:

error: unable to download 'https://api.github.com/repos/flox/floxpkgs/commits/HEAD': HTTP error 401

       response body:

       {
         "message": "Bad credentials",
         "documentation_url": "https://docs.github.com/rest"
       }

       … while fetching the input 'github:flox/floxpkgs'

Running gh auth login doesn’t help fix this. git config --list returns:

alias.bdm=!git branch --merged | grep -v '*' | xargs -n 1 git branch -d
alias.branch-name=rev-parse --abbrev-ref HEAD
alias.h1rd=hard HEAD~1
alias.hard=reset --hard
alias.history=log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short
alias.last=log -1 HEAD
alias.lg=log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --
alias.ll=log --stat
alias.lol=log --graph --decorate --pretty=oneline --abbrev-commit
alias.lola=log --graph --decorate --pretty=oneline --abbrev-commit --all
alias.rank=shortlog -sn --no-merges
alias.recent=for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'
alias.s1ft=soft HEAD~1
alias.sha=log --pretty=format:'%h' -n 1
alias.soft=reset --soft
alias.unstage=reset HEAD --
color.ui=true
color.branch.current=yellow reverse
color.branch.local=yellow
color.branch.remote=green
color.diff.frag=magenta bold
color.diff.meta=yellow bold
color.diff.new=green bold
color.diff.old=red bold
color.diff.whitespace=red reverse
color.status.added=yellow
color.status.changed=green
color.status.untracked=cyan
commit.gpgsign=true
core.autocrlf=input
core.editor=emacs -nw
core.whitespace=fix,-indent-with-non-tab,trailing-space,cr-at-eol
credential.https://github.com.helper=/nix/store/xmxq8x7ca1cvxp9b9prcicqnvq8p71yf-gh-2.21.1/bin/gh auth git-credential
delta.features=side-by-side line-numbers decorations
delta.minus-style=syntax "#3f0001"
delta.plus-style=syntax "#003800"
delta.syntax-theme=base16-256
delta.decorations.commit-decoration-style=bold yellow box ul
delta.decorations.file-decoration-style=none
delta.decorations.file-style=bold yellow ul
delta.decorations.hunk-header-decoration-style=cyan box ul
delta.interactive.keep-plus-minus-markers=false
delta.line-numbers.line-numbers-left-style=cyan
delta.line-numbers.line-numbers-minus-style=124
delta.line-numbers.line-numbers-plus-style=28
delta.line-numbers.line-numbers-right-style=cyan
delta.magit-delta.keep-plus-minus-markers=true
delta.magit-delta.line-numbers=false
delta.magit-delta.side-by-side=false
diff.colormoved=default
diff.tool=meld
difftool.prompt=false
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
filter.lfs.smudge=git-lfs smudge -- %f
github.user=robertodr
gitlab.user=robertodr
gpg.program=/nix/store/z1rh7c2h2r485rw3nqim8kixhxxr2yvv-gnupg-2.3.7/bin/gpg2
grep.linenumber=true
help.autocorrect=0
http.sslverify=false
init.defaultbranch=main
interactive.difffilter=delta --color-only --features=interactive
log.mailmap=true
magithub.online=false
magithub.status.includeissuessection=false
magithub.status.includepullrequestssection=false
magithub.status.includestatusheader=false
merge.tool=meld
mergetool.prompt=false
pager.diff=delta
pager.log=delta
pager.reflog=delta
pager.show=delta
pull.rebase=false
push.default=current
tag.gpgsign=true

[edited]

the docs have now been updated. :slight_smile:

1 Like

Thank you! That worked!

1 Like