Keycloak
Keycloak is an open-source identity and access management (IAM) software by Red Hat. Keycloak protects applications and services reliably with minimal additional code. It can perform authentication itself or integrate existing identity providers. Out of the box it supports OAuth2/OpenID Connect and SAML, both for applications and for identity providers. In the Blueprint Microservice, Keycloak is used for authentication. Technical users in the system context are managed directly in Keycloak. To use Keycloak, a realm must be created on a Keycloak instance.
The following table lists some important Keycloak terms and concepts:
| Name | Description |
|---|---|
| Realm | A self-contained configuration. Several realms can run on the same Keycloak instance but are otherwise completely separate. |
| Client | An application in a realm. This can be an application that wants to access another one, an application the user logs in to, or an application that is only accessed. |
| User | A user who can log in and access applications. |
| Service Account | A special user that a client can use to access another application without an actual user. It is bound to one client. → technical user |
| Role | A role that can be assigned to a user. Describes what the user may do on a system. There are realm roles that are valid on all clients, and there are client-specific roles. A client-specific role may only be used on that client. |
| Identity Provider | An external system that can perform authentication and confirm the identity of users. |
| Authentication Flows and States | Authentication in Keycloak is carried out by means of authentication states, which are grouped into authentication flows. For example, there is an authentication flow for the login with a browser, one for a logout, etc. More specialized login procedures can be integrated by means of custom flows. The Keycloak documentation describes how authentication flows are configured. |
| Token Mapper | Token mappers can be defined to determine which information is stored in the issued access token. They map user information to token claims. |
Security notes
Do not use the wildcard "*"
In the configuration options "Valid Redirect URIs", "Valid post logout redirect URIs" and "Web origins", the wildcard character "*" should not be used, in particular not in place of a subdomain. In the CORS configuration, "+" can be used, because this automatically configures the origins from "Valid Redirect URIs", which is generally sensible.
Limit the blast radius
The clients should be configured such that they only issue tokens for a specific audience. An audience can be, for example, one or more microservices. A microservice must reject tokens that do not contain it as an audience. This way, the token of a client can only be used to access the resources the client needs, and not other resources the user would also be authorized for.
See Audience validation for the configuration of the audience of a client.
Troubleshooting with the event log
Keycloak logs all important events (e.g. successful or failed logins) in an event log, independently of the technical logging. The event log of a realm can be viewed via the Keycloak web UI. To do this, event logging must first be switched on under "Events/Config". In addition to the login events, admin events can also be stored, but these are usually not relevant.
When the event log is switched on, the events can be viewed and searched under "Events/Login Events". Further information can be found in the Keycloak documentation.
Keycloak from a local Docker image
Keycloak can be started locally using its Docker image.
Further documentation
Related
- Authentication and authorization — the overview of authentication and authorization in jEAP: authentication contexts, functional and data authorization, OpenID Connect and OAuth2.
- Minimizing access token sizes — keep tokens issued by Keycloak lean.
- Audience validation — restrict the audience of a client's tokens.
- Configuring audiences in Keycloak — client scopes and audience mappers for resource audiences.
- Authorizing Keycloak clients for consuming application resources — how consuming applications obtain Keycloak clients.
- Tokens in the Blueprint Microservice — the claims Keycloak puts into tokens.
- Role concept in the Blueprint Microservice — user roles and business partner roles.
- OpenID Connect / OAuth2 mock server — the local replacement for Keycloak on DEV.