-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(pubsub): support kafka tls and sasl/plain auth #7046
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
Changes from 18 commits
d431550
366ce56
4339cb2
e89d31c
5a513d0
61aefd0
131c130
3071725
f1d9283
e31f186
185fbb4
a1510bf
45d4f33
a68e2e6
6ee9a2b
a0753a8
d0d5566
d56772c
99bced1
6f87da0
9f497b8
30b00a7
643414d
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 |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| -- | ||
| -- 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. | ||
| -- | ||
| local core = require("apisix.core") | ||
|
|
||
|
|
||
| local schema = { | ||
| type = "object", | ||
| properties = { | ||
| sasl = { | ||
| type = "object", | ||
| properties = { | ||
| username = { | ||
| type = "string", | ||
| default = "", | ||
tzssangglass marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }, | ||
| password = { | ||
| type = "string", | ||
| default = "", | ||
|
||
| }, | ||
| }, | ||
| required = {"username", "password"}, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
|
|
||
| local _M = { | ||
| version = 0.1, | ||
| priority = 508, | ||
| name = "kafka-proxy", | ||
| schema = schema, | ||
| } | ||
|
|
||
|
|
||
| function _M.check_schema(conf) | ||
| return core.schema.check(schema, conf) | ||
| end | ||
|
|
||
|
|
||
| function _M.access(conf, ctx) | ||
| if conf.sasl then | ||
| ctx.kafka_consumer_enable_sasl = true | ||
| ctx.kafka_consumer_sasl_username = conf.sasl.username | ||
| ctx.kafka_consumer_sasl_password = conf.sasl.password | ||
| end | ||
| end | ||
|
|
||
|
|
||
| return _M | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -435,7 +435,7 @@ local function check_upstream_conf(in_dp, conf) | |||||||||||||
| end | ||||||||||||||
| end | ||||||||||||||
|
|
||||||||||||||
| if conf.tls then | ||||||||||||||
| if conf.tls and conf.tls.client_cert and conf.tls.client_key then | ||||||||||||||
|
||||||||||||||
| if conf.tls and conf.tls.client_cert and conf.tls.client_key then | |
| if conf.tls and conf.tls.client_cert then |
is enough?
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.
Yes, it's enough, we ensure client_cert and client_key both exist by jsonschema's dependencies. Any one of them separate exist is forbidden.
Lines 416 to 419 in 99bced1
| dependencies = { | |
| client_cert = {"client_key"}, | |
| client_key = {"client_cert"}, | |
| } |
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.
removed
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,9 @@ | |
| before_install() { | ||
| sudo cpanm --notest Test::Nginx >build.log 2>&1 || (cat build.log && exit 1) | ||
|
|
||
| # generating SSL certificates for Kafka | ||
| keytool -genkeypair -keyalg RSA -dname "CN=127.0.0.1" -alias 127.0.0.1 -keystore ./ci/pod/kafka/kafka-server/selfsigned.jks -validity 365 -keysize 2048 -storepass changeit | ||
|
|
||
|
Contributor
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. so, add this to
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. ditto |
||
| # launch deps env | ||
| make ci-env-up | ||
| ./ci/linux-ci-init-service.sh | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,8 @@ | ||
| ALLOW_PLAINTEXT_LISTENER=yes | ||
| KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE=true | ||
| KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://127.0.0.1:9092 | ||
| KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE=false | ||
| KAFKA_CFG_LISTENERS=PLAINTEXT://0.0.0.0:9092,SSL://0.0.0.0:9093,SASL_PLAINTEXT://0.0.0.0:9094 | ||
| KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://127.0.0.1:9092,SSL://127.0.0.1:9093,SASL_PLAINTEXT://127.0.0.1:9094 | ||
| KAFKA_CFG_SSL_ENDPOINT_IDENTIFICATION_ALGORITHM= | ||
| KAFKA_CFG_SSL_KEYSTORE_LOCATION=/opt/bitnami/kafka/config/certs/kafka.keystore.jks | ||
| KAFKA_CFG_SSL_KEYSTORE_PASSWORD=changeit | ||
| KAFKA_CFG_SSL_KEY_PASSWORD=changeit |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| // | ||
| // 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. | ||
| // | ||
|
|
||
| KafkaServer { | ||
| org.apache.kafka.common.security.plain.PlainLoginModule required | ||
| username="admin" | ||
| password="admin-secret" | ||
| user_admin="admin-secret"; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| # | ||
| # 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'; | ||
|
|
||
| repeat_each(1); | ||
| no_long_string(); | ||
| no_root_location(); | ||
|
|
||
| add_block_preprocessor(sub { | ||
| my ($block) = @_; | ||
|
|
||
| if ((!defined $block->error_log) && (!defined $block->no_error_log)) { | ||
| $block->set_value("no_error_log", "[error]"); | ||
| } | ||
|
|
||
| if (!defined $block->request) { | ||
| $block->set_value("request", "GET /t"); | ||
| } | ||
| }); | ||
|
|
||
| run_tests(); | ||
|
|
||
| __DATA__ | ||
|
|
||
| === TEST 1: sanity | ||
| --- config | ||
| location /t { | ||
| content_by_lua_block { | ||
| local test_cases = { | ||
| {}, | ||
| {sasl = {username = "user", password = "pwd"}}, | ||
| {sasl = {username = "user"}}, | ||
| {sasl = {username = "user", password = 1234}}, | ||
| } | ||
| local plugin = require("apisix.plugins.kafka-proxy") | ||
|
|
||
| for _, case in ipairs(test_cases) do | ||
| local ok, err = plugin.check_schema(case) | ||
| ngx.say(ok and "done" or err) | ||
| end | ||
| } | ||
| } | ||
| --- response_body | ||
| done | ||
| done | ||
| property "sasl" validation failed: property "password" is required | ||
| property "sasl" validation failed: property "password" validation failed: wrong type: expected string, got number |
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.
Is it more appropriate to put it in the
linux-ci-init-service.shscript ?Uh oh!
There was an error while loading. Please reload this page.
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.
First make sure that the certificate exists for docker-compose to start kafka. If the certificate does not exist then the kafka container will crash.