Skip to content

Commit

Permalink
schema_registry: Reject records if schema id validation without registry
Browse files Browse the repository at this point in the history
If the schema registry is disabled, but schema id validation is enabled,
reject records and log an error.

Fixes redpanda-data#11116

Signed-off-by: Ben Pope <ben@redpanda.com>
  • Loading branch information
BenPope committed Jun 14, 2023
1 parent e0bc73e commit 0891042
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/v/pandaproxy/schema_registry/validation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -457,9 +457,16 @@ std::optional<schema_id_validator> maybe_make_schema_id_validator(
const model::topic& topic,
const cluster::topic_properties& props) {
auto mode = config::shard_local_cfg().enable_schema_id_validation();
return api != nullptr && should_validate_schema_id(props, mode)
? std::make_optional<schema_id_validator>(api, topic, props, mode)
: std::nullopt;
if (should_validate_schema_id(props, mode)) {
if (!api) {
vlog(
plog.error,
"{} requires schema_registry to be enabled in redpanda.yaml",
config::shard_local_cfg().enable_schema_id_validation.name());
}
return std::make_optional<schema_id_validator>(api, topic, props, mode);
}
return std::nullopt;
}

ss::future<schema_id_validator::result>
Expand Down
40 changes: 40 additions & 0 deletions tests/rptest/tests/schema_registry_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import json
from typing import Optional
import uuid
import re
import requests
import time
import random
Expand Down Expand Up @@ -2176,6 +2177,45 @@ def test_enable_schema_id_validation(self, mode):
pass


class SchemaValidationWithoutSchemaRegistry(RedpandaTest):
INVALID_CONFIG_LOG_ALLOW_LIST = DEFAULT_LOG_ALLOW_LIST + [
re.compile(
r"enable_schema_id_validation requires schema_registry to be enabled in redpanda.yaml"
),
]

def __init__(self, *args, **kwargs):
super(SchemaValidationWithoutSchemaRegistry,
self).__init__(*args,
extra_rp_conf={
'enable_schema_id_validation':
SchemaIdValidationMode.REDPANDA.value
},
schema_registry_config=None,
**kwargs)

@cluster(num_nodes=1, log_allow_list=INVALID_CONFIG_LOG_ALLOW_LIST)
def test_disabled_schema_registry(self):
rpk = RpkTool(self.redpanda)
topic = "no_schema_registry"
rpk.create_topic(
topic,
config={
TopicSpec.PROPERTY_RECORD_KEY_SCHEMA_ID_VALIDATION: 'true',
})
try:
rpk.produce(topic, "key", "value")
assert False, "expected INVALID_RECORD"
except RpkException as e:
print(e)
assert "INVALID_RECORD" in e.stderr

wait_until(lambda: self.redpanda.search_log_all(
"enable_schema_id_validation requires schema_registry to be enabled in redpanda.yaml"
),
timeout_sec=5)


class SchemaValidationTopicPropertiesTest(RedpandaTest):
def __init__(self, *args, **kwargs):
super(SchemaValidationTopicPropertiesTest,
Expand Down

0 comments on commit 0891042

Please sign in to comment.