Skip to content

Trying to build from Gitea / Forgejo fails with authentication required #60

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

Closed
Unkn0wnCat opened this issue Oct 19, 2023 · 7 comments · Fixed by #87
Closed

Trying to build from Gitea / Forgejo fails with authentication required #60

Unkn0wnCat opened this issue Oct 19, 2023 · 7 comments · Fixed by #87

Comments

@Unkn0wnCat
Copy link

Hello everyone,

I have a public repository on an installation of Forgejo (a fork of Gitea), and if I try to use envbuilder to build from the URL of this repository I get the following output under Coder:

envbuilder - Build development environments from repositories in a container
#1: 📦 Cloning https://git.1in9.net/raider/wroofauth to /workspaces/wroofauth...
Failed to clone repository: clone "https://git.1in9.net/raider/wroofauth": authentication required
Falling back to the default image...
#2: Deleting filesystem...
#2: 🏗️ Building image...
[...]

Cloning with a normal git client works fine. Adding the ".git" at the end of the URL has no effect.

Feel free to reproduce this using my repo at https://git.1in9.net/raider/wroofauth

Kind regards,
Kevin

@ggjulio
Copy link

ggjulio commented Nov 3, 2023

Hi, I have the exact same issue on bitbucket server . (but works fine with github repos)
It creates an empty folder named repo_name or repo_name.git (based on the url)
Cloning manually inside the fallback image works fine however.

envbuilder version : 0.2.3

@sthdev
Copy link

sthdev commented Nov 14, 2023

I have the same issue with envbuilder 0.2.4.

@matifali matifali added the bug label Nov 14, 2023
@sthdev
Copy link

sthdev commented Nov 15, 2023

I got it working by explicitly setting access credentials for GitLab (the git repository containing the .devcontainer spec is located on my GitLab instance). However, the Git repository is public. There should be no need to authenticate to GitLab.

In contrast, envbuilder can access public GitHub repositories without problems. Is there a special handling for GitHub repositories? From the comments above, it seems that this problem only occurs with non-GitHub repos.

BTW, I am using envbuilder in a Coder template (Coder 2.3.3) running on K8s 1.24.

@wolf-yuan-6115
Copy link

wolf-yuan-6115 commented Dec 4, 2023

Maybe it's because https://github.com/coder/envbuilder/blob/main/envbuilder.go#L357-L358 passing Git username as (blank) and password as (blank)?

So GitHub might resolve it as not logged in but other git provider resolved it as user not found

@AisonSu
Copy link

AisonSu commented Feb 7, 2024

Oh guys, I don't think this is a bug, because I initially encountered the same problem as you did, but I solved it by looking at the documentation – of course, I have to say that the information here is really incomplete, which took me half a day to figure out.

Here's my solution:

Firstly, you need to add an OAuth2 application on your Gitea/GitLab/Bitbucket, and the URI address is documented here; please modify it according to your actual situation.

Secondly, you need to add the relevant environment variables as guided in the documentation. Please note that all variables should not be enclosed in double quotes and ensure that the CODER_ACCESS_URL environment variable is set correctly.

Lastly, modify the template file by adding the following block of "coder_external_auth" data:

data "coder_external_auth" "any name you like here" {
    id = the CODER_EXTERNAL_AUTH_0_ID you set in the first step
}

And within the "resource" "docker_container" "workspace", add the following environment variables:

env {
    "GIT_USERNAME=oauth",
    "GIT_PASSWORD=${data.coder_external_auth.the name you set in the second step.access_token}"
}

and then click "Build" and then "Publish".


After completing all these steps,You will find that your workspace creation now includes an additional repository authorization option. Complete the authorization, and you will be able to perform a normal git clone.

@ggjulio
Copy link

ggjulio commented Feb 9, 2024

Hi @AisonSu,
Your solution seem to work because envbuilder now run authenticated queries against the git SCM provider.

However if for some reason we can't set up an oauth app, clones of public repos will fail. (Except on GitHub which works fine)

wolf-yuan-6115 is probably right about the root cause.

@nwrkbiz
Copy link
Contributor

nwrkbiz commented Feb 11, 2024

Hi, I have implemented a fix for this, you can test this using following image:
ghcr.io/nwrkbiz/envbuilder:0.2.6.0

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

Successfully merging a pull request may close this issue.

7 participants