Skip to content

KAFKA-8404: Add HttpHeader to RestClient HTTP Request and Connector REST API#6791

Merged
rhauch merged 16 commits into
apache:trunkfrom
haidangdam:KAFKA-8404-add-headers-connectors-rest
Jun 4, 2019
Merged

KAFKA-8404: Add HttpHeader to RestClient HTTP Request and Connector REST API#6791
rhauch merged 16 commits into
apache:trunkfrom
haidangdam:KAFKA-8404-add-headers-connectors-rest

Conversation

@haidangdam

@haidangdam haidangdam commented May 23, 2019

Copy link
Copy Markdown
Contributor

Description:
The ticket: https://issues.apache.org/jira/browse/KAFKA-8404
Add HttpHeader to Connector REST API.
Adding Authorization header to the Connector's Rest Client HTTP Request
Backporting to Kafka version 2.0

Testing:
Logic Test with Mocking.

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

@haidangdam

Copy link
Copy Markdown
Contributor Author

@rayokota @C0urante please review my PR. Thanks!

@haidangdam

Copy link
Copy Markdown
Contributor Author

retest me

@rayokota rayokota left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@haidangdam , this looks good! Left a few minor comments.

@haidangdam

haidangdam commented May 23, 2019

Copy link
Copy Markdown
Contributor Author

@haidangdam , this looks good! Left a few minor comments.

@rayokota Hi. Thanks for the input. I have already pushed the changed version.

@rayokota rayokota left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@haidangdam , left a few more nits. Thanks!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add param description

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add param description

@haidangdam

Copy link
Copy Markdown
Contributor Author

@rhauch Hi, would you mind taking a look at this PR. Thanks

@rhauch rhauch changed the title Add HttpHeader to RestClient HTTP Request and Connector REST API KAFKA-8404: Add HttpHeader to RestClient HTTP Request and Connector REST API May 23, 2019

@rhauch rhauch left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix, @haidangdam! Just a few small comments/suggestions, but otherwise looks good.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead of null we could use NO_HEADERS instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this. Would you like to have HttpHeaders nullHeaders = null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to see:

connectorsResource.createConnector(FORWARD, NULL_HEADERS, bodyIn);

to make it much more clear what the second parameter is and that most of the tests are not specifying headers.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thanks for clearer instruction.

@C0urante C0urante left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good @haidangdam, just one question.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the REST API requires authorization, won't this request fail due to lack of headers?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any answer to this?

@haidangdam haidangdam Jun 3, 2019

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi. Pattern will filter out this endpoint so that authorization will not fail.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @haidangdam, you mean there is no Authorization for POST /connectors/xx/tasks, so anyone can change tasks configuration ??

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently this endpoint should be secured through other means, such as mutual TLS.

@haidangdam
haidangdam force-pushed the KAFKA-8404-add-headers-connectors-rest branch 2 times, most recently from de9032a to 78c867e Compare June 3, 2019 17:41

@rayokota rayokota left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the backslashes in this regex string are necessary; can it be simplified to "/?connectors/[^/]+/tasks/?"?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, why don't we initialize the final as a Pattern instance so that we don't have to parse the pattern with every request?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good addition too. We should definitely clean up the regex if possible too, though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup. changed as well! Thanks for the suggestion

@rhauch rhauch left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update, @haidangdam. A few questions and suggestions.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any answer to this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to see:

connectorsResource.createConnector(FORWARD, NULL_HEADERS, bodyIn);

to make it much more clear what the second parameter is and that most of the tests are not specifying headers.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, why don't we initialize the final as a Pattern instance so that we don't have to parse the pattern with every request?

@C0urante C0urante left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the fix @haidangdam!

Ideally we'll follow up to lock down the putTaskConfig resource, but that's probably out of scope for this PR and, while incomplete, this is strictly an improvement over the state of authentication in the existing REST API code.

@rhauch rhauch left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks, @haidangdam!

@haidangdam
haidangdam force-pushed the KAFKA-8404-add-headers-connectors-rest branch from 0674512 to d30d6ce Compare June 3, 2019 23:02
@rhauch

rhauch commented Jun 3, 2019

Copy link
Copy Markdown
Contributor

The JDK 11 build failed on a Stream test, and all Connect tests passed with these changes in that build. The Connect tests all passed in the JDK 8 build, also.

@rayokota, @haidangdam: let's rebase this PR branch and run the Connect system tests with it. The rebase is necessary to pick up some Connect system test fixes that were merged since this branch was last rebased.

