aquasecurity / fanal

Static Analysis Library for Containers
Apache License 2.0
199 stars 100 forks source link

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

Open grzesjam opened 2 years ago

grzesjam commented 2 years ago

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.

https://github.com/aquasecurity/fanal/blob/f400923828e8f96e0b02b7e6098b4715826c018c/artifact/remote/git.go#L111-L132

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