You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2022/03/11 11:15:36 UTC
[GitHub] [kafka] omkreddy commented on a change in pull request #10738: KAFKA-6945: KIP-373, allow users to create delegation token for others
omkreddy commented on a change in pull request #10738:
URL: https://github.com/apache/kafka/pull/10738#discussion_r824587983
##########
File path: core/src/main/scala/kafka/admin/AclCommand.scala
##########
@@ -467,8 +467,11 @@ object AclCommand extends Logging {
if (opts.options.has(opts.delegationTokenOpt))
opts.options.valuesOf(opts.delegationTokenOpt).forEach(token => resourceFilters += new ResourcePatternFilter(JResourceType.DELEGATION_TOKEN, token.trim, patternType))
+ if (opts.options.has(opts.userPrincipalOpt))
+ resourceFilters += new ResourcePatternFilter(JResourceType.USER, opts.options.valueOf(opts.userPrincipalOpt), patternType)
+
if (resourceFilters.isEmpty && dieIfNoResourceFound)
- CommandLineUtils.printUsageAndDie(opts.parser, "You must provide at least one resource: --topic <topic> or --cluster or --group <group> or --delegation-token <Delegation Token ID>")
Review comment:
nit: unwanted space
##########
File path: core/src/test/scala/integration/kafka/api/DelegationTokenEndToEndAuthorizationWithOwnerTest.scala
##########
@@ -0,0 +1,57 @@
+/**
+ * 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.
+ */
+package kafka.api
+
+import kafka.admin.AclCommand
+import kafka.utils.JaasTestUtils
+import org.apache.kafka.clients.admin.{Admin, CreateDelegationTokenOptions}
+import org.apache.kafka.common.security.auth.KafkaPrincipal
+import org.apache.kafka.common.security.token.delegation.DelegationToken
+
+class DelegationTokenEndToEndAuthorizationWithOwnerTest extends DelegationTokenEndToEndAuthorizationTest {
Review comment:
Can we add a negative test (i.e) try to create token for a user without valid permissions?
##########
File path: core/src/main/scala/kafka/admin/AclCommand.scala
##########
@@ -467,8 +467,11 @@ object AclCommand extends Logging {
if (opts.options.has(opts.delegationTokenOpt))
opts.options.valuesOf(opts.delegationTokenOpt).forEach(token => resourceFilters += new ResourcePatternFilter(JResourceType.DELEGATION_TOKEN, token.trim, patternType))
+ if (opts.options.has(opts.userPrincipalOpt))
Review comment:
Should we update AclCommandTest ? Can we add any checks to checkArgs() method.
##########
File path: core/src/main/scala/kafka/server/KafkaApis.scala
##########
@@ -2926,24 +2926,36 @@ class KafkaApis(val requestChannel: RequestChannel,
trace(s"Sending create token response for correlation id ${request.header.correlationId} " +
s"to client ${request.header.clientId}.")
requestHelper.sendResponseMaybeThrottle(request, requestThrottleMs =>
- CreateDelegationTokenResponse.prepareResponse(requestThrottleMs, createResult.error, request.context.principal, createResult.issueTimestamp,
- createResult.expiryTimestamp, createResult.maxTimestamp, createResult.tokenId, ByteBuffer.wrap(createResult.hmac)))
+ CreateDelegationTokenResponse.prepareResponse(request.context.requestVersion, requestThrottleMs, createResult.error, createResult.owner,
+ createResult.tokenRequester, createResult.issueTimestamp, createResult.expiryTimestamp, createResult.maxTimestamp, createResult.tokenId,
+ ByteBuffer.wrap(createResult.hmac)))
}
+ val ownerPrincipalName = createTokenRequest.data().ownerPrincipalName()
+ val owner = if (ownerPrincipalName == null || ownerPrincipalName.isEmpty) {
+ request.context.principal
+ } else {
+ new KafkaPrincipal(createTokenRequest.data().ownerPrincipalType(), ownerPrincipalName)
+ }
+ val requester = request.context.principal
+
if (!allowTokenRequests(request))
Review comment:
We should also add authorizer check if `owner != requester` ? also a test for this scenario.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org