Repository navigation
[fix](load) Validate Routine Load Kafka client properties #69391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sollhui
wants to merge
10
commits into
apache:master
Choose a base branch
from
sollhui:fix/routine-load-kafka-properties
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+922
−50
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8da5e9f
[fix](load) Validate Routine Load Kafka client properties
sollhui b00894a
[fix](load) Preserve managed Kerberos login without shell commands
sollhui 498a8a2
[fix](load) Use the default Kerberos cache without modifying librdkafka
sollhui 0b6f54d
[doc](load) Remove standalone Kafka property validation document
sollhui 50fc95a
[fix](load) Limit Kafka property PR to security hardening
sollhui b7ef8bc
[fix](load) Preserve migrated Kafka jobs during recovery
sollhui 28d9ed9
[fix](regression) Use allowed Kafka properties in Routine Load displa…
sollhui 970880e
[test](load) Use managed file references in SSL configuration test
sollhui db80030
[test](load) Complete catalog mocks for Kafka recovery test
sollhui 41c559f
[fix](load) Separate Kafka ALTER replay from runtime preparation
sollhui File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| #include "load/routine_load/kafka_properties.h" | ||
|
|
||
| #include <gen_cpp/BackendService_constants.h> | ||
| #include <librdkafka/rdkafkacpp.h> | ||
|
|
||
| #include "common/status.h" | ||
| #include "util/string_util.h" | ||
|
|
||
| namespace doris { | ||
|
|
||
| Status configure_kafka_security(RdKafka::Conf& conf, | ||
| const std::map<std::string, std::string>& properties) { | ||
| for (const auto& [key, value] : properties) { | ||
| // A new FE also sends zero explicitly to protect rolling upgrades to old BEs. | ||
| // Never allow a user to re-enable the default kinit command with a nonzero interval. | ||
| if (key == "sasl.kerberos.min.time.before.relogin" && value != "0") { | ||
| return Status::InvalidArgument( | ||
| "PAUSE: Kafka property '{}' is not allowed in Routine Load with a nonzero " | ||
| "value; " | ||
| "Kerberos tickets must be managed externally", | ||
| key); | ||
| } | ||
| // Certificate paths supplied by SQL users must be Doris-managed files. | ||
| if (g_BackendService_constants.KAFKA_FILE_PROPERTIES.contains(key)) { | ||
| if (!starts_with(value, "FILE:") || value.size() == 5) { | ||
| return Status::InvalidArgument( | ||
| "PAUSE: Kafka property '{}' must reference a file registered with CREATE " | ||
| "FILE", | ||
| key); | ||
| } | ||
| } else if (!g_BackendService_constants.KAFKA_ALLOWED_PROPERTIES.contains(key) && | ||
| !g_BackendService_constants.KAFKA_DORIS_PROPERTIES.contains(key)) { | ||
| // For example, plugin.library.paths can load code during Conf::set(), | ||
| // before a consumer is even created. Unknown properties fail closed. | ||
| return Status::InvalidArgument( | ||
| "PAUSE: Kafka property '{}' is not allowed in Routine Load", key); | ||
| } | ||
| } | ||
|
|
||
| // Rejecting kinit.cmd alone is insufficient: the default command interpolates | ||
| // the principal/keytab. Setting the interval to zero disables both the initial | ||
| // command and the refresh timer. Operators must maintain the ticket cache. | ||
| // This is mandatory, so do not use init's best-effort set_conf wrapper here. | ||
| std::string error; | ||
| if (conf.set("sasl.kerberos.min.time.before.relogin", "0", error) != RdKafka::Conf::CONF_OK) { | ||
| return Status::InternalError( | ||
| "PAUSE: failed to disable Kafka Kerberos command execution: {}", error); | ||
| } | ||
| return Status::OK(); | ||
| } | ||
|
|
||
| } // namespace doris |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <map> | ||
| #include <string> | ||
|
|
||
| namespace RdKafka { | ||
| class Conf; | ||
| } | ||
|
|
||
| namespace doris { | ||
| class Status; | ||
|
|
||
| // Validate the entire map before applying any user properties, then disable | ||
| // librdkafka's shell-based Kerberos ticket acquisition and renewal. | ||
| Status configure_kafka_security(RdKafka::Conf& conf, | ||
| const std::map<std::string, std::string>& properties); | ||
| } // namespace doris |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| #include "load/routine_load/kafka_properties.h" | ||
|
|
||
| #include <gen_cpp/BackendService_constants.h> | ||
| #include <gtest/gtest.h> | ||
| #include <librdkafka/rdkafkacpp.h> | ||
|
|
||
| #include <memory> | ||
|
|
||
| #include "common/status.h" | ||
| #include "load/routine_load/data_consumer.h" | ||
|
|
||
| namespace doris { | ||
|
|
||
| TEST(KafkaPropertiesTest, RejectExecutableAndUnknownProperties) { | ||
| std::unique_ptr<RdKafka::Conf> conf(RdKafka::Conf::create(RdKafka::Conf::CONF_GLOBAL)); | ||
| for (const auto* key : | ||
| {"sasl.kerberos.kinit.cmd", "sasl.kerberos.keytab", | ||
| "sasl.kerberos.min.time.before.relogin", "plugin.library.paths", "ssl.engine.location", | ||
| "ssl.engine.id", "ssl.providers", "unknown.future.property", "sasl.jaas.config"}) { | ||
| auto status = configure_kafka_security(*conf, {{key, "sensitive-value"}}); | ||
| EXPECT_FALSE(status.ok()) << key; | ||
| EXPECT_NE(status.to_string().find("is not allowed in Routine Load"), std::string::npos); | ||
| EXPECT_EQ(status.to_string().find("sensitive-value"), std::string::npos); | ||
| } | ||
| } | ||
|
|
||
| TEST(KafkaPropertiesTest, RejectKerberosRefreshReenable) { | ||
| std::unique_ptr<RdKafka::Conf> conf(RdKafka::Conf::create(RdKafka::Conf::CONF_GLOBAL)); | ||
| for (const auto* value : {"1", "60000", "00", "FILE:123:checksum"}) { | ||
| EXPECT_FALSE( | ||
| configure_kafka_security(*conf, {{"sasl.kerberos.min.time.before.relogin", value}}) | ||
| .ok()); | ||
| } | ||
| } | ||
|
|
||
| TEST(KafkaPropertiesTest, RequireManagedCertificateFiles) { | ||
| std::unique_ptr<RdKafka::Conf> conf(RdKafka::Conf::create(RdKafka::Conf::CONF_GLOBAL)); | ||
| for (const auto& key : g_BackendService_constants.KAFKA_FILE_PROPERTIES) { | ||
| for (const auto* value : {"/etc/ssl/private/key.pem", "relative.pem", "", "FILE:"}) { | ||
| EXPECT_FALSE(configure_kafka_security(*conf, {{key, value}}).ok()) << key; | ||
| } | ||
| EXPECT_TRUE(configure_kafka_security(*conf, {{key, "FILE:123:checksum"}}).ok()) << key; | ||
| } | ||
| } | ||
|
|
||
| TEST(KafkaPropertiesTest, DisableDefaultKerberosCommand) { | ||
| std::unique_ptr<RdKafka::Conf> conf(RdKafka::Conf::create(RdKafka::Conf::CONF_GLOBAL)); | ||
| ASSERT_TRUE(configure_kafka_security(*conf, {}).ok()); | ||
| std::string value; | ||
| ASSERT_EQ(RdKafka::Conf::CONF_OK, conf->get("sasl.kerberos.min.time.before.relogin", value)); | ||
| EXPECT_EQ("0", value); | ||
| // Principal values can contain shell metacharacters. They remain data because | ||
| // neither the initial kinit command nor its renewal timer can run. | ||
| ASSERT_TRUE(configure_kafka_security(*conf, {{"sasl.kerberos.principal", "user;unused"}, | ||
| {"security.protocol", "SASL_PLAINTEXT"}, | ||
| {"sasl.mechanisms", "GSSAPI"}}) | ||
| .ok()); | ||
| ASSERT_EQ(RdKafka::Conf::CONF_OK, conf->get("sasl.kerberos.min.time.before.relogin", value)); | ||
| EXPECT_EQ("0", value); | ||
| } | ||
|
|
||
| TEST(KafkaPropertiesTest, AcceptConsumerAndAwsProperties) { | ||
| std::unique_ptr<RdKafka::Conf> conf(RdKafka::Conf::create(RdKafka::Conf::CONF_GLOBAL)); | ||
| EXPECT_TRUE(configure_kafka_security(*conf, {{"group.id", "test-group"}, | ||
| {"sasl.kerberos.min.time.before.relogin", "0"}, | ||
| {"isolation.level", "read_committed"}, | ||
| {"fetch.max.bytes", "1048576"}, | ||
| {"security.protocol", "SASL_SSL"}, | ||
| {"sasl.mechanism", "OAUTHBEARER"}, | ||
| {"aws.region", "us-east-1"}}) | ||
| .ok()); | ||
| } | ||
|
|
||
| TEST(KafkaPropertiesTest, ConsumerRejectsBeforeResolvingFilesOrCreatingClient) { | ||
| auto ctx = std::make_shared<StreamLoadContext>(nullptr); | ||
| TKafkaLoadInfo info; | ||
| info.__set_properties( | ||
| {{"https.ca.location", "FILE:123:checksum"}, {"plugin.library.paths", "unused.so"}}); | ||
| ctx->kafka_info = std::make_unique<KafkaLoadInfo>(info); | ||
| KafkaDataConsumer consumer(ctx); | ||
| // No ExecEnv or Kafka broker: rejection must precede FILE resolution and | ||
| // client creation even when an allowed property is present in the same map. | ||
| auto status = consumer.init(ctx); | ||
| EXPECT_FALSE(status.ok()); | ||
| EXPECT_NE(status.to_string().find("plugin.library.paths"), std::string::npos); | ||
| } | ||
|
|
||
| } // namespace doris |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.