-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-12394: Return TOPIC_AUTHORIZATION_FAILED in delete topic response if no describe permission
#10223
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
KAFKA-12394: Return TOPIC_AUTHORIZATION_FAILED in delete topic response if no describe permission
#10223
Changes from all commits
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 |
|---|---|---|
|
|
@@ -1874,7 +1874,7 @@ class KafkaApis(val requestChannel: RequestChannel, | |
| if (topic.name() != null && topic.topicId() != Uuid.ZERO_UUID) | ||
| throw new InvalidRequestException("Topic name and topic ID can not both be specified.") | ||
| val name = if (topic.topicId() == Uuid.ZERO_UUID) topic.name() | ||
| else zkSupport.controller.controllerContext.topicNames.getOrElse(topic.topicId(), null) | ||
| else zkSupport.controller.controllerContext.topicName(topic.topicId).orNull | ||
| results.add(new DeletableTopicResult() | ||
| .setName(name) | ||
| .setTopicId(topic.topicId())) | ||
|
|
@@ -1884,20 +1884,27 @@ class KafkaApis(val requestChannel: RequestChannel, | |
| val authorizedDeleteTopics = authHelper.filterByAuthorized(request.context, DELETE, TOPIC, | ||
| results.asScala.filter(result => result.name() != null))(_.name) | ||
| results.forEach { topic => | ||
| val unresolvedTopicId = !(topic.topicId() == Uuid.ZERO_UUID) && topic.name() == null | ||
| if (!config.usesTopicId && topicIdsFromRequest.contains(topic.topicId)) { | ||
| topic.setErrorCode(Errors.UNSUPPORTED_VERSION.code) | ||
| topic.setErrorMessage("Topic IDs are not supported on the server.") | ||
| } else if (unresolvedTopicId) | ||
| topic.setErrorCode(Errors.UNKNOWN_TOPIC_ID.code) | ||
| else if (topicIdsFromRequest.contains(topic.topicId) && !authorizedDescribeTopics(topic.name)) | ||
| topic.setErrorCode(Errors.UNKNOWN_TOPIC_ID.code) | ||
| else if (!authorizedDeleteTopics.contains(topic.name)) | ||
| topic.setErrorCode(Errors.TOPIC_AUTHORIZATION_FAILED.code) | ||
| else if (!metadataCache.contains(topic.name)) | ||
| topic.setErrorCode(Errors.UNKNOWN_TOPIC_OR_PARTITION.code) | ||
| else | ||
| toDelete += topic.name | ||
| val unresolvedTopicId = topic.topicId() != Uuid.ZERO_UUID && topic.name() == null | ||
| if (!config.usesTopicId && topicIdsFromRequest.contains(topic.topicId)) { | ||
| topic.setErrorCode(Errors.UNSUPPORTED_VERSION.code) | ||
| topic.setErrorMessage("Topic IDs are not supported on the server.") | ||
| } else if (unresolvedTopicId) { | ||
| topic.setErrorCode(Errors.UNKNOWN_TOPIC_ID.code) | ||
| } else if (topicIdsFromRequest.contains(topic.topicId) && !authorizedDescribeTopics.contains(topic.name)) { | ||
|
|
||
| // Because the client does not have Describe permission, the name should | ||
| // not be returned in the response. Note, however, that we do not consider | ||
| // the topicId itself to be sensitive, so there is no reason to obscure | ||
| // this case with `UNKNOWN_TOPIC_ID`. | ||
| topic.setName(null) | ||
|
Member
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. I just noticed that the
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. That's a good question. I agree using
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. We have one dependence here which makes this a little more work than I wanted to do here: https://github.com/apache/kafka/blob/trunk/core/src/main/scala/kafka/server/KafkaApis.scala#L1909. I filed a separate JIRA so that we don't forget about it: https://issues.apache.org/jira/browse/KAFKA-12395. |
||
| topic.setErrorCode(Errors.TOPIC_AUTHORIZATION_FAILED.code) | ||
| } else if (!authorizedDeleteTopics.contains(topic.name)) { | ||
|
Member
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. according to #10184 (comment), should it handle the case
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. I guess there are really two sub-cases. Here's how they are currently handled: This seems defensible to me. The
Member
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.
That makes sense to me. We have to make sure this rule is applied to #10184 :) |
||
| topic.setErrorCode(Errors.TOPIC_AUTHORIZATION_FAILED.code) | ||
| } else if (!metadataCache.contains(topic.name)) { | ||
| topic.setErrorCode(Errors.UNKNOWN_TOPIC_OR_PARTITION.code) | ||
| } else { | ||
| toDelete += topic.name | ||
| } | ||
| } | ||
| // If no authorized topics return immediately | ||
| if (toDelete.isEmpty) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.