Keycloak
Keycloak is an open source identity and access management server with support for OpenID Connect, OAUTH 2.0 and SAML 2.0.
Administration
An administrative user with the username
admin is automatically created in the
master realm. Its initial password can be
configured by setting services (K)
and defaults to changeme. The password is
not stored safely and should be changed immediately in the
admin panel.
Refer to the Keycloak Server Administration Guide for information on how to administer your Keycloak instance.
Database access
Keycloak can use PostgreSQL, MariaDB or MySQL, as set by services (K).
If services (K) is enabled (the default), the selected database is enabled and a keycloak database and user are created. Keycloak connects to it over its Unix socket without a password.
External database access can be configured by setting
services (K) to false and setting
services (K),
services (K),
services (K),
services (K) and
services (K) as
appropriate. Note that you need to manually create the database
and allow the configured database user full access to it.
When connecting over TCP, services (K) must be set to the path to a file containing the password used to log in to the database.
Warning
The path should be provided as a string, not a Nix path, since Nix paths are copied into the world readable Nix store.
Unix socket authentication
Keycloak can connect via Unix socket, avoiding the need for a database password.
To use Unix sockets with an external database, set services (K)
to the socket directory for PostgreSQL (e.g., /run/postgresql) or the socket file for MySQL and MariaDB (e.g., /run/mysqld/mysqld.sock). The required junixsocket plugins are added automatically.
Hostname
The hostname is used to build the public URL used as base for all frontend requests and must be configured through services (K).
Note
If you're migrating an old Wildfly based Keycloak instance
and want to keep compatibility with your current clients,
you'll likely want to set services (K)
to /auth. See the option description
for more details.
services (K) Keycloak has the capability to offer a separate URL for backchannel requests, enabling internal communication while maintaining the use of a public URL for frontchannel requests. Moreover, the backchannel is dynamically resolved based on incoming headers endpoint.
For more information on hostname configuration, see the Hostname section of the Keycloak Server Installation and Configuration Guide.
Setting up TLS/SSL
By default, Keycloak won't accept unsecured HTTP connections originating from outside its local network.
HTTPS support requires a TLS/SSL certificate and a private key, both PEM formatted. Their paths should be set through services (K) and services (K).
Warning
The paths should be provided as a strings, not a Nix paths, since Nix paths are copied into the world readable Nix store.
Themes
You can package custom themes and make them visible to Keycloak through services (K). See the Themes section of the Keycloak Server Development Guide and the description of the aforementioned NixOS option for more information.
Configuration file settings
Keycloak server configuration parameters can be set in
services (K). These correspond
directly to options in
conf/keycloak.conf. Some of the most
important parameters are documented as suboptions, the rest can
be found in the All
configuration section of the Keycloak Server Installation and
Configuration Guide.
Options containing secret data should be set to an attribute
set containing the attribute _secret - a
string pointing to a file containing the value the option
should be set to. See the description of
services (K) for an example.
Example configuration
A basic configuration with some custom settings could look like this:
{
services.keycloak = {
enable = true;
settings = {
hostname = "keycloak.example.com";
};
initialAdminPassword = "e6Wcm0RrtegMEHl"; # change on first login
sslCertificate = "/run/keys/ssl_cert";
sslCertificateKey = "/run/keys/ssl_key";
};
}