I'm trying to set up the following architecture but I'm struggling:
Keycloak container with this image jboss/keycloak:7.0.0
Apache with mod_auth_openidc
The apache has a protected directory
Apache does an SSL client Authent
I want to configure the following scenario:
A user visits mywebsite/demo
Apache prompt him to authenticate with his certificate
Apache forward the info to keycloak
Keycloak uses X509/Validate Username to validate the certificate (CN)
Return the resource to the user once authenticated
I have the following config for Apache vhost :
Listen 8081 https
<VirtualHost *:8081>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/
SSLEngine on
SSLCipherSuite HIGH
SSLProtocol all -SSLv3 -TLSv1.3
SSLCertificateFile /etc/apache2/ssl/serv.crt
SSLCertificateKeyFile /etc/apache2/ssl/serv.key
SSLCACertificateFile /etc/apache2/ssl/ca.crt
<Location /pdf >
ProxyPass http://mywebsite:5001/pdf
ProxyPassReverse http://mywebsite:5001/pdf
</Location>
#RequestHeader set CERT_CHAIN ""
RequestHeader set SSL_CLIENT_CERT ""
OIDCCryptoPassphrase passphrase
OIDCProviderMetadataURL https://mywebsite:9004/auth/realms/demorealm/.well-known/openid-configuration
OIDCClientID demo2
OIDCClientSecret e6dc781f-49c0-4cfa-9cde-411f9d8bc2cb
OIDCSSLValidateServer Off
OIDCRedirectURI https://mywebsite:9998/demo2/redirect
OIDCRemoteUserClaim preferred_username
OIDCInfoHook access_token id_token userinfo session
<Location /demo2 >
SSLVerifyClient require
SSLVerifyDepth 2
#RequestHeader set SSL_CLIENT_CERT_CHAIN_0 "%{{CERT_CHAIN}}s"
RequestHeader set SSL_CLIENT_CERT "%{SSL_CLIENT_CERT}s"
#Require ssl
AuthType openid-connect
Require valid-user
Loglevel debug
</Location>
</VirtualHost>
For the keycloak container, I'm not sure if the container consider my standalone.xml if I mount it instead of the default so I have executed the following jboss commands:
/subsystem=keycloak-server/spi=x509cert-lookup:write-attribute(name=default-provider, value="apache") /subsystem=keycloak-server/spi=x509cert-lookup/provider=apache:write-attribute(name=properties.sslClientCert,value="SSL_CLIENT_CERT") /subsystem=keycloak-server/spi=x509cert-lookup/provider=apache:write-attribute(name=properties.sslCertChainPrefix,value="CERT_CHAIN") /subsystem=keycloak-server/spi=x509cert-lookup/provider=apache:write-attribute(name=properties.certificateChainLength,value="10") :reload
My keycloak is configured as follow : Client redirections :
And the Authentication flow :
Config execution authenticator
But when I visit the website I get this error as a user "Team XYZ" with certificate CN "Team XYZ" :
{"error_description":"X509 client certificate is missing.","error":"invalid_request"}
Keycloak Logs :
21:10:24,178 WARN [org.keycloak.services.x509.AbstractClientCertificateFromHttpHeadersLookup] (default task-49) HTTP header "SSL_CLIENT_CERT" is empty
20:09:48,062 WARN [org.keycloak.events] (default task-9) type=LOGIN_ERROR, realmId=5c005f6f-a912-4788-bf53-345551eb0e01, clientId=demo2, userId=null, ipAddress=Dummy, error=user_not_found, auth_method=openid-connect, auth_type=code, response_type=code, redirect_uri=https://mywebsite:9998/demo2/redirect, code_id=d2b3aecf-0a53-4d3a-85fd-3433aee61d61, response_mode=query, authSessionParentId=d2b3aecf-0a53-4d3a-85fd-3433aee61d61, authSessionTabId=FqOsf6BrEBk
Can someone please help me, I've been stuck with this for days now.