-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat(kafka-logger): add TLS support for Kafka brokers #13607
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
AlinsRan
merged 13 commits into
apache:master
from
ecsimsw:feat/kafka-logger-tls-support
Jul 16, 2026
Merged
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
63d67f7
feat(kafka-logger): add TLS support for Kafka brokers
ecsimsw e6188df
feat(error-log-logger): add TLS support for Kafka brokers
ecsimsw f65e419
test(kafka-logger): add TLS schema and integration tests
ecsimsw bcaa0f6
test(error-log-logger): add TLS schema and integration tests for Kafka
ecsimsw a1d30c3
docs: add TLS attributes and examples for kafka-logger and error-log-…
ecsimsw c8eca19
test(kafka-logger): remove TLS integration tests that require SSL Kaf…
ecsimsw 4136aa2
style(error-log-logger): fix trailing blank lines in test file
ecsimsw 3d1c591
feat(kafka-logger): warn when TLS certificate verification is disabled
ecsimsw 5fbd9d7
feat(error-log-logger): warn when TLS certificate verification is dis…
ecsimsw 34369cf
test(kafka-logger): move TLS schema tests into kafka-logger2.t
ecsimsw a6649ac
test(kafka-logger): add SSL Kafka listener to plugin CI environment
ecsimsw ff6a2da
test(kafka-logger): add TLS integration and security-warning tests
ecsimsw 83c7a92
fix(error-log-logger): run check_tls_bool after schema check
ecsimsw 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
Some comments aren't visible on the classic Files Changed page.
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
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,127 @@ | ||
| # | ||
| # 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. | ||
| # | ||
| use t::APISIX 'no_plan'; | ||
|
AlinsRan marked this conversation as resolved.
Outdated
|
||
|
|
||
| repeat_each(1); | ||
| no_long_string(); | ||
| no_root_location(); | ||
|
|
||
| add_block_preprocessor(sub { | ||
| my ($block) = @_; | ||
|
|
||
| if (!$block->request) { | ||
| $block->set_value("request", "GET /t"); | ||
| } | ||
| }); | ||
|
|
||
| add_block_preprocessor(sub { | ||
| my ($block) = @_; | ||
|
|
||
| my $extra_init_by_lua = <<_EOC_; | ||
| local bp_manager = require("apisix.utils.batch-processor-manager") | ||
| local core = require("apisix.core") | ||
| local function log_send_data(entry) | ||
| local data = type(entry) == "table" and core.json.encode(entry) or entry | ||
| core.log.info("send data to kafka: ", data) | ||
| end | ||
| local old_add = bp_manager.add_entry | ||
| bp_manager.add_entry = function(self, conf, entry, max_pending_entries) | ||
| local ok = old_add(self, conf, entry, max_pending_entries) | ||
| if ok then | ||
| log_send_data(entry) | ||
| end | ||
| return ok | ||
| end | ||
| local old_new = bp_manager.add_entry_to_new_processor | ||
| bp_manager.add_entry_to_new_processor = function(self, conf, entry, ctx, func, max_pending_entries) | ||
| local ok = old_new(self, conf, entry, ctx, func, max_pending_entries) | ||
| if ok then | ||
| log_send_data(entry) | ||
| end | ||
| return ok | ||
| end | ||
| _EOC_ | ||
|
|
||
| if (!defined $block->extra_init_by_lua) { | ||
| $block->set_value("extra_init_by_lua", $extra_init_by_lua); | ||
| } | ||
| }); | ||
|
AlinsRan marked this conversation as resolved.
Outdated
|
||
|
|
||
| run_tests; | ||
|
|
||
| __DATA__ | ||
|
|
||
| === TEST 1: tls schema validation - valid tls config | ||
| --- config | ||
| location /t { | ||
| content_by_lua_block { | ||
| local plugin = require("apisix.plugins.kafka-logger") | ||
| local ok, err = plugin.check_schema({ | ||
| brokers = {{host = "127.0.0.1", port = 9093}}, | ||
| kafka_topic = "test", | ||
| tls = { verify = false } | ||
| }) | ||
| if not ok then | ||
| ngx.say(err) | ||
| end | ||
| ngx.say("done") | ||
| } | ||
| } | ||
| --- response_body | ||
| done | ||
|
|
||
|
|
||
|
|
||
| === TEST 2: tls schema validation - without tls (backward compatibility) | ||
| --- config | ||
| location /t { | ||
| content_by_lua_block { | ||
| local plugin = require("apisix.plugins.kafka-logger") | ||
| local ok, err = plugin.check_schema({ | ||
| brokers = {{host = "127.0.0.1", port = 9092}}, | ||
| kafka_topic = "test" | ||
| }) | ||
| if not ok then | ||
| ngx.say(err) | ||
| end | ||
| ngx.say("done") | ||
| } | ||
| } | ||
| --- response_body | ||
| done | ||
|
|
||
|
|
||
|
|
||
| === TEST 3: tls schema validation - wrong type for verify | ||
| --- config | ||
| location /t { | ||
| content_by_lua_block { | ||
| local plugin = require("apisix.plugins.kafka-logger") | ||
| local ok, err = plugin.check_schema({ | ||
| brokers = {{host = "127.0.0.1", port = 9093}}, | ||
| kafka_topic = "test", | ||
| tls = { verify = "abc" } | ||
| }) | ||
| if not ok then | ||
| ngx.say(err) | ||
| end | ||
| ngx.say("done") | ||
| } | ||
| } | ||
| --- response_body | ||
| property "tls" validation failed: property "verify" validation failed: wrong type: expected boolean, got string | ||
| done | ||
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.