Troubleshoot built-in SSO

If a user can't log in through Keycloak, the P4 Web Server log and the table of common problems help you find the cause. Many failures happen after the browser shows that the login succeeded, so the cause is not always visible in the browser.

Check the P4 Web Server log

The P4 Web Server writes messages about logins to the webserver.log file. The file is in the directory that the webserver.log.path configurable sets. To learn more, see Configurables in the P4 CLI Reference.

Resolve common problems

Symptom Cause Solution

The browser shows an error from Keycloak about an invalid redirect URI.

The P4 Web Server sends the value of auth.idp.web_uri with the verify path as the redirect URI. Keycloak compares the redirect URI with the valid redirect URIs of the client, and the scheme, host, port, and path must match exactly. A common cause is a client entry or an auth.idp.web_uri value that uses http when the web server uses https.

Set auth.idp.web_uri to the https address of the web server. Add the matching redirect URI to the client in Keycloak, and then restart the P4 Web Server. To learn how, see Configure Keycloak for built-in SSO.

The browser and the web server log show that the login succeeded, but p4 login fails with Authentication failed.

The value of auth.idp.audience doesn't match the audience of the access token. P4 Server checks the audience after the browser login finishes.

Set auth.idp.audience to the audience in the access token. The default audience of Keycloak is account. Alternatively, add an audience mapper to the client in Keycloak, and set auth.idp.audience to the client ID. Then run p4 login again. To learn how, see Configure P4 Server for built-in SSO.

The first login of a user fails. The browser shows IdP token did not include the required 'p4_username' claim for the first-login lookup., and p4 login reports Authentication failed.

The token doesn't contain the claim. Common causes are an attribute that the user profile of the realm doesn't allow, an attribute that is not set on the user, a mapper on an optional client scope, or, when you use an identity provider broker, an Attribute Importer that is not set to Force.

Complete the claim setup in Keycloak, or set auth.idp.subject_claim to email. To learn how, see Configure Keycloak for built-in SSO.

The first login of a user fails when auth.idp.subject_claim is email.

Two Keycloak users share an email address, or no P4 Server user with AuthMethod: idp has the email address of the Keycloak user. Exactly one AuthMethod: idp user can have a given email address. The first login also fails if the email address of the Keycloak user isn't verified.

Give each user a unique email address, and set AuthMethod: idp for the matching user. In Keycloak, verify the email address of the user. To learn how, see Set up users for built-in SSO.

The browser shows that the login succeeded, but p4 login fails with Authentication failed. and no ticket exists.

The P4 Server user is already linked to a different Keycloak user, for example after you rename a user or reuse a username. P4 Server refuses the link after the browser shows its result, so the browser page doesn't show the failure.

Log in with the Keycloak user that is linked to the P4 Server user. If the link is no longer correct, for example because you moved users to a new identity provider, contact Perforce Support to clear the link.

The first login of a user on an edge server fails while the commit server is down or unreachable. Later logins of users who have logged in before succeed.

The edge server sends the first login of each user to the commit server, which links the Keycloak user to the P4 Server user. The edge server can't reach the commit server.

Restore the connection between the edge server and the commit server, and then log in again. To learn more, see Configure built-in SSO in a distributed environment.

The p4 login command waits and then times out, and the browser login is not completed.

The login was not completed before the time limit that auth.idp.timeout sets. The default limit is 60 seconds.

Complete the browser login sooner. If logins are slow, increase auth.idp.timeout. A longer limit doesn't fix a user or audience that doesn't match.

Keycloak rejects the client when a user logs in.

The client secret is not supplied: P4IDPCLIENTSECRET, P4IDPCLIENTSECRETFILE, and P4IDPCLIENTSECRETNAME are all unset in the environment of the p4d service, or the value is wrong.

Set the variable in the environment of the p4d service account, and then restart the service. To learn how, see Configure P4 Server for built-in SSO.

Every login fails before Keycloak shows the sign-in page. The P4 Web Server log contains oidc_client_setup_failed.

The P4 Web Server can't set up its connection to Keycloak. The log message names the cause. Common causes are:

  • The value of auth.idp.issuer_url, or an endpoint that Keycloak lists in its discovery document, uses http.

  • The client secret is shorter than 32 bytes.

  • The value of auth.idp.auth_method is private_key_jwt, and no usable signing key is set.

Configure Keycloak to use https, and set auth.idp.issuer_url to the https URL of the realm. Use a client secret of at least 32 bytes. For private_key_jwt, provide a signing key. To learn how, see Configure P4 Server for built-in SSO.

The p4 login command fails immediately with Web server on IP:PORT does not host the IdP service.

The P4 Web Server at the address that auth.idp.web_uri sets doesn't run the idp service. For example, the web server was started with --services=restapi.

Restart the web server with --services=idp, or without the --services option to run all services. To learn how, see Configure P4 Server for built-in SSO.

The P4 Web Server can't connect to Keycloak because of a certificate error.

The server doesn't trust the certificate of Keycloak, for example because a private certificate authority signed the certificate.

Set ssl.client.ca.path to a PEM file that contains the certificate of the certificate authority, or add the certificate authority to the certificate store of the operating system. Then run p4 admin restart or restart P4 Server. A restart of the web server alone doesn't apply the change. To learn how, see Configure P4 Server for built-in SSO.

The browser returns to the login page repeatedly, or the login never completes.

The P4 Web Server uses HTTP. Browsers don't return secure session cookies over HTTP.

Use HTTPS. To learn how, see Configure P4 Server for built-in SSO.

A user that you renamed in P4 Server can't log in.

The p4_username claim in Keycloak still contains the previous username.

Change the p4_username attribute of the user in Keycloak to the new username. Alternatively, set auth.idp.subject_claim to email. Matching by email works only for users with the idp authentication method.

A command with the -T option fails with a message about an invalid password.

The server can't validate the token. When the server refuses a token, the client can report a password error. Common causes are:

  • The server has no built-in SSO configuration.

  • The aud claim of the token doesn't match auth.idp.audience.

  • The iss claim of the token doesn't match auth.idp.issuer_url.

  • The token has expired.

Set the auth.idp configurables, and check the aud, iss, and exp claims of the token against the configuration. To learn how, see Configure P4 Server for built-in SSO.

A change to an auth.idp configurable doesn't take effect.

The server picks up most changes within about 10 seconds. A login that is already in progress uses the previous values. The P4 Web Server reads auth.idp.web_uri only when the web server starts.

Wait about 10 seconds, and then repeat the action. After you change auth.idp.web_uri, restart the P4 Web Server.