-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-8265: Initial implementation for ConnectorClientConfigPolicy to enable overrides (KIP-458) #6624
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
Merged
KAFKA-8265: Initial implementation for ConnectorClientConfigPolicy to enable overrides (KIP-458) #6624
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bd3caab
Initial implementation for ConnectorClientConfigPOlicy to enable over…
mageshn cbcf395
Fix review comments
mageshn f04cc54
use List<ConfigValue> instead of PolicyViolationException
mageshn 4dbe3fc
Fix rebase issue
mageshn c59db5a
Fix checkstyle issue
mageshn ededad7
Fix review comments, add more unit tests and include integration test
mageshn bff32a6
Fix config doc
mageshn 59f2916
Update connect/api/src/main/java/org/apache/kafka/connect/connector/p…
mageshn 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
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 |
|---|---|---|
|
|
@@ -531,6 +531,10 @@ public static Set<String> configNames() { | |
| return CONFIG.names(); | ||
| } | ||
|
|
||
| public static ConfigDef configDef() { | ||
| return CONFIG; | ||
|
Member
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.
Contributor
Author
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. That's a good point @ijuma. What do you think about returning a copy like |
||
| } | ||
|
|
||
| public static void main(String[] args) { | ||
| System.out.println(CONFIG.toHtmlTable()); | ||
| } | ||
|
|
||
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
47 changes: 47 additions & 0 deletions
47
...n/java/org/apache/kafka/connect/connector/policy/ConnectorClientConfigOverridePolicy.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,47 @@ | ||
| /* | ||
| * 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.Configurable; | ||
| import org.apache.kafka.common.config.ConfigValue; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * <p>An interface for enforcing a policy on overriding of client configs via the connector configs. | ||
| * | ||
| * <p>Common use cases are ability to provide principal per connector, <code>sasl.jaas.config</code> | ||
| * and/or enforcing that the producer/consumer configurations for optimizations are within acceptable ranges. | ||
| */ | ||
| public interface ConnectorClientConfigOverridePolicy extends Configurable, AutoCloseable { | ||
|
|
||
|
|
||
| /** | ||
| * Worker will invoke this while constructing the producer for the SourceConnectors, DLQ for SinkConnectors and the consumer for the | ||
| * SinkConnectors to validate if all of the overridden client configurations are allowed per the | ||
| * policy implementation. This would also be invoked during the validate of connector configs via the Rest API. | ||
| * | ||
| * If there are any policy violations, the connector will not be started. | ||
| * | ||
| * @param connectorClientConfigRequest an instance of {@code ConnectorClientConfigRequest} that provides the configs to overridden and | ||
| * its context; never {@code null} | ||
| * @return list of {@link ConfigValue} instances that describe each client configuration in the request and includes an | ||
| {@link ConfigValue#errorMessages error} if the configuration is not allowed by the policy; never null | ||
| */ | ||
| List<ConfigValue> validate(ConnectorClientConfigRequest connectorClientConfigRequest); | ||
| } |
101 changes: 101 additions & 0 deletions
101
...src/main/java/org/apache/kafka/connect/connector/policy/ConnectorClientConfigRequest.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,101 @@ | ||
| /* | ||
| * 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.connect.connector.Connector; | ||
| import org.apache.kafka.connect.health.ConnectorType; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| public class ConnectorClientConfigRequest { | ||
|
|
||
| private Map<String, Object> clientProps; | ||
| private ClientType clientType; | ||
| private String connectorName; | ||
| private ConnectorType connectorType; | ||
| private Class<? extends Connector> connectorClass; | ||
|
|
||
| public ConnectorClientConfigRequest( | ||
| String connectorName, | ||
| ConnectorType connectorType, | ||
| Class<? extends Connector> connectorClass, | ||
| Map<String, Object> clientProps, | ||
| ClientType clientType) { | ||
| this.clientProps = clientProps; | ||
| this.clientType = clientType; | ||
| this.connectorName = connectorName; | ||
| this.connectorType = connectorType; | ||
| this.connectorClass = connectorClass; | ||
| } | ||
|
|
||
| /** | ||
| * Provides Config with prefix {@code producer.override.} for {@link ConnectorType#SOURCE}. | ||
| * Provides Config with prefix {@code consumer.override.} for {@link ConnectorType#SINK}. | ||
| * Provides Config with prefix {@code producer.override.} for {@link ConnectorType#SINK} for DLQ. | ||
| * Provides Config with prefix {@code admin.override.} for {@link ConnectorType#SINK} for DLQ. | ||
| * | ||
| * @return The client properties specified in the Connector Config with prefix {@code producer.override.} , | ||
| * {@code consumer.override.} and {@code admin.override.}. The configs don't include the prefixes. | ||
| */ | ||
| public Map<String, Object> clientProps() { | ||
| return clientProps; | ||
| } | ||
|
|
||
| /** | ||
| * {@link ClientType#PRODUCER} for {@link ConnectorType#SOURCE} | ||
| * {@link ClientType#CONSUMER} for {@link ConnectorType#SINK} | ||
| * {@link ClientType#PRODUCER} for DLQ in {@link ConnectorType#SINK} | ||
| * {@link ClientType#ADMIN} for DLQ Topic Creation in {@link ConnectorType#SINK} | ||
| * | ||
| * @return enumeration specifying the client type that is being overriden by the worker; never null. | ||
| */ | ||
| public ClientType clientType() { | ||
| return clientType; | ||
| } | ||
|
|
||
| /** | ||
| * Name of the connector specified in the connector config. | ||
| * | ||
| * @return name of the connector; never null. | ||
| */ | ||
| public String connectorName() { | ||
| return connectorName; | ||
| } | ||
|
|
||
| /** | ||
| * Type of the Connector. | ||
| * | ||
| * @return enumeration specifying the type of the connector {@link ConnectorType#SINK} or {@link ConnectorType#SOURCE}. | ||
| */ | ||
| public ConnectorType connectorType() { | ||
| return connectorType; | ||
| } | ||
|
|
||
| /** | ||
| * The class of the Connector. | ||
| * | ||
| * @return the class of the Connector being created; never null | ||
| */ | ||
| public Class<? extends Connector> connectorClass() { | ||
| return connectorClass; | ||
| } | ||
|
|
||
| public enum ClientType { | ||
| PRODUCER, CONSUMER, ADMIN; | ||
| } | ||
| } |
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
57 changes: 57 additions & 0 deletions
57
...rg/apache/kafka/connect/connector/policy/AbstractConnectorClientConfigOverridePolicy.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,57 @@ | ||
| /* | ||
| * 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.ConfigValue; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public abstract class AbstractConnectorClientConfigOverridePolicy implements ConnectorClientConfigOverridePolicy { | ||
|
|
||
| @Override | ||
| public void close() throws Exception { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public final List<ConfigValue> validate(ConnectorClientConfigRequest connectorClientConfigRequest) { | ||
| Map<String, Object> inputConfig = connectorClientConfigRequest.clientProps(); | ||
| return inputConfig.entrySet().stream().map(this::configValue).collect(Collectors.toList()); | ||
| } | ||
|
|
||
| protected ConfigValue configValue(Map.Entry<String, Object> configEntry) { | ||
| ConfigValue configValue = | ||
| new ConfigValue(configEntry.getKey(), configEntry.getValue(), new ArrayList<>(), new ArrayList<String>()); | ||
| validate(configValue); | ||
| return configValue; | ||
| } | ||
|
|
||
| protected void validate(ConfigValue configValue) { | ||
| if (!isAllowed(configValue)) { | ||
| configValue.addErrorMessage("The '" + policyName() + "' policy does not allow '" + configValue.name() | ||
| + "' to be overridden in the connector configuration."); | ||
| } | ||
| } | ||
|
|
||
| protected abstract String policyName(); | ||
|
|
||
| protected abstract boolean isAllowed(ConfigValue configValue); | ||
| } |
46 changes: 46 additions & 0 deletions
46
...ava/org/apache/kafka/connect/connector/policy/AllConnectorClientConfigOverridePolicy.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,46 @@ | ||
| /* | ||
| * 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.ConfigValue; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Allows all client configurations to be overridden via the connector configs by setting {@code client.config.policy} to {@code All} | ||
| */ | ||
| public class AllConnectorClientConfigOverridePolicy extends AbstractConnectorClientConfigOverridePolicy { | ||
| private static final Logger log = LoggerFactory.getLogger(AllConnectorClientConfigOverridePolicy.class); | ||
|
|
||
| @Override | ||
| protected String policyName() { | ||
| return "All"; | ||
| } | ||
|
|
||
| @Override | ||
| protected boolean isAllowed(ConfigValue configValue) { | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public void configure(Map<String, ?> configs) { | ||
| log.info("Setting up All Policy for ConnectorClientConfigOverride. This will allow all client configurations to be overridden"); | ||
| } | ||
| } |
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.