2022-01-18 09:51:43 +00:00
<#import "/templates/guide.adoc" as tmpl>
<#import "/templates/kc.adoc" as kc>
2022-02-09 13:58:31 +00:00
<#import "/templates/links.adoc" as links>
2022-01-18 09:51:43 +00:00
<@tmpl.guide
2022-02-02 07:48:04 +00:00
title="Configuring TLS"
2023-11-08 14:09:04 +00:00
summary="Learn how to configure {project_name}'s https certificates for ingoing and outgoing requests as well as mTLS."
2022-01-27 09:03:11 +00:00
includedOptions="https-* http-enabled">
2022-01-18 09:51:43 +00:00
2022-02-02 07:48:04 +00:00
Transport Layer Security (short: TLS) is crucial to exchange data over a secured channel.
2023-11-08 14:09:04 +00:00
For production environments, you should never expose {project_name} endpoints through HTTP, as sensitive data is at the core of what {project_name} exchanges with other applications.
In this {section}, you will learn how to configure {project_name} to use HTTPS/TLS.
2022-01-18 09:51:43 +00:00
2023-11-08 14:09:04 +00:00
== Configuring TLS in {project_name}
{project_name} can be configured to load the required certificate infrastructure using files in PEM format or from a Java Keystore.
2022-02-02 07:48:04 +00:00
When both alternatives are configured, the PEM files takes precedence over the Java Keystores.
2022-01-18 09:51:43 +00:00
=== Providing certificates in PEM format
2023-11-08 14:09:04 +00:00
When you use a pair of matching certificate and private key files in PEM format, you configure {project_name} to use them by running the following command:
2022-01-18 09:51:43 +00:00
<@kc.start parameters="--https-certificate-file=/path/to/certfile.pem --https-certificate-key-file=/path/to/keyfile.pem"/>
2023-11-08 14:09:04 +00:00
{project_name} creates a keystore out of these files in memory and uses this keystore afterwards.
2022-01-18 09:51:43 +00:00
2022-02-02 07:48:04 +00:00
=== Providing a Java Keystore
2023-11-08 14:09:04 +00:00
When no keystore file is explicitly configured, but `http-enabled` is set to false, {project_name} looks for a `conf/server.keystore` file.
2022-01-18 09:51:43 +00:00
2022-02-02 07:48:04 +00:00
As an alternative, you can use an existing keystore by running the following command:
2022-01-18 09:51:43 +00:00
<@kc.start parameters="--https-key-store-file=/path/to/existing-keystore-file"/>
2022-02-02 07:48:04 +00:00
==== Setting the Keystore password
2022-05-30 19:42:51 +00:00
You can set a secure password for your keystore using the `https-key-store-password` option:
2022-01-18 09:51:43 +00:00
<@kc.start parameters="--https-key-store-password=<value>"/>
2022-02-02 07:48:04 +00:00
2022-01-18 09:51:43 +00:00
If no password is set, the default password `password` is used.
2022-02-02 07:48:04 +00:00
== Configuring TLS protocols
2023-11-08 14:09:04 +00:00
By default, {project_name} does not enable deprecated TLS protocols.
2022-02-02 07:48:04 +00:00
If your client supports only deprecated protocols, consider upgrading the client.
However, as a temporary work-around, you can enable deprecated protocols by running the following command:
2022-01-18 09:51:43 +00:00
<@kc.start parameters="--https-protocols=<protocol>[,<protocol>]"/>
2022-02-02 07:48:04 +00:00
To also allow TLSv1.2, use a command such as the following: `kc.sh start --https-protocols=TLSv1.3,TLSv1.2`.
2022-01-18 09:51:43 +00:00
2022-02-02 07:48:04 +00:00
== Switching the HTTPS port
2023-11-08 14:09:04 +00:00
{project_name} listens for HTTPS traffic on port `8443`. To change this port, use the following command:
2022-01-18 09:51:43 +00:00
<@kc.start parameters="--https-port=<port>"/>
== Using a truststore
2022-05-30 19:42:51 +00:00
In order to properly validate client certificates and enable certain authentication methods like two-way TLS or mTLS, you can set
a trust store with all the certificates (and certificate chain) the server should be trusting. There are number of capabilities that rely
on this trust store to properly authenticate clients using certificates such as:
* Mutual-TLS Client Authentication
* End-User X.509 Browser Authentication
2022-01-18 09:51:43 +00:00
2022-02-02 07:48:04 +00:00
You can configure the location of this truststore by running the following command:
2022-05-30 19:42:51 +00:00
2022-01-18 09:51:43 +00:00
<@kc.start parameters="--https-trust-store-file=/path/to/file"/>
2023-11-08 14:09:04 +00:00
NOTE: This trust store is targeted for authenticating clients where {project_name} is acting as a server. For configuring a trust store
where {project_name} is acting as a client to external services through TLS, see <@links.server id="keycloak-truststore"/>.
2022-05-30 19:42:51 +00:00
2022-01-18 09:51:43 +00:00
=== Setting the truststore password
2022-05-30 19:42:51 +00:00
You can set a secure password for your truststore using the `https-trust-store-password` option:
2022-02-22 08:10:12 +00:00
<@kc.start parameters="--https-trust-store-password=<value>"/>
2022-01-18 09:51:43 +00:00
If no password is set, the default password `password` is used.
== Securing credentials
2022-02-02 07:48:04 +00:00
Avoid setting a password in plaintext by using the CLI or adding it to `conf/keycloak.conf` file.
2023-04-17 06:44:34 +00:00
Instead use good practices such as using a vault / mounted secret. For more detail, see <@links.server id="vault"/> and <@links.server id="configuration-production" />.
2022-02-02 07:48:04 +00:00
2022-02-09 13:58:31 +00:00
== Enabling mutual TLS
2023-11-08 14:09:04 +00:00
Authentication using mTLS is disabled by default. To enable mTLS certificate handling when {project_name} is the server and needs to validate certificates from requests made to {project_name} endpoints, put the appropriate certificates in {project_name} truststore and use the following command to enable mTLS:
2022-02-09 13:58:31 +00:00
<@kc.start parameters="--https-client-auth=<none|request|required>"/>
2023-11-08 14:09:04 +00:00
Using the value `required` sets up {project_name} to always ask for certificates and fail if no certificate is provided in a request. By setting the value to `request`, {project_name} will also accept requests without a certificate and only validate the correctness of a certificate if it exists.
2022-02-09 13:58:31 +00:00
2023-11-08 14:09:04 +00:00
Be aware that this is the basic certificate configuration for mTLS use cases where {project_name} acts as server. When {project_name} acts as client instead, e.g. when {project_name} tries to get a token from a token endpoint of a brokered identity provider that is secured by mTLS, you need to set up the HttpClient to provide the right certificates in the keystore for the outgoing request. To configure mTLS in these scenarios, see <@links.server id="outgoinghttp"/>.
2022-01-18 09:51:43 +00:00
2024-06-26 10:02:36 +00:00
NOTE: Management interface properties are inherited from the main HTTP server, including mTLS settings.
It means when mTLS is set, it is also enabled for the management interface.
To override the behavior, use the `https-management-client-auth` property.
2022-02-02 07:48:04 +00:00
</@tmpl.guide>