Enable OAuth 2.0/OIDC authentication for Aiven for Apache Kafka® Schema Registry
Use OAuth 2.0/OpenID Connect (OIDC) to authenticate requests to Karapace Schema Registry with a JSON Web Token (JWT) issued by your identity provider.
You can also enable role-based authorization to control which Schema Registry operations clients can perform.
Prerequisites
Before you begin, make sure you have:
- An Aiven for Apache Kafka® service with Schema Registry enabled
- Karapace version 6.2.1 or later
- Access to an OIDC-compliant identity provider
- The following OIDC provider settings configured for your Aiven for Apache
Kafka service:
kafka.sasl_oauthbearer_jwks_endpoint_urlkafka.sasl_oauthbearer_expected_issuerkafka.sasl_oauthbearer_expected_audience
Schema Registry uses the same OIDC provider settings as Apache Kafka.
The Aiven Console does not require the expected issuer or audience settings when you configure Kafka OIDC, but Schema Registry requires both for authentication.
For more information about configuring these settings, see Enable OAuth 2.0/OIDC authentication for Apache Kafka®.
If your service runs a Karapace version earlier than 6.2.1, apply the available maintenance update first.
For more information, see Set the Karapace version.
Enable OIDC authentication
Karapace Schema Registry validates the JWT in the Authorization header
against the OIDC provider settings configured for the service.
This differs from the Karapace REST proxy, where Apache Kafka validates the bearer token.
In Karapace 6.2.3 and later, enabling OIDC authentication does not disable basic authentication. Clients can authenticate with a bearer token or with basic authentication.
Schemas remain visible in the Aiven Console after you enable OIDC authentication because the Console connects to Schema Registry with basic credentials.
You cannot disable Schema Registry basic authentication in the Aiven Console or with the Aiven CLI.
- Console
- CLI
- In the Aiven Console, select your project and choose your Aiven for Apache Kafka service.
- Click Service settings.
- Click Advanced configuration > Configure.
- Click Add configuration options.
- Add
schema_registry_config.sasl_oauthbearer_authentication_enabled. - Set the option to Enabled.
- Click Save configuration.
Run the following command:
avn service update SERVICE_NAME \
-c schema_registry_config.sasl_oauthbearer_authentication_enabled=true
Replace SERVICE_NAME with the name of your Aiven for Apache Kafka service.
Enable role-based authorization
When OIDC authentication is enabled and role-based authorization is disabled, any client with a valid token can access Schema Registry.
To restrict access based on roles, enable
schema_registry_config.sasl_oauthbearer_authorization_enabled.
Enabling role-based authorization also enables OIDC authentication if it is not already enabled.
When you enable authorization, add the roles claim path and HTTP method roles options. If you do not change the values, Karapace uses the defaults.
- Console
- CLI
- In the Aiven Console, select your project and choose your Aiven for Apache Kafka service.
- Click Service settings.
- Click Advanced configuration > Configure.
- Click Add configuration options.
- Add
schema_registry_config.sasl_oauthbearer_authorization_enabled. - Set the option to Enabled.
- Add
schema_registry_config.sasl_oauthbearer_roles_claim_path. - Add
schema_registry_config.sasl_oauthbearer_method_roles. - Click Save configuration.
Run the following command:
avn service update SERVICE_NAME \
-c schema_registry_config.sasl_oauthbearer_authorization_enabled=true
Replace SERVICE_NAME with the name of your Aiven for Apache Kafka service.
To use a different roles claim path, add
schema_registry_config.sasl_oauthbearer_roles_claim_path. For example:
avn service update SERVICE_NAME \
-c schema_registry_config.sasl_oauthbearer_authorization_enabled=true \
-c schema_registry_config.sasl_oauthbearer_roles_claim_path=realm_access.roles
By default:
- Karapace reads roles from
resource_access.karapace.roles. GETrequests are allowed forkarapace.schema:readandkarapace.subject:read.POST,PUT, andDELETErequests are blocked.
How role-based authorization works
Karapace extracts roles from the JWT using the configured claim path and checks them against the roles allowed for the requested HTTP method.
Karapace does not create or assign roles. You create and assign roles in your identity provider.
Role names are strings that you define. For example, you can use names such as
karapace.schema:read. They are not built-in Karapace roles.
In Karapace, you configure which roles can use each HTTP method.
For each request, Karapace does the following:
- Validates the JWT signature, expiration, issuer, and audience.
- Reads the roles from the configured claim path. The default path is
resource_access.karapace.roles. - Looks up the roles allowed for the requested HTTP method in
schema_registry_config.sasl_oauthbearer_method_roles. - Allows the request if at least one role in the JWT matches an allowed role.
Karapace matches exact role strings and does not use a role hierarchy. A role
grants access only when the same string appears in both the JWT and
schema_registry_config.sasl_oauthbearer_method_roles.
If your identity provider includes roles at a different path, such as
realm_access.roles, set
schema_registry_config.sasl_oauthbearer_roles_claim_path to that path.
Default HTTP method roles
If you do not set schema_registry_config.sasl_oauthbearer_method_roles,
Karapace uses this default mapping:
| Action | HTTP method | Default roles |
|---|---|---|
| Read schemas | GET | karapace.schema:read, karapace.subject:read |
| Register or update schemas | POST, PUT | None |
| Delete schemas | DELETE | None |
An empty array ([]) means no role can use that method, even with a valid
token.
A client whose token includes karapace.schema:read can send GET requests.
POST, PUT, and DELETE requests remain blocked until you
customize roles for HTTP methods.
{
"GET": [
"karapace.schema:read",
"karapace.subject:read"
],
"POST": [],
"PUT": [],
"DELETE": []
}
Example JWT
The identity provider issues a token that includes the roles assigned to the user or client. For example:
{
"sub": "alex",
"resource_access": {
"karapace": {
"roles": [
"karapace.schema:read",
"karapace.schema:write"
]
}
}
}
This example omits the issuer, audience, and expiration claims. Karapace validates these claims before it reads roles.
The default claim path, resource_access.karapace.roles, matches this example.
Configure roles in your identity provider
How you configure roles varies by identity provider.
In your identity provider, do the following:
- Create the roles and assign them to users or clients.
- Configure the provider to include those roles in the claim that Karapace reads.
- Confirm that issued tokens include the roles in that claim.
Use the same role strings that you plan to list in
schema_registry_config.sasl_oauthbearer_method_roles.
Customize roles for HTTP methods
Set schema_registry_config.sasl_oauthbearer_method_roles to a JSON string
that maps each HTTP method to the roles that can use it.
Karapace does not infer permissions from role names. To allow a client to use an HTTP method, list the role under that method.
The following mapping uses a common role convention:
| Role | HTTP methods |
|---|---|
karapace.schema:read | GET |
karapace.schema:write | GET, POST, PUT, DELETE |
Each key in the JSON object is an HTTP method. Each value is a list of roles allowed for that method:
{
"GET": [
"karapace.schema:read",
"karapace.schema:write"
],
"POST": [
"karapace.schema:write"
],
"PUT": [
"karapace.schema:write"
],
"DELETE": [
"karapace.schema:write"
]
}
When you set this option, include GET, POST, PUT, and DELETE. To block
a method, set its value to [].
- Console
- CLI
- In the Aiven Console, select your project and choose your Aiven for Apache Kafka service.
- Click Service settings.
- Click Advanced configuration > Configure.
- Click Add configuration options.
- Add
schema_registry_config.sasl_oauthbearer_method_roles. - Enter the JSON object as a single string.
- Click Save configuration.
Run the following command:
avn service update SERVICE_NAME \
-c 'schema_registry_config.sasl_oauthbearer_method_roles={"GET":["karapace.schema:read","karapace.schema:write"],"POST":["karapace.schema:write"],"PUT":["karapace.schema:write"],"DELETE":["karapace.schema:write"]}'
Replace SERVICE_NAME with the name of your Aiven for Apache Kafka service.
Send a request to Schema Registry
Send the JWT in the Authorization header of each Schema Registry request.
You can use curl or any HTTP client that supports bearer tokens.
On the service Overview page, open Connection information and copy the Schema Registry URL.
The following example lists subjects:
curl \
--header "Authorization: Bearer ACCESS_TOKEN" \
"SCHEMA_REGISTRY_URL/subjects"
Replace the following:
ACCESS_TOKEN: A valid JWT from your identity provider.SCHEMA_REGISTRY_URL: The Schema Registry URL from Connection information.
This example sends a GET request.
- If OIDC authentication is enabled and role-based authorization is disabled, any client with a valid token can send the request.
- If role-based authorization is also enabled, the token must include a role
allowed for
GET. With the default mapping, the allowed roles arekarapace.schema:readandkarapace.subject:read.
Before sending POST, PUT, or DELETE requests, configure an allowed role
for the corresponding method. The default mapping blocks these methods.
Disable OIDC authentication and authorization
To disable OIDC authentication and role-based authorization, set both options to Disabled.
Disabling OIDC authentication does not affect basic authentication. Basic authentication remains enabled.
- Console
- CLI
- In the Aiven Console, select your project and choose your Aiven for Apache Kafka service.
- Click Service settings.
- Click Advanced configuration > Configure.
- Set
schema_registry_config.sasl_oauthbearer_authorization_enabledto Disabled. - Set
schema_registry_config.sasl_oauthbearer_authentication_enabledto Disabled. - Click Save configuration.
Run the following command:
avn service update SERVICE_NAME \
-c schema_registry_config.sasl_oauthbearer_authorization_enabled=false \
-c schema_registry_config.sasl_oauthbearer_authentication_enabled=false
Replace SERVICE_NAME with the name of your Aiven for Apache Kafka service.
Related pages