1
<#import "/templates/guide.adoc" as tmpl>
2
<#import "/templates/kc.adoc" as kc>
3
<#import "/templates/links.adoc" as links>
7
summary="Learn how to configure {project_name}'s https certificates for ingoing and outgoing requests as well as mTLS."
8
includedOptions="https-* http-enabled">
10
Transport Layer Security (short: TLS) is crucial to exchange data over a secured channel.
11
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.
12
In this {section}, you will learn how to configure {project_name} to use HTTPS/TLS.
14
== Configuring TLS in {project_name}
15
{project_name} can be configured to load the required certificate infrastructure using files in PEM format or from a Java Keystore.
16
When both alternatives are configured, the PEM files takes precedence over the Java Keystores.
18
=== Providing certificates in PEM format
19
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:
21
<@kc.start parameters="--https-certificate-file=/path/to/certfile.pem --https-certificate-key-file=/path/to/keyfile.pem"/>
23
{project_name} creates a keystore out of these files in memory and uses this keystore afterwards.
25
=== Providing a Java Keystore
26
When no keystore file is explicitly configured, but `http-enabled` is set to false, {project_name} looks for a `conf/server.keystore` file.
28
As an alternative, you can use an existing keystore by running the following command:
29
<@kc.start parameters="--https-key-store-file=/path/to/existing-keystore-file"/>
31
==== Setting the Keystore password
32
You can set a secure password for your keystore using the `https-key-store-password` option:
33
<@kc.start parameters="--https-key-store-password=<value>"/>
35
If no password is set, the default password `password` is used.
37
== Configuring TLS protocols
38
By default, {project_name} does not enable deprecated TLS protocols.
39
If your client supports only deprecated protocols, consider upgrading the client.
40
However, as a temporary work-around, you can enable deprecated protocols by running the following command:
42
<@kc.start parameters="--https-protocols=<protocol>[,<protocol>]"/>
44
To also allow TLSv1.2, use a command such as the following: `kc.sh start --https-protocols=TLSv1.3,TLSv1.2`.
46
== Switching the HTTPS port
47
{project_name} listens for HTTPS traffic on port `8443`. To change this port, use the following command:
48
<@kc.start parameters="--https-port=<port>"/>
52
In order to properly validate client certificates and enable certain authentication methods like two-way TLS or mTLS, you can set
53
a trust store with all the certificates (and certificate chain) the server should be trusting. There are number of capabilities that rely
54
on this trust store to properly authenticate clients using certificates such as:
56
* Mutual-TLS Client Authentication
57
* End-User X.509 Browser Authentication
59
You can configure the location of this truststore by running the following command:
61
<@kc.start parameters="--https-trust-store-file=/path/to/file"/>
63
NOTE: This trust store is targeted for authenticating clients where {project_name} is acting as a server. For configuring a trust store
64
where {project_name} is acting as a client to external services through TLS, see <@links.server id="keycloak-truststore"/>.
66
=== Setting the truststore password
67
You can set a secure password for your truststore using the `https-trust-store-password` option:
68
<@kc.start parameters="--https-trust-store-password=<value>"/>
69
If no password is set, the default password `password` is used.
71
== Securing credentials
72
Avoid setting a password in plaintext by using the CLI or adding it to `conf/keycloak.conf` file.
73
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" />.
76
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:
78
<@kc.start parameters="--https-client-auth=<none|request|required>"/>
80
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.
82
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"/>.