Skip to content
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

Add Gitea Oauth #2622

Merged
merged 14 commits into from
Apr 13, 2019
Merged

Add Gitea Oauth #2622

merged 14 commits into from
Apr 13, 2019

Conversation

techknowlogick
Copy link

@techknowlogick techknowlogick commented Mar 8, 2019

With fallback to basic auth if Gitea server does not support oauth

Linked to drone/go-login#3

With fallback to basic auth if Gitea server does not support oauth
@CLAassistant
Copy link

CLAassistant commented Mar 8, 2019

CLA assistant check
All committers have signed the CLA.

@techknowlogick techknowlogick changed the title WIP: Add Gitea Oauth Add Gitea Oauth Mar 8, 2019
@bradrydzewski
Copy link

awesome! one question: how does gitea handle the scenario where two separate go routines try to refresh the access token at the same time? this is something that caused issues in early gitlab oauth implementations, so just want to understand a bit more :)

@techknowlogick
Copy link
Author

Tests fail because the above linked PR isn't merged

@bradrydzewski
Copy link

I just merged :)

@techknowlogick
Copy link
Author

Thanks @bradrydzewski 😄

@techknowlogick
Copy link
Author

@jonasfranz could you answer @bradrydzewski's question above?

@techknowlogick techknowlogick changed the title Add Gitea Oauth WIP: Add Gitea Oauth Mar 8, 2019
@techknowlogick techknowlogick changed the title WIP: Add Gitea Oauth Add Gitea Oauth Mar 8, 2019
@techknowlogick
Copy link
Author

techknowlogick commented Mar 8, 2019

@bradrydzewski looking through Gitea OAuth code, refreshing token isn't implemented in Gitea (yet). I was able to compile drone and login with this PR and it pulled all the repos. I've also been able to submit an updated PR to go-login with being able to use RedirectURL.

@appleboy
Copy link

appleboy commented Mar 9, 2019

also update the provideClient func:

    case config.Github.ClientID != "":
        return provideGithubClient(config)
-    case config.Gitea.Server != "":
+    case config.Gitea.ClientID != "":
        return provideGiteaClient(config)
    case config.GitLab.ClientID != "":
        return provideGitlabClient(config)

@techknowlogick
Copy link
Author

@appleboy I kept config.Gitea.ClientID != "" codition so this doesn't break for Gitea users < 1.8 so they can still use username/password

@appleboy
Copy link

appleboy commented Mar 9, 2019

@techknowlogick Good catch. Thanks for the PR. LGTM.

@jonasfranz
Copy link

jonasfranz commented Mar 9, 2019

Refresh tokens are implemented. You can only use an access token or refresh token once to redeem a new token.

@bradrydzewski
Copy link

bradrydzewski commented Mar 9, 2019

For context, GitLab had a similar restriction a few years ago that they since removed. Here are some issues that we ran into as a result #855

There are some other documented issues described in these threads:
doorkeeper-gem/doorkeeper#815
doorkeeper-gem/doorkeeper#449

It is very exciting to see oauth support land in Gitea (congrats!) and I look forward to taking advantage of this in Drone. However, we need to solve for these issues before we can merge this pull request, otherwise the current refresh token restrictions will break Drone.

@tboerger
Copy link

tboerger commented Mar 9, 2019

Great to see that this gets finally integrated

Server string `envconfig:"DRONE_GITEA_SERVER"`
SkipVerify bool `envconfig:"DRONE_GITEA_SKIP_VERIFY"`
Debug bool `envconfig:"DRONE_GITEA_DEBUG"`
Server string `envconfig:"DRONE_GITEA_SERVER" default:"https://try.gitea.io"`
Copy link

@bradrydzewski bradrydzewski Mar 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this default needs to be removed. An zero value server string is the only way we know if gitea is configured or not.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Thanks :)

I've updated.

@appleboy
Copy link

@techknowlogick conflicts.

Copy link

@bradrydzewski bradrydzewski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to merge this pull request, we need to address refresh token issues raised in my earlier comment #2622 (comment)

@jonasfranz
Copy link

@bradrydzewski do you propose to remove refresh token invalidation after a new token is signed?

@bradrydzewski
Copy link

bradrydzewski commented Apr 11, 2019

