keycloak-h...ent-install(1)
π NAME π
keycloak-httpd-client-install β tools to configure Apache HTTPD as a Keycloak client. π¦
And yes bestie, this is the keycloak-h...ent-install(1) page from the General Commands Manual β the name got squished in the header but it's the same icon, don't worry. β¨
π SYNOPSIS π
keycloak-httpd-client-install --app-name APP_NAME -s | --keycloak-server-url KEYCLOAK_SERVER_URL -r | --keycloak-realm KEYCLOAK_REALM -l | --protected-locations PROTECTED_LOCATIONS [ options ]
Configure mod_auth_mellon or mod_auth_openidc as a Keycloak client. That's the whole vibe. π
β¨ OPTIONS β¨
-h,--helpβ show this help message and exit. classic. π--versionβ display version and exit.--no-root-checkβ permit running by non-root (default:False). normally it wants root, this is the permission slip.-v,--verboseβ be chatty (default:False). give me the yapping, i want it.-d,--debugβ turn on debug info (default:False).--show-tracebackβ exceptions print traceback in addition to error message (default:False). for when you NEED the receipts.--log-fileLOG_FILE β log file pathname (default:/var/log/python-keycloak-httpd-client/keycloak-httpd-client-install.log).--app-nameAPP_NAME β name of the web app being protected bymod_auth_mellon(default:None).--forceβ forcefully override safety checks (default:False). she's forceful for a reason, be careful bestie.--permit-insecure-transportβ normally secure transport such as TLS is required, this defeats that check (default:False). it literally says insecure in the name. it's giving bad idea energy.--tls-verifyβ TLS certificate verification for requests to the server. May be one of case insenstive[true, yes, on]to enable,[false, no, off]to disable. Or the pathname to a OpenSSL CA bundle to use. (default:True).
π Program Configuration: π
--template-dirTEMPLATE_DIR β Template location (default:/usr/share/keycloak-httpd-client-install/templates).--httpd-dirHTTPD_DIR β Template location (default:/etc/httpd). (yes it says "Template location" again, that's what the man page says, i'm not editing the queen's words)
π Keycloak IdP: π
-r,--keycloak-realmKEYCLOAK_REALM β realm name (default:None).-s,--keycloak-server-urlKEYCLOAK_SERVER_URL β Keycloak server URL (default:None).-a,--keycloak-auth-role root-admin|realm-admin|anonymousβ authenticating as what type of user (default:root-admin).-u,--keycloak-admin-usernameKEYCLOAK_ADMIN_USERNAME β admin user name (default:admin).-P,--keycloak-admin-password-fileKEYCLOAK_ADMIN_PASSWORD_FILE β file containing the admin password (or use a hyphen"-"to indicate the password will be read from stdin) (default:None). this is the safe way, take notes π--keycloak-admin-realmKEYCLOAK_ADMIN_REALM β realm admin belongs to (default:master).--initial-access-tokenINITIAL_ACCESS_TOKEN β realm initial access token for client registeration (default:None).--client-originate-method native|registrationβ The method used on the Keycloak REST interface for creating a new client. There are two possibilities:nativeβ A KeycloakclientRespresentationJSON object is sent to the Keycloak client REST endpoint. This is a native Keycloak data format understood only by Keycloak and as such permits setting values unique to Keycloak. This is sometimes refered to as the default client data format.registrationβ The data used to create the client is sent to the Keycloak registration endpoint. The data format depends on the type of client being created and can be controlled by the--client-data-format. The registration method has the advantage of not requiring admin privileges, see the Authentication Levels and Permissions and 0 details.
(default: native)
--client-data-formatCLIENT_DATA_FORMAT β Must be one ofdefault|oidc|saml2. When using the registration client originate method this selects the type of data used to create the client. For OIDC it can be eitherdefaultto use Keycloak'sclientRespresentationJSON object oroidcfor the OpenID Connect Dynamic Client Registration JSON object. For OIDC it defaults todefault. For SAML it must besaml2.) (default:default)defaultβ A KeycloakclientRepresentationJSON Object sent to the/realms/{realm}/clients-registrations/defaultendpoint.oidcβ A OIDC Dynamic Client Registeration JSON object sent to the/realms/{realm}/clients-registrations/openid-connectendpoint.saml2β A SAML metadata entity descriptor in XML format sent to the/realms/{realm}/clients-registrations/saml2-entity-descriptorendpoint.
πΈ Common Client Options πΈ
-t,--client-type openidc|mellonβ Which kind of client. Formod_auth_openidcuse"openidc". Formod_auth_mellonuse"mellon". pick your fighter π«--clientidCLIENTID β The clientid Keycloak identifies the client by. This has different meanings depending on the type of client:- SAML β It is the EntityID and defaults to
{client_https_url}/{mellon_root}/{mellon_endpoint_path}/metadata) - OIDC β It is the clientid and defaults to
{client_hostname}-{app_name}
- SAML β It is the EntityID and defaults to
--client-hostnameCLIENT_HOSTNAME β The fully qualified host name the client is running on or responds to.--client-https-portCLIENT_HTTPS_PORT β SSL/TLS port used to connect to client.--crypto-passphraseCRYPTO_PASSPHRASE β Used to encrypt cookies, cache data, etc. If not supplied a random string will be generated. she's got a random string for you if you don't bring your own π--location-rootLOCATION_ROOT β Common root ancestor for all protected locations.
π¦ mod_auth_oidc OIDC RP Client Options π¦
--oidc-redirect-uriOIDC_REDIRECT_URI β The OIDCredirect_uri. Must be an antecedent (i.e. child) of one of the protected locations. (default: The first protected location appened with"/redirect_uri")--oidc-logout-uriOIDC_REDIRECT_URI β Can be used to add the location the user is redirected to after logout as an additionalredirectUrivalue in Keycloak's client representation. The location should not be nested under any of the protected locations, otherwise the login process would start again. (default:None). do NOT nest it, she will loop forever, that's not the vibe π--oidc-client-secretOIDC_CLIENT_SECRET β OIDC client secret (default: generated random string).--oidc-remote-user-claimOIDC_REMOTE_USER_CLAIM β claim used when setting theREMOTE_USERvariable (default:"sub").
β mod_auth_mellon SP Client Options β
--mellon-key-fileMELLON_KEY_FILE β certficate key file (default:None).--mellon-cert-fileMELLON_CERT_FILE β certficate file (default:None).--mellon-endpointMELLON_ENDPOINT β Used to form theMellonEndpointPath, e.g.{mellon_root}/{mellon_endpoint}(default:mellon).--mellon-idp-attr-nameMELLON_IDP_ATTR_NAME β Name of the attributemod_auth_mellonadds which will contain the IdP entity id (default:{client_https_url}/{mellon_root}/{mellon_endpoint_path}/metadata)--mellon-organization-nameMELLON_ORGANIZATION_NAME β Add SAMLOrganizationNameto SP metadata (default:None).--mellon-organization-display-nameMELLON_ORGANIZATION_DISPLAY_NAME β Add SAMLOrganizationDisplayNameto SP metadata (default:None).--mellon-organization-urlMELLON_ORGANIZATION_URL β Add SAMLOrganizationURLto SP metadata (default:None).-l,--protected-locationsPROTECTED_LOCATIONS β Web location to be protected by client. May be specified multiple times (default:[]). stack it up, she takes multiples π
π DEPRECATED OPTIONS π
bestie. these are old. they still exist but they are over. use the new ones, i'm begging. π
-p,--keycloak-admin-passwordβ It is insecure to pass a password on the command line. Use one of the other methods detailed in the How to pass the Keycloak admin password topic. literally everyone can see it in your process list. no. stop.--mellon-protected-locationsβ Use-lor--protected-locationsinstead.--mellon-hostnameβ Use--client-hostnameinstead.--mellon-https-portβ Use--client-https-portinstead.--mellon-rootβ Use--location-rootinstead.--mellon-entity-idβ Use--clientidinstead.
β¨ DESCRIPTION β¨
keycloak-httpd-client-install is the little helper that configures an httpd (that's Apache, bestie) instance as a client of the Keycloak Identity Provider (IdP) β using either the mod_auth_openidc or the mod_auth_mellon authentication module. The whole reason we're here? Serving up authentication and authorization services to your web applications. It's giving infrastructure, it's giving β¨ security β¨.
π Quick Start
Okay so despite the absolute wealth of options this tool hands you, you can literally just run it with a minimum of 4 little pieces of information:
- an application name
- a web resource to protect (like a location)
- the Keycloak server and realm
- Keycloak authentication credentials
π Simple Example
sudo keycloak-httpd-client-install \
--app-name foo \
--protected-location /private \
--keycloak-server-url keycloak.example.com \
--keycloak-realm my_organization \
--keycloak-admin-password-file admin_passwd
π«Ά heads up: by defaultmod_auth_openidcis what gets configured as the client. Wanna domod_auth_melloninstead? Just add this option and you're so set:--client-type mellon.
π How to pass the Keycloak admin password
You can hand the Keycloak admin password over in any of the ways listed below β and this is the exact order the tool goes looking for it:
- It tries the
--keycloak-admin-password-fileargument first. If it's a hyphen-, the password gets read from stdin. Otherwise the argument is treated as the name of a file, the file gets opened, and the password is read from the file. π - Then it tests whether the
KEYCLOAK_ADMIN_PASSWORDenvironment variable exists. IfKEYCLOAK_ADMIN_PASSWORDis defined, the password is read from it. - Then it prompts for the password from the terminal.
π bestie the numbers go 1, 2, 4. No, we don't know where 3 went. We simply keep it real and keep it canon. Moving on π
π Authentication Levels and Permissions
This tool is capable of a whole range of configuration steps, but the extent of those operations can be circumscribed by the privilege level (authorization) the tool is run with. That privilege level is determined by the --keycloak-auth-role command line option, which may be one of these:
root-adminβ the Keycloak installation has a super realm normally calledmaster, and that's the container for all realms hosted by the Keycloak instance. A user with administration privileges in themasterrealm can perform all operations on all realms hosted by the instance. Think of such a user as a root user, or root admin. πrealm-adminβ each subordinate realm in the Keycloak instance may have its own administrator(s), and their privileges are restricted exclusively to that realm.anonymousβ the tool doesn't authenticate as a user, so no privileges are granted by virtue of being anyone. Any privilege comes by virtue of an initial access token passed in via the-initial-access-tokencommand line option. Think of an initial access token as a one time password scoped to a specific realm. The initial access token has to be generated by an administrator with sufficient privileges on the realm and given to the user of the tool. And the privileges that token confers are limited to registering the client in the realm utilizing the Keycloak client registration service.
Selecting which authentication role gets used is determined by a combination of the --keycloak-auth-role option and the --keycloak-admin-realm option. When the authentication role is one of root-admin or realm-admin, the tool authenticates as a user in a specific realm β and the --keycloak-admin-realm option declares the realm that administrator will authenticate to. For the root-admin role this is typically the master realm. For the realm-admin role this would be the realm the tool is registering the client in.
π§ Determining which authentication role to use
In general, the principle of least privilege should apply β grant the tool the least privilege necessary to perform the required action. In order of least privilege to greatest privilege, here are the operations possible under the defined authentication roles:
anonymous
- Can register the client using only the Keycloak client registration service. The tool cannot determine a prori if the client already exists in the realm, and it also can't adjust any configuration options on the client. π
- The realm must pre-exist.
realm-admin
- Can enumerate the existing clients in the realm to determine if a conflict would occur.
- Can delete a pre-existing client and replace it with the new client definition if the
--forceoption is supplied. - Can modify the client's configuration.
- Can use either the client registration service or the REST API to create the client.
- The realm must pre-exist and contain the realm admin user.
root-admin
- Includes all of the privileged operations conferred by
realm-admin. - Can enumerate existing realms on the Keycloak instance to verify the existence of the target realm the client is to be installed in.
- Can create the target realm if it does not exist.
π οΈ Client creation methods
Keycloak offers two methods to add a client to a realm, and you pick between them with the --client-originate-method option. β¨
registration
Originally designed to support the OIDC Dynamic Client Registration service, it can also be used to register clients with Keycloak's default clientRepresentation JSON Object, or SAML SP clients using SAML Entity Descriptor Metadata in XML format β it all depends on the exact endpoint utilized. See --cient-data-formt for details. The primary benefit of the client origination method is that it does not require admin privileges; instead an initial access token issued by the realm admin is used, and this is called anonymous authentication. Selected with --client-originate-method register. π
The client registration service requires the use of an initial access token. For all authentication roles, an initial access token can be provided on the command line via the initial-access-token option. That initial access token will have to have been provided by a Keycloak administrator who pre-creates it. But if the authentication role is either root-admin or realm-admin, the tool has sufficient privilege to obtain an initial access token on its own behalf β which negates the need for a Keycloak admin to supply one externally. Slay.
native
This method sends Keycloak's native clientRepresentation JSON object to the auth/admin/realms/{realm}/clients client endpoint to create or update a client.
If the client is a SAML SP, its Entity Descriptor XML Metadata is first sent to the auth/admin/realms/{realm}/client-description-converter conversion endpoint, which returns a native clientRepresention JSON object derived from the SAML SP metadata. That derived clientRepresentation is subsequently sent to the client REST endpoint.
The client registration service may be used by the following authentication roles:
root-adminrealm-adminanonymous(requires use of--initial-access-token)
The REST API may be used by the following authentication roles:
root-adminrealm-admin
β¨ OPERATION β¨
okay so bestie, keycloak-httpd-client-install performs the following operational steps which can be grouped into two major operational groups:
- Configure the httpd client
- Add the httpd client to the Keycloak server.
Configure the httpd client π
- Create directories. Files written by
keycloak-httpd-client-installneed a destination directory (see FILES). If the necessary directories are not present they are created. - Set up template environment. Many of the files written by
keycloak-httpd-client-installare based onjinga2templates. The default template file location can be overridden with the--template-diroption. - Set up X509 Certificiates. Some client configurations require the use of X509 certificates and keys. If these were not supplied as an option a self-signed certificate will be generated.
- Build the
mod_auth_openidcormod_auth_mellonhttpd config file. This is the httpd configuration file which will be installed in Apache'sconf.dconfiguration directory. It contains configuration directives formod_auth_openidcormod_auth_mellondepending on which client is being configured. - Build the client's protocol description. For
mod_auth_openidcthis means building JSON object which describes the client. It will be sent to the Keycloak server to add the client to the realm. Formod_auth_mellonthis means building the SAML SP XML metadata. The SP metadata is used both bymod_auth_mellonwhen it initializes and is also sent to the Keycloak server when adding the client to the Keycloak realm.
Add the httpd client to the Keycloak server. π
- Connect to Keycloak Server. A session is established with the Keycloak server. OAuth2 is used to log in as the admin user using the
--keycloak-admin-usernameand--keycloak-admin-password-fileoptions if you're using admin privileges. Otherwise a non-authenticated (e.g. anonymous) session is established and an initial access token supplied to you by a Keycloak admin will be used to register the client. - Query realms from Keycloak server, optionally create new realm. Keycloak supports multi-tenancy, it may present many IdP's each one specified by a Keycloak realm. The
--keycloak-realmoption identifies which Keycloak realm we will bind to. The Keycloak realm may already exist on the Keycloak server, if it doeskeycloak-httpd-client-installwill use it. If the Keycloak realm does not exist yet it will be created for you.
Requires the root-admin auth role.
- Query realm clients from Keycloak server, optionally delete existing. Before a new client can be added to the Keycloak realm we must assure it does not conflict with an existing client. If the client is already registered in the Keycloak realm
keycloak-httpd-client-installwill stop processing and exit with an error unless the--forceoption is used.--forcewill cause the existing client on the Keycloak realm to be deleted first so that it can be replaced in the next step.
Requires either the root-admin or realm-admin auth role.
- Create new client in Keycloak realm. The client description is sent to one of the Keycloak server's REST endpoints to add the client to the realm. The choice of which endpoint is used and the data format sent is a function of the
client-originate-method, the auth role and client data format. Most users will simply allow the tool to select the optimal combination. - Adjust client configuration. Override default Keycloak client values. This varies by Keycloak release.
Requires either the root-admin or realm-admin auth role.
- Add attributes to be returned in assertion. The client is configured to return necessary attributes. The added attributes are:
- Groups user is a member of.
Requires either the root-admin or realm-admin auth role.
- Retrieve IdP metadata from Keycloak server. The
mod_auth_mellonSP needs SAML metadata that describes the Keycloak IdP. The metadata for the Keycloak IdP is fetched from the Keycloak server and stored in a location referenced in themod_auth_mellonSP httpd configuration file. (see FILES)mod_auth_openidcalso needs a description of the Keycloak IdP but unlikemod_auth_mellonit is capable of fetching the Keycloak IdP description automatically via theOIDCProviderMetadataURLdirective and periodically refreshing it. Therefore this step is skipped formod_auth_openidc.
π¦ STRUCTURE π¦
The overarching organization is to produce a web application. An independent set of mod_auth_openidc or mod_auth_mellon files are created per application and registered with the Keycloak server. This permits multiple indpendent client and/or protected web resources to be handled by one Apache instance. When you run keycloak-httpd-client-install you must supply an application name via the --app-name option.
Within the web application you may protect multiple independent web resources specified via the --protected-locations /xxx option. This will cause a location block similar to this to be generated per location (depending on the client type):
mod_auth_openidc
OIDCClientID ...
OIDCProviderMetadataURL ...
OIDCCryptoPassphrase ...
OIDCClientSecret ...
OIDCRedirectURI ...
OIDCRemoteUserClaim ...
<Location /xxx>
AuthType openid-connect
Require valid-user
</Location>
mod_auth_mellon
<Location />
MellonEnable info
MellonEndpointPath ...
MellonSPMetadataFile ...
MellonSPPrivateKeyFile ...
MellonSPCertFile ...
MellonIdPMetadataFile ...
MellonIdP ...
</Location>
<Location /xxx>
AuthType Mellon
MellonEnable auth
Require valid-user
</Location>
These will be added to the client's HTTPD configuration file.
The location of the client configuration directives in the client configuration file depend on the client type.
- For
mod_auth_openidcthe directives are global to the module and hence can be located anywhere outside a location directive. The tool places them at the top of the client configuration file. - For
mod_auth_mellonthe directives must be located in a location block handled bymod_auth_mellon.mod_auth_mellonsupports directive inheritance, thus anymod_auth_mellonlocation block located below in the URL hierarchy will inherit directives from above. To avoid duplicate declarations ofmod_auth_mellondirectives that can be shared by subsequentmod_auth_mellonlocation block (and protect against future cut-n-paste errors) the shared commonmod_auth_mellondirectives are located at the location-root.
π Changes from the previous version π
keycloak-httpd-client-installnow supportsmod_auth_opendicin addition tomod_auth_mellon.- Some
mod_auth_mellonspecific options (e.g.--mellon-*) can be shared withmod_auth_openidc. These were renamed to have a--client-*prefix instead. The previous names continue to work but will emit adeprecatonwarning and will be removed in a future release. - The
--client-originatedescriptor method has been renamed tonative. - The
{httpd_dir}/saml2directory containing SAML data files (e.g. metadata, keys, certs, etc.) has been renamed to{httpd_dir}/federationto better reflect it's use as a location to store data used in federated authentication.
πΈ FILES πΈ
So like, here's literally everything keycloak-httpd-client-install creates when you run it, bestie. Manifest time π
Directories and files created by running keycloak-httpd-client-install:
{httpd_dir}/federationβ this dir holds the data files that get used while federated auth is happening. It's the SP's little stash π{httpd_dir}/conf.d/{app_name}_mellon_keycloak_{realm}.confβ THE mainmod_auth_mellonconfig file for your app. It binds to the Keycloak realm IdP, and it's generated from themellon_httpd.conftemplate file. Main character energy fr β¨{httpd_dir}/federation/{app_name}.certβ themod_auth_mellonSP X509 certificate file, in PEM format π{httpd_dir}/federation/{app_name}.keyβ themod_auth_mellonSP X509 key file, also PEM. Guard this one with your life π{httpd_dir}/federation/{app_name}_keycloak_{realm}_idp_metadata.xmlβ the Keycloak SAML2 IdP metadata file. It gets fetched from the Keycloak server, not made locally π{httpd_dir}/federation/{app_name}_sp_metadata.xmlβ themod_auth_mellonSAML2 SP metadata file, generated from thesp_metadata.xmltemplate file π¦{httpd_dir}/conf.d/{app_name}_oidc_keycloak_{realm}.confβ THE mainmod_auth_openidcconfig file for your app. It binds to the Keycloak realm IdP and is generated from theoidc_httpd.conftemplate file π
Files referenced by keycloak-httpd-client-install when it runs:
/usr/share/python-keycloak-httpd-client/templates/*β jinja2 templates π
Log files:
/var/log/python-keycloak-httpd-client/keycloak-httpd-client-install.logβ the installation log file π
π DEBUGGING π
Okay so if you're confused about something, the --verbose and --debug options bump up how much detail gets dumped on your console. Cute, right?
But ngl, the log file logs everything at the DEBUG level, so it's usually way easier to just go read the log file when you're debugging. See LOGGING below, iykyk π
π LOGGING π
keycloak-httpd-client-install logs all its operations to a rotated log file. You can override the default log file with the --log-file option β no cap π«Ά
Every single run of keycloak-httpd-client-install creates a new log file. Any previous log file gets rotated as a numbered version, and it keeps a maximum of 3 previous log files. Periodt.
Logging to the log file happens at the DEBUG level, which includes all HTTP requests and responses β so yeah, extremely useful for debugging. It's giving receipts π
π§ TEMPLATES π§
Many of the files generated by keycloak-httpd-client-install come from jinja2 templates, where the tool substitutes in the values it figured out while running. You can override the default template file location with the --template-dir option β¨
{template_dir}/mellon_httpd.confβ the template used to generate the httpd configuration file formod_auth_mellon, i.e.{httpd_dir}/conf.d/{app_name}_mellon_keycloak_{realm}.conf{template_dir}/sp_metadata.tplβ the template used to generate SAML SP Metadata{template_dir}/oidc_httpd.confβ the template used to generate the httpd configuration file formod_auth_openidc, i.e.{httpd_dir}/conf.d/{app_name}_oidc_keycloak_{realm}.conf{template_dir}/oidc-client-registration.tplβ the template used to generate the OIDC Dynamic Client Registration data sent to Keycloak's client registration endpoint/realms/{realm}/clients-registrations/openid-connect{template_dir}/oidc-client-representation.tplβ the template used to generate the KeycloakclientRepresentationJSON object used to create a new client using native method, or the registration method using the default client data format at the/realms/{realm}/clients-registrations/defaultendpoint
π¦ EXIT STATUS π¦
Vibe check on how it ended π
0βSUCCESSβ1βOPERATION_ERROR2βCONFIGURATION_ERROR3βINSUFFICIENT_PRIVILEGE4βCOMMUNICATION_ERROR5βALREADY_EXISTS_ERROR
π AUTHOR π
John Dennis <jdennis@redhat.com> β the legend who wrote all of this, ty for your service π«‘π
And that's the whole page, bestie, we made it to the end π The footer of this one just reads keycloak-h...ent-install(1) β yes the name is literally truncated mid-word in the header/footer because it's that long, iconic behavior honestly π. No version or date line survived in what we got, so I'm not gonna make one up β but the source is this keycloak-httpd-client-install(1) manual page as shipped, and this was part 4 of 4. Go forth and federate, you absolute icon ππ
π¦ where this page comes from
- centos-stream 10: python3-keycloak-httpd-client-install 1.3-2.el10 Β· GPL-3.0-or-later
- centos-stream 9: python3-keycloak-httpd-client-install 1.3-1.el9 Β· GPL-3.0-or-later
- fedora 43: python3-keycloak-httpd-client-install 1.3-6.fc43 Β· GPL-3.0-or-later
- fedora 44: python3-keycloak-httpd-client-install 1.3-7.fc44 Β· GPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms