プロジェクト

全般

プロフィール

Vote #78126

未完了

OAuth2 support for Redmine API Apps (OAuth2 Provider)

Admin Redmine さんがほぼ2年前に追加. ほぼ2年前に更新.

ステータス:
New
優先度:
通常
担当者:
-
カテゴリ:
REST API_32
開始日:
2022/05/09
期日:
進捗率:

0%

予定工数:
category_id:
32
version_id:
32
issue_org_id:
24808
author_id:
347
assigned_to_id:
107353
comments:
28
status_id:
1
tracker_id:
2
plus1:
7
affected_version:
closed_on:
affected_version_id:
ステータス-->[New]

説明

I think, we should make Redmine an OAuth2 provider, so that client apps using Redmine's API can ask users to authenticate rather than asking for an API key. Another goal would be to limit access to API client apps, so that not all apps gain access to the full scope of data a user has access to.

I'm working on this currently and I will hopefully be able to submit a patch soon. Here's a first screenshot:

!{width:500px}redmine_oauth2_provider.png!


journals

The attached patch series implements full OAuth2 provider support for Redmine.

h2. Background

OAuth2 is a widely adopted protocol for granting access to API client applications. More information can be found here:

* https://oauth.net/2/
* https://aaronparecki.com/2012/07/29/2/oauth2-simplified

h2. Screenshots

Here are a few screenshots that show how it looks like:

!{width:500px}apps.png!
_Admins are able to create/modify/delete OAuth2 client apps from the user interface._

!{width:500px}redmine_oauth2_provider.png!
_OAuth2 App credentials are generated and can then be used in API clients._

!{width:500px}auth_prompt.png!
_In order for an App to gain access to Redmine, it must ask the user for permission._

!{width:500px}my_account.png!
_Regular users are able to see which apps currently have access to their data from their *My Account* area._

!{width:500px}authorized_apps.png!
_Regular users are able to revoke access to individual apps._

h2. Live Demo

We are providing a live demo server and client via these links:

h3. https://server.redmine-oauth.planio.org

Username/Password is @admin:oauth2@. The content on this server will be reset every 60 minutes. Feel free to create your own OAuth2 applications via the "Admin section":https://server.redmine-oauth.planio.org/oauth/applications, but please don't modify/delete the "Sinatra Client App".

h3. https://client.redmine-oauth.planio.org

You can use this app to try out the authentication/authorization flow. Feel free to create your own user accounts on the Redmine server for this.

The @/issues@ API will only work if the @view_issues@ scope is requested. If only the standard scopes are requested, you will see an error here (on purpose).

Feel free to download the client app code from our "Planio repository":https://support.plan.io/projects/redmine-oauth2-client/repository to try out everything locally.

h2. The patch series

* @0001@ changes the base layout to use named routes. The old hash-style routes (e.g. @{controller => 'search', :action => 'index'}@) would get namespaced when the layout is used in a namespaced controller in a plugin or engine which is the case with the Doorkeeper gem introduced later.
* @0002@ changes the MenuManager in a similar way and prevents the rendered menu links from getting namespaced in the above scenario.
* @0003@ adds the Doorkeeper Gem and integrates it with Redmine in the relevant places. You could apply patches @0001@-@0003@ only to get functioning OAuth2 provider support already. In detail, what happens is:
** @Gemfile@ - Gem is added in
** @app/controllers/application_controller.rb@ - Doorkeeper is used as a new optional authentication mechanism that is tried when regular Redmine API auth fails
** @app/views/my/account.html.erb@ - Link to Doorkeeper's views for managing a user's authorized apps
** @config/initializers/doorkeeper.rb@ - "Configure Doorkeeper":https://github.com/doorkeeper-gem/doorkeeper#configuration so that it ties in with Redmine's user and admin authentication
** @config/routes.rb@ - Add Doorkeeper specific routes and @root_url@ which is needed by it
** @db/migrate/20170107092155_create_doorkeeper_tables.rb@ - Migrations to add Doorkeeper tables
** @lib/redmine.rb@ - Link to Doorkeeper's views for managing available apps within the admin section
** @public/stylesheets/application.css@ - Icon for Apps
** @test/unit/lib/redmine/i18n_test.rb@ - Fix locale counting in tests because doorkeeper-i18n introduces languages unknown to Redmine
* @0004@ - integrates Doorkeeper further by overriding all views with Redmine compatible markup and makes use of Redmine's @deny_access@ and @require_login@ methods which become available once the Doorkeeper controllers are set to inherit from Redmine's @ApplicationController@
* @0005@ - changes @Role#allowed_to?@ so that it can accept an optional @scope@ parameter which can be an array of permission symbols that will be used as a logical @AND@ filter.
* @0006@ - Allows OAuth2 client apps to use Redmine permissions as "Scopes in the sense of OAuth2":https://tools.ietf.org/html/rfc6749#section-3.3. This way, admins and application developers can limit the abilities of client apps. An app will generally have _at most_ the permissions defined by the App definition or as reqested by the app during the auhtorization step. Of course, the app will never have _more_ permissions than the user is has requested authorization for would have in a normal interactive scenario.

