OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Add new health check for token exchange capability
Jan Sandbrink56ed7b375526
diff --git a/docs/system-admin-guide/files/external-file-storages/health-status/README.md b/docs/system-admin-guide/files/external-file-storages/health-status/README.mdindex d6b29bb9591..0f624b04493 100644--- a/docs/system-admin-guide/files/external-file-storages/health-status/README.md+++ b/docs/system-admin-guide/files/external-file-storages/health-status/README.md@@ -98,6 +98,7 @@ of setup. The following table lists the error codes related to those checks.| Error code | Error description | Possible reasons | Next steps and solutions ||-----------------------------------|-----------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|+| ERR_OIDC_PROVIDER_CANT_EXCHANGE | The storage was configured to exchange a new token from the OpenID provider, but the provider does not support token exchange. | Metadata for the OpenID provider is outdated or the storage setup is incompatible with the OpenID provider of the current user. | Please check if the current user authenticates through a provider that supports token exchange. If the provider supports token exchange, but you receive this error, then refresh provider metadata by submitting the discovery endpoint form again or manually add all supported grant types to the "supported grant types" configuration of the provider. || ERR_OIDC_TOKEN_ACQUISITION_FAILED | No token could be acquired for accessing the file storage. | The OpenID Connect (OIDC) setup doesn't have the necessary audience, nor does it provide the possibility to exchange tokens. | Please check if you configured the correct file storage audience in OpenProject. || ERR_OIDC_TOKEN_EXCHANGE_FAILED | The token exchange failed or was necessary and not supported. | The exchange failed on the given audience. An exchange might also have been attempted, if no refresh token was available, but the access token was expired. | Please check if you configured the correct file storage audience in OpenProject, and if the OIDC identity provider allows exchanging tokens for that audience. Also make sure that the identity provider is handing out refresh tokens. || ERR_OIDC_TOKEN_REFRESH_FAILED | The expired access token could not get refreshed. | The OIDC provider failed to refresh the token. This might happen due to an expired or revoked refresh token. | Please check the configuration of the OIDC identity provider of refresh tokens for misconfiguration. |diff --git a/modules/storages/app/common/storages/adapters/providers/nextcloud/validators/authentication_validator.rb b/modules/storages/app/common/storages/adapters/providers/nextcloud/validators/authentication_validator.rbindex 638d6e1bbd4..d2068eac2e9 100644--- a/modules/storages/app/common/storages/adapters/providers/nextcloud/validators/authentication_validator.rb+++ b/modules/storages/app/common/storages/adapters/providers/nextcloud/validators/authentication_validator.rb@@ -76,6 +76,7 @@ module Storagesregister_checks(:non_provisioned_user,:provisioned_user_provider,+ :provider_capabilities,:token_negotiable,:user_bound_request,:offline_access@@ -83,6 +84,7 @@ module Storagesnon_provisioned_usernon_oidc_provisioned_user+ provider_capabilitiestoken_negotiableuser_bound_requestoffline_access@@ -104,6 +106,14 @@ module Storagesendend+ def provider_capabilities+ if [email protected]_token? || @user.authentication_provider.token_exchange_capable?+ pass_check(:provider_capabilities)+ else+ fail_check(:provider_capabilities, :oidc_provider_cant_exchange)+ end+ end+def token_negotiableservice = OpenIDConnect::UserTokens::FetchService.new(user: @user, exchange_scope: @storage.token_exchange_scope)diff --git a/modules/storages/app/models/storages/nextcloud_storage.rb b/modules/storages/app/models/storages/nextcloud_storage.rbindex 029c6a862fb..76eacb81bb0 100644--- a/modules/storages/app/models/storages/nextcloud_storage.rb+++ b/modules/storages/app/models/storages/nextcloud_storage.rb@@ -78,6 +78,10 @@ module Storagesstorage_audienceend+ def exchanges_token?+ storage_audience.present? && storage_audience != OpenIDConnect::UserToken::IDP_AUDIENCE+ end+def authenticate_via_idp?%w[oauth2_sso oauth2_sso_with_two_way_oauth2_fallback].include?(authentication_method)enddiff --git a/modules/storages/config/locales/en.yml b/modules/storages/config/locales/en.ymlindex 5e8f5cff359..d67b9dd1320 100644--- a/modules/storages/config/locales/en.yml+++ b/modules/storages/config/locales/en.yml@@ -263,6 +263,7 @@ en:header: Authenticationnon_provisioned_user: User provisioned by IDPoffline_access: Configured OIDC offline_access scope+ provider_capabilities: Provider capabilitiesprovisioned_user_provider: User provisioned by OIDCtoken_negotiable: User token capabilitiesuser_bound_request: User-based request authentication@@ -313,6 +314,7 @@ en:oidc_cant_refresh_token: There was an error while trying to check your access to the storage. Please check the server logs for further information.oidc_non_oidc_user: The current user, while provisioned, wasn't provisioned by an OpenID Connect (OIDC) Identity Provider. Please re-run the check with an OIDC provisioned user.oidc_non_provisioned_user: The current user isn't provided by an OpenID Connect Identity Provider. Please re-run the check with a provided user.+ oidc_provider_cant_exchange: The OpenID Connect provider does not seem to support token exchange, but token exchange was configured for the storage.oidc_token_acquisition_failed: Your OpenID Connect setup doesn't provide the necessary audience, nor does it provide token exchange capabilities. Please check out our documentation for more information.oidc_token_exchange_failed: There seems to be a problem with the Token Exchange setup on your OpenID Connect Provider. Please check its configuration and try again.oidc_token_refresh_failed: There was an error while trying to check your access to the storage. Please check the server logs for further information.diff --git a/modules/storages/spec/common/storages/adapters/providers/nextcloud/validators/authentication_validator_spec.rb b/modules/storages/spec/common/storages/adapters/providers/nextcloud/validators/authentication_validator_spec.rbindex 8536f105824..102c77d49e2 100644--- a/modules/storages/spec/common/storages/adapters/providers/nextcloud/validators/authentication_validator_spec.rb+++ b/modules/storages/spec/common/storages/adapters/providers/nextcloud/validators/authentication_validator_spec.rb@@ -72,7 +72,8 @@ module Storagesendcontext "when using OpenID Connect" do- let(:storage) { create(:nextcloud_storage_configured, :oidc_sso_enabled) }+ let(:storage) { create(:nextcloud_storage_configured, :oidc_sso_enabled, storage_audience:) }+ let(:storage_audience) { OpenIDConnect::UserToken::IDP_AUDIENCE }let(:user) { create(:user, identity_url: "#{oidc_provider.slug}:123123123123") }let!(:oidc_provider) { create(:oidc_provider, scope:) }@@ -101,7 +102,7 @@ module Storagesexpect(result[:non_provisioned_user].code).to eq(:oidc_non_provisioned_user)state_count = result.tally- expect(state_count).to eq({ skipped: 4, warning: 1 })+ expect(state_count).to eq({ skipped: 5, warning: 1 })endit "returns a warning if the user is not provisioned by an oidc provider" do@@ -114,7 +115,7 @@ module Storagesexpect(result[:provisioned_user_provider].code).to eq(:oidc_non_oidc_user)state_count = result.tally- expect(state_count).to eq({ success: 1, skipped: 3, warning: 1 })+ expect(state_count).to eq({ success: 1, skipped: 4, warning: 1 })endcontext "when the offline_access scope is not configured" do@@ -128,22 +129,36 @@ module Storagesexpect(result[:offline_access].code).to eq(:offline_access_scope_missing)state_count = result.tally- expect(state_count).to eq({ success: 4, warning: 1 })+ expect(state_count).to eq({ success: 5, warning: 1 })endend- end- describe "checks related to the token" do- context "when the token doesn't have the necessary audiences" do- it "returns a validation failure in case the server does not support token exchange" do- create(:oidc_user_token, user:)+ context "when configured to exchange a token" do+ let(:storage_audience) { "my-audience" }++ it "returns an error" do+ create(:oidc_user_token, user:, extra_audiences: storage.audience)result = validator.call- expect(result[:token_negotiable]).to be_failure- expect(result[:token_negotiable].code).to eq(:oidc_token_acquisition_failed)+ expect(result[:provider_capabilities]).to be_failure+ expect(result[:provider_capabilities].code).to eq(:oidc_provider_cant_exchange)++ state_count = result.tally+ expect(state_count).to eq({ success: 2, failure: 1, skipped: 3 })+ end++ context "and when the OIDC provider can exchange tokens" do+ let!(:oidc_provider) { create(:oidc_provider, :token_exchange_capable, scope:) }++ it "succeeds" do+ create(:oidc_user_token, user:, extra_audiences: storage.audience)+ expect(validator.call).to be_success+ endendend+ end+ describe "checks related to the token" docontext "when the existing token requires a refresh" dolet(:expired_storage_token) docreate(:oidc_user_token, user:, extra_audiences: storage.audience, expires_at: 10.hours.ago)@@ -182,6 +197,8 @@ module Storagesendcontext "when the server supports token exchange" do+ let(:storage_audience) { "my-audience" }+let(:oidc_provider) { create(:oidc_provider, :token_exchange_capable, scope: "offline_access") }let!(:exchangeable_token) { create(:oidc_user_token, user:, refresh_token: nil) }