devcontainer-features icon indicating copy to clipboard operation
devcontainer-features copied to clipboard

GIT authentication in rstudio-server not working

Open behrica opened this issue 1 year ago • 8 comments

I am using the rstudio feature

"ghcr.io/rocker-org/devcontainer-features/rstudio-server": {}

But I am unable to get github authentication working when using the rstudio GIT ui. It always fails with "authentication required" I tried all possible ways including environment vars or git helpers , but nothing worked.

Is somebody aware of instructions for a "working authentication" of the rstudio-sever devcontainer feature with GitHub.

(Git in VSCode is fully functional)

With quite some "magic" I got git push/pull working in the rstudio Terminal, but not in the UI, including setting of env vars.

The most concrete issue was, that I could not configure the rserver process with environment vars in "/etc/rstudio/env-vars". I this a known issue ?

behrica avatar Jun 21 '24 10:06 behrica

From what tool do you use the Feature? What does the git config look like?

If you are using VS Code Devcontainers, this issue may be related r-lib/pak#633.

eitsupi avatar Jun 22 '24 09:06 eitsupi

I use Codespaces and, the devcontaioner.json is this:

{
	"name": "R (rocker/r-ver base)",
	"image": "ghcr.io/rocker-org/devcontainer/r-ver:4.4",
	"features": {
		"ghcr.io/rocker-org/devcontainer-features/pandoc:1": {},
		"ghcr.io/rocker-org/devcontainer-features/r-packages:1": {
			"packages": "rmarkdown,devtools,tidyverse,r-lib/xml2,jsonlite,httr2",
			 "additionalRepositories": "CRAN = 'https://packagemanager.posit.co/cran/2024-06-10'"
		},
		"ghcr.io/rocker-org/devcontainer-features/rstudio-server": {}
	},
	"postAttachCommand": {
        "rstudio-start": "rserver"
    },
    "forwardPorts": [
        8787
    ],
    "portsAttributes": {
        "8787": {
            "label": "RStudio IDE"
        }
	},

   "remoteEnv":{
       //not working
	"GCM_CREDENTIAL_STORE": "cache"
   }
   
}

behrica avatar Jun 22 '24 17:06 behrica

The "high level description of the issue" could as well be expressed as:

The rstudio instances started by the rstudio-feature ""ghcr.io/rocker-org/devcontainer-features/rstudio-server" does not inherit the correctly setup GIT authentication configuration from Codespaces. Additionally I could not find documentation anywhere about this.

behrica avatar Jun 22 '24 17:06 behrica

The "root cause" of the issues likes in the fact that when using the rstudio server together with codespaces, the source code will not be cloned by rstudio . As it is cloned already by Codespaces, which configures certain GIT authentication methods- So when using rstudio a ".git" folder is alreday present. And I did not find a way to "tell rstudio" how to authenticate the existing and gloned repo. It does not "detect" the VSCode GIT setup or similar

behrica avatar Jun 22 '24 17:06 behrica

I found a workaround, namely to "change" the remote url, so replacing an url like: https://github.com/my-project

via

git remote set-url origin xxxx@https://github.com/my-project

where xxx is a github token. After doing this, the GIT features of rstudio seems to work, but it lost the "tracking remote", so needed to set this by hand as well.

behrica avatar Jun 22 '24 17:06 behrica

The rstudio instances started by the rstudio-feature ""ghcr.io/rocker-org/devcontainer-features/rstudio-server" does not inherit the correctly setup GIT authentication configuration from Codespaces.

I believe RStudio Server is intentionally designed not to read environment variables. For example, if you search the internet you will find the following post: https://stackoverflow.com/questions/16867720/rstudio-server-environment-variables-not-loading

I guess what we could do here is use a lifecycle script to write the environment variables to something like Renviron before RStudio Server starts, does that make sense? Pull Requests are welcome!

eitsupi avatar Jun 23 '24 03:06 eitsupi

Renviron would not work I believe, as this sets it for the "rsession". But the rstudio GIT UI tools are part of "rserver" itself, not the rsession. I tried to set manual env-vars as documented here: https://docs.posit.co/ide/server-pro/1.4.1722-1/server-management.html chapter 2.1.4, but this did not have any visible effect to me.

behrica avatar Jun 24 '24 05:06 behrica

Could you ask about the RStudio IDE in the upstream? I believe we just have a standard setup here.

eitsupi avatar Jun 24 '24 15:06 eitsupi