h2. Considerations

h3. Why use Doorkeeper?

Implementing OAuth2 "by hand" seemed like re-inventing the wheel. Building and maintaining such security-critical code is both error-prone and non-trivial. The "Doorkeeper Gem":https://github.com/doorkeeper-gem/doorkeeper is the de-facto standard solution for implementing an OAuth2 provider in Rails. It's tried and tested, well-maintained and used by many high profile apps and services.

Integrating it with Redmine required only minor changes to Redmine's code base itself which should hopefully make maintenance of this functionality quite easy.

h3. Why can only admins create apps?

The decision that only Redmine admins can add new API client applications is debatable, but it felt like the easiest solution for this first version. Allowing regular users to create apps would have required more overridden Doorkeeper controllers, new Redmine permissions (e.g. @add_apps@, @view_apps@, @destroy_apps@, etc.)

In addition to that, enabling/diasbling things like the REST API, JSONP support, etc. is currently also only available to admins, so I thought it would be consistent.

h3. Some translations are missing! Where are the I18n keys?

At the moment, I've included them via the "@doorkeeper-i18n@ Gem":https://github.com/doorkeeper-gem/doorkeeper-i18n. Technically, we could pull the locales in to Redmine's code base. However, – in the spirit of open source – I'd advcate in favor of keeping them in the external Gem and working with the Doorkeeper maintainers to improve them if needed. I've fixed "two":https://github.com/doorkeeper-gem/doorkeeper-i18n/commit/45c6faa5e848af99e4cb8d047d6db5a362d08270 "issues":https://github.com/doorkeeper-gem/doorkeeper-i18n/commit/d4e88c4fd7882c0181f4179b29014f6b2e1562c2 with the locales already via pull requests and they were accepted rather quickly.

That's it for now. I am looking forward to your feedback!
--------------------------------------------------------------------------------
IMO, I think that the OAuth2.0 provider will be a great addition to Redmine and a feature that we'll use for sure at our future integrations with other apps.

What I like very much is the separation between the users and applications. Now we've some users named like "<application_name>-Generic User" used to authenticate the API calls. Having the possibility to define them as apps and manage their permissions from a different screen is very useful.
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Slightly updated version of 0003, using wider columns for scopes
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
And another fix.
--------------------------------------------------------------------------------
+1
--------------------------------------------------------------------------------
+1

What is the current "status" of this? Is this kind of planned for a future release?

We have two apps that could benefit by this (I've been looking at the redmine_oauth_provider plugin, but it appears that it doesn't work with the current level of Redmine).
--------------------------------------------------------------------------------
+1
--------------------------------------------------------------------------------
I think that "Needs feedback" is a wrong status here. According to #12827 this status means that this ticket is waiting for author's feedback, and such tickets are invisible for developers. Jan could you updated patchset and Status here?
--------------------------------------------------------------------------------
I'm setting the status to *New* then, as requested. Ideally, we could get some more feedback from other contributors if the feature is desired and if yes, I'd be happy to rebase the patches on current trunk.
--------------------------------------------------------------------------------
I think it can be a nice feature for Redmine and would make it much easier to manage things like bots, dashboards and applications of that kind. IMHO it's definitely worth a rebase.
+1
--------------------------------------------------------------------------------
+1
--------------------------------------------------------------------------------
+1
--------------------------------------------------------------------------------
I'm also interested in this.
--------------------------------------------------------------------------------
+1
--------------------------------------------------------------------------------
I rebased this patch on current master and added a brief system test that covers application creation, authorization and usage with an actual oauth2 client.