@rhauch
rhauch merged commit 1a3fe9a into apache:trunk Jun 4, 2019
rhauch pushed a commit that referenced this pull request Jun 4, 2019
…EST API (#6791)

When Connect forwards a REST request from one worker to another, the Authorization header was not forwarded. This commit changes the Connect framework to add include the authorization header when forwarding requests to other workers.

Author: Hai-Dang Dam <damquanghaidang@gmail.com>
Reviewers: Robert Yokota <rayokota@gmail.com>, Randall Hauch <rhauch@gmail.com>
rhauch pushed a commit that referenced this pull request Jun 4, 2019
…EST API (#6791)

When Connect forwards a REST request from one worker to another, the Authorization header was not forwarded. This commit changes the Connect framework to add include the authorization header when forwarding requests to other workers.

Author: Hai-Dang Dam <damquanghaidang@gmail.com>
Reviewers: Robert Yokota <rayokota@gmail.com>, Randall Hauch <rhauch@gmail.com>

# Conflicts:
#	connect/runtime/src/main/java/org/apache/kafka/connect/runtime/rest/resources/ConnectorsResource.java
#	connect/runtime/src/test/java/org/apache/kafka/connect/runtime/rest/resources/ConnectorsResourceTest.java
rhauch pushed a commit that referenced this pull request Jun 4, 2019
…EST API (#6791)

When Connect forwards a REST request from one worker to another, the Authorization header was not forwarded. This commit changes the Connect framework to add include the authorization header when forwarding requests to other workers.

Author: Hai-Dang Dam <damquanghaidang@gmail.com>
Reviewers: Robert Yokota <rayokota@gmail.com>, Randall Hauch <rhauch@gmail.com>

# Conflicts:
#	connect/runtime/src/main/java/org/apache/kafka/connect/runtime/rest/resources/ConnectorsResource.java
#	connect/runtime/src/test/java/org/apache/kafka/connect/runtime/rest/resources/ConnectorsResourceTest.java

# Conflicts:
#	connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/DistributedHerder.java
rhauch pushed a commit that referenced this pull request Jun 4, 2019
…EST API (#6791)

When Connect forwards a REST request from one worker to another, the Authorization header was not forwarded. This commit changes the Connect framework to add include the authorization header when forwarding requests to other workers.

Author: Hai-Dang Dam <damquanghaidang@gmail.com>
Reviewers: Robert Yokota <rayokota@gmail.com>, Randall Hauch <rhauch@gmail.com>

# Conflicts:
#	connect/runtime/src/main/java/org/apache/kafka/connect/runtime/rest/resources/ConnectorsResource.java
#	connect/runtime/src/test/java/org/apache/kafka/connect/runtime/rest/resources/ConnectorsResourceTest.java

# Conflicts:
#	connect/runtime/src/main/java/org/apache/kafka/connect/runtime/distributed/DistributedHerder.java
omkreddy added a commit to confluentinc/kafka that referenced this pull request Jun 4, 2019
* AK_REPO/2.3:
  KAFKA-8155: Add 2.2.0 release to system tests (apache#6597)
  KAFKA-8404: Add HttpHeader to RestClient HTTP Request and Connector REST API (apache#6791)
  KAFKA-8473: Adjust Connect system tests for incremental cooperative rebalancing (apache#6872)
  KAFKA-8475: Temporarily restore SslFactory.sslContext() helper
  KAFKA-8449: Restart tasks on reconfiguration under incremental cooperative rebalancing (apache#6850)
  KAFKA-8426; Fix for keeping the ConfigProvider configs consistent with KIP-297 (apache#6750)
  KAFKA-8425: Fix for correctly handling immutable maps (KIP-421 bug) (apache#6795)
  MINOR: Reordering the props modification with configs construction
wicknicks pushed a commit to wicknicks/kafka that referenced this pull request Jun 12, 2019
…EST API (apache#6791)

When Connect forwards a REST request from one worker to another, the Authorization header was not forwarded. This commit changes the Connect framework to add include the authorization header when forwarding requests to other workers.

Author: Hai-Dang Dam <damquanghaidang@gmail.com>
Reviewers: Robert Yokota <rayokota@gmail.com>, Randall Hauch <rhauch@gmail.com>
pengxiaolong pushed a commit to pengxiaolong/kafka that referenced this pull request Jun 14, 2019
…EST API (apache#6791)

When Connect forwards a REST request from one worker to another, the Authorization header was not forwarded. This commit changes the Connect framework to add include the authorization header when forwarding requests to other workers.

Author: Hai-Dang Dam <damquanghaidang@gmail.com>
Reviewers: Robert Yokota <rayokota@gmail.com>, Randall Hauch <rhauch@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants