-
Notifications
You must be signed in to change notification settings - Fork 153
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
Adding git_remote
fallback for gitlab_remote
use without full API access (Resolves #604)
#608
base: main
Are you sure you want to change the base?
Conversation
My main worry with making the GitLab remote more complex is our team doesn't use GitLab, so it is possible this will break in the future without us realizing it. We would definitely need some tests to avoid this. |
Thanks @jimhester - I'm happy to add in tests as much as possible. If you think the implementation looks sound, then I can get to work on tests and updating docs. I was just hesitant to invest more time fleshing out the peripheral bits until getting some impressions on the approach. |
…v/gitlab-git-api-fallback-2
git_remote
fallback for gitlab_remote
use without full API access (Resolves #604)git_remote
fallback for gitlab_remote
use without full API access (Resolves #604)
git_remote
fallback for gitlab_remote
use without full API access (Resolves #604)git_remote
fallback for gitlab_remote
use without full API access (Resolves #604)
@jimhester - this PR is ready whenever you have an opportunity to take a look. The only CI errors are ones that also exist on To trace through the changes, it is easiest to start with Just to highlight a critical design choice: Design Feedback Request: is it preferred to keep the full url including username and password (
For now, I chose to scrub the username and password from the url before this is added to a DESCRIPTION file to prioritize safety of access tokens over the update experience. The self-hosted GitLab issues are currently a big pain point at my org, so some help in moving this forward would be greatly appreciated. |
Thank you for this PR. This is a must when working on private GitLab instances. I tried it in a CI instance with the following classical use cases I guess. The PR solves the problems encountered with current version of {remotes}. This can be accepted as is. Use
|
Do you think that it could be a good idea to allow |
Thanks for considering this PR, @jimhester. Just wanted to highlight this bit in the PR thread for your consideration. I tried my best to dig into how
Currently user-specific url components are stripped to minimize any printing/saving of tokens. |
I guess we should strip them, though it would then break updating packages later. However if you still set the |
As described in #604, the current
gitlab_remote
makes use of API endpoints that are not available to tokens generated for use within gitlab CI (stored in the$CI_JOB_TOKEN
env var), throwing errors when these tokens are used.This PR adds code to first ping the API at a generic endpoint (querying for /version). If that request fails and
isTRUE(getOption("remotes.gitlab_git_fallback", TRUE))
, agit_remote
is returned.If
git2r
is available, a credentials object is created from theauth_token
. Otherwise, the token is embedded in the url in the form ofhttp://gitlab-ci-token:[email protected]/namespace/project.git
.This allows
install_gitlab
to be used within CI jobs on non-public deployments of GitLab without the creation and embedding of personal tokens. Pipeline engineers need only to runexport GITLAB_PAT=$CI_JOB_TOKEN
prior to installing remotes.Changelog
install_gitlab
will defer to usinginstall_git
when authentication doesn't provide adequate API access to download a source archivegit2r::cred_user_pass
ifgit2r
is availablegitlab-ci-token
. When providing a PAT, GitLab ignores the username unless one is using aCI_JOB_TOKEN
token within a CI job, in which case it must begitlab-ci-token
. Because of this, it covers both scenarios to passgitlab-ci-token
in both cases. Unfortunately I wasn't able to find any documentation to reference for this behavior, it was only narrowed down through testing.http://<username>:<password>@host.com/repo.git
)DESCRIPTION
(Design Feedback Request: is it preferred to keep the full url for updates, or to exclude the password so that it isn't leaked through things likerenv
?)git()
updated to take an optionaldisplay_args
command to provide output using censored git url as to not display access tokens in console output. This is used inremote_download.xgit_remote
to display git commands without printing passwords to console.parse_git_url()
updated to also extract a username and password, though it might be worth taking on a dependency to handle url parsing since this is regex is getting pretty involvedgit_anon_url()
introduced to strip out username and password components from a urlgit_censored_url()
introduced to replace the password component with asterisksgit_remote
when the GitLab host API requests failgit_fallback = getOption("remotes.gitlab_git_fallback", TRUE)
parameter toinstall_gitlab
This is an initial pass just to experiment with implementation. Please let me know if this looks like a reasonable approach, and then I can polish this PR with