I'd also like to add that, since a few weeks, we're using this feature successfully at "Planio":https://plan.io/redmine-hosting for authenticating the native Planio Storage client apps.
--------------------------------------------------------------------------------
Thanks Jens. I would really enjoy seeing this making its way into a future Redmine release and I believe it will help Redmine get more third party apps and integrations!
--------------------------------------------------------------------------------
Another update to this patch. Notable changes are:

* updated to Doorkeeper 5.4, which allowed for the following improvements:
** secrets (tokens, application secret) are now stored as hashes
** support for "PKCE":https://github.com/doorkeeper-gem/doorkeeper/wiki/Using-PKCE-flow (most relevant for non-confidential clients)
* introduced an @admin@ scope which allows Administrators to grant admin permissions to client applications
* fixed a stored CSRF vulnerability that was present in one of the original Doorkeeper templates. It was only exploitable by Administrators but if you're using an older version of this patch, at least update your views according to this "doorkeeper commit":https://github.com/doorkeeper-gem/doorkeeper/commit/39916a613b7dcc738aa38f7a17e1de9757bd0754

We also just released the "omniauth-redmine-oauth2":https://rubygems.org/gems/omniauth-redmine-oauth2 gem (source code at "Planio":https://support.plan.io/projects/omniauth-redmine-oauth2/repository and "Github":https://github.com/planio-gmbh/omniauth-redmine-oauth2). We also built a small Rails app to "demonstrate usage of the gem":https://support.plan.io/projects/omniauth-redmine-oauth2/repository/rails-demo .

Currently this patch makes two I18n tests fail. This is due to the inclusion of the "doorkeeper-i18n":https://github.com/doorkeeper-gem/doorkeeper-i18n gem, which introduces 4 locales that aren't present in Redmine. In general, we would need to decide if we want to include these 3rd party translation at all (they do not cover all of Redmine's locales by a large margin) or if we incorporate them into Redmine. As of now the patch just overrides a few strings to make the wording more Redmine-like.

Due to the Doorkeeper upgrade I was more or less forced to squash the last 4 commits of the previous patch series, so it's down to 4 commits now.
--------------------------------------------------------------------------------
Jens, I've started to look to the provided patches and to test this feature. For now, I've committed all 4 patches to the "Gitlab":https://gitlab.com/redmine-org/redmine/-/commits/feature/24808_oauth2_support instance in order to get the tests results. Besides the I18n test fails, there are some Rubocop warnings that should be fixed.

Am I wrong if I say that patches @0001@ and @0002@ can be extracted from this issue and delivered as separated ticket? In this way, we will down this feature to 2 patches and it will be easier to maintain/rebase it.

I've assigning this to the next major release version because the changes are too huge for a minor version.
--------------------------------------------------------------------------------
thanks for looking into this! I just created #35075 and #35076 with the first two patches of this series. Both should not cause test failures or rubocop warnings. I'll look into these next and update this issue accordingly.
--------------------------------------------------------------------------------
Thanks Marius for looking into this. I think it should greatly improve the Redmine API to use state of the art authorization!
--------------------------------------------------------------------------------
here are the remaining two patches, updated to the most recent doorkeeper release (5.5.1), rebased on current master, and hopefully with a lot less rubocop warnings.
--------------------------------------------------------------------------------
+100000000000000
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Excellent proposal, looking forward to seeing this merged for the next major release.
--------------------------------------------------------------------------------
The patches need some changes to work with Rails 6 and zeitwerk autoloader.
--------------------------------------------------------------------------------

Admin Redmine さんがほぼ2年前に更新

  • カテゴリREST API_32 にセット
  • 対象バージョンCandidate for next major release_32 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0