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

Is there a way to get gitcreds working on RStudio server (linux)? #29

Closed
lcolladotor opened this issue Feb 24, 2021 · 3 comments
Closed

Comments

@lcolladotor
Copy link

Hi,

I'm having a bit of a problem with gitcreds on an RStudio Server 1.4.1103 that I'm using for teaching a class this week. I'm able to create a GitHub token and store it with gitcreds.

> usethis::create_github_token()
● Call `gitcreds::gitcreds_set()` to register this token in the local Git credential store
  It is also a great idea to store this token in any password-management software that you useOpening URL 'https://github.com/settings/tokens/new?scopes=repo,user,gist,workflow&description=R:GITHUB_PAT'
> gitcreds::gitcreds_set()


? Enter password or token: a358aac525e5b498editedETCETERA
-> Adding new credentials...
-> Removing credetials from cache...
-> Done.
> gitcreds::gitcreds_get("https://github.com")
<gitcreds>
  protocol: https
  host    : github.com
  username: PersonalAccessToken
  password: <-- hidden -->
> gitcreds::gitcreds_get("https://github.com")$password
[1] "a358aac525e5b498editedETCETERA"

I can change R projects, restart R, and well, I get the same info back from gitcreds::gitcreds_get("https://github.com").

> gitcreds::gitcreds_get("https://github.com")
<gitcreds>
  protocol: https
  host    : github.com
  username: PersonalAccessToken
  password: <-- hidden -->
