github / gh-net

A network bridge between a Codespace and a local machine.
https://github.com/github/gh-net
285 stars 21 forks source link

Authentication Loop #34

Closed kingces95 closed 2 years ago

kingces95 commented 2 years ago

When I follow the gh-net setup instructions I am asked to authenticate, I do, but then I'm told I'm still unauthenticated. What am I doing wrong?

$ sudo gh extension install github/gh-net
[sudo] password for chrkin:
To get started with GitHub CLI, please run:  gh auth login
Alternatively, populate the GH_TOKEN environment variable with a GitHub API authentication token.

$ gh auth login
? What account do you want to log into? GitHub.com
? You're already logged into github.com. Do you want to re-authenticate? No

Indeed, gh appears to think I am logged in.

$ gh auth status
github.com
  ✓ Logged in to github.com as kingces95 (/home/chrkin/.config/gh/hosts.yml)
  ✓ Git operations for github.com configured to use ssh protocol.

Let's try logout then log back in.

$ gh auth logout
✓ Logged out of github.com account 'kingces95'

$ gh auth status
You are not logged into any GitHub hosts. Run gh auth login to authenticate.

$ gh auth login
? What account do you want to log into? GitHub.com
? What is your preferred protocol for Git operations? SSH
? Upload your SSH public key to your GitHub account? /home/chrkin/.ssh/id_rsa.pub
? Title for your SSH key: GitHub CLI
? How would you like to authenticate GitHub CLI? Login with a web browser

! First copy your one-time code: 29F0-3C7E
Press Enter to open github.com in your browser...
✓ Authentication complete.
- gh config set -h github.com git_protocol ssh
✓ Configured git protocol
HTTP 422: Validation Failed (https://api.github.com/user/keys)
key is already in use

I expect if the command says validation failed that I wouldn't be logged in. Actually, if I run status I see I am logged in.

$ gh auth status
github.com
  ✓ Logged in to github.com as kingces95 (/home/chrkin/.config/gh/hosts.yml)
  ✓ Git operations for github.com configured to use ssh protocol.
  ✓ Token: *******************

Regardless, I still cannot install the extension

$ sudo gh extension install github/gh-net
To get started with GitHub CLI, please run:  gh auth login
Alternatively, populate the GH_TOKEN environment variable with a GitHub API authentication token.

Let's try delete the ssh key locally and in github and try the flow again.

$ gh auth login
? What account do you want to log into? GitHub.com
? You're already logged into github.com. Do you want to re-authenticate? Yes
? What is your preferred protocol for Git operations? SSH
? Generate a new SSH key to add to your GitHub account? Yes
? Enter a passphrase for your new SSH key (Optional)
? Title for your SSH key: GitHub CLI
? How would you like to authenticate GitHub CLI? Login with a web browser

! First copy your one-time code: 54AC-4320
Press Enter to open github.com in your browser...
✓ Authentication complete.
- gh config set -h github.com git_protocol ssh
✓ Configured git protocol
✓ Uploaded the SSH key to your GitHub account: /home/chrkin/.ssh/id_ed25519.pub
✓ Logged in as kingces95

$ sudo gh extension install github/gh-net
To get started with GitHub CLI, please run:  gh auth login
Alternatively, populate the GH_TOKEN environment variable with a GitHub API authentication token.

I see that a new key was upload to github. Cool! But I still get the same error trying to install the extension.

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.4 LTS
Release:        20.04
Codename:       focal
$ gh version
gh version 2.13.0 (2022-06-22)
https://github.com/cli/cli/releases/tag/v2.13.0

I'm running ubuntu on WSL2 on a DevBox.

joshspicer commented 2 years ago

sudo gh extension install github/gh-net

Can you try installing the extension without sudo? I think you'll only need sudo when launching gh-net

kingces95 commented 2 years ago

Dropping the sudo works. Might wanna update the instructions.

gh extension install github/gh-net
legomushroom commented 2 years ago

@kingces95 the issue is that the GitHub CLI authentication happens for the current user, and because we have to use sudo for the extension, you have to auth with sudo too:

  1. Get your token: gh auth status -t -> copy the current auth token.
  2. Reuse the token with sudo: echo {TOKEN} | sudo auth login --with-token
  3. Install the extension: sudo gh extension install github/gh-net

The related issue on the GitHub CLI side: https://github.com/cli/cli/issues/5456