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

How to ensure only users part of an organization can login ? #228

Open
kedare opened this issue Apr 29, 2024 · 2 comments
Open

How to ensure only users part of an organization can login ? #228

kedare opened this issue Apr 29, 2024 · 2 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@kedare
Copy link

kedare commented Apr 29, 2024

Hello.

I was doing some tests by integrating some generics identity provider (let's say github) and setting it as IDP for an organization.

I was expecting the authentication to fail as the mail would not match the domain from the organization but I could successfully login, it would not login with the user of the org (let's say [email protected]) but would create a new user [email protected] instead, not part of any organization)

  • Is there a way to prevent any non existing user from being created ? I have User registration set to off so I would not expect any user from being created automatically.
  • Is there something I can add on the authentication flow to prevent any login from user that are not already part of an organization ?

Also as it looks like the social IDP integrations are singleton, it is usually okay to have a single Github integration for all the organizations ?

Thanks

@xgp
Copy link
Member

xgp commented Apr 29, 2024

Using "social login providers" for organizations wasn't really an intended use case. Our expectation is that generic SAML or OIDC are used to connect to organization-owned IdPs that are the source of truth for who is and who is not a member of an organization. That way, we don't do filtering after the identity brokering on email domain, as we assume that the IdP controls access.

I have User registration set to off so I would not expect any user from being created automatically.

This is true for the default Keycloak behavior also. Creating an "account" linked to an identity broker is not considered "user registration" in Keycloak either.

Is there a way to prevent any non existing user from being created?

Yes. You would have to create a custom authenticator and put it in the flows that you assign to the "Post login flow" and "First login flow" in the IdP.

Is there something I can add on the authentication flow to prevent any login from user that are not already part of an organization ?

Same as above. You would have to create a custom authenticator and put it in the flows that you assign to the "Post login flow" and "First login flow" in the IdP.

However, I can see the following as potentially valuable additions, so we'd look at a PR:

  • Custom authenticator that prevent brokered login from user that are not already part of an organization
  • Custom authenticator that checks email domain rules and prevents brokered login from an organization-owned IdP that doesn't correspond to the domains in the organization model. This should probably be configurable on the "verified" state of the domain(s).

@xgp xgp added enhancement New feature or request help wanted Extra attention is needed labels May 20, 2024
@MGLL
Copy link
Contributor

MGLL commented May 24, 2024

Hello,

regarding this topic, there is a possible workaround with "active organization authenticator".

Upon login, it will ask the user to select an organization> However, if the user have no organizations, he will get an error message and it should prevent him to connect:

image

Else, indeed, a custom authenticator which enforce an user to have an organization seems the way to go (just a validation which check the user belongs to any organization).
There is possible example here:

private void tryOrganizationSelectionChallenge(AuthenticationFlowContext context) {
List<OrganizationModel> organizations =
provider.getUserOrganizationsStream(context.getRealm(), context.getUser()).toList();
if (organizations.isEmpty()) {
log.warnf(
"Select organization challenge couldn't be performed because the user has no organization.");
failChallenge(context, "noOrganizationError");
} else if (organizations.size() == 1) {
log.infof("User has 1 organization, skip organization selection challenge.");
updateActiveOrganizationAttributeAndSucceedChallenge(context, organizations.get(0).getId());
} else {
LoginFormsProvider loginForm = context.form();
loginForm.setAttribute("organizations", organizations);
context.challenge(loginForm.createForm("select-organization.ftl"));
}

best

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants