-
Notifications
You must be signed in to change notification settings - Fork 871
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
Best way to authenticate against a git repository in a build process #1601
Comments
I don't think i have clear answer for you, but i try my best to provide you more context. Personally, i would suggest customer always provide credential explicit instead of using cred manager in CI system. |
Personally I think the ideal solution would be if we could just "prepare" the environment in a way such that we can call
Do any of the above options exist today? I don't think letting users create PAT-Tokens and manually setting up things is very nice. |
I think here is what we can do to make it a better experience for customer:
|
But that is only true for scripts not for vsts-tasks, correct? We actually have a vsts-task where we want to setup stuff in such a way that it "just works" as well. |
then, System.AccessToken is always there for a vsts-task, so you should be able to achieve your goal to make is "just work" |
But can I make git use it when a 3rd party code is between the task and the git call:
To elaborate: With Nuget we can setup a "dummy" credential provider and then
|
@matthid |
Thanks. we will take a look at that but I guess it should do. |
[skip ci] advanced [skip ci] better format [skip ci] extract to misc/format.py [skip ci] use it [skip ci] add clang format [skip ci] use sudo [skip ci] use python3 [skip ci] use git add . [skip ci] checkout head [skip ci] try [skip ci] try again [skip ci] help [skip ci] wewe [skip ci] username [skip ci] adv api [skip ci] pid [skip ci] 957 [skip ci] sp [skip ci] head [skip ci] token [skip ci] token [skip ci] follow microsoft/azure-pipelines-agent#1601 [skip ci] bearer [skip ci] ?? [skip ci] test [skip ci] try again [skip ci] [skip ci] 2 [skip ci] f [skip ci] we [skip ci] fix [skip ci] c [skip ci] fi [skip ci] t [skip ci] u [skip ci] hack [skip ci] det [skip ci] fx [skip ci] a [skip ci] m [skip ci] as [skip ci] d [skip ci] ssh-key [skip ci] enforce code format [skip ci] trigger [skip ci] simp [skip ci] adv [skip ci] format diff [skip ci] f [skip ci] add pip git [skip ci] name [skip ci] t [skip ci] sss [skip ci] add [skip fmt] [skip ci] fix [skip ci] [skip fmt] break [skip ci] break 2 [skip ci] fix [skip ci] fs [skip ci] ha [skip ci] 3 [skip ci] rea [skip ci] f [skip ci] master [skip ci] c [skip ci] fix [skip ci] fetch [skip ci] f [skip ci] fix [skip ci] squash [skip ci] name [skip ci] difs [skip ci] save [skip ci] save [skip ci] fix fmt [skip ci] real fix [skip ci] [skip fmt] break [skip ci] fix again
[skip ci] [skip fmt] add persubmit.yml [skip ci] advanced [skip ci] better format [skip ci] extract to misc/format.py [skip ci] use it [skip ci] add clang format [skip ci] use sudo [skip ci] use python3 [skip ci] use git add . [skip ci] checkout head [skip ci] try [skip ci] try again [skip ci] help [skip ci] wewe [skip ci] username [skip ci] adv api [skip ci] pid [skip ci] 957 [skip ci] sp [skip ci] head [skip ci] token [skip ci] token [skip ci] follow microsoft/azure-pipelines-agent#1601 [skip ci] bearer [skip ci] ?? [skip ci] test [skip ci] try again [skip ci] [skip ci] 2 [skip ci] f [skip ci] we [skip ci] fix [skip ci] c [skip ci] fi [skip ci] t [skip ci] u [skip ci] hack [skip ci] det [skip ci] fx [skip ci] a [skip ci] m [skip ci] as [skip ci] d [skip ci] ssh-key [skip ci] enforce code format [skip ci] trigger [skip ci] simp [skip ci] adv [skip ci] format diff [skip ci] f [skip ci] add pip git [skip ci] name [skip ci] t [skip ci] sss [skip ci] add [skip fmt] [skip ci] fix [skip ci] [skip fmt] break [skip ci] break 2 [skip ci] fix [skip ci] fs [skip ci] ha [skip ci] 3 [skip ci] rea [skip ci] f [skip ci] master [skip ci] c [skip ci] fix [skip ci] fetch [skip ci] f [skip ci] fix [skip ci] squash [skip ci] name [skip ci] difs [skip ci] save [skip ci] save [skip ci] fix fmt [skip ci] real fix [skip ci] [skip fmt] break [skip ci] fix again [skip ci] [skip fmt] [skip ci] sfsf [skip ci] works anyway [skip ci] we
@TingluoHuang Thank you for posting your last solution! I can verify that by doing this fixes my issues with
|
I came across this issue when I was searching for a solution to my problem, so I'm going to leave my solution here in case it helps someone else someday. The above solution from TingluoHuang did not work for me (UPDATE: it does work if the
In my case, I am running a Terraform script in my pipeline that references modules from other Git repositories (all repos are in ADO). So it's similar to matthid's case where there is an intermediary program invoking Git. Using one of the modules looks like this:
We have a few of these, and some of these also reference others in a nested way. On a developer's machine, this works well because the credential manager supplies the right creds to every connection. But in pipelines it didn't work because all our ADO projects/repositories are set to private. One option would be to pass in an ADO PAT, but I thought that should be unnecessary since the pipeline's access token is already available. At first, my solution was to overwrite the URL to include the token like so:
This works fine but is a little clunky. It also doesn't work in the nested case, because when dependent modules are downloaded they don't have the token in the URLs, so then you have to go back and overwrite all instances in the module cache dir again, which is even more clunky. In the end I found the
This works very well in the pipeline and also preserves the behavior of just letting the credential manager do its thing when running on a developer's machine. Note that this requires the proper |
Be careful setting global git configs on agent machines, since global can cause side effects in other processes. Specifically, it injects the token of the current job at a level accessible by other processes (current and later), and that token is short lived - this means that its both a security issue and a breaking change for the other processes the moment the token is invalidated. Additionally, on rare occasion something breaks during a pipeline run that causes the token cleanup step to not be called (we MUST assume that any call can be the last call that occurs - think BSOD), which leaves git broken on the machine until hard cleanup is done (and a beast to diagnose what happened since it only fails on subsequent pipeline runs). We had the same terraform git reference issue, and the solution that worked for us with not side effects was to:
This works every time, is scoped to the current pipeline run, and does not have cross-process security implications. One caveat: If the terraform has nested git references (i.e., one terraform repo references another repo that also has repo references) then it becomes much more difficult to deal with. However, the recommendation from hashicorp/terraform is that nested references should not be a practice - such practice is an indicator of other structural problems that should be resolved first. |
Thanks for the comment, but there's a few other things that affect what I think you're saying. Sorry if these weren't clear:
We have the nested git references problem that you describe. We were initially doing your same steps to resolve, but the problem was that The current method does effectively the same thing - replacing the URL to include the token - just at the git config level instead of in each individual file. It just makes sense to me that if the git credential manager on my dev machine can handle this scenario fine, there's got to be a similarly simple way to make it work in CI. The recommendation from HashiCorp is noted and thanks for mentioning it. I would be interested to know the specifics of the "structural problems" they mention if you have a link. |
Well either way, your comment got me thinking again, and after some experimentation I just discovered that the previous solution posted with the I guess that method and the one I posted are essentially equivalent, but after thinking about it more I do take your point about breaking other processes. Maybe someday in the future this will not be running on an ephemeral image and it will suddenly starting breaking other things. Future me won't like that very much. I'll go back and include an |
We do this in a bash task during build (where we have 'Allow script to access oauth token' enable on the phase run on agent, GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0="http.extraHeader" GIT_CONFIG_VALUE_0="Authorization: Bearer $SYSTEM_ACCESSTOKEN" composer update Or we could do the same with 'git' (which also works..) Token is not 'unfolded' or shown in any files this way. |
Description
On of our users reported fsprojects/Paket#3228
The basic problem is to authenticate against a tfs repository within a build process.
Can we just use System.Accesstoken? Is there documentation around that? Is there a credential manager we can use or implement ourself (like it is for nuget) or any other way to hook into the process?
The text was updated successfully, but these errors were encountered: