-
Notifications
You must be signed in to change notification settings - Fork 992
Extend query config with query.masked config with Type.PASSWORD for secure query masking #1593
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
base: 10.9.x
Are you sure you want to change the base?
Changes from 5 commits
5198b37
bb93366
330e9fe
b8d712a
3a22709
9330777
48350ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ | |
| import io.confluent.connect.jdbc.source.JdbcSourceConnectorConfig.TransactionIsolationMode; | ||
| import org.apache.kafka.common.config.Config; | ||
| import org.apache.kafka.common.config.ConfigValue; | ||
| import org.apache.kafka.common.config.types.Password; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
|
|
@@ -80,7 +81,8 @@ public Config validate() { | |
| } | ||
|
|
||
| boolean validationResult = validateMultiConfigs() | ||
| && validateLegacyNewConfigCompatibility(); | ||
| && validateLegacyNewConfigCompatibility() | ||
| && validateQueryConfigs(); | ||
|
|
||
| if (validationResult && isUsingNewConfigs()) { | ||
| validationResult = validateTableInclusionConfigs() | ||
|
|
@@ -150,6 +152,16 @@ private boolean validateMultiConfigs() { | |
| return true; | ||
| } | ||
|
|
||
| private boolean hasAnyQueryConfig() { | ||
| String query = config.getString(JdbcSourceConnectorConfig.QUERY_CONFIG); | ||
| Password queryMasked = | ||
| config.getPassword(JdbcSourceConnectorConfig.QUERY_MASKED_CONFIG); | ||
|
||
| boolean hasQuery = query != null && !query.trim().isEmpty(); | ||
| boolean hasQueryMasked = | ||
| queryMasked != null && queryMasked.value() != null && !queryMasked.value().trim().isEmpty(); | ||
| return hasQuery || hasQueryMasked; | ||
| } | ||
|
|
||
| /** | ||
| * Validate legacy/new config compatibility and requirements. | ||
| * Implements the pattern: legacyKeys vs newKeys with early returns. | ||
|
|
@@ -158,6 +170,11 @@ private boolean validateLegacyNewConfigCompatibility() { | |
| // Define legacy and new config keys | ||
| boolean usingLegacyConfigs = isUsingLegacyConfigs(); | ||
| boolean usingNewConfigs = isUsingNewConfigs(); | ||
| boolean hasQuery = hasAnyQueryConfig(); | ||
|
|
||
| if (hasQuery) { | ||
| return true; | ||
| } | ||
|
|
||
| if (usingLegacyConfigs && usingNewConfigs) { | ||
| return addConfigErrorsForLegacyAndNewConfigConflict(); | ||
|
|
@@ -273,6 +290,9 @@ private boolean addConfigErrorsForLegacyAndNewConfigConflict() { | |
| * Validate that at least one configuration is provided. | ||
| */ | ||
| private boolean addConfigErrorsForNoConfigProvided() { | ||
| if (hasAnyQueryConfig()) { | ||
| return true; | ||
| } | ||
| String msg = "At least one table filtering configuration is required. " | ||
| + "Provide one of: " + JdbcSourceConnectorConfig.TABLE_WHITELIST_CONFIG + ", " | ||
| + JdbcSourceConnectorConfig.TABLE_BLACKLIST_CONFIG + ", " | ||
|
|
@@ -305,6 +325,48 @@ private boolean validateTableInclusionConfigs() { | |
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Validate that only one of query or query.masked configs is set at a time. | ||
| * Both configs should not be set simultaneously to avoid ambiguity. | ||
| */ | ||
| private boolean validateQueryConfigs() { | ||
| String query = config.getString(JdbcSourceConnectorConfig.QUERY_CONFIG); | ||
| Password queryMasked = | ||
| config.getPassword(JdbcSourceConnectorConfig.QUERY_MASKED_CONFIG); | ||
|
|
||
| boolean hasQuery = query != null && !query.isEmpty(); | ||
| boolean hasQueryMasked = queryMasked != null | ||
| && queryMasked.value() != null | ||
| && !queryMasked.value().isEmpty(); | ||
|
|
||
| if (hasQuery && hasQueryMasked) { | ||
| String msg = "Both 'query' and 'query.masked' configs cannot be set at the same time. " | ||
| + "Please use only one of them."; | ||
|
|
||
| addConfigError(JdbcSourceConnectorConfig.QUERY_CONFIG, msg); | ||
| addConfigError(JdbcSourceConnectorConfig.QUERY_MASKED_CONFIG, msg); | ||
|
|
||
| log.error("Validation failed: Both query and query.masked configs are set"); | ||
| return false; | ||
| } | ||
|
|
||
| if ((hasQuery || hasQueryMasked) && (isUsingLegacyConfigs() || isUsingNewConfigs())) { | ||
| String msg = | ||
| "Do not specify table filtering configs with 'query' or 'query.masked'. " | ||
| + "Remove table.whitelist / table.blacklist / table.include.list / " | ||
| + "table.exclude.list."; | ||
|
||
| addConfigError(JdbcSourceConnectorConfig.QUERY_CONFIG, msg); | ||
| addConfigError(JdbcSourceConnectorConfig.QUERY_MASKED_CONFIG, msg); | ||
| addConfigError(JdbcSourceConnectorConfig.TABLE_WHITELIST_CONFIG, msg); | ||
| addConfigError(JdbcSourceConnectorConfig.TABLE_BLACKLIST_CONFIG, msg); | ||
| addConfigError(JdbcSourceConnectorConfig.TABLE_INCLUDE_LIST_CONFIG, msg); | ||
| addConfigError(JdbcSourceConnectorConfig.TABLE_EXCLUDE_LIST_CONFIG, msg); | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
|
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. Added a validation in order to limit using of either of query or query.masked config. |
||
| /** | ||
| * Validate plugin-specific needs. This method can be overridden by specific | ||
| * connector implementations to add their own validation logic. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extend this Options method, because of falling to checkstyle error of exceeding 128 lines in a method.