> gitcreds::gitcreds_cache_envvar("https://github.com")
[1] "GITHUB_PAT_GITHUB_COM"
> gitcreds::gitcreds_list_helpers()
[1] "cache"
> gitcreds::gitcreds_list()
Error in gitcreds$throw(gitcreds$new_error("gitcreds_unknown_helper",  : 
  Unknown credential helper: `cache`, cannot list credentials

However, at some point, I'm no longer able to retrieve the information. It's almost like wherever the token is cached gets deleted. Is there a way to find what would the cache location be? I haven't been able to figure out what triggers the break in behavior. I mean, after gitcreds::gitcreds_set() I really only use commands like usethis::use_github() and none of the gitcreds commands.

> Sys.getenv("GITHUB_PAT_GITHUB_COM")
[1] "protocol:https:host:github.com:username:PersonalAccessToken:password:a358aac525e5b498editedETCETERA"

After reading https://gitcreds.r-lib.org/reference/gitcreds_get.html#arguments (Credential helpers section) I see that but most Linux distributions do not set up a default credential helper. which makes me guess that at some point the environment variable GITHUB_PAT_GITHUB_COM gets un-set. For now I told students to use usethis::edit_r_environ() although I'm aware that this is no longer the suggested setup. Though hmm, maybe I'm missing something else that could be done to get gitcreds working on this linux environment.

(at some point this happens:)

> gitcreds::gitcreds_get("https://github.com")
Error in throw(new_error("gitcreds_no_credentials", url = url)) : 
  Could not find any credentials
> traceback()
4: stop(cond)
3: throw(new_error("gitcreds_no_credentials", url = url))
2: gitcreds_parse_output(out, url)
1: gitcreds::gitcreds_get("https://github.com")

Let me know if there's any other information I can provide that would be useful.

Best,
Leo

Related to lcolladotor/rnaseq_LCG-UNAM_2021@e15bb0f.

> options(width = 120)
> sessioninfo::session_info()
─ Session info ───────────────────────────────────────────────────────────────────────────────────────────────────────
 setting  value                       
 version  R version 4.0.3 (2020-10-10)
 os       Ubuntu 20.04.1 LTS          
 system   x86_64, linux-gnu           
 ui       RStudio                     
 language (EN)                        
 collate  en_US.UTF-8                 
 ctype    en_US.UTF-8                 
 tz       America/Mexico_City         
 date     2021-02-23Packages ─────────────────────────────────────────────────────────────────────────────────────────────────────────── 
 package     * version    date       lib source                             
 assertthat    0.2.1      2019-03-21 [2] CRAN (R 4.0.3)                     
 bookdown      0.21       2020-10-13 [2] CRAN (R 4.0.3)                     
 cli           2.3.0      2021-01-31 [2] CRAN (R 4.0.3)                     
 data.table    1.14.0     2021-02-21 [2] CRAN (R 4.0.3)                     
 digest        0.6.27     2020-10-24 [2] CRAN (R 4.0.3)                     
 ellipsis      0.3.1      2020-05-15 [2] CRAN (R 4.0.3)                     
 evaluate      0.14       2019-05-28 [2] CRAN (R 4.0.3)                     
 generics      0.1.0      2020-10-31 [2] CRAN (R 4.0.3)                     
 gitcreds      0.1.1      2020-12-04 [2] CRAN (R 4.0.3)                     
 glue          1.4.2      2020-08-27 [2] CRAN (R 4.0.3)                     
 hms           1.0.0      2021-01-13 [1] CRAN (R 4.0.3)                     
 htmltools     0.5.1.1    2021-01-22 [2] CRAN (R 4.0.3)                     
 knitr         1.31       2021-01-27 [2] CRAN (R 4.0.3)                     
 lifecycle     0.2.0      2020-03-06 [2] CRAN (R 4.0.3)                     
 lubridate     1.7.9.2    2020-11-13 [1] CRAN (R 4.0.3)                     
 magrittr      2.0.1      2020-11-17 [2] CRAN (R 4.0.3)                     
 pkgconfig     2.0.3      2019-09-22 [2] CRAN (R 4.0.3)                     
 Rcpp          1.0.6      2021-01-15 [2] CRAN (R 4.0.3)                     
 rlang         0.4.10     2020-12-30 [2] CRAN (R 4.0.3)                     
 rmarkdown     2.7        2021-02-19 [2] CRAN (R 4.0.3)                     
 rsthemes      0.2.1.9000 2021-02-23 [1] Github (gadenbuie/rsthemes@521572b)
 rstudioapi    0.13       2020-11-12 [2] CRAN (R 4.0.3)                     
 sessioninfo   1.1.1      2018-11-05 [2] CRAN (R 4.0.3)                     
 suncalc       0.5.0      2019-04-03 [1] CRAN (R 4.0.3)                     
 vctrs         0.3.6      2020-12-17 [2] CRAN (R 4.0.3)                     
 withr         2.4.1      2021-01-26 [2] CRAN (R 4.0.3)                     
 xfun          0.20       2021-01-06 [2] CRAN (R 4.0.3)                     
 yaml          2.2.1      2020-02-01 [2] CRAN (R 4.0.3)                     

[1] /home/compu2/R/x86_64-pc-linux-gnu-library/4.0
[2] /usr/local/lib/R/site-library
[3] /usr/lib/R/site-library
[4] /usr/lib/R/library
> system("git --version")
git version 2.25.1
RStudio Server
Version 1.4.1103
© 2009-2021 RStudio, PBC
"Wax Begonia" (458706c3, 2021-01-06) for Ubuntu Bionic
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36
@gaborcsardi
Copy link
Member

Yes, on Linux you often don't have a proper credential store, especially on a server. In your case

> gitcreds::gitcreds_list_helpers()
[1] "cache"

means that you are using the cache credential helper: https://git-scm.com/docs/git-credential-cache

This credential helper stores the credentials in memory, so they are lost after a reboot. It also has a timeout, defaulting to 900 seconds.

If you can use an .Renviron file on RStudio server, then it is probably simplest to set up the token as an environment variable in .Renviron. You can set GITHUB_PAT_GITHUB_COM or just GITHUB_PAT, and gitcreds (and thus usethis, etc.) still picks these up.

lcolladotor added a commit to lcolladotor/biocthis that referenced this issue Feb 24, 2021
lcolladotor added a commit to lcolladotor/biocthis that referenced this issue Feb 24, 2021
@lcolladotor
Copy link
Author

Thank you very much for the explanation Gábor!

Best,
Leo

@gaborcsardi
Copy link
Member

NP, we'll try to explain this better in the gitcreds and/or usethis docs.

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