cmccabe commented on code in PR #14169: URL: https://github.com/apache/kafka/pull/14169#discussion_r1288918541
########## core/src/main/scala/kafka/server/metadata/AclPublisher.scala: ########## @@ -0,0 +1,99 @@ +/** + * 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.server.metadata + +import kafka.utils.Logging +import org.apache.kafka.image.loader.LoaderManifest +import org.apache.kafka.image.{MetadataDelta, MetadataImage} +import org.apache.kafka.metadata.authorizer.ClusterMetadataAuthorizer +import org.apache.kafka.server.authorizer.Authorizer +import org.apache.kafka.server.fault.FaultHandler + +import scala.concurrent.TimeoutException + + +class AclPublisher( + id: Int, + faultHandler: FaultHandler, + nodeType: String, + authorizer: Option[Authorizer], +) extends Logging with org.apache.kafka.image.publisher.MetadataPublisher { + logIdent = s"[${name()}] " + + override def name(): String = s"AclPublisher ${nodeType} id=${id}" + + var completedInitialLoad = false + + override def onMetadataUpdate( + delta: MetadataDelta, + newImage: MetadataImage, + manifest: LoaderManifest + ): Unit = { + val deltaName = s"MetadataDelta up to ${newImage.offset()}" + + // Apply changes to ACLs. This needs to be handled carefully because while we are + // applying these changes, the Authorizer is continuing to return authorization + // results in other threads. We never want to expose an invalid state. For example, + // if the user created a DENY ALL acl and then created an ALLOW ACL for topic foo, + // we want to apply those changes in that order, not the reverse order! Otherwise + // there could be a window during which incorrect authorization results are returned. + Option(delta.aclsDelta()).foreach { aclsDelta => + authorizer match { + case Some(authorizer: ClusterMetadataAuthorizer) => if (aclsDelta.isSnapshotDelta) { Review Comment: yes, good point. -- 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-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org