Skip to content

Blog

Keycloak "HTTPS required": causes and safe fixes

What the Keycloak "HTTPS required" page means, how Require SSL decides, how to get back into a locked master realm, and why turning SSL off is the wrong fix.

Author
The RealmDeploy team
Published

"HTTPS required" is Keycloak refusing to run a sign-in over plain HTTP. It is a safety check, and it usually fires at the worst moment: the first time you open a new server's admin console from your own machine.

Two things decide it. One is the realm's Require SSL setting. The other is how Keycloak sees the request: the scheme of the URL it resolved, and the address the request came from. Get either wrong and the page appears.

The quick fix people find online is to set Require SSL to none. That makes the message go away and leaves passwords and tokens on the wire in clear text. There is almost always a better fix.

What you see

On the sign-in page, under Keycloak's error title We are sorry..., the message is:

HTTPS required

Both strings come from Keycloak's login theme messages. When a token request is refused for the same reason, the token endpoint answers 403 with this JSON:

{ "error": "invalid_request", "error_description": "HTTPS required" }

With saved events turned on, a refused sign-in is recorded with the error ssl_required.

How Keycloak decides

Each realm has a Require SSL setting with three values. The admin console's help text describes them: None means HTTPS is not required for any client IP address. External requests means localhost and private IP addresses can access without HTTPS. All requests means HTTPS is required for all IP addresses.

New realms, including master, use External requests.

For External requests, Keycloak 26.8.2 treats an address as local when it is a loopback address, a site-local address (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16), a link-local address, or an IPv6 unique local address (fc00::/7). Everything else is external.

The check itself is short. Keycloak shows "HTTPS required" when the resolved base URL is not https and the realm's setting requires SSL for the client's address. Both halves matter:

  • The scheme comes from hostname when it is a full URL. When hostname is only a host name, or when hostname-strict is false, the scheme comes from the request, or from the proxy's forwarded headers when proxy-headers is set.
  • The client address is the TCP peer, or the address in X-Forwarded-For or Forwarded when proxy-headers is set.

Causes, most common first

  1. You open a server over plain HTTP from a public address. A dev or test server, often start-dev in Docker on a cloud VM, opened from your laptop as http://<public IP>:8080. Your address is external, and the URL is HTTP.
  2. A proxy ends TLS but does not tell Keycloak. proxy-headers is set but the proxy sends no X-Forwarded-Proto, or sends http. Keycloak sees a real public client address and an HTTP scheme.
  3. hostname is a bare host name and the scheme is taken from the request, which arrives over HTTP from the proxy.
  4. Require SSL is All requests and someone reaches Keycloak over HTTP from inside the network, for example a health check or a script.
  5. A load balancer with a public address sits in front without forwarded headers. Keycloak sees the balancer's address as the client, and it is not private.

Diagnose it step by step

  1. Note the exact URL in the address bar. Is it http://? Is it an IP address or the real host name?

  2. Open the discovery document for the realm and read issuer. An http:// issuer means Keycloak resolved an HTTP base URL.

    curl -s http://203.0.113.10:8080/realms/master/.well-known/openid-configuration | jq -r .issuer
    
  3. Check the server options with bin/kc.sh show-config. Look at hostname, hostname-strict, http-enabled and proxy-headers.

  4. Check the proxy's headers. Confirm it sends X-Forwarded-Proto: https and the real client address, and that it overwrites what the client sent.

  5. Use the hostname debug page for a short time: start with --hostname-debug=true and open /realms/<realm>/hostname-debug through the proxy. It shows the URLs Keycloak resolved.

  6. Look at events if you can still sign in to some realm: the failed attempts carry ssl_required.

  7. Test from inside the network. curl from the Keycloak host to http://localhost:8080/realms/master/ works under External requests. If that works and the outside does not, the setting is doing its job and the fix is TLS.

Fixes

Put TLS in front, and tell Keycloak about it

The right fix is HTTPS for every user. Behind a proxy that ends TLS:

bin/kc.sh start \
  --hostname=https://auth.example.com \
  --http-enabled=true \
  --proxy-headers=xforwarded

With hostname as a full https:// URL, the frontend scheme is fixed to HTTPS. The proxy should still send X-Forwarded-For and X-Forwarded-Proto so that Keycloak records the right client address.

Without a proxy, give Keycloak a certificate directly:

bin/kc.sh start \
  --hostname=https://auth.example.com \
  --https-certificate-file=/opt/keycloak/conf/tls.crt \
  --https-certificate-key-file=/opt/keycloak/conf/tls.key

For a throwaway dev server, connect locally

If you are testing on a VM, reach the admin console through an SSH tunnel instead of the public address. Your request then arrives from localhost, which External requests allows:

ssh -L 8080:localhost:8080 [email protected]
# then open http://localhost:8080/admin/ on your own machine

This keeps the realm setting at its default and keeps the admin console off the internet.

Locked out of the master realm

If the master realm's admin console shows "HTTPS required" and you have no HTTPS yet, there are two ways back in. Try them in this order.

From inside the network with kcadm.sh. Under External requests, a request from localhost or a private address is allowed over HTTP. Run the admin CLI on the Keycloak host or in its container:

cd /opt/keycloak/bin
./kcadm.sh config credentials --server http://localhost:8080 \
  --realm master --user admin
./kcadm.sh get realms/master --fields sslRequired

Signing in this way lets you fix what is wrong, such as a client or an identity provider, without touching the setting. If Require SSL was changed to All requests and you must change it back, set it to External requests, not none:

./kcadm.sh update realms/master -s sslRequired=external

In the database, as a last resort. Only when no local access is possible. Take a backup first. The setting is the SSL_REQUIRED column of the REALM table, with the values NONE, EXTERNAL and ALL. On PostgreSQL the table and column names are lowercase; the values stay uppercase:

-- PostgreSQL. Back up first. Then, for the master realm only:
UPDATE realm SET ssl_required = 'EXTERNAL' WHERE name = 'master';

Keycloak caches realms, so restart every Keycloak node after the change. Then fix TLS, and check that the realm still says External requests or All requests.

Why not set it to none

None turns the check off for every address. Sign-in forms, session cookies and tokens then cross the network in clear text whenever someone uses an HTTP URL. Anyone on the path can read them. It also hides the real fault, a proxy or hostname setting, until it causes a different error such as an issuer mismatch or a redirect loop. Fix the transport, and keep the check.

On RealmDeploy

Your Keycloak only answers over HTTPS on your own hostname. TLS ends at our gateway with a Let's Encrypt certificate we issue and renew, hostname is set to your https:// address, and plain HTTP requests are redirected to HTTPS. So the transport side of this error is handled for you.

Require SSL is a realm setting, and it is yours to set in your admin console. We suggest leaving it at External requests or setting it to All requests. If you see "HTTPS required" on your RealmDeploy hostname, write to us from the dashboard or with the contact form with the time and URL. See Custom domains and TLS.

Tools that help

  • Hostname helper: build the hostname, http-enabled and proxy-headers options so the scheme comes out as HTTPS.
  • Reverse proxy config: generate a proxy config that sends X-Forwarded-Proto and overwrites client headers.
  • kcadm command builder: write the kcadm.sh commands for signing in and updating a realm.
  • CIDR calculator: check whether an address falls inside the private ranges Keycloak treats as local.
  • OIDC discovery viewer: read the issuer to see which scheme Keycloak resolved.
  • X.509 decoder: check the certificate you give Keycloak or the proxy.