Keycloak is an open-source, self-hosted identity and access management solution that provides single sign-on (SSO), user authentication, and authorization services for applications. In AMT environments, Keycloak enables secure authentication for Java backend services and Python client scripts through standard OAuth2 and OpenID Connect protocols.
By centralizing authentication and identity management, Keycloak eliminates the need for applications to handle user credentials directly, supports role-based access control, and provides a unified authentication experience across multiple AMT components. It is particularly useful when you need to secure gRPC communication between Python clients and Java backend services, or when implementing enterprise-grade authentication with features like multi-factor authentication, user federation, and session management.
Download and extract the latest version of Keycloak.
keycloak-<version>\bin folder.kc.bat start-devstart-dev parameter is only meant for development. For production or HTTPS
configuration, use kc.bat start and configure certificates as described in the HTTPS Configuration
section below.
http://localhost:8080/admin (or
https://localhost:8443/admin if HTTPS is configured).
http://localhost:8080/realms/AMTRealm/account (or
https://localhost:8443/realms/AMTRealm/account if HTTPS is configured) to open the Account Console.
http://localhost:8080/admin (or
https://localhost:8443/admin if HTTPS is configured).
For gRPC authentication with Python clients, you need to register a backend resource server client. This client is used as the audience target for tokens but doesn't perform authentication itself.
| Note |
|---|
| The backend client is registered in Keycloak primarily for administration purposes, so it can be selected as an audience in token audience mappers. It doesn't authenticate itself. |
For production environments or when using Python client libraries with gRPC, Keycloak should be configured to use HTTPS. This requires generating a certificate and configuring Keycloak to run in production mode.
Create a directory for certificates and generate a self-signed certificate using OpenSSL:
# Windows PowerShell
New-Item -ItemType Directory -Force -Path "C:\Tools\certs"
cd C:\Tools\certs
# Generate certificate (365 days validity)
openssl req -x509 -newkey rsa:2048 -nodes -keyout localhost.key -out localhost.pem -days 365 -subj "/CN=localhost"This creates two files:
localhost.pem - The certificate (public)localhost.key - The private key (keep secure)Edit the Keycloak configuration file at <keycloak-dir>\conf\keycloak.conf:
# HTTPS Certificate Configuration
https-certificate-file=C:/Tools/certs/localhost.pem
https-certificate-key-file=C:/Tools/certs/localhost.key
https-port=8443
# Disable HTTP (optional, recommended for production)
http-enabled=false
# Allow any hostname (for development)
hostname-strict=falseHTTPS with custom certificates requires Keycloak to run in production mode:
# Navigate to Keycloak bin directory
cd <keycloak-dir>\bin
# Start in production mode (required for HTTPS)
kc.bat start| Note |
|---|
Development mode (start-dev) ignores custom HTTPS certificate configuration. You must use
start for HTTPS to work with self-signed certificates.
|
Keycloak will now be accessible at https://localhost:8443
When using Python client libraries (such as amt-jcl) with Keycloak for gRPC authentication, additional configuration is required for OIDC and certificate trust.
Python clients require a confidential client configuration with client credentials flow enabled.
backend_audience_scope), and set it as Default.Configure your Python application's jcl_config.json file with the following settings:
{
"oidc_url": "https://localhost:8443/realms/AMTRealm/protocol/openid-connect/token",
"oidc_client_id": "amt-python-client",
"oidc_client_secret": "<YOUR_CLIENT_SECRET>",
"oidc_scope": "openid offline_access backend_audience_scope",
"cert": "path/to/server1.pem",
"app_host": "localhost",
"app_grpc_port": "8081"
}| Field | Description |
|---|---|
| oidc_url | Keycloak token endpoint URL |
| oidc_client_id | The Python client ID created in Keycloak |
| oidc_client_secret | Client secret from Keycloak Credentials tab |
| oidc_scope | Scopes to request. Must include the backend scope to get the correct audience |
| cert | Path to the server certificate that the Java backend serves on the gRPC port |
When Keycloak uses HTTPS with self-signed certificates, Python clients need to trust the certificate to avoid SSL verification errors.
Set the REQUESTS_CA_BUNDLE environment variable to point to the Keycloak certificate:
# Windows PowerShell
$env:REQUESTS_CA_BUNDLE = "C:\Tools\certs\localhost.pem"
# Windows Command Prompt
set REQUESTS_CA_BUNDLE=C:\Tools\certs\localhost.pem
# Linux/macOS
export REQUESTS_CA_BUNDLE=/path/to/localhost.pemThis allows Python's requests library to trust the self-signed certificate when connecting to Keycloak.
If the Java backend needs to validate tokens by connecting to Keycloak's JWKS endpoint over HTTPS with a self-signed certificate, import the certificate into the Java truststore:
keytool -importcert -alias keycloak -file localhost.pem -keystore $JAVA_HOME/lib/security/cacerts -storepass changeit -nopromptSymptom: Python scripts fail with error:
[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self-signed certificateSolution:
REQUESTS_CA_BUNDLE environment variable to point to the certificate filejcl_config.json matches the Java backend's server certificateSymptom: Java backend rejects tokens with "invalid audience"
Solution:
oidc_scope in Python configuration includes the backend scope nameSymptom: Python client cannot connect to Java backend
Solution:
cert path in jcl_config.json points to the correct server1.pem
(the certificate served by the Java backend on port 8081)app_grpc_portjcl_config.json matches what the server is servingSymptom: Python client cannot obtain tokens from Keycloak
Solution:
oidc_client_secret matches the value in Keycloakoidc_urlREQUESTS_CA_BUNDLE if using self-signed certificates