@jonasfranz yes, I think invalidating existing refresh tokens after a new refresh token is generated causes more problems than it solves (see the doorkeeper issues I referenced above). Google and Bitbucket, for example, only invalidate refresh tokens if the user revokes access to the application. Or you could make refresh tokens optional (neither GitLab or GitHub use refresh tokens, although there are security benefits that need to be weighed).

@lunny
Copy link

lunny commented Apr 12, 2019

@techknowlogick go.mod conflicted

@jonasfranz
Copy link

@bradrydzewski With my latest PR, Gitea will not invalidate refresh tokens by default. But there is an option to enable token invalidation.

@bradrydzewski
Copy link

@jonasfranz awesome, can you link to the pull request here. Once it is merged, we can merge this pull request. Also I will need to document the minimum version of Gitea that will be required -- can you let me know which version this will be? Thanks!!

@jonasfranz
Copy link

@bradrydzewski The PR is already merged: go-gitea/gitea#6584

It will be in version 1.8.0 (or 1.8.0-rc3 if we have a rc3).

@techknowlogick
Copy link
Author

@lunny conflict resolved.

@appleboy
Copy link

@bradrydzewski Already merged in Gitea.

@bradrydzewski
Copy link

excellent. one last request -- can we get an entry for this in the changelog? thanks!

@lunny
Copy link

lunny commented Apr 13, 2019

@bradrydzewski I think yes. This could be in release notes of v1.8.

@bradrydzewski
Copy link

bradrydzewski commented Apr 13, 2019

what I mean is that we need an entry for this change in Drone's changelog file (in the unreleased section) https://github.com/drone/drone/blob/master/CHANGELOG.md

@techknowlogick
Copy link
Author

@bradrydzewski added

@bradrydzewski bradrydzewski merged commit 1a01a70 into harness:master Apr 13, 2019
@techknowlogick techknowlogick deleted the gitea-oauth branch April 13, 2019 18:22
@tboerger
Copy link

This works with gitea master? Or also with some stable release?

@techknowlogick
Copy link
Author

@tboerger it works with 1.8.0 which was just released yesterday, but Drone can still work with older versions of gitea using basic auth.

@oliver006
Copy link

oliver006 commented Apr 21, 2019

I've been using it successfully with docker images gitea:v1.8.0-rc3 (and 1.8.0 now that it's released) and drone/drone@sha256:7acfbba60ac6c35537b099ce612aac0af3cdbfa2e48d0ee96730cd4c904b89fa (the sha of the image right after this PR got merged).

But there seems to be a little problem with refreshing the gitea token. After a while, I'm no longer to e.g. enable a gitea repo for drone. I'm still logged in and can modify settings within drone. Once I log out and back in, everything is fine.

Should I open a separate issue to track the problem?

@techknowlogick
Copy link
Author

@oliver006 between rc3 and final gitea released a patch that should fix the issue you described above. Please feel free to open an issue in gitea tracker if this comes up again.

@oliver006
Copy link

oliver006 commented Apr 22, 2019

Thanks for the quick response @techknowlogick . I tried with Gitea 1.8.0 and the drone/drone image I mentioned above but it's still not working. I get:

image

I checked in the DB, the user_oauth_expiry value is unchanged (and 2h in the past).

I'll open an issue in the Gitea project.

[edit]
Opened: go-gitea/gitea#6703

@bradrydzewski
Copy link

I think the issue is that if Gitea uses a refresh token, a refresher needs to be configured. See https://github.com/drone/drone/blob/master/cmd/drone-server/inject_login.go#L166

@frostieDE
Copy link

This features needs some documentation, or am I missing something on the docs? 😄

@ukos-git
Copy link

here are my quick notes for installing:

  • go to your gitea instance application settings page: https://gitea.io/user/settings/applications
  • add a oauth instance with arbitrary id and redirect to the login page: https://gitea.io/login

Screenshot from 2019-04-28 15-40-02

  • you will get ClientID and ClientSecret:

Screenshot from 2019-04-28 15-41-13

  • add the generated values to your drone environement:
DRONE_GITEA_CLIENT_ID=XXX
DRONE_GITEA_CLIENT_SECRET=XXX

be sure to use latest gitea/gitea and drone/drone images (gitea version is displayed in ui bottom left. Today is Gitea Version: 345bc06)

Probably not enough for a PR to docs but better than no documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants