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

Self-Hosted Gitlab with API-Token: 401 Unauthorized #40

Closed
addiks opened this issue Aug 14, 2020 · 8 comments · Fixed by #41
Closed

Self-Hosted Gitlab with API-Token: 401 Unauthorized #40

addiks opened this issue Aug 14, 2020 · 8 comments · Fixed by #41
Labels
bug Something isn't working

Comments

@addiks
Copy link

addiks commented Aug 14, 2020

When I try to run todocheck on our private gitlab instance (13.2.3), I get the following failed result:

$ export TODOCHECK_AUTH_TOKEN=[MY-PERSONAL-ACCESS-TOKEN]
$ ~/Schreibtisch/todocheck-0.2.0-linux-x86_64 --config .todocheck.yaml --basepath src/
2020/08/14 17:08:05 couldn't traverse basepath: failed traversing file src/Some/Example/File.php: couldn't check todo line: couldn't fetch task status: bad status code upon fetching task: 401 - {"message":"401 Unauthorized"}
$ 

When I try to manually fetch the issue-details from the gitlab-API using curl, I get this successful result:

$ curl --header "PRIVATE-TOKEN: [MY-PERSONAL-ACCESS-TOKEN]" "https://our-gitlab-instance.com/api/v4/projects/3/issues/1"
{"id":16,"iid":1,"project_id":3,"title":"Some Title","description":"Lorem ipsum dolor sit amet.","state":"opened","created_at":"2020-08-14T14:47:36.336Z","updated_at":"2020-08-14T14:47:36.336Z","closed_at":null,"closed_by":null,"labels":[],"milestone":null,"assignees":[],"author":{"id":6,"name":"Gerrit Addiks","username":"gerrit","state":"active","avatar_url":"https://our-gitlab-instance.com/uploads/-/system/user/avatar/6/avatar.png","web_url":"https://our-gitlab-instance.com/gerrit"},"assignee":null,"user_notes_count":0,"merge_requests_count":0,"upvotes":0,"downvotes":0,"due_date":null,"confidential":false,"discussion_locked":null,"web_url":"https://our-gitlab-instance.com/foo/bar/-/issues/1","time_stats":{"time_estimate":0,"total_time_spent":0,"human_time_estimate":null,"human_total_time_spent":null},"task_completion_status":{"count":0,"completed_count":0},"has_tasks":false,"_links":{"self":"https://our-gitlab-instance.com/api/v4/projects/3/issues/1","notes":"https://our-gitlab-instance.com/api/v4/projects/3/issues/1/notes","award_emoji":"https://our-gitlab-instance.com/api/v4/projects/3/issues/1/award_emoji","project":"https://our-gitlab-instance.com/api/v4/projects/3"},"references":{"short":"#1","relative":"#1","full":"foo/bar#1"},"subscribed":true,"moved_to_id":null}
$

My .todocheck.yaml file:

origin: https://our-gitlab-instance.com/foo/bar
issue_tracker: GITLAB
auth:
  type: apitoken

Why is todocheck unable to fetch the issue while curl can, using the same access-token?
Is there maybe some way to enable debugging and/or to see what exact HTTP(S) requests are being sent?

@preslavmihaylov preslavmihaylov added the question Further information is requested label Aug 14, 2020
@preslavmihaylov
Copy link
Owner

preslavmihaylov commented Aug 14, 2020

Hey @addiks, I attempted to reproduce the problem locally using a private gitlab repository I have setup for testing Gitlab integration. Unfortunately, I don't get the same error message on my end.

I've created a branch which I've instrumented \w http request debug information.

Feel free to checkout that branch, build the release binaries via:

# Requires go being installed
./release.sh <dst-dir> <version>

Alternatively, if you're not into installing go & building from source, I've built a binary from that branch & uploaded it here.

Could you try reproducing the issue with that version of the app & let me know if you're able to find the root cause?

@addiks
Copy link
Author

addiks commented Aug 14, 2020

When I try to download the binary I am asked for a password for that file: "You need access, Ask for access, or switch to an account with access".

I also tried to compile it from source, but got stuck on these error-messages:

$ ./release.sh bin/ 0.2.0
main.go:10:2: cannot find package "github.com/preslavmihaylov/todocheck/authmanager" in any of:
	/usr/lib/go-1.6/src/github.com/preslavmihaylov/todocheck/authmanager (from $GOROOT)
	($GOPATH not set)
