Set up users for built-in SSO

To let a user log in through Keycloak, set the authentication method of the user to idp. The user can then run p4 login and sign in with a browser.

Set the authentication method for users

You must have super access to set the authentication method of a user.

Before you set the authentication method, ensure that the user exists in P4 Server, and in Keycloak with a matching p4_username attribute or a unique email address.

To set the authentication method for an existing user, for example bob, follow these steps:

  1. To open the user form, run the following command:

    p4 user -f bob
  2. In the user form, set the AuthMethod field:

    AuthMethod: idp
  3. Save the form and close the editor.

To use idp as the authentication method for all new users by default, run the following command:

p4 configure set auth.default.method=idp

To learn about the field, see p4 user in the P4 CLI Reference.

You can't combine idp with +2fa in the authentication method. If you try, P4 Server reports 2FA cannot be used with IdP authentication. Users with the idp authentication method can't use p4 passwd. The command reports Cannot change password for IdP user; it is managed by the identity provider.

How P4 Server matches users

On the first login of a user, P4 Server matches the Keycloak user to a P4 Server user by the claim that auth.idp.subject_claim sets. The values are p4_username (the default) and email.

After the first login, P4 Server matches the user by the unique Keycloak ID of the user. A later change to the email address of the user in Keycloak doesn't break sign-in.

When auth.idp.subject_claim is email, exactly one built-in SSO user can have a given email address. The match is not case-sensitive.

When auth.idp.subject_claim is email, P4 Server matches a user only if the token marks the email address as verified. Otherwise, the first login fails. To mark email addresses as verified in Keycloak, do one of the following:

  • To make users verify their email address when they log in, in the realm settings, on the Login tab, turn on Verify email. Keycloak must be able to connect to a mail server.

  • To mark the email address of a user as verified, in the user details, turn on Email verified.

Log in

To log in to P4 Server as a built-in SSO user, follow these steps:

  1. Run the following command:

    p4 login
  2. In the browser that opens, sign in with the credentials of your organization.

  3. Wait for p4 login to finish. The command completes within the number of seconds that auth.idp.timeout sets. The default is 60.

If a browser cannot open, for example on a headless machine or when P4USEBROWSER is false, the command prints a URL. Open the URL in a browser on another device. To learn about the variable, see P4USEBROWSER in the P4 CLI Reference.

Other clients that support browser-based login open the browser for the user, as when the user runs p4 login.

Log out

The p4 logout and p4 logout -a commands remove the ticket of the user and the tokens that P4 Server caches for the user.

The commands don't sign the user out of Keycloak. The next p4 login can complete without a password prompt.

To end the Keycloak session, sign out of Keycloak or of the identity provider of your organization.

Control access for users with other authentication methods

When auth.idp.allow_non_idp_users is 1 (the default), a user with any authentication method can run commands if the user presents a valid token. The setting applies to tokens that the user provides with the -T option, the P4ACCESSTOKEN environment variable, or the Authorization: Bearer header of a REST API request.

To restrict token access to users with the idp authentication method, run the following command. You must have super access to P4 Server.

p4 configure set auth.idp.allow_non_idp_users=0