Haydar
08/26/2024, 12:38 PMLari Hotari
08/26/2024, 1:20 PMRunLLM
08/26/2024, 1:20 PMnbf (not before) claim is optional in JWT tokens. If Keycloak is not including this claim, you can either configure Keycloak to include it or adjust Pulsar's settings to not require it. According to the OpenID Connect documentation, Pulsar validates several claims, but nbf is not mandatory.
2. Authentication Failures
Authentication failures can be due to several reasons:
- Incorrect Configuration: Ensure that the issuerUrl, clientCredentialsFile, and audience are correctly set in both the Pulsar broker and the Spring Boot application.
- Token Validation: Verify that the tokens issued by Keycloak are valid and contain the necessary claims (iss, aud, exp, etc.). You can use tools like jwt.io to decode and inspect the tokens.
3. Private Key Error
The error Required configuration parameter: privateKey suggests that Pulsar is expecting a private key for token validation. However, when using OIDC, the public key from the issuer's JWKS endpoint should be used instead. Ensure that the oidc.auth.provider.openid.clientCredentialsFile is correctly pointing to the JSON file with client credentials.
Example Configuration
Here is an example configuration for the Pulsar broker and Spring Boot application:
Broker Configuration (broker.conf):
# Specify the authentication provider
authenticationProviders=org.apache.pulsar.broker.authentication.oidc.AuthenticationProviderOpenID
# Enable authentication
authenticationEnabled=true
# Disable authorization (if not needed)
authorizationEnabled=false
# OpenID Connect configuration
oidc.auth.provider.openid.issuerUrl=http://your-keycloak-server/realms/master
oidc.auth.provider.openid.clientCredentialsFile=file:///path/to/your/client-credentials.json
oidc.auth.provider.openid.audience=account
# Allowed token issuers and audiences
openIDAllowedTokenIssuers=http://your-keycloak-server/realms/master
openIDAllowedAudiences=account
# Optional settings
openIDRoleClaim=sub
openIDRequireIssuersUseHttps=false
# Token validation settings
authenticationRefreshCheckSeconds=120
openIDAcceptedTimeLeewaySeconds=120
openIDKeyIdCacheMissRefreshSeconds=120
Spring Boot Application Configuration:RunLLM
08/26/2024, 1:21 PMURL issuerUrl = new URL("http://your-keycloak-server/realms/master");
URL credentialsUrl = new URL("file:///path/to/your/client-credentials.json");
String audience = "account";
System.out.println("PulsarClient initializing...");
// Build Pulsar Client with OAuth2 Authentication
return PulsarClient.builder()
.serviceUrl("pulsar://your-pulsar-server:6650")
.authentication(AuthenticationFactoryOAuth2.clientCredentials(issuerUrl, credentialsUrl, audience))
.operationTimeout(30, TimeUnit.SECONDS)
.connectionTimeout(30, TimeUnit.SECONDS)
.build();
Credentials JSON File (client-credentials.json):
{
"client_id": "client_id",
"client_secret": "client_secret",
"type": "client_credentials",
"grant_type": "client_credentials"
}
Would you like more detail on any specific part of the configuration or troubleshooting steps?
Sources:
- Authentication using OpenID Connect
- GitHub Issue: Pulsar Authorization with Keycloak 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.