···11+# Keycloak {#module-services-keycloak}
22+33+[Keycloak](https://www.keycloak.org/) is an
44+open source identity and access management server with support for
55+[OpenID Connect](https://openid.net/connect/),
66+[OAUTH 2.0](https://oauth.net/2/) and
77+[SAML 2.0](https://en.wikipedia.org/wiki/SAML_2.0).
88+99+## Administration {#module-services-keycloak-admin}
1010+1111+An administrative user with the username
1212+`admin` is automatically created in the
1313+`master` realm. Its initial password can be
1414+configured by setting [](#opt-services.keycloak.initialAdminPassword)
1515+and defaults to `changeme`. The password is
1616+not stored safely and should be changed immediately in the
1717+admin panel.
1818+1919+Refer to the [Keycloak Server Administration Guide](
2020+ https://www.keycloak.org/docs/latest/server_admin/index.html
2121+) for information on
2222+how to administer your Keycloak
2323+instance.
2424+2525+## Database access {#module-services-keycloak-database}
2626+2727+Keycloak can be used with either PostgreSQL, MariaDB or
2828+MySQL. Which one is used can be
2929+configured in [](#opt-services.keycloak.database.type). The selected
3030+database will automatically be enabled and a database and role
3131+created unless [](#opt-services.keycloak.database.host) is changed
3232+from its default of `localhost` or
3333+[](#opt-services.keycloak.database.createLocally) is set to `false`.
3434+3535+External database access can also be configured by setting
3636+[](#opt-services.keycloak.database.host),
3737+[](#opt-services.keycloak.database.name),
3838+[](#opt-services.keycloak.database.username),
3939+[](#opt-services.keycloak.database.useSSL) and
4040+[](#opt-services.keycloak.database.caCert) as
4141+appropriate. Note that you need to manually create the database
4242+and allow the configured database user full access to it.
4343+4444+[](#opt-services.keycloak.database.passwordFile)
4545+must be set to the path to a file containing the password used
4646+to log in to the database. If [](#opt-services.keycloak.database.host)
4747+and [](#opt-services.keycloak.database.createLocally)
4848+are kept at their defaults, the database role
4949+`keycloak` with that password is provisioned
5050+on the local database instance.
5151+5252+::: {.warning}
5353+The path should be provided as a string, not a Nix path, since Nix
5454+paths are copied into the world readable Nix store.
5555+:::
5656+5757+## Hostname {#module-services-keycloak-hostname}
5858+5959+The hostname is used to build the public URL used as base for
6060+all frontend requests and must be configured through
6161+[](#opt-services.keycloak.settings.hostname).
6262+6363+::: {.note}
6464+If you're migrating an old Wildfly based Keycloak instance
6565+and want to keep compatibility with your current clients,
6666+you'll likely want to set [](#opt-services.keycloak.settings.http-relative-path)
6767+to `/auth`. See the option description
6868+for more details.
6969+:::
7070+7171+[](#opt-services.keycloak.settings.hostname-strict-backchannel)
7272+determines whether Keycloak should force all requests to go
7373+through the frontend URL. By default,
7474+Keycloak allows backend requests to
7575+instead use its local hostname or IP address and may also
7676+advertise it to clients through its OpenID Connect Discovery
7777+endpoint.
7878+7979+For more information on hostname configuration, see the [Hostname
8080+section of the Keycloak Server Installation and Configuration
8181+Guide](https://www.keycloak.org/server/hostname).
8282+8383+## Setting up TLS/SSL {#module-services-keycloak-tls}
8484+8585+By default, Keycloak won't accept
8686+unsecured HTTP connections originating from outside its local
8787+network.
8888+8989+HTTPS support requires a TLS/SSL certificate and a private key,
9090+both [PEM formatted](https://en.wikipedia.org/wiki/Privacy-Enhanced_Mail).
9191+Their paths should be set through
9292+[](#opt-services.keycloak.sslCertificate) and
9393+[](#opt-services.keycloak.sslCertificateKey).
9494+9595+::: {.warning}
9696+ The paths should be provided as a strings, not a Nix paths,
9797+since Nix paths are copied into the world readable Nix store.
9898+:::
9999+100100+## Themes {#module-services-keycloak-themes}
101101+102102+You can package custom themes and make them visible to
103103+Keycloak through [](#opt-services.keycloak.themes). See the
104104+[Themes section of the Keycloak Server Development Guide](
105105+ https://www.keycloak.org/docs/latest/server_development/#_themes
106106+) and the description of the aforementioned NixOS option for
107107+more information.
108108+109109+## Configuration file settings {#module-services-keycloak-settings}
110110+111111+Keycloak server configuration parameters can be set in
112112+[](#opt-services.keycloak.settings). These correspond
113113+directly to options in
114114+{file}`conf/keycloak.conf`. Some of the most
115115+important parameters are documented as suboptions, the rest can
116116+be found in the [All
117117+configuration section of the Keycloak Server Installation and
118118+Configuration Guide](https://www.keycloak.org/server/all-config).
119119+120120+Options containing secret data should be set to an attribute
121121+set containing the attribute `_secret` - a
122122+string pointing to a file containing the value the option
123123+should be set to. See the description of
124124+[](#opt-services.keycloak.settings) for an example.
125125+126126+## Example configuration {#module-services-keycloak-example-config}
127127+128128+A basic configuration with some custom settings could look like this:
129129+```
130130+services.keycloak = {
131131+ enable = true;
132132+ settings = {
133133+ hostname = "keycloak.example.com";
134134+ hostname-strict-backchannel = true;
135135+ };
136136+ initialAdminPassword = "e6Wcm0RrtegMEHl"; # change on first login
137137+ sslCertificate = "/run/keys/ssl_cert";
138138+ sslCertificateKey = "/run/keys/ssl_key";
139139+ database.passwordFile = "/run/keys/db_password";
140140+};
141141+```
···11-<chapter xmlns="http://docbook.org/ns/docbook"
22- xmlns:xlink="http://www.w3.org/1999/xlink"
33- xmlns:xi="http://www.w3.org/2001/XInclude"
44- version="5.0"
55- xml:id="module-services-keycloak">
66- <title>Keycloak</title>
77- <para>
88- <link xlink:href="https://www.keycloak.org/">Keycloak</link> is an
99- open source identity and access management server with support for
1010- <link xlink:href="https://openid.net/connect/">OpenID
1111- Connect</link>, <link xlink:href="https://oauth.net/2/">OAUTH
1212- 2.0</link> and <link
1313- xlink:href="https://en.wikipedia.org/wiki/SAML_2.0">SAML
1414- 2.0</link>.
1515- </para>
1616- <section xml:id="module-services-keycloak-admin">
1717- <title>Administration</title>
1818- <para>
1919- An administrative user with the username
2020- <literal>admin</literal> is automatically created in the
2121- <literal>master</literal> realm. Its initial password can be
2222- configured by setting <xref linkend="opt-services.keycloak.initialAdminPassword" />
2323- and defaults to <literal>changeme</literal>. The password is
2424- not stored safely and should be changed immediately in the
2525- admin panel.
2626- </para>
2727-2828- <para>
2929- Refer to the <link
3030- xlink:href="https://www.keycloak.org/docs/latest/server_admin/index.html">
3131- Keycloak Server Administration Guide</link> for information on
3232- how to administer your Keycloak
3333- instance.
3434- </para>
3535- </section>
3636-3737- <section xml:id="module-services-keycloak-database">
3838- <title>Database access</title>
3939- <para>
4040- Keycloak can be used with either
4141- PostgreSQL,
4242- MariaDB or
4343- MySQL. Which one is used can be
4444- configured in <xref
4545- linkend="opt-services.keycloak.database.type" />. The selected
4646- database will automatically be enabled and a database and role
4747- created unless <xref
4848- linkend="opt-services.keycloak.database.host" /> is changed
4949- from its default of <literal>localhost</literal> or <xref
5050- linkend="opt-services.keycloak.database.createLocally" /> is
5151- set to <literal>false</literal>.
5252- </para>
5353-5454- <para>
5555- External database access can also be configured by setting
5656- <xref linkend="opt-services.keycloak.database.host" />, <xref
5757- linkend="opt-services.keycloak.database.name" />, <xref
5858- linkend="opt-services.keycloak.database.username" />, <xref
5959- linkend="opt-services.keycloak.database.useSSL" /> and <xref
6060- linkend="opt-services.keycloak.database.caCert" /> as
6161- appropriate. Note that you need to manually create the database
6262- and allow the configured database user full access to it.
6363- </para>
6464-6565- <para>
6666- <xref linkend="opt-services.keycloak.database.passwordFile" />
6767- must be set to the path to a file containing the password used
6868- to log in to the database. If <xref linkend="opt-services.keycloak.database.host" />
6969- and <xref linkend="opt-services.keycloak.database.createLocally" />
7070- are kept at their defaults, the database role
7171- <literal>keycloak</literal> with that password is provisioned
7272- on the local database instance.
7373- </para>
7474-7575- <warning>
7676- <para>
7777- The path should be provided as a string, not a Nix path, since Nix
7878- paths are copied into the world readable Nix store.
7979- </para>
8080- </warning>
8181- </section>
8282-8383- <section xml:id="module-services-keycloak-hostname">
8484- <title>Hostname</title>
8585- <para>
8686- The hostname is used to build the public URL used as base for
8787- all frontend requests and must be configured through <xref
8888- linkend="opt-services.keycloak.settings.hostname" />.
8989- </para>
9090-9191- <note>
9292- <para>
9393- If you're migrating an old Wildfly based Keycloak instance
9494- and want to keep compatibility with your current clients,
9595- you'll likely want to set <xref
9696- linkend="opt-services.keycloak.settings.http-relative-path"
9797- /> to <literal>/auth</literal>. See the option description
9898- for more details.
9999- </para>
100100- </note>
101101-102102- <para>
103103- <xref linkend="opt-services.keycloak.settings.hostname-strict-backchannel" />
104104- determines whether Keycloak should force all requests to go
105105- through the frontend URL. By default,
106106- Keycloak allows backend requests to
107107- instead use its local hostname or IP address and may also
108108- advertise it to clients through its OpenID Connect Discovery
109109- endpoint.
110110- </para>
111111-112112- <para>
113113- For more information on hostname configuration, see the <link
114114- xlink:href="https://www.keycloak.org/server/hostname">Hostname
115115- section of the Keycloak Server Installation and Configuration
116116- Guide</link>.
117117- </para>
118118- </section>
119119-120120- <section xml:id="module-services-keycloak-tls">
121121- <title>Setting up TLS/SSL</title>
122122- <para>
123123- By default, Keycloak won't accept
124124- unsecured HTTP connections originating from outside its local
125125- network.
126126- </para>
127127-128128- <para>
129129- HTTPS support requires a TLS/SSL certificate and a private key,
130130- both <link
131131- xlink:href="https://en.wikipedia.org/wiki/Privacy-Enhanced_Mail">PEM
132132- formatted</link>. Their paths should be set through <xref
133133- linkend="opt-services.keycloak.sslCertificate" /> and <xref
134134- linkend="opt-services.keycloak.sslCertificateKey" />.
135135- </para>
136136-137137- <warning>
138138- <para>
139139- The paths should be provided as a strings, not a Nix paths,
140140- since Nix paths are copied into the world readable Nix store.
141141- </para>
142142- </warning>
143143- </section>
144144-145145- <section xml:id="module-services-keycloak-themes">
146146- <title>Themes</title>
147147- <para>
148148- You can package custom themes and make them visible to
149149- Keycloak through <xref linkend="opt-services.keycloak.themes"
150150- />. See the <link
151151- xlink:href="https://www.keycloak.org/docs/latest/server_development/#_themes">
152152- Themes section of the Keycloak Server Development Guide</link>
153153- and the description of the aforementioned NixOS option for
154154- more information.
155155- </para>
156156- </section>
157157-158158- <section xml:id="module-services-keycloak-settings">
159159- <title>Configuration file settings</title>
160160- <para>
161161- Keycloak server configuration parameters can be set in <xref
162162- linkend="opt-services.keycloak.settings" />. These correspond
163163- directly to options in
164164- <filename>conf/keycloak.conf</filename>. Some of the most
165165- important parameters are documented as suboptions, the rest can
166166- be found in the <link
167167- xlink:href="https://www.keycloak.org/server/all-config">All
168168- configuration section of the Keycloak Server Installation and
169169- Configuration Guide</link>.
170170- </para>
171171-172172- <para>
173173- Options containing secret data should be set to an attribute
174174- set containing the attribute <literal>_secret</literal> - a
175175- string pointing to a file containing the value the option
176176- should be set to. See the description of <xref
177177- linkend="opt-services.keycloak.settings" /> for an example.
178178- </para>
179179- </section>
180180-181181-182182- <section xml:id="module-services-keycloak-example-config">
183183- <title>Example configuration</title>
184184- <para>
185185- A basic configuration with some custom settings could look like this:
186186-<programlisting>
11+<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="module-services-keycloak">
22+ <title>Keycloak</title>
33+ <para>
44+ <link xlink:href="https://www.keycloak.org/">Keycloak</link> is an
55+ open source identity and access management server with support for
66+ <link xlink:href="https://openid.net/connect/">OpenID
77+ Connect</link>, <link xlink:href="https://oauth.net/2/">OAUTH
88+ 2.0</link> and
99+ <link xlink:href="https://en.wikipedia.org/wiki/SAML_2.0">SAML
1010+ 2.0</link>.
1111+ </para>
1212+ <section xml:id="module-services-keycloak-admin">
1313+ <title>Administration</title>
1414+ <para>
1515+ An administrative user with the username <literal>admin</literal>
1616+ is automatically created in the <literal>master</literal> realm.
1717+ Its initial password can be configured by setting
1818+ <xref linkend="opt-services.keycloak.initialAdminPassword"></xref>
1919+ and defaults to <literal>changeme</literal>. The password is not
2020+ stored safely and should be changed immediately in the admin
2121+ panel.
2222+ </para>
2323+ <para>
2424+ Refer to the
2525+ <link xlink:href="https://www.keycloak.org/docs/latest/server_admin/index.html">Keycloak
2626+ Server Administration Guide</link> for information on how to
2727+ administer your Keycloak instance.
2828+ </para>
2929+ </section>
3030+ <section xml:id="module-services-keycloak-database">
3131+ <title>Database access</title>
3232+ <para>
3333+ Keycloak can be used with either PostgreSQL, MariaDB or MySQL.
3434+ Which one is used can be configured in
3535+ <xref linkend="opt-services.keycloak.database.type"></xref>. The
3636+ selected database will automatically be enabled and a database and
3737+ role created unless
3838+ <xref linkend="opt-services.keycloak.database.host"></xref> is
3939+ changed from its default of <literal>localhost</literal> or
4040+ <xref linkend="opt-services.keycloak.database.createLocally"></xref>
4141+ is set to <literal>false</literal>.
4242+ </para>
4343+ <para>
4444+ External database access can also be configured by setting
4545+ <xref linkend="opt-services.keycloak.database.host"></xref>,
4646+ <xref linkend="opt-services.keycloak.database.name"></xref>,
4747+ <xref linkend="opt-services.keycloak.database.username"></xref>,
4848+ <xref linkend="opt-services.keycloak.database.useSSL"></xref> and
4949+ <xref linkend="opt-services.keycloak.database.caCert"></xref> as
5050+ appropriate. Note that you need to manually create the database
5151+ and allow the configured database user full access to it.
5252+ </para>
5353+ <para>
5454+ <xref linkend="opt-services.keycloak.database.passwordFile"></xref>
5555+ must be set to the path to a file containing the password used to
5656+ log in to the database. If
5757+ <xref linkend="opt-services.keycloak.database.host"></xref> and
5858+ <xref linkend="opt-services.keycloak.database.createLocally"></xref>
5959+ are kept at their defaults, the database role
6060+ <literal>keycloak</literal> with that password is provisioned on
6161+ the local database instance.
6262+ </para>
6363+ <warning>
6464+ <para>
6565+ The path should be provided as a string, not a Nix path, since
6666+ Nix paths are copied into the world readable Nix store.
6767+ </para>
6868+ </warning>
6969+ </section>
7070+ <section xml:id="module-services-keycloak-hostname">
7171+ <title>Hostname</title>
7272+ <para>
7373+ The hostname is used to build the public URL used as base for all
7474+ frontend requests and must be configured through
7575+ <xref linkend="opt-services.keycloak.settings.hostname"></xref>.
7676+ </para>
7777+ <note>
7878+ <para>
7979+ If you're migrating an old Wildfly based Keycloak instance and
8080+ want to keep compatibility with your current clients, you'll
8181+ likely want to set
8282+ <xref linkend="opt-services.keycloak.settings.http-relative-path"></xref>
8383+ to <literal>/auth</literal>. See the option description for more
8484+ details.
8585+ </para>
8686+ </note>
8787+ <para>
8888+ <xref linkend="opt-services.keycloak.settings.hostname-strict-backchannel"></xref>
8989+ determines whether Keycloak should force all requests to go
9090+ through the frontend URL. By default, Keycloak allows backend
9191+ requests to instead use its local hostname or IP address and may
9292+ also advertise it to clients through its OpenID Connect Discovery
9393+ endpoint.
9494+ </para>
9595+ <para>
9696+ For more information on hostname configuration, see the
9797+ <link xlink:href="https://www.keycloak.org/server/hostname">Hostname
9898+ section of the Keycloak Server Installation and Configuration
9999+ Guide</link>.
100100+ </para>
101101+ </section>
102102+ <section xml:id="module-services-keycloak-tls">
103103+ <title>Setting up TLS/SSL</title>
104104+ <para>
105105+ By default, Keycloak won't accept unsecured HTTP connections
106106+ originating from outside its local network.
107107+ </para>
108108+ <para>
109109+ HTTPS support requires a TLS/SSL certificate and a private key,
110110+ both
111111+ <link xlink:href="https://en.wikipedia.org/wiki/Privacy-Enhanced_Mail">PEM
112112+ formatted</link>. Their paths should be set through
113113+ <xref linkend="opt-services.keycloak.sslCertificate"></xref> and
114114+ <xref linkend="opt-services.keycloak.sslCertificateKey"></xref>.
115115+ </para>
116116+ <warning>
117117+ <para>
118118+ The paths should be provided as a strings, not a Nix paths,
119119+ since Nix paths are copied into the world readable Nix store.
120120+ </para>
121121+ </warning>
122122+ </section>
123123+ <section xml:id="module-services-keycloak-themes">
124124+ <title>Themes</title>
125125+ <para>
126126+ You can package custom themes and make them visible to Keycloak
127127+ through <xref linkend="opt-services.keycloak.themes"></xref>. See
128128+ the
129129+ <link xlink:href="https://www.keycloak.org/docs/latest/server_development/#_themes">Themes
130130+ section of the Keycloak Server Development Guide</link> and the
131131+ description of the aforementioned NixOS option for more
132132+ information.
133133+ </para>
134134+ </section>
135135+ <section xml:id="module-services-keycloak-settings">
136136+ <title>Configuration file settings</title>
137137+ <para>
138138+ Keycloak server configuration parameters can be set in
139139+ <xref linkend="opt-services.keycloak.settings"></xref>. These
140140+ correspond directly to options in
141141+ <filename>conf/keycloak.conf</filename>. Some of the most
142142+ important parameters are documented as suboptions, the rest can be
143143+ found in the
144144+ <link xlink:href="https://www.keycloak.org/server/all-config">All
145145+ configuration section of the Keycloak Server Installation and
146146+ Configuration Guide</link>.
147147+ </para>
148148+ <para>
149149+ Options containing secret data should be set to an attribute set
150150+ containing the attribute <literal>_secret</literal> - a string
151151+ pointing to a file containing the value the option should be set
152152+ to. See the description of
153153+ <xref linkend="opt-services.keycloak.settings"></xref> for an
154154+ example.
155155+ </para>
156156+ </section>
157157+ <section xml:id="module-services-keycloak-example-config">
158158+ <title>Example configuration</title>
159159+ <para>
160160+ A basic configuration with some custom settings could look like
161161+ this:
162162+ </para>
163163+ <programlisting>
187164services.keycloak = {
188165 enable = true;
189166 settings = {
190190- hostname = "keycloak.example.com";
167167+ hostname = "keycloak.example.com";
191168 hostname-strict-backchannel = true;
192169 };
193193- initialAdminPassword = "e6Wcm0RrtegMEHl"; # change on first login
194194- sslCertificate = "/run/keys/ssl_cert";
195195- sslCertificateKey = "/run/keys/ssl_key";
196196- database.passwordFile = "/run/keys/db_password";
170170+ initialAdminPassword = "e6Wcm0RrtegMEHl"; # change on first login
171171+ sslCertificate = "/run/keys/ssl_cert";
172172+ sslCertificateKey = "/run/keys/ssl_key";
173173+ database.passwordFile = "/run/keys/db_password";
197174};
198175</programlisting>
199199- </para>
200200-201201- </section>
202202- </chapter>
176176+ </section>
177177+</chapter>