The schema mode defines whether a schema registry or a specific subject allows changes, such as writing or editing schemas.
The supported values for schema mode are Readonly and Readwrite. If not explicitly set at the schema registry level, the schema mode defaults to Readwrite. For more information about schema mode including its values, see Schema mode.
Schema mode is managed as a JSON object containing key-value pairs. For example, the following is a sample:
{
"mode": "READWRITE"
}
Configurations set at the subject level override those set at the schema registry level. If a schema mode is not explicitly specified at the subject level, it inherits the value from the schema registry.
Required roles and permissions to update schema mode
To get the permissions that
you need to update schema mode for a schema registry or subject,
ask your administrator to grant you the
Managed Kafka Schema Registry Editor (roles/managedkafka.schemaRegistryEditor
)
IAM role on your project.
For more information about granting roles, see Manage access to projects, folders, and organizations.
This predefined role contains the permissions required to update schema mode for a schema registry or subject. To see the exact permissions that are required, expand the Required permissions section:
Required permissions
The following permissions are required to update schema mode for a schema registry or subject:
-
Grant the following permission on the resource for which you want to update the mode:
managedkafka.mode.update
You might also be able to get these permissions with custom roles or other predefined roles.
Higher-level roles like Managed Kafka Schema Registry Admin
(roles/managedkafka.schemaRegistryAdmin
) also include these permissions.
For more information about the predefined roles available for Managed Service for Apache Kafka, see the Access control documentation.
Update schema mode for a subject
Console
To update the schema mode for the entire schema registry, follow these steps:
- In the Google Cloud console, go to the Schema registries page.
A list of schema registries in your project is displayed.
- Click the name of the schema registry for which you want to update the schema mode.
The Schema registry details page opens.
- In the main details section for the registry, find the
Schema mode setting and click the Edit icon next to it.
The Edit schema mode page opens.
- From the schema mode dropdown menu, select the value.
For more information about these values, see About schema mode.
- Click Save.
To update the schema mode for a specific subject, follow these steps:
- In the Google Cloud console, go to the Schema registries page.
- Click the name of the schema registry that contains the subject.
The Schema registry details page opens.
- In the Subjects in this schema registry table, click the name of the subject for which you want to update the schema mode.
- Find the Schema mode setting for the subject and
click the Edit icon next to it.
The Edit schema mode page opens.
- From the Schema mode dropdown menu, select the value.
Choosing a value here overrides the registry-level setting for this
specific subject.
For more information about these values, see About schema mode.
- Click Save.
REST
The request must be authenticated with an access token in the
Authorization
header. To obtain an access token for the current
Application Default Credentials:
gcloud auth application-default print-access-token
.
To update the schema mode, make a PUT
request to the
REST API endpoint for the schema registry or a
specific subject using the
projects.locations.schemaRegistries.contexts.mode.update
method.
Updating schema mode for the schema registry (default config):
PUT https://managedkafka.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/schemaRegistries/SCHEMA_REGISTRY_ID/mode
Updating schema mode for a subject in the default context:
PUT https://managedkafka.googleapis.com/v1main/projects/PROJECT_ID/locations/LOCATION/schemaRegistries/SCHEMA_REGISTRY_ID/mode/SUBJECT
Updating schema mode for a specific subject in a context:
PUT https://managedkafka.googleapis.com/v1main/projects/PROJECT_ID/locations/LOCATION/schemaRegistries/SCHEMA_REGISTRY_ID/contexts/CONTEXT_ID/mode/SUBJECT
Replace the following path parameters:
PROJECT_ID
: your Google Cloud project ID.LOCATION
: the region where the schema registry exists.SCHEMA_REGISTRY_ID
: the unique ID of the schema registry.CONTEXT_ID
: the ID of the context containing the subject. Omit/contexts/CONTEXT_ID
for the default context.SUBJECT
: the ID of the subject for which to change the mode.
Request body:
Include a JSON object in the request body specifying the mode details.
{ "mode": "MODE_TYPE" }
Replace MODE_TYPE
with one of the valid string options for the mode:
READWRITE
READONLY
Example—set subject user_events
schema mode to
Readonly
in the default context:
Request to PUT https://managedkafka.googleapis.com/v1main/projects/my-gcp-project/locations/us-east1/schemaRegistries/main-registry/mode/user_events
With body:
{ "mode": "READONLY" }
If successful, the API returns a 200 OK
status code and a
response body containing the JSON representation of the updated mode
configuration or the subject or context resource reflecting this change.
For more information, see the REST API documentation.