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

Unable to register secret with gh command #581

Open
eitsupi opened this issue Mar 9, 2024 · 8 comments
Open

Unable to register secret with gh command #581

eitsupi opened this issue Mar 9, 2024 · 8 comments

Comments

@eitsupi
Copy link

eitsupi commented Mar 9, 2024

I think this is strictly a bug in the gitcreds package, but rhub2 doesn't seem to recognize it even though I registered the secret in the GitHub CLI.

$ gh secret list
NAME   UPDATED            
RHUB2  about 3 minutes ago
> rhub2::rhub_doctor()
✔ Found R package at /workspaces/httpgd.Found git repository at /workspaces/httpgd.Do you have a GitHub personal access token (PAT)?

This hangs:

> gitcreds::gitcreds_get()
@gaborcsardi
Copy link
Collaborator

What OS and what credential helper?

@eitsupi
Copy link
Author

eitsupi commented Mar 9, 2024

What OS and what credential helper?

I haven't set any credential helpers on Ubuntu 22.04 on the container.
Maybe I need to do something with environment variables? It wasn't clear to me. (In other words, I don't need to worry about anything as long as I use the gh command)

@gaborcsardi
Copy link
Collaborator

gaborcsardi commented Mar 9, 2024

AFAIR gh just stores your token in a plain text file, and I suspect that it installs its own credential helper that does not work well with gitcreds, apparently. Btw. does command line git work with https and the token that was installed in gh? I.e. can you do git push etc. without typing in your password?

What's the output of git config credential.helper?

Until this is fixed in gitcreds, a workaround is indeed to set the GITHUB_PAT env var.

@eitsupi
Copy link
Author

eitsupi commented Mar 9, 2024

Thanks, since I am working within VS Code Dev Containers, it appears that the credential helpers set up by VS Code Dev Containers are being used.

$ git config credential.helper
!f() { /home/user/.vscode-server/bin/1e790d77f81672c49be070e04474901747115651/node /tmp/vscode-remote-containers-dfcfcb41-7bf4-4916-bc63-9db9c9b00bfe.js git-credential-helper $*; }; f

(As a side note, I was wondering why installing packages on GitHub using pak::pak() causes a hang, perhaps this is the cause)

It turns out that gh has store credentials on ~/.config/gh/hosts.yml. (cli/cli#7023)

github.com:
    users:
        eitsupi:
            oauth_token: gho_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    git_protocol: https
    oauth_token: gho_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    user: eitsupi

@gaborcsardi
Copy link
Collaborator

Thanks! I'll investigate how to work with those helpers.

In the meanwhile, does seeing a GITHUB_PAT env var work?

@gaborcsardi
Copy link
Collaborator

Btw. what's the simplest way to spin up the dev container that you are using?

@eitsupi
Copy link
Author

eitsupi commented Mar 9, 2024

In the meanwhile, does seeing a GITHUB_PAT env var work?

I set with export GITHUB_PAT=gho_xxxxx, but it looks like I need to set up the host, etc.?

> gitcreds::gitcreds_get()
<gitcreds>
  protocol: NA
  host    : NA
  username: NA
  password: <-- hidden -->

In any case, it was enough for me to run the workflow manually from the GitHub.com UI, so I don't need to run it from R.

Btw. what's the simplest way to spin up the dev container that you are using?

I used devcontainer.json like this:

{
	"image": "ghcr.io/rocker-org/devcontainer/r-ver:4"
}

I believe it is the closed source VS Code Dev Container extension that set up the Git credential helper, so you probably need to create a container from VS Code. (Codespaces seems to set another credential helper)

@gaborcsardi
Copy link
Collaborator

I set with export GITHUB_PAT=gho_xxxxx, but it looks like I need to set up the host, etc.?

No, that's enough and it should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants