kafka-connect-tools icon indicating copy to clipboard operation
kafka-connect-tools copied to clipboard

Basic auth support?

Open muscovitebob opened this issue 5 years ago • 9 comments

Great CLI! Does it include basic auth support? I see no references to it in the repo.

muscovitebob avatar May 08 '20 16:05 muscovitebob

You should can set it in the KAFKA_CONNECT_REST variable.

export KAFKA_CONNECT_REST="http://myserver:myport"

andrewstevenson avatar May 11 '20 08:05 andrewstevenson

Indeed, this is good enough for my purposes, thanks! Although with more complex passwords including special characters I suspect this will not work.

muscovitebob avatar May 11 '20 08:05 muscovitebob

You should can set it in the KAFKA_CONNECT_REST variable.

export KAFKA_CONNECT_REST="http://myserver:myport" I don't think passing basic auth in the url works with the current implementation.

@muscovitebob, can you confirm it?

andreybratus avatar May 11 '20 08:05 andreybratus

I am not very happy about the implementation, but it should do the job: https://github.com/lensesio/kafka-connect-tools/pull/37

andreybratus avatar May 11 '20 09:05 andreybratus

I am having a bit of an issue with building the project to test it. I've obtained Gradle 5 and am following the readme. From the project dir I do:

gradle-5.6.4/bin/gradle buildCli

Which returns:

> Task :test FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':test'.
> Could not find matching constructor for: org.gradle.process.internal.DefaultExecActionFactory(org.gradle.api.internal.file.BaseDirFileResolver)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Does this look familiar?

muscovitebob avatar May 11 '20 09:05 muscovitebob

I had a similar issue. I reckon it's related to gradle version and incompatibility of some plugin, most likely scalatest gradle plugin. Try using the gradlew wrapper.

./gradlew clean buildCli

andreybratus avatar May 11 '20 09:05 andreybratus

Thanks, that helped. Testing against my Kafka Connect cluster, which is HTTPs and secured with BasicAuth. I have the following format of env variable:

export KAFKA_CONNECT_REST='https://USERNAME:ALPHANUMERICPASSWORD@HOSTNAME:PORT'

Then running:

./gradlew clean buildCli
bin/connect-cli ps

Yields:

java.lang.Exception:  Error: the Kafka Connect API returned status code 401
	at com.datamountaineer.connect.tools.RestKafkaConnectApi.non2xxException(RestKafkaConnectApi.scala:124)
	at com.datamountaineer.connect.tools.RestKafkaConnectApi.com$datamountaineer$connect$tools$RestKafkaConnectApi$$req(RestKafkaConnectApi.scala:141)
	at com.datamountaineer.connect.tools.RestKafkaConnectApi$$anonfun$activeConnectorNames$1.apply(RestKafkaConnectApi.scala:153)
	at com.datamountaineer.connect.tools.RestKafkaConnectApi$$anonfun$activeConnectorNames$1.apply(RestKafkaConnectApi.scala:152)
	at scala.util.Try$.apply(Try.scala:192)
	at com.datamountaineer.connect.tools.RestKafkaConnectApi.activeConnectorNames(RestKafkaConnectApi.scala:152)
	at com.datamountaineer.connect.tools.ExecuteCommand$.apply(Cli.scala:66)
	at com.datamountaineer.connect.tools.Cli$.main(Cli.scala:209)
	at com.datamountaineer.connect.tools.Cli.main(Cli.scala)

And to make sure it is not an issue with the bash variable, running:

curl -X GET ${KAFKA_CONNECT_REST}

Indeed returns information about my Kafka Connect cluster.

So it appears that some logic in current master is stripping the credentials info out of the URL string.

muscovitebob avatar May 11 '20 09:05 muscovitebob

I suggested a quick fix here: https://github.com/lensesio/kafka-connect-tools/pull/37

You can try to apply it or build from my fork https://github.com/andreybratus/kafka-connect-tools/tree/feature/basic-auth

andreybratus avatar May 11 '20 10:05 andreybratus

Checked out the fork/branch and can confirm that at least with ps it works. I will test the other commands later but looking at the code as the request method is used in all the methods I do not anticipate any issues. Thanks @andreybratus ! Might still be an issue if the password includes : however.

muscovitebob avatar May 11 '20 10:05 muscovitebob