Skip to content

Add support for single-tenant mode to Microsoft Identity Provider#20699

Merged
ssilvert merged 2 commits into
keycloak:mainfrom
Tasssadar:microsoft-tenantid
Oct 10, 2023
Merged

Add support for single-tenant mode to Microsoft Identity Provider#20699
ssilvert merged 2 commits into
keycloak:mainfrom
Tasssadar:microsoft-tenantid

Conversation

@Tasssadar

Copy link
Copy Markdown
Contributor

This is pretty much #11207, but updated to main. Description copied from #11207:

This change allows the usage of "single-tenant" App Registrations on Azure AD.

Microsoft distinguishes between single-tenant and multi-tenant app registrations.
Usually, enterprise companies would rather like to use so called "single-tenant" app registrations instead of multi-tenant app registrations [1], as they're limited to users in their tenant.
Since 2018, Microsoft disallowed the use of the global "/common/" endpoints for single-tenant applications [2]. The usual answer on the internet has been "use the generic oidc provider". While the generic OIDC provider works fine most of the cases, it doesn't work properly when using the "exchange-token" feature of keycloak.

The generic OIDC connector maps user identities to the OIDC subject field "sub" [3], which differs on the same account for every client on Microsoft [4] (OIDC spec refers to the 'pairwise' mode here [5]). However, the microsoft social connector stores the object id of the account in keycloak for federated users [6].

Therefore, while using the token-exchange feature from external to internal tokens, the different "sub" fields per client for the same account leads to mapping problems [7]. The token-exchange provider fails to find the respective user and tries to create a new user with the same mail address, which fails.

This patch allows to use the Microsoft social provider with single-tenant apps, which makes it easier for admins to configure microsoft federation, if the only need a single-tenant to federate, as they have to configure way less properties compared to the generic OIDC adapter resolves the token-exchange feature for Microsoft federated users

[1] https://docs.microsoft.com/en-us/azure/active-directory/develop/single-and-multi-tenant-apps
[2] https://keycloak.discourse.group/t/how-to-configure-microsoft-identity-provider-with-single-tenant/11741 https://lists.jboss.org/pipermail/keycloak-user/2019-February/017254.html
[3] https://github.com/keycloak/keycloak/blob/main/services/src/main/java/org/keycloak/broker/oidc/OIDCIdentityProvider.java#L651
[4] https://stackoverflow.com/questions/52876679/the-sub-claim-value-is-different-between-access-and-id-tokens
[5] https://openid.net/specs/openid-connect-core-1_0.html#SubjectIDTypes
[6] https://github.com/keycloak/keycloak/blob/main/services/src/main/java/org/keycloak/social/microsoft/MicrosoftIdentityProvider.java#L80
[7] https://github.com/keycloak/keycloak/blob/main/services/src/main/java/org/keycloak/protocol/oidc/DefaultTokenExchangeProvider.java#L485

Fixes #20695
Closes #11207

@Tasssadar Tasssadar requested review from a team as code owners May 31, 2023 14:45
@ghost ghost added team/ui labels May 31, 2023
@Tasssadar Tasssadar force-pushed the microsoft-tenantid branch 3 times, most recently from e18fbe6 to 815e5ce Compare June 1, 2023 08:48
@Tasssadar Tasssadar changed the title Add support for single-tenant mode to Microsoft Identnity Provider Add support for single-tenant mode to Microsoft Identity Provider Jun 1, 2023
@Tasssadar Tasssadar force-pushed the microsoft-tenantid branch from 815e5ce to 25e620a Compare June 1, 2023 09:35

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If possible we prefer to use test id's to retrieve elements during test, for more information see the Cypress Testing Library documentation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hi, not sure what you mean here - this file is pretty much copypasted from ProviderGoogleGeneralSettings verbatim, and all the Provider tests use this method to get the input element.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can search the project for findByTestId to get an idea of what needs to be done. Older code still uses id as we haven't updated it to match the new conventions everywhere.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I updated it to findByTestId. I also see the tests are failing, but it does not seem to be related to this PR.

@jonkoops

jonkoops commented Jun 1, 2023

Copy link
Copy Markdown
Contributor

@ssilvert can I get your input on the Java code for this one?

@jonkoops jonkoops requested a review from ssilvert June 1, 2023 10:33
@Tasssadar Tasssadar force-pushed the microsoft-tenantid branch from 25e620a to bbd5f8a Compare June 1, 2023 11:03
ssilvert
ssilvert previously approved these changes Jun 1, 2023

@ssilvert ssilvert left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Java code looks fine. Technically, the copyright should be updated to 2023. But I'm not going to hold this up for that.

jonkoops
jonkoops previously approved these changes Jun 5, 2023
@cypress

cypress Bot commented Jun 5, 2023

Copy link
Copy Markdown

1 flaky test on run #9331 ↗︎

0 527 48 0 Flakiness 1

Details:

Merge 3a1aa9e into 521db01...
Project: Keycloak Admin UI Commit: b87b69846a ℹ️
Status: Passed Duration: 10:54 💡
Started: Oct 10, 2023 7:08 PM Ended: Oct 10, 2023 7:19 PM
Flakiness  cypress/e2e/realm_settings_general_tab_test.spec.ts • 1 flaky test • chrome

View Output Video

Test Artifacts
Realm settings general tab tests > Test all general tab switches Test Replay Output Screenshots

Review all test suite changes for PR #20699 ↗︎

@jonkoops

jonkoops commented Jun 5, 2023

Copy link
Copy Markdown
Contributor

@pedroigor since you reviewed the original PR, can I ask you to review this one as well?

@Exordian

Exordian commented Jun 5, 2023

Copy link
Copy Markdown

Thanks for taking over!

auto-merge was automatically disabled June 12, 2023 12:32

Head branch was pushed to by a user without write access

@Tasssadar Tasssadar force-pushed the microsoft-tenantid branch from 976e7bc to 55af7ab Compare July 4, 2023 15:33
@Tasssadar

Copy link
Copy Markdown
Contributor Author

Rebased, I'm not sure I fixed the ProviderMicrosoftGeneralSettings.ts test right though, we'll see.

@Tasssadar

Copy link
Copy Markdown
Contributor Author

Hello, anything I can do to help push this along?

@Tasssadar Tasssadar force-pushed the microsoft-tenantid branch from 8d8a2b5 to 7dcb648 Compare August 8, 2023 11:39
@jonkoops

Copy link
Copy Markdown
Contributor

@pedroigor @ssilvert could y'all give this another look?

@jonkoops jonkoops left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Changes to the client-side tests look good to me.

@zeddD1abl0

Copy link
Copy Markdown

Just wanting to +1 this merge. It's currently holding us back from using KeyCloak with Microsoft for the reasons explained. KeyCloak will be our enterprise management interface, and we don't really want it to be multi-tenant capable if possible.

@ssilvert ssilvert left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for single-tenant in Microsoft Identity Provider

6 participants