main.go:11:2: cannot find package "github.com/preslavmihaylov/todocheck/authmanager/authmiddleware" in any of:
	/usr/lib/go-1.6/src/github.com/preslavmihaylov/todocheck/authmanager/authmiddleware (from $GOROOT)
	($GOPATH not set)
main.go:12:2: cannot find package "github.com/preslavmihaylov/todocheck/checker/errors" in any of:
	/usr/lib/go-1.6/src/github.com/preslavmihaylov/todocheck/checker/errors (from $GOROOT)
	($GOPATH not set)
main.go:13:2: cannot find package "github.com/preslavmihaylov/todocheck/config" in any of:
	/usr/lib/go-1.6/src/github.com/preslavmihaylov/todocheck/config (from $GOROOT)
	($GOPATH not set)
main.go:14:2: cannot find package "github.com/preslavmihaylov/todocheck/fetcher" in any of:
	/usr/lib/go-1.6/src/github.com/preslavmihaylov/todocheck/fetcher (from $GOROOT)
	($GOPATH not set)
main.go:15:2: cannot find package "github.com/preslavmihaylov/todocheck/issuetracker" in any of:
	/usr/lib/go-1.6/src/github.com/preslavmihaylov/todocheck/issuetracker (from $GOROOT)
	($GOPATH not set)
main.go:16:2: cannot find package "github.com/preslavmihaylov/todocheck/traverser/todoerrs" in any of:
	/usr/lib/go-1.6/src/github.com/preslavmihaylov/todocheck/traverser/todoerrs (from $GOROOT)
	($GOPATH not set)
shasum: todocheck-0.2.0-windows-x86_64.exe: 
can't load package: package .: no buildable Go source files in /home/gerrit/git/todocheck/bin
./release.sh: Zeile 21: cd: bin/: Datei oder Verzeichnis nicht gefunden
can't load package: package .: no buildable Go source files in /home/gerrit/git/todocheck/bin
./release.sh: Zeile 21: cd: bin/: Datei oder Verzeichnis nicht gefunden
can't load package: package .: no buildable Go source files in /home/gerrit/git/todocheck/bin
./release.sh: Zeile 21: cd: bin/: Datei oder Verzeichnis nicht gefunden
$

(Datei oder Verzeichnis nicht gefunden = File not found)

Since i'm really not proficient with go and a bit of research suggests that issues with GOPATH might be version-related (I'm on ubuntu 16.04, installing newer software can sometimes be non-trivial), I don't think that dumping more time into this will yield any results.

@preslavmihaylov
Copy link
Owner

Yeah, I didn’t consider that you’d have to setup the whole go toolchain.

I gave you access to the file in gdrive. Try downloading that.

@addiks
Copy link
Author

addiks commented Aug 14, 2020

Executing request:
	METHOD - GET
	URL - https://gitlab.com/api/v4/projects/foo%2Fbar/issues/1
	HEADERS - Private-Token:[MY-PERSONAL-ACCESS-TOKEN]

The request is being sent to a completely different domain. It is talking to gitlab.com instead of our own gitlab-instance on our-gitlab-instance.com.

@addiks
Copy link
Author

addiks commented Aug 14, 2020

It seems to completely disregard the configured domain in my .todocheck.yaml.
Could this line be the reason that the requests are being sent to gitlab.com instead to the configured domain?

@preslavmihaylov
Copy link
Owner

Ah yes, that is exactly the root cause. I will fix that & make a new patch.

Thanks for reporting!

@preslavmihaylov preslavmihaylov added bug Something isn't working and removed question Further information is requested labels Aug 15, 2020
@preslavmihaylov
Copy link
Owner

Hey @addiks I've created a new PR for this in #41

Before merging it, could you double-check that it works for your setup? Here are the binaries for that branch

@addiks
Copy link
Author

addiks commented Aug 15, 2020

This seems to be working for me. It does not crash (or stop?) anymore, correctly detects missing issues in our gitlab instance and hides the messages again if the issue exists in the tracker. Looks like everything is working fine now.

@addiks addiks changed the title Gitlab with API-Token: 401 Unauthorized Self-Hosted Gitlab with API-Token: 401 Unauthorized Aug 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants