-
Notifications
You must be signed in to change notification settings - Fork 14.8k
KAFKA-19824: New AllowlistConnectorClientConfigOverridePolicy (KIP-1188) #20750
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
Merged
+244
−5
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
64 changes: 64 additions & 0 deletions
64
...g/apache/kafka/connect/connector/policy/AllowlistConnectorClientConfigOverridePolicy.java
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,64 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
| package org.apache.kafka.connect.connector.policy; | ||
|
|
||
| import org.apache.kafka.common.config.AbstractConfig; | ||
| import org.apache.kafka.common.config.ConfigDef; | ||
| import org.apache.kafka.common.config.ConfigValue; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Allows only client configurations specified via <code>connector.client.config.override.allowlist</code> to be | ||
| * overridden by connectors. By default, <code>connector.client.config.override.allowlist</code> is empty so connectors | ||
| * can't override any client configurations. | ||
| */ | ||
| public class AllowlistConnectorClientConfigOverridePolicy extends AbstractConnectorClientConfigOverridePolicy { | ||
|
|
||
| public static final String ALLOWLIST_CONFIG = "connector.client.config.override.allowlist"; | ||
|
|
||
| private static final Logger LOGGER = LoggerFactory.getLogger(AllowlistConnectorClientConfigOverridePolicy.class); | ||
| private static final List<String> ALLOWLIST_CONFIG_DEFAULT = List.of(); | ||
| private static final String ALLOWLIST_CONFIG_DOC = "List of client configurations that can be overridden by " + | ||
| "connectors. If empty, connectors can't override any client configurations."; | ||
| private static final ConfigDef CONFIG_DEF = new ConfigDef() | ||
| .define(ALLOWLIST_CONFIG, ConfigDef.Type.LIST, ALLOWLIST_CONFIG_DEFAULT, ConfigDef.Importance.MEDIUM, ALLOWLIST_CONFIG_DOC); | ||
|
|
||
| private List<String> allowlist = ALLOWLIST_CONFIG_DEFAULT; | ||
|
|
||
| @Override | ||
| protected String policyName() { | ||
| return "Allowlist"; | ||
| } | ||
|
|
||
| @Override | ||
| protected boolean isAllowed(ConfigValue configValue) { | ||
| return allowlist.contains(configValue.name()); | ||
| } | ||
|
|
||
| @Override | ||
| public void configure(Map<String, ?> configs) { | ||
| AbstractConfig config = new AbstractConfig(CONFIG_DEF, configs); | ||
| allowlist = config.getList(ALLOWLIST_CONFIG); | ||
| LOGGER.info("Setting up Allowlist policy for ConnectorClientConfigOverride. This will allow the following client configurations" | ||
| + " to be overridden. {}", allowlist); | ||
| } | ||
| } |
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 |
|---|---|---|
|
|
@@ -32,7 +32,9 @@ | |
| /** | ||
| * Allows all {@code sasl} configurations to be overridden via the connector configs by setting {@code connector.client.config.override.policy} to | ||
| * {@code Principal}. This allows to set a principal per connector. | ||
| * @deprecated Use {@link AllowlistConnectorClientConfigOverridePolicy} instead. | ||
| */ | ||
| @Deprecated(since = " 4.2", forRemoval = true) | ||
| public class PrincipalConnectorClientConfigOverridePolicy extends AbstractConnectorClientConfigOverridePolicy { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mimaison Do you have time to open a minor PR to fix the warning? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good spot! I opened #20793 |
||
| private static final Logger log = LoggerFactory.getLogger(PrincipalConnectorClientConfigOverridePolicy.class); | ||
|
|
||
|
|
@@ -52,6 +54,9 @@ protected boolean isAllowed(ConfigValue configValue) { | |
|
|
||
| @Override | ||
| public void configure(Map<String, ?> configs) { | ||
| log.warn("The Principal ConnectorClientConfigOverridePolicy is deprecated, use the Allowlist policy instead. " | ||
| + "To replicate the Principal policy behavior, set the connector.client.config.override.allowlist configuration to \"{}\"", | ||
| String.join(",", ALLOWED_CONFIG)); | ||
| log.info("Setting up Principal policy for ConnectorClientConfigOverride. This will allow `sasl` client configuration to be " | ||
| + "overridden."); | ||
| } | ||
|
|
||
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
76 changes: 76 additions & 0 deletions
76
...ache/kafka/connect/connector/policy/AllowlistConnectorClientConfigOverridePolicyTest.java
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,76 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
| package org.apache.kafka.connect.connector.policy; | ||
|
|
||
| import org.apache.kafka.clients.admin.AdminClientConfig; | ||
| import org.apache.kafka.clients.consumer.ConsumerConfig; | ||
| import org.apache.kafka.clients.producer.ProducerConfig; | ||
|
|
||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.stream.Stream; | ||
|
|
||
| public class AllowlistConnectorClientConfigOverridePolicyTest extends BaseConnectorClientConfigOverridePolicyTest { | ||
|
|
||
| private static final List<String> ALL_CONFIGS = Stream.of( | ||
| ProducerConfig.configNames(), | ||
| ConsumerConfig.configNames(), | ||
| AdminClientConfig.configNames()) | ||
| .flatMap(Collection::stream) | ||
| .toList(); | ||
|
|
||
| private AllowlistConnectorClientConfigOverridePolicy policy; | ||
|
|
||
| @BeforeEach | ||
| public void setUp() { | ||
| policy = new AllowlistConnectorClientConfigOverridePolicy(); | ||
| } | ||
|
|
||
| @Override | ||
| protected ConnectorClientConfigOverridePolicy policyToTest() { | ||
| return policy; | ||
| } | ||
|
|
||
| @Test | ||
| public void testDenyAllByDefault() { | ||
| for (String config : ALL_CONFIGS) { | ||
| testInvalidOverride(Map.of(config, new Object())); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testAllowConfigs() { | ||
| Set<String> allowedConfigs = Set.of( | ||
| ProducerConfig.ACKS_CONFIG, | ||
| ConsumerConfig.CLIENT_ID_CONFIG, | ||
| AdminClientConfig.CONNECTIONS_MAX_IDLE_MS_CONFIG | ||
| ); | ||
| policy.configure(Map.of(AllowlistConnectorClientConfigOverridePolicy.ALLOWLIST_CONFIG, String.join(",", allowedConfigs))); | ||
| for (String config : ALL_CONFIGS) { | ||
| if (!allowedConfigs.contains(config)) { | ||
| testInvalidOverride(Map.of(config, new Object())); | ||
| } else { | ||
| testValidOverride(Map.of(config, new Object())); | ||
| } | ||
| } | ||
| } | ||
| } |
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
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
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.