Skip to content

Commit 8836987

Browse files
Require authentication for SCIM requests
Handling authentication through our regular warden strategies. Permissions-wise the only thing we can check for is whether the authenticated user is an admin. Though this will require us to grant admin privileges to all SCIM clients, which might be more than we want to do.
1 parent b4b18c1 commit 8836987

File tree

4 files changed

+66
-3
lines changed

4 files changed

+66
-3
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# frozen_string_literal: true
2+
3+
#-- copyright
4+
# OpenProject is an open source project management software.
5+
# Copyright (C) the OpenProject GmbH
6+
#
7+
# This program is free software; you can redistribute it and/or
8+
# modify it under the terms of the GNU General Public License version 3.
9+
#
10+
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
11+
# Copyright (C) 2006-2013 Jean-Philippe Lang
12+
# Copyright (C) 2010-2013 the ChiliProject Team
13+
#
14+
# This program is free software; you can redistribute it and/or
15+
# modify it under the terms of the GNU General Public License
16+
# as published by the Free Software Foundation; either version 2
17+
# of the License, or (at your option) any later version.
18+
#
19+
# This program is distributed in the hope that it will be useful,
20+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
# GNU General Public License for more details.
23+
#
24+
# You should have received a copy of the GNU General Public License
25+
# along with this program; if not, write to the Free Software
26+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27+
#
28+
# See COPYRIGHT and LICENSE files for more details.
29+
#++
30+
31+
module ScimV2
32+
module ScimControllerMixins
33+
def self.included(base)
34+
base.prepend(Overwrites)
35+
end
36+
37+
module Overwrites
38+
# Completely overwriting authenticate method of Scimitar
39+
def authenticate
40+
return handle_scim_error(Scimitar::AuthenticationError.new) unless OpenProject::FeatureDecisions.scim_api_active?
41+
42+
warden = request.env["warden"]
43+
User.current = warden.authenticate! scope: :scim_v2
44+
45+
# Only admins are able to manage users, so that's the only permission we can check for it
46+
handle_scim_error(Scimitar::AuthenticationError.new) unless User.current.admin?
47+
end
48+
end
49+
end
50+
end

app/models/user.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,3 +764,7 @@ def self.default_admin_account_changed?
764764
!User.active.find_by_login("admin").try(:current_password).try(:matches_plaintext?, "admin")
765765
end
766766
end
767+
768+
# Fix for development (and non eagerloaded environments), where User.find(...) would not return service accounts before
769+
# they've been autoloaded.
770+
require "service_account"

config/initializers/scimitar.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
patch: Scimitar::Supportable.unsupported
3434
})
3535
Scimitar.engine_configuration = Scimitar::EngineConfiguration.new(
36-
token_authenticator: Proc.new do |_token, _options|
37-
OpenProject::FeatureDecisions.scim_api_active?
38-
end
36+
application_controller_mixin: ScimV2::ScimControllerMixins
3937
)
4038
end

config/initializers/warden.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@
2626
anonymous_fallback]
2727
end
2828

29+
OpenProject::Authentication.update_strategies(OpenProject::Authentication::Scope::SCIM_V2, { store: false }) do |_|
30+
# TODO: reduce?
31+
%i[global_basic_auth
32+
user_basic_auth
33+
basic_auth_failure
34+
oauth
35+
jwt_oidc
36+
session
37+
anonymous_fallback]
38+
end
39+
2940
Rails.application.configure do |app|
3041
app.config.middleware.use OpenProject::Authentication::Manager
3142
end

0 commit comments

Comments
 (0)