jenkins-x-plugins / jx-project

a binary plugin for creating quickstarts and importing projects
Apache License 2.0
2 stars 30 forks source link

Authentication workflow for creating a project is confusing, does not work with non-Github URLs #244

Open jmmk opened 3 years ago

jmmk commented 3 years ago

This may be three separate issues: 1 - confusing workflow, 2 - fails with Bitbucket, 3 - Git SSH support


I'm operating in a new Jenkins X installation running locally in minikube on macOS. To get things running, I had to input a username and token giving access to the "cluster git repository", which was clear in the documentation and makes sense.

When attempting to create a new project with jx project quickstart, the authentication prompts did not make sense. Here was the first:

? please enter the git username to use for server https://github.com: <some username entered>

to create a git token click this URL https://github.com/settings/tokens/new?scopes=repo,read:user,read:org,user:email,admin:repo_hook,delete_repo,write:packages,read:packages,write:discussion,workflow
you can then copy the token into the following input...

? please enter the git API token to use for server https://github.com: <some token entered>
saved git credentials to file /Users/<user>/git/credentials
  1. Why does it specify "for https://github.com"? My project may be hosted somewhere else
  2. What is this username/token used for? Should it be credentials for the same bot user that had access to the cluster repository? My personal credentials?

Then the next prompts:

Username for 'https://github.com': <user>
Password for 'https://user@github.com': <pass>
  1. What is the difference in these credentials and the ones I just entered?
  2. Why do I need a username and password? I use only SSH to push/pull from repositories and those keys are configured in ~/.ssh/config and could potentially be pulled/stored in a secret the same way a user/pass might
  3. Again, why github.com?

I decided to try jx project instead of jx project quickstart, and Import code from a git repository.

If I use a git SSH URL like git@bitbucket.org/user/project.git, it fails with error: failed to create authenticated git URL: failed to parse URL git@bitbucket.org:traackr/influencer-dashboard.git: parse git@bitbucket.org:user/project.git: first path segment in URL cannot contain colon (similar to the issue I reported here: https://github.com/jenkins-x/jx-admin/issues/160).

If I use a Bitbucket HTTPS URL, I see this failure:

? Which git repository URL to import:  https://bitbucket.org/user/project.git
error: failed to clone in directory '': failed to clone repository https://<github username>:<github access token>@bitbucket.org/user/project.git to directory: /tmp/project: failed to run 'git clone https://<github username>:<github access token>@bitbucket.org/user/project.git /tmp/project' command in directory '/tmp', output: 'Cloning into '/tmp/project'...
remote: Invalid username or password
fatal: Authentication failed for 'https://<github username>:<github access token>@bitbucket.org/user/project.git/''
  1. This seems to be the "import from any git URL" option. Why is it injecting the github credentials into the URL?

In summary:

  1. It's not clear from the prompts what the credentials are being used for
  2. I would prefer to use SSH URLs and SSH keys for git repository access. For API access (e.g. webhooks), I would prefer to use a separate non-user account and it should be very clear that I am configuring it for that purpose.
  3. I know that Github has the highest level of support, but I expected it to be able to fetch from any git repository
mrwatson commented 3 years ago

+1 for this issue. I'm attempting a new Jenkins X test setup with minikube and an in-house BitBucket server and see the exact same issues. It is not clear how to proceed.

mrwatson commented 3 years ago

This line appears to be the issue, at least for me: https://github.com/jenkins-x/jx-helpers/blob/b2e95cf9766d08df2e2378ef1efe181874ce9208/pkg/kube/jxenv/env.go#L428

The URL is not constructed correctly. The error message reports that the URL is ***/scm/bitbucket/jx3-minikube.git, but it should really be ***/scm/bitbucket/<bitbucket group name>/jx3-minikube.git.