-
Notifications
You must be signed in to change notification settings - Fork 90
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
Support specifying bearerToken for git http token authentication #442
Conversation
7ebe947
to
41da3e2
Compare
Force pushed with sign-off in commit message, which DCO was unhappy about. |
19ba225
to
960b2e0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you @blurpy for this PR!
@blurpy i'm sorry i think i spoke too soon regarding the casing. I just noticed that we use both camel case and snake case for the secret currently ( |
@aryan9600 I would leave as is until fluxcd/flux2#3366 (or a better alternative) is agreed on as both |
Any preference for now, to decide between |
Think we would prefer |
Should I delete my last commit, to revert back to |
That would be the most effective way of removing it, so fine with me :-) |
e2bd366
to
960b2e0
Compare
Commit has been removed :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me, but someone else might want to take a look as well.
Thank you @blurpy 🙇
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, thanks! 🎖️
Excellent :) Are there any more steps I need to do in order for this to be included in the next release of |
A few observations, some of which may require some discussion. This feature is being added only to the go-git implementation. Should we just ignore the libgit2 implementation? It wouldn't be hard to just add a header in the corresponding transport code of libgit2. Or if we decide to not add such improvements/new features to libgit2, how about adding a check for such new things in the Line 259 in 946d9ac
The After reading about token auth support in some of the different git providers, it seems like not all of them support token based authentication easily. Some have very specific requirements like creating an app account for which such token can be generated. Not so automation friendly. I think it'd be better to have at least some kind of test that makes use of token auth. GitKit seems to only have support for basic auth at present, but maybe we can extend it to add support for token auth as well and use it in our git e2e tests. |
On the I don't mind the the adhoc change to |
I am indifferent to adding this to the libgit2 implementation, but if I had to choose, I'd say no mainly because of the reasons @pjbgf mentions above.
I completely agree, this would remove the direct use of CGO and make the project Makefile much simpler. |
Regarding the recent discussion, does that mean it could take a while to get this feature in a release? We would love to use this soon 😃 |
@blurpy I think for this PR, it should be enough to add the last thing I mentioned about not allowing token auth over HTTP without an option to explicitly configure it to do so:
It would be nice to add e2e test for it separately as discussed above. Since this doesn't break or change any existing feature, based on your testing against bitbucket, I think we should be able to release it soon, before we have those tests. Others may have a different opinion about it. |
Also, we have a self-hosted bitbucket server that we run our e2e tests against. Maybe in addition to gitkit, we can add token auth e2e test against bitbucket too. |
Ok, I will try to get that done tomorrow when I'm back at work.
Sounds great!
That sounds like fun, but due to my time constraints I think it's better if you make a separate issue and open it for others to work on. |
We need to upgrade our test instance. I will do that this week. |
@darkowlzz I think it's ready now. I added some new (slightly duplicating) tests in I have tested that both basic auth and bearer token still works in a new build of |
@blurpy Thanks for testing it again. Based on your testing, would you like to create a source-controller PR to update the docs, adding a section about bearer token in the GitRepository Secret reference docs? |
Good catch. This is the exact message I got with a bearer token over
So I rolled back to stable Then I tried to clone using basic auth and
Next test was removing secret ref from gitrepository, so it connects without credentials (tested both http and https), and I got this message:
All those 3 tests gave the same error message, perhaps suggesting that none of them sent any credentials? I also tried to clone using the regular git client with a bearer token over http to see if that even works:
Yes, that worked fine. But notice this line:
So, my theory now is that the http client in go is following redirects, but loosing the authentication headers in the process. Could that be the case? I think I have seen that in other http clients. |
I did find some old comment regarding this here: https://stackoverflow.com/a/32753865
Not sure if it's still valid, but might look like it. |
@blurpy yep, its valid, i was able to reproduce this |
after doing some research, it looks like the best practice is to NOT forward the authorization header when following a redirect. (ref: composer/composer#6716) |
I think that makes sense too, even though it's a bit confusing. |
Looks like adding a section to the docs should be quick, so I can give it a go. Update: see fluxcd/source-controller#1000 |
f077586
to
47333c5
Compare
Rebased from main. |
All good, we can now test this with our bitbucket infrastructure. |
As an alternative to username and password with http basic authentication. Signed-off-by: Christian Ihle <[email protected]>
Signed-off-by: Christian Ihle <[email protected]>
Signed-off-by: Christian Ihle <[email protected]>
47333c5
to
9b9b723
Compare
Signed-off-by: Christian Ihle <[email protected]>
…evant Signed-off-by: Christian Ihle <[email protected]>
Signed-off-by: Christian Ihle <[email protected]>
Signed-off-by: Christian Ihle <[email protected]>
Can we include github app authentication, too? Something like this is great if you are working in an environment, where you need to use a github server instance, where access is only available using https and personal access tokens are valide only for a certain time. |
Signed-off-by: Christian Ihle <[email protected]>
@michas2 Thanks for sharing the github app authentication docs. This PR adds support for accepting and using a bearer token for git authentication. We have other ongoing work for testing this feature against different git providers separately. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Thanks a lot of adding this feature and all the improvements.
Here's a source-controller RC image with this feature to try |
Thanks @darkowlzz! I tested it, but I can't get it to sync with bearer tokens. I then tried to build the image myself with these changes:
And then it worked again. Could |
@blurpy yeah, sorry I selected the wrong branch for it. This one should work Also, regarding github app authentication, I gave it a try and found out that they don't support bearer token, it's in the same doc posted above. They use a fixed username for app auth for http access. Based on that, I just created a small go program to generate the token and write to a Secret, and run it as a Kubernetes CronJob - https://github.com/darkowlzz/github-app-secret . |
Ah, thank you, that one worked :) |
As an alternative to username and password with http basic authentication.
Makes it possible to fix fluxcd/source-controller#251 by configuring the secret referenced by a
GitRepository
like this:My requirement is being able to use Flux with repository HTTP access tokens in Bitbucket Server. That way we can limit access to a single repository without making dedicated users for every repository.
With dedicated users, we can use basic auth and personal access tokens in combination with the username, but I've failed to get repository access tokens to work with basic auth. Setting a random username gives access denied, and setting a real username gives access denied and gets the user blocked.
According to the documentation they recommend using bearer auth for repository tokens, and with the changes in this PR I was able to get the Flux source controller to successfully sync with a repository token.
I've tested this against Bitbucket Server v8.4.1, and the
main
branch of https://github.com/fluxcd/source-controller with this ingo.mod
:make all
completes without errors in both this repository andsource-controller
.