Skip to content
This repository has been archived by the owner on Jun 21, 2022. It is now read-only.

GitLab's token doesn't work if GitHub's token is set #531

Open
grzesjam opened this issue May 18, 2022 · 0 comments
Open

GitLab's token doesn't work if GitHub's token is set #531

grzesjam opened this issue May 18, 2022 · 0 comments

Comments

@grzesjam
Copy link

grzesjam commented May 18, 2022

Expected Behavior

When URL is github.com it uses GITHUB_TOKEN token, and if gitlab.com uses GITLAB_TOKEN token
OR
Have one generic GIT_AUTH_TOKEN used for authentications (with warning its always used for all connections)
OR
Provide GIT_AUTH_TOKEN array and all tokens be checked/matched for access

Actual Behavior

Regardless of URL if GITHUB_TOKEN is set its always used, always auth is returned.

githubToken := os.Getenv("GITHUB_TOKEN")
if githubToken != "" {
auth = &http.BasicAuth{
Username: gitUsername,
Password: githubToken,
}
return auth
}
// Otherwise we check if a GitLab token was provided
gitlabToken := os.Getenv("GITLAB_TOKEN")
if gitlabToken != "" {
auth = &http.BasicAuth{
Username: gitUsername,
Password: gitlabToken,
}
return auth
}
// If no token was provided, we simply return a nil,
// which will make the request to be unauthenticated
return nil

Steps to Reproduce the Problem

  1. Set dummy/real GITHUB_TOKEN ( export GITHUB_TOKEN="ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
  2. Set real GITLAB_TOKEN ( export GITLAB_TOKEN="glpat-xxxxxxxxxxxxxxxxxxxx" )
  3. Run remote repo scanning in trivy or any other tool using this library ( trivy repo https://gitlab.com/private-organization/private-repo or trivy repo https://gitlab.com/gitlab-org/gitlab )
  4. Get git error: authentication required

Specifications

  • Version: trivy - 0.25.0 , fanal - v0.0.0-20220516143651-a81c666fb9b5
  • Platform: linux (ubuntu and apline)
  • Subsystem: Trivy
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant