-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
d431550
chore: merge kafka support
bzp2010 366ce56
feat: add tls verify
bzp2010 4339cb2
feat: kafka support tls
bzp2010 e89d31c
feat: support sasl/plain auth
bzp2010 5a513d0
test: add kafka-proxy cases
bzp2010 61aefd0
test: kafka env support tls and sasl
bzp2010 131c130
test: add tls and sasl cases
bzp2010 3071725
docs: add tls and sasl
bzp2010 f1d9283
feat: ensure client cert and key exist sametime
bzp2010 e31f186
debug: kafka docker compose
bzp2010 185fbb4
fix: ensure ssl generated for kafka
bzp2010 a1510bf
debug: remove log
bzp2010 45d4f33
chore: check int64 convert bound
bzp2010 a68e2e6
chore: ensure pubsub proto use absolute link
bzp2010 6ee9a2b
fix: replace all Pub-Sub to PubSub
bzp2010 a0753a8
docs: fix style
bzp2010 d0d5566
Merge master
bzp2010 d56772c
test: add upstream tls cases
bzp2010 99bced1
docs: add kafka-proxy documentation
bzp2010 6f87da0
fix: review
bzp2010 9f497b8
fix: remove kafka proxy sasl default value
bzp2010 30b00a7
fix: add kafka proxy to category
bzp2010 643414d
fix: typo
bzp2010 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
| 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. | ||
| -- | ||
| local core = require("apisix.core") | ||
|
|
||
|
|
||
| local schema = { | ||
| type = "object", | ||
| properties = { | ||
| sasl = { | ||
| type = "object", | ||
| properties = { | ||
| username = { | ||
| type = "string", | ||
| }, | ||
| password = { | ||
| type = "string", | ||
| }, | ||
| }, | ||
| 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 |
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 |
|---|---|---|
|
|
@@ -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 | ||
|
|
||
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 |
|---|---|---|
| @@ -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 |
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,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"; | ||
| }; |
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,80 @@ | ||
| --- | ||
| title: kafka-proxy | ||
| keywords: | ||
| - APISIX | ||
| - Plugin | ||
| - Kafka proxy | ||
| description: This document contains information about the Apache APISIX kafka-proxy Plugin. | ||
| --- | ||
|
|
||
| <!-- | ||
| # | ||
| # 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. | ||
| # | ||
| --> | ||
|
|
||
| ## Description | ||
|
|
||
| The `kafka-proxy` plugin can be used to configure advanced parameters for the kafka upstream of Apache APISIX, such as SASL authentication. | ||
|
|
||
| ## Attributes | ||
|
|
||
| | Name | Type | Required | Default | Valid values | Description | | ||
| |-------------------|---------|----------|---------|---------------|------------------------------------| | ||
| | sasl | object | optional | | {"username": "user", "password" :"pwd"} | SASL/PLAIN authentication configuration, when this configuration exists, turn on SASL authentication; this object will contain two parameters username and password, they must be configured. | | ||
| | sasl.username | string | required | | | SASL/PLAIN authentication username | | ||
| | sasl.password | string | required | | | SASL/PLAIN authentication password | | ||
|
|
||
| :::note | ||
| If SASL authentication is enabled, the `sasl.username` and `sasl.password` must be set. | ||
| The current SASL authentication only supports PLAIN mode, which is the username password login method. | ||
| ::: | ||
|
|
||
| ## Example usage | ||
|
|
||
| When we use scheme as the upstream of kafka, we can add kafka authentication configuration to it through this plugin. | ||
|
|
||
| ```shell | ||
| curl -X PUT 'http://127.0.0.1:9080/apisix/admin/routes/r1' \ | ||
| -H 'X-API-KEY: <api-key>' \ | ||
| -H 'Content-Type: application/json' \ | ||
| -d '{ | ||
| "uri": "/kafka", | ||
| "plugins": { | ||
| "kafka-proxy": { | ||
| "sasl": { | ||
| "username": "user", | ||
| "password": "pwd" | ||
| } | ||
| } | ||
| }, | ||
| "upstream": { | ||
| "nodes": { | ||
| "kafka-server1:9092": 1, | ||
| "kafka-server2:9092": 1, | ||
| "kafka-server3:9092": 1 | ||
| }, | ||
| "type": "none", | ||
| "scheme": "kafka" | ||
| } | ||
| }' | ||
| ``` | ||
|
|
||
| Now, we can test it by connecting to the `/kafka` endpoint via websocket. | ||
|
|
||
| ## Disable Plugin | ||
|
|
||
| To disable the `kafka-proxy` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect. |
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
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.
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.