This is an automated email from the ASF dual-hosted git repository.
SteNicholas pushed a commit to branch branch-0.7
in repository https://gitbox.apache.org/repos/asf/celeborn.git
The following commit(s) were added to refs/heads/branch-0.7 by this push:
new 7be6d0f642 [CELEBORN-2539] Restrict external Master RPCs to
application operations
7be6d0f642 is described below
commit 7be6d0f642d750afabfa9e114f6a1328f2f150cd
Author: Kalvin2077 <[email protected]>
AuthorDate: Thu Nov 5 20:11:31 2026 +0800
[CELEBORN-2539] Restrict external Master RPCs to application operations
### What changes were proposed in this pull request?
With `celeborn.auth.enabled=true`, restrict the Master's external RPC
endpoint to application operations.
`RpcMessageOrigin` records the receiving path. `Inbox` invokes
authorization before both request/reply and one-way dispatch, and
`Master.authorize` enforces the application-operation allowlist. Internal
service traffic and local management calls retain their existing access.
Diff size: non-test code +93/-12; tests +407/-9; docs/other +4/-0.
### Why are the changes needed?
Application authentication does not currently prevent external RPC callers
from invoking worker lifecycle and cluster management handlers. These requests
must be rejected before they change cluster state.
### Does this PR resolve a correctness bug?
- [x] Yes
### Does this PR introduce _any_ user-facing change?
- [x] Yes
External management RPCs are rejected when authentication is enabled.
Existing application operations, authentication-disabled behavior, and the
internal-port trust model are preserved. No new configuration is introduced.
### How was this patch tested?
Local build/package and focused tests passed on JDK 17. `dev/reformat` for
`common/master` and Spotless checks passed.
`InboxSuite`, `NettyRpcEnvSuite`, `MasterRpcAuthorizationSuite`,
`MasterApplicationMetaAuthSuite`, and `MasterSuite` passed, covering forged
sender addresses, request/reply and one-way rejection without state changes,
and allowed internal/local calls.
Closes #3945 from Kalvin2077/fix/worker-event-authorization.
Authored-by: Kalvin2077 <[email protected]>
Signed-off-by: Nicholas Jiang <[email protected]>
(cherry picked from commit cc4a6e8aac3bfe9eb821366745664fa0bad16e22)
Signed-off-by: Nicholas Jiang <[email protected]>
---
.../celeborn/common/rpc/RpcCallContext.scala | 2 +-
.../apache/celeborn/common/rpc/RpcEndpoint.scala | 6 +
.../celeborn/common/rpc/RpcMessageOrigin.scala | 45 ++++
.../celeborn/common/rpc/RpcMetricsTracker.scala | 2 +-
.../celeborn/common/rpc/netty/Dispatcher.scala | 4 +-
.../apache/celeborn/common/rpc/netty/Inbox.scala | 9 +-
.../common/rpc/netty/NettyRpcCallContext.scala | 6 +-
.../celeborn/common/rpc/netty/NettyRpcEnv.scala | 6 +-
.../celeborn/common/rpc/netty/InboxSuite.scala | 8 +-
.../common/rpc/netty/NettyRpcEnvSuite.scala | 64 +++++-
docs/security.md | 10 +
.../deploy/master/InternalRpcEndpoint.scala | 3 +
.../celeborn/service/deploy/master/Master.scala | 29 +++
.../master/MasterApplicationMetaAuthSuite.scala | 235 ++++++++++++++++++++-
.../master/MasterRpcAuthorizationSuite.scala | 107 ++++++++++
15 files changed, 517 insertions(+), 19 deletions(-)
diff --git
a/common/src/main/scala/org/apache/celeborn/common/rpc/RpcCallContext.scala
b/common/src/main/scala/org/apache/celeborn/common/rpc/RpcCallContext.scala
index fce781928d..b8fa37c64e 100644
--- a/common/src/main/scala/org/apache/celeborn/common/rpc/RpcCallContext.scala
+++ b/common/src/main/scala/org/apache/celeborn/common/rpc/RpcCallContext.scala
@@ -21,7 +21,7 @@ package org.apache.celeborn.common.rpc
* A callback that [[RpcEndpoint]] can use to send back a message or failure.
It's thread-safe
* and can be called in any thread.
*/
-trait RpcCallContext {
+trait RpcCallContext extends RpcMessageOrigin {
/**
* Reply a message to the sender. If the sender is [[RpcEndpoint]], its
[[RpcEndpoint.receive]]
diff --git
a/common/src/main/scala/org/apache/celeborn/common/rpc/RpcEndpoint.scala
b/common/src/main/scala/org/apache/celeborn/common/rpc/RpcEndpoint.scala
index 8d12c227af..5050b4f47b 100644
--- a/common/src/main/scala/org/apache/celeborn/common/rpc/RpcEndpoint.scala
+++ b/common/src/main/scala/org/apache/celeborn/common/rpc/RpcEndpoint.scala
@@ -80,6 +80,12 @@ trait RpcEndpoint {
case _ => context.sendFailure(new CelebornException(self + " won't reply
anything"))
}
+ /**
+ * Checks a message before either receive path runs. Throw to reject it;
otherwise the original
+ * message is dispatched. Forwarders must retain its origin.
+ */
+ def authorize(origin: RpcMessageOrigin, message: Any): Unit = ()
+
def checkRegistered(): Boolean = true
/**
diff --git
a/common/src/main/scala/org/apache/celeborn/common/rpc/RpcMessageOrigin.scala
b/common/src/main/scala/org/apache/celeborn/common/rpc/RpcMessageOrigin.scala
new file mode 100644
index 0000000000..51c1296d17
--- /dev/null
+++
b/common/src/main/scala/org/apache/celeborn/common/rpc/RpcMessageOrigin.scala
@@ -0,0 +1,45 @@
+/*
+ * 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 org.apache.celeborn.common.rpc
+
+/**
+ * The origin of an RPC message as determined by the receiver: local dispatch
or the receiving RpcEnv.
+ * This is independent of the sender address in the message and does not
authenticate the caller.
+ */
+trait RpcMessageOrigin {
+ // An unknown origin does not acquire local or internal authority.
+ def isLocal: Boolean = false
+
+ /** The receiving environment, assigned by the network handler rather than
the wire message. */
+ def receivingRpcEnv: Option[RpcEnv] = None
+}
+
+private[celeborn] object RpcMessageOrigin {
+ private val localOrigin: RpcMessageOrigin = new RpcMessageOrigin {
+ override val isLocal: Boolean = true
+ }
+
+ def local(): RpcMessageOrigin = localOrigin
+
+ def remote(receiver: RpcEnv): RpcMessageOrigin = {
+ require(receiver != null, "A remote message requires its receiving RPC
environment")
+ new RpcMessageOrigin {
+ override val receivingRpcEnv: Option[RpcEnv] = Some(receiver)
+ }
+ }
+}
diff --git
a/common/src/main/scala/org/apache/celeborn/common/rpc/RpcMetricsTracker.scala
b/common/src/main/scala/org/apache/celeborn/common/rpc/RpcMetricsTracker.scala
index e9eedeb2e8..d56e135e98 100644
---
a/common/src/main/scala/org/apache/celeborn/common/rpc/RpcMetricsTracker.scala
+++
b/common/src/main/scala/org/apache/celeborn/common/rpc/RpcMetricsTracker.scala
@@ -137,7 +137,7 @@ private[celeborn] class RpcMetricsTracker(
val processTime = rpc.endProcessTime - rpc.dequeueTime
record(content, queueTime, processTime)
logSlowRpc(message, queueTime, processTime)
- case one @ OneWayMessage(_, content) =>
+ case one @ OneWayMessage(_, content, _) =>
val queueTime = one.dequeueTime - one.enqueueTime
val processTime = one.endProcessTime - one.dequeueTime
record(content, queueTime, processTime)
diff --git
a/common/src/main/scala/org/apache/celeborn/common/rpc/netty/Dispatcher.scala
b/common/src/main/scala/org/apache/celeborn/common/rpc/netty/Dispatcher.scala
index d8282a64c7..200b2719ce 100644
---
a/common/src/main/scala/org/apache/celeborn/common/rpc/netty/Dispatcher.scala
+++
b/common/src/main/scala/org/apache/celeborn/common/rpc/netty/Dispatcher.scala
@@ -153,10 +153,10 @@ private[celeborn] class Dispatcher(nettyEnv: NettyRpcEnv,
rpcSource: RpcSource)
}
/** Posts a one-way message. */
- def postOneWayMessage(message: RequestMessage): Unit = {
+ def postOneWayMessage(message: RequestMessage, origin: RpcMessageOrigin):
Unit = {
postMessage(
message.receiver.name,
- OneWayMessage(message.senderAddress, message.content),
+ OneWayMessage(message.senderAddress, message.content, origin),
e => throw e)
}
diff --git
a/common/src/main/scala/org/apache/celeborn/common/rpc/netty/Inbox.scala
b/common/src/main/scala/org/apache/celeborn/common/rpc/netty/Inbox.scala
index ced47a75bb..7a8b640495 100644
--- a/common/src/main/scala/org/apache/celeborn/common/rpc/netty/Inbox.scala
+++ b/common/src/main/scala/org/apache/celeborn/common/rpc/netty/Inbox.scala
@@ -26,7 +26,7 @@ import scala.util.control.NonFatal
import org.apache.celeborn.common.CelebornConf
import org.apache.celeborn.common.exception.CelebornException
import org.apache.celeborn.common.internal.Logging
-import org.apache.celeborn.common.rpc.{RpcAddress, RpcEndpoint,
RpcMetricsTracker, ThreadSafeRpcEndpoint}
+import org.apache.celeborn.common.rpc.{RpcAddress, RpcEndpoint,
RpcMessageOrigin, RpcMetricsTracker, ThreadSafeRpcEndpoint}
sealed private[celeborn] trait InboxMessage extends RpcTimeMetrics
@@ -38,7 +38,8 @@ private[celeborn] trait RpcTimeMetrics {
private[celeborn] case class OneWayMessage(
senderAddress: RpcAddress,
- content: Any)
+ content: Any,
+ origin: RpcMessageOrigin)
extends InboxMessage
private[celeborn] case class RpcMessage(
@@ -125,6 +126,7 @@ private[celeborn] class Inbox(
message match {
case RpcMessage(_sender, content, context) =>
try {
+ endpoint.authorize(context, content)
endpoint.receiveAndReply(context).applyOrElse[Any, Unit](
content,
{ msg =>
@@ -138,7 +140,8 @@ private[celeborn] class Inbox(
throw e
}
- case OneWayMessage(_sender, content) =>
+ case OneWayMessage(_sender, content, origin) =>
+ endpoint.authorize(origin, content)
endpoint.receive.applyOrElse[Any, Unit](
content,
{ msg =>
diff --git
a/common/src/main/scala/org/apache/celeborn/common/rpc/netty/NettyRpcCallContext.scala
b/common/src/main/scala/org/apache/celeborn/common/rpc/netty/NettyRpcCallContext.scala
index 3a51e7c74e..e90ec0eb1f 100644
---
a/common/src/main/scala/org/apache/celeborn/common/rpc/netty/NettyRpcCallContext.scala
+++
b/common/src/main/scala/org/apache/celeborn/common/rpc/netty/NettyRpcCallContext.scala
@@ -21,7 +21,7 @@ import scala.concurrent.Promise
import org.apache.celeborn.common.internal.Logging
import org.apache.celeborn.common.network.client.{RpcResponseCallback,
TransportClient}
-import org.apache.celeborn.common.rpc.{RpcAddress, RpcCallContext}
+import org.apache.celeborn.common.rpc.{RpcAddress, RpcCallContext, RpcEnv}
abstract private[celeborn] class NettyRpcCallContext(override val
senderAddress: RpcAddress)
extends RpcCallContext with Logging {
@@ -46,6 +46,8 @@ private[celeborn] class LocalNettyRpcCallContext(
p: Promise[Any])
extends NettyRpcCallContext(senderAddress) {
+ override val isLocal: Boolean = true
+
override protected def send(message: Any): Unit = {
p.success(message)
}
@@ -61,6 +63,8 @@ private[celeborn] class RemoteNettyRpcCallContext(
val transportClient: TransportClient)
extends NettyRpcCallContext(senderAddress) {
+ override def receivingRpcEnv: Option[RpcEnv] = Option(nettyEnv)
+
override protected def send(message: Any): Unit = {
val reply = nettyEnv.serialize(message)
callback.onSuccess(reply)
diff --git
a/common/src/main/scala/org/apache/celeborn/common/rpc/netty/NettyRpcEnv.scala
b/common/src/main/scala/org/apache/celeborn/common/rpc/netty/NettyRpcEnv.scala
index ed002d3b0b..44252819e4 100644
---
a/common/src/main/scala/org/apache/celeborn/common/rpc/netty/NettyRpcEnv.scala
+++
b/common/src/main/scala/org/apache/celeborn/common/rpc/netty/NettyRpcEnv.scala
@@ -224,7 +224,7 @@ class NettyRpcEnv(
if (remoteAddr == address) {
// Message to a local RPC endpoint.
try {
- dispatcher.postOneWayMessage(message)
+ dispatcher.postOneWayMessage(message, RpcMessageOrigin.local())
} catch {
case e: RpcEnvStoppedException => logDebug(e.getMessage)
}
@@ -602,6 +602,8 @@ private[celeborn] class NettyRpcHandler(
dispatcher: Dispatcher,
nettyEnv: NettyRpcEnv) extends BaseMessageHandler with Logging {
+ private val remoteOrigin = RpcMessageOrigin.remote(nettyEnv)
+
// A variable to track the remote RpcEnv addresses of all clients
private val remoteAddresses = JavaUtils.newConcurrentHashMap[RpcAddress,
RpcAddress]()
@@ -611,7 +613,7 @@ private[celeborn] class NettyRpcHandler(
try {
val message = requestMessage.body().nioByteBuffer()
val messageToDispatch = internalReceive(client, message)
- dispatcher.postOneWayMessage(messageToDispatch)
+ dispatcher.postOneWayMessage(messageToDispatch, remoteOrigin)
} catch {
case e: Exception =>
logError("Error while invoking NettyRpcHandler#receive() for one-way
message.", e)
diff --git
a/common/src/test/scala/org/apache/celeborn/common/rpc/netty/InboxSuite.scala
b/common/src/test/scala/org/apache/celeborn/common/rpc/netty/InboxSuite.scala
index a0c23368b6..ff9b89c941 100644
---
a/common/src/test/scala/org/apache/celeborn/common/rpc/netty/InboxSuite.scala
+++
b/common/src/test/scala/org/apache/celeborn/common/rpc/netty/InboxSuite.scala
@@ -26,7 +26,7 @@ import org.scalatest.BeforeAndAfter
import org.apache.celeborn.CelebornFunSuite
import org.apache.celeborn.common.CelebornConf
import org.apache.celeborn.common.metrics.source.Role
-import org.apache.celeborn.common.rpc.{RpcAddress, RpcMetricsTracker,
RpcSource, TestRpcEndpoint}
+import org.apache.celeborn.common.rpc.{RpcAddress, RpcMessageOrigin,
RpcMetricsTracker, RpcSource, TestRpcEndpoint}
import org.apache.celeborn.common.util.ThreadUtils
class InboxSuite extends CelebornFunSuite with BeforeAndAfter {
@@ -67,7 +67,7 @@ class InboxSuite extends CelebornFunSuite with BeforeAndAfter
{
test("post") {
val dispatcher = mock(classOf[Dispatcher])
- val message = OneWayMessage(null, "hi")
+ val message = OneWayMessage(null, "hi", RpcMessageOrigin.local())
inbox.post(message)
inbox.process(dispatcher)
assert(inbox.isEmpty)
@@ -110,7 +110,7 @@ class InboxSuite extends CelebornFunSuite with
BeforeAndAfter {
new Runnable {
override def run(): Unit = {
for (_ <- 0 until 100) {
- val message = OneWayMessage(null, "hi")
+ val message = OneWayMessage(null, "hi", RpcMessageOrigin.local())
inbox.post(message)
}
exitLatch.countDown()
@@ -171,7 +171,7 @@ class InboxSuite extends CelebornFunSuite with
BeforeAndAfter {
when(endpoint.receive).thenThrow(new OutOfMemoryError())
val dispatcher = mock(classOf[Dispatcher])
val inbox = initInbox(endpoint, None)
- inbox.post(OneWayMessage(null, "hi"))
+ inbox.post(OneWayMessage(null, "hi", RpcMessageOrigin.local()))
intercept[OutOfMemoryError] {
inbox.process(dispatcher)
}
diff --git
a/common/src/test/scala/org/apache/celeborn/common/rpc/netty/NettyRpcEnvSuite.scala
b/common/src/test/scala/org/apache/celeborn/common/rpc/netty/NettyRpcEnvSuite.scala
index 3cdb3fcfe5..bfec3e81b7 100644
---
a/common/src/test/scala/org/apache/celeborn/common/rpc/netty/NettyRpcEnvSuite.scala
+++
b/common/src/test/scala/org/apache/celeborn/common/rpc/netty/NettyRpcEnvSuite.scala
@@ -17,7 +17,7 @@
package org.apache.celeborn.common.rpc.netty
-import java.util.concurrent.ExecutionException
+import java.util.concurrent.{ExecutionException, LinkedBlockingQueue, TimeUnit}
import scala.concurrent.duration._
@@ -144,6 +144,68 @@ class NettyRpcEnvSuite extends RpcEnvSuite with TimeLimits
{
RequestMessage(nettyEnv, client, msg3.serialize(nettyEnv)))
}
+ test("ask and send retain remote origin even with a forged local sender
address") {
+ val observed = new LinkedBlockingQueue[RpcMessageOrigin]()
+ val errors = new LinkedBlockingQueue[Throwable]()
+ val received = new LinkedBlockingQueue[String]()
+ val local = env.setupEndpoint(
+ "origin-authorization",
+ new ThreadSafeRpcEndpoint {
+ override val rpcEnv: RpcEnv = env
+ override def authorize(origin: RpcMessageOrigin, message: Any): Unit =
{
+ observed.add(origin)
+ if (!origin.isLocal) {
+ throw new SecurityException("Remote request denied")
+ }
+ }
+ override def receive: PartialFunction[Any, Unit] = {
+ case message: String => received.add(message)
+ }
+ override def receiveAndReply(context: RpcCallContext):
PartialFunction[Any, Unit] = {
+ case message: String =>
+ received.add(message)
+ context.reply(message)
+ }
+ override def onError(cause: Throwable): Unit = { errors.add(cause) }
+ })
+ val remoteEnv = createRpcEnv(createCelebornConf(), "origin-client", 0)
+ .asInstanceOf[NettyRpcEnv]
+ try {
+ val remote = remoteEnv.setupEndpointRef(env.address,
"origin-authorization")
+ remote.send("remote-send")
+ assert(errors.poll(5, TimeUnit.SECONDS).isInstanceOf[SecurityException])
+ val sendOrigin = observed.poll(5, TimeUnit.SECONDS)
+ assert(sendOrigin != null && !sendOrigin.isLocal &&
sendOrigin.receivingRpcEnv.contains(env))
+
+ val failure =
intercept[CelebornException](remote.askSync[String]("remote-ask"))
+ assert(failure.getCause.isInstanceOf[SecurityException])
+ assert(errors.poll(5, TimeUnit.SECONDS).isInstanceOf[SecurityException])
+ val askOrigin = observed.poll(5, TimeUnit.SECONDS)
+ assert(askOrigin != null && !askOrigin.isLocal &&
askOrigin.receivingRpcEnv.contains(env))
+
+ val connection = remoteEnv.createClient(env.address)
+ val forged =
+ new RequestMessage(env.address,
remote.asInstanceOf[NettyRpcEndpointRef], "forged")
+ connection.send(forged.serialize(remoteEnv))
+ assert(errors.poll(5, TimeUnit.SECONDS).isInstanceOf[SecurityException])
+ val forgedOrigin = observed.poll(5, TimeUnit.SECONDS)
+ assert(forgedOrigin != null)
+ assert(!forgedOrigin.isLocal &&
forgedOrigin.receivingRpcEnv.contains(env))
+ assert(received.isEmpty)
+
+ local.send("local-send")
+ assert(local.askSync[String]("local-ask") == "local-ask")
+ assert(received.poll(5, TimeUnit.SECONDS) == "local-send")
+ assert(received.poll(5, TimeUnit.SECONDS) == "local-ask")
+ assert(observed.poll(5, TimeUnit.SECONDS).isLocal)
+ assert(observed.poll(5, TimeUnit.SECONDS).isLocal)
+ } finally {
+ remoteEnv.shutdown()
+ remoteEnv.awaitTermination()
+ env.stop(local)
+ }
+ }
+
test("StackOverflowError should be sent back and Dispatcher should survive")
{
val numUsableCores = 2
val conf = createCelebornConf()
diff --git a/docs/security.md b/docs/security.md
index 8fa7b62fd1..4be17721d6 100644
--- a/docs/security.md
+++ b/docs/security.md
@@ -87,6 +87,16 @@ Even though Celeborn does not transmit the secret, in the
clear, as part of auth
Note: SASL **requires use of internal port**.
+When authentication is enabled, the Master's regular RPC port accepts only
application
+operations. Worker lifecycle and cluster management operations require the
internal RPC
+port or a local call, such as one issued by the Master's HTTP management API.
+
+During rolling upgrades with authentication enabled, ensure that every Master
an
+application may connect to supports and allows the RPC messages it sends.
Upgrade
+those Masters before deploying clients that use new application RPC messages.
+A Master rejects external messages outside its allowlist even after successful
+application authentication.
+
| Property Name | Default | Description |
| ------ | ------------- | ----------- |
| celeborn.auth.enabled | false | Enables Authentication |
diff --git
a/master/src/main/scala/org/apache/celeborn/service/deploy/master/InternalRpcEndpoint.scala
b/master/src/main/scala/org/apache/celeborn/service/deploy/master/InternalRpcEndpoint.scala
index 92ece136d3..022535adcc 100644
---
a/master/src/main/scala/org/apache/celeborn/service/deploy/master/InternalRpcEndpoint.scala
+++
b/master/src/main/scala/org/apache/celeborn/service/deploy/master/InternalRpcEndpoint.scala
@@ -44,6 +44,9 @@ private[celeborn] class InternalRpcEndpoint(
logDebug(s"Client $address got disconnected.")
}
+ override def authorize(origin: RpcMessageOrigin, message: Any): Unit =
+ master.authorize(origin, message)
+
override def receive: PartialFunction[Any, Unit] = {
master.receive
}
diff --git
a/master/src/main/scala/org/apache/celeborn/service/deploy/master/Master.scala
b/master/src/main/scala/org/apache/celeborn/service/deploy/master/Master.scala
index 75ceb951a9..6ab88ecec7 100644
---
a/master/src/main/scala/org/apache/celeborn/service/deploy/master/Master.scala
+++
b/master/src/main/scala/org/apache/celeborn/service/deploy/master/Master.scala
@@ -437,6 +437,21 @@ private[celeborn] class Master(
}
}
+ // Authentication requires a dedicated internal port. Its service traffic
and local management
+ // calls remain trusted; external callers may only use the existing
application operations.
+ override def authorize(origin: RpcMessageOrigin, message: Any): Unit = {
+ if (authEnabled && !origin.isLocal &&
+ !origin.receivingRpcEnv.contains(internalRpcEnvInUse)) {
+ if (!origin.receivingRpcEnv.contains(rpcEnv)) {
+ throw new SecurityException("Master RPC request has no recognized
receiver origin.")
+ }
+ if (!Master.ExternalApplicationOperations.exists(_.isInstance(message)))
{
+ throw new SecurityException(
+ s"External Master RPC is not authorized to handle
${message.getClass.getSimpleName}.")
+ }
+ }
+ }
+
override def receive: PartialFunction[Any, Unit] = {
case _: PbCheckForWorkerTimeout =>
executeWithLeaderChecker(null, timeoutDeadWorkers())
@@ -1643,6 +1658,20 @@ private[celeborn] class Master(
}
private[deploy] object Master extends Logging {
+ // Keep this allowlist in sync when adding application messages to the
external Master RPC endpoint.
+ private val ExternalApplicationOperations: Set[Class[_]] = Set(
+ classOf[RegisterApplicationInfo],
+ classOf[HeartbeatFromApplication],
+ classOf[RequestSlots],
+ classOf[PbRequestWorkers],
+ classOf[PbBatchUnregisterShuffles],
+ classOf[PbUnregisterShuffle],
+ classOf[ApplicationLost],
+ classOf[PbReviseLostShuffles],
+ classOf[CheckQuota],
+ classOf[PbCheckWorkersAvailable],
+ classOf[PbApplicationMetaRequest])
+
def main(args: Array[String]): Unit = {
SignalUtils.registerLogger(log)
val conf = new CelebornConf()
diff --git
a/master/src/test/scala/org/apache/celeborn/service/deploy/master/MasterApplicationMetaAuthSuite.scala
b/master/src/test/scala/org/apache/celeborn/service/deploy/master/MasterApplicationMetaAuthSuite.scala
index 50662f0383..26786b26e3 100644
---
a/master/src/test/scala/org/apache/celeborn/service/deploy/master/MasterApplicationMetaAuthSuite.scala
+++
b/master/src/test/scala/org/apache/celeborn/service/deploy/master/MasterApplicationMetaAuthSuite.scala
@@ -17,7 +17,8 @@
package org.apache.celeborn.service.deploy.master
-import java.io.{PrintWriter, StringWriter}
+import java.io.{ByteArrayOutputStream, DataOutputStream, ObjectOutputStream,
PrintWriter, StringWriter}
+import java.nio.ByteBuffer
import java.util
import scala.collection.mutable.ArrayBuffer
@@ -26,11 +27,16 @@ import org.scalatest.BeforeAndAfterAll
import org.scalatest.funsuite.AnyFunSuite
import org.apache.celeborn.common.CelebornConf
+import org.apache.celeborn.common.identity.UserIdentifier
+import org.apache.celeborn.common.meta.{DiskInfo, WorkerInfo, WorkerStatus}
import org.apache.celeborn.common.metrics.source.Role
import org.apache.celeborn.common.network.sasl.registration.RegistrationInfo
-import org.apache.celeborn.common.protocol.{PbApplicationMeta,
PbApplicationMetaRequest, PbReviseLostShufflesResponse, RpcNameConstants,
TransportModuleConstants}
-import
org.apache.celeborn.common.protocol.message.ControlMessages.ReviseLostShuffles
+import org.apache.celeborn.common.protocol.{PbApplicationMeta,
PbApplicationMetaRequest, PbRegisterWorkerResponse,
PbReviseLostShufflesResponse, PbWorkerEventResponse, RpcNameConstants,
StorageInfo, TransportModuleConstants, WorkerEventType}
+import
org.apache.celeborn.common.protocol.message.ControlMessages.{CheckQuota,
CheckQuotaResponse, CheckWorkersAvailable, HeartbeatFromWorker,
HeartbeatFromWorkerResponse, RegisterWorker, RemoveWorkersUnavailableInfo,
ReportWorkerDecommission, ReportWorkerUnavailable, ReviseLostShuffles,
WorkerEventRequest, WorkerExclude, WorkerLost}
import org.apache.celeborn.common.rpc.{ClientSaslContextBuilder, RpcAddress,
RpcEndpointRef, RpcEnv, RpcSecurityContextBuilder}
+import org.apache.celeborn.common.rpc.netty.{NettyRpcEnv, RpcFailure}
+import org.apache.celeborn.common.serializer.JavaSerializer
+import org.apache.celeborn.common.util.ByteBufferInputStream
/**
* End-to-end authorization checks for application-scoped Master RPCs with
auth enabled,
@@ -48,6 +54,9 @@ class MasterApplicationMetaAuthSuite extends AnyFunSuite
private val conf = new CelebornConf()
.set(CelebornConf.AUTH_ENABLED.key, "true")
.set(CelebornConf.INTERNAL_PORT_ENABLED.key, "true")
+ // A single dispatcher makes the reply after a one-way message a
completion barrier.
+ .set("celeborn.rpc.dispatcher.threads", "1")
+ .set("celeborn.rpc.RpcEndpointVerifier.separate.enabled", "false")
private var master: Master = _
private var externalAddress: RpcAddress = _
@@ -64,7 +73,12 @@ class MasterApplicationMetaAuthSuite extends AnyFunSuite
override def afterAll(): Unit = {
clientEnvs.foreach(_.shutdown())
if (master != null) {
- shutdownMaster()
+ try {
+ shutdownMaster()
+ } finally {
+ master.internalRpcEnvInUse.shutdown()
+ master.internalRpcEnvInUse.awaitTermination()
+ }
}
super.afterAll()
}
@@ -172,4 +186,217 @@ class MasterApplicationMetaAuthSuite extends AnyFunSuite
assert(victimShuffles.size() == 1)
assert(!victimShuffles.contains(3))
}
+
+ test("registered applications cannot issue worker events") {
+ val worker = new WorkerInfo("localhost", 18001, 18002, 18003, 18004, 18005)
+ val disk = new DiskInfo("/event-test", 1024L * 1024 * 1024, 0L, 0L, 0L,
StorageInfo.Type.HDD)
+ val internal = workerInternalRef()
+ assert(internal.askSync[PbRegisterWorkerResponse](RegisterWorker(
+ worker.host,
+ worker.rpcPort,
+ worker.pushPort,
+ worker.fetchPort,
+ worker.replicatePort,
+ worker.internalPort,
+ "/default-rack",
+ Map(disk.mountPoint -> disk),
+ Map.empty,
+ "event-register-worker")).getSuccess)
+
+ val appId = "worker-event-app"
+ val secret = "worker-event-secret"
+ val app = registeredAppRef(appId, secret)
+ assert(app.askSync[PbApplicationMeta](metaRequest(appId)).getSecret ==
secret)
+ assert(master.statusSystem.availableWorkers.contains(worker))
+
+ val heartbeat = HeartbeatFromWorker(
+ worker.host,
+ worker.rpcPort,
+ worker.pushPort,
+ worker.fetchPort,
+ worker.replicatePort,
+ Seq(disk),
+ util.Collections.emptyMap(),
+ util.Collections.emptySet(),
+ false,
+ WorkerStatus.normalWorkerStatus())
+
+ try {
+ Seq(WorkerEventType.Immediately, WorkerEventType.Decommission).foreach {
event =>
+ val failure = intercept[Exception] {
+ app.askSync[PbWorkerEventResponse](WorkerEventRequest(
+ util.Arrays.asList(worker),
+ event,
+ "app-worker-event"))
+ }
+ assertSecurityFailure(failure)
+ }
+ assert(master.statusSystem.workersMap.containsKey(worker.toUniqueId))
+ assert(master.statusSystem.availableWorkers.contains(worker))
+ assert(!master.statusSystem.workerEventInfos.containsKey(worker))
+ val unchanged = internal.askSync[HeartbeatFromWorkerResponse](heartbeat)
+ assert(unchanged.registered)
+ assert(unchanged.workerEvent == WorkerEventType.None)
+
+ // The HTTP management path issues the same event through local
self.askSync.
+ assert(master.handleWorkerEvent(WorkerEventType.Immediately,
Seq(worker))._1)
+ assert(!master.statusSystem.availableWorkers.contains(worker))
+ val delivered = internal.askSync[HeartbeatFromWorkerResponse](heartbeat)
+ assert(delivered.registered)
+ assert(delivered.workerEvent == WorkerEventType.Immediately)
+ } finally {
+ master.statusSystem.workersMap.remove(worker.toUniqueId)
+ master.statusSystem.availableWorkers.remove(worker)
+ master.statusSystem.workerEventInfos.remove(worker)
+ }
+ }
+
+ private def assertSecurityFailure(failure: Throwable): Unit = {
+ val causes = Iterator.iterate[Throwable](failure)(_.getCause).takeWhile(_
!= null).toSeq
+ assert(causes.exists(_.isInstanceOf[SecurityException]),
stackTraceOf(failure))
+ assert(stackTraceOf(failure).contains("External Master RPC is not
authorized"))
+ }
+
+ private def registration(worker: WorkerInfo, disk: DiskInfo) =
RegisterWorker(
+ worker.host,
+ worker.rpcPort,
+ worker.pushPort,
+ worker.fetchPort,
+ worker.replicatePort,
+ worker.internalPort,
+ "/default-rack",
+ Map(disk.mountPoint -> disk),
+ Map.empty,
+ "origin-register-worker")
+
+ private def workerLost(worker: WorkerInfo) = WorkerLost(
+ worker.host,
+ worker.rpcPort,
+ worker.pushPort,
+ worker.fetchPort,
+ worker.replicatePort,
+ "origin-worker-lost")
+
+ private def withWorker(f: (WorkerInfo, DiskInfo, RpcEndpointRef) => Unit):
Unit = {
+ val worker = new WorkerInfo("localhost", 18101, 18102, 18103, 18104, 18105)
+ val disk = new DiskInfo("/origin-test", 1024L * 1024 * 1024, 0L, 0L, 0L,
StorageInfo.Type.HDD)
+ val internal = workerInternalRef()
+ assert(internal.askSync[PbRegisterWorkerResponse](registration(worker,
disk)).getSuccess)
+ try {
+ f(worker, disk, internal)
+ } finally {
+ master.statusSystem.workersMap.remove(worker.toUniqueId)
+ master.statusSystem.availableWorkers.remove(worker)
+ master.statusSystem.lostWorkers.remove(worker)
+ master.statusSystem.workerEventInfos.remove(worker)
+ master.statusSystem.excludedWorkers.remove(worker)
+ master.statusSystem.manuallyExcludedWorkers.remove(worker)
+ master.statusSystem.shutdownWorkers.remove(worker)
+ master.statusSystem.decommissionWorkers.remove(worker)
+ master.statusSystem.workerLostEvents.remove(worker)
+ }
+ }
+
+ // Exercise the existing Java object stream path without adding a protobuf
codec.
+ private def askLegacy(env: NettyRpcEnv, message: Any): Unit = {
+ val bytes = new ByteArrayOutputStream()
+ val header = new DataOutputStream(bytes)
+ header.writeBoolean(false)
+ header.writeBoolean(true)
+ header.writeUTF(externalAddress.host)
+ header.writeInt(externalAddress.port)
+ header.writeUTF(RpcNameConstants.MASTER_EP)
+ val objects = new ObjectOutputStream(header)
+ objects.writeObject(message)
+ objects.close()
+ val connection = env.createClient(externalAddress)
+ val response = connection.sendRpcSync(ByteBuffer.wrap(bytes.toByteArray),
5000)
+ val input = new JavaSerializer(conf).newInstance()
+ .deserializeStream(new ByteBufferInputStream(response))
+ try {
+ input.readObject[Any]() match {
+ case RpcFailure(cause) => throw cause
+ case _ => // Successful legacy responses need no application payload
decoding here.
+ }
+ } finally {
+ input.close()
+ }
+ }
+
+ Seq("register", "heartbeat", "unavailable", "decommission", "exclude",
"lost", "remove")
+ .foreach { operation =>
+ test(s"registered applications cannot issue worker $operation requests")
{
+ withWorker { (worker, disk, _) =>
+ val appId = s"worker-$operation-app"
+ val app = registeredAppRef(appId, s"$appId-secret")
+ assert(app.askSync[PbApplicationMeta](metaRequest(appId)).getSecret
== s"$appId-secret")
+ val workers = util.Collections.singletonList(worker)
+ val request = operation match {
+ case "register" => registration(worker, disk)
+ case "heartbeat" => HeartbeatFromWorker(
+ worker.host,
+ worker.rpcPort,
+ worker.pushPort,
+ worker.fetchPort,
+ worker.replicatePort,
+ Seq(disk),
+ util.Collections.emptyMap(),
+ util.Collections.emptySet(),
+ false,
+ WorkerStatus.normalWorkerStatus())
+ case "unavailable" => ReportWorkerUnavailable(workers)
+ case "decommission" => ReportWorkerDecommission(workers)
+ case "exclude" => WorkerExclude(workers,
util.Collections.emptyList(), "exclude")
+ case "lost" => workerLost(worker)
+ case "remove" => RemoveWorkersUnavailableInfo(workers, "remove")
+ }
+ val lostTime = System.currentTimeMillis()
+ master.statusSystem.lostWorkers.put(worker, lostTime)
+ val failure = intercept[Exception] {
+ if (operation == "exclude") {
+ askLegacy(clientEnvs.last.asInstanceOf[NettyRpcEnv], request)
+ } else {
+ app.askSync[Any](request)
+ }
+ }
+ assert(master.statusSystem.workersMap.containsKey(worker.toUniqueId))
+ assert(master.statusSystem.availableWorkers.contains(worker))
+ // A reply encoding failure can happen after mutation; it is not an
authorization denial.
+ assert(master.statusSystem.lostWorkers.containsKey(worker))
+ assert(master.statusSystem.lostWorkers.get(worker) == lostTime)
+ assert(!master.statusSystem.manuallyExcludedWorkers.contains(worker))
+ assert(!master.statusSystem.shutdownWorkers.contains(worker))
+ assert(!master.statusSystem.decommissionWorkers.contains(worker))
+ assertSecurityFailure(failure)
+ }
+ }
+ }
+
+ test("registered applications cannot send one-way worker loss") {
+ withWorker { (worker, _, internal) =>
+ val appId = "one-way-worker-app"
+ val app = registeredAppRef(appId, "one-way-secret")
+ app.send(workerLost(worker))
+ // This fixture has one dispatcher thread; the following reply is a
completion barrier.
+ assert(app.askSync[PbApplicationMeta](metaRequest(appId)).getSecret ==
"one-way-secret")
+ assert(master.statusSystem.workersMap.containsKey(worker.toUniqueId))
+ assert(master.statusSystem.availableWorkers.contains(worker))
+
+ internal.askSync[Any](workerLost(worker))
+ assert(!master.statusSystem.workersMap.containsKey(worker.toUniqueId))
+
+ val disk = new DiskInfo("/local-test", 1024L * 1024 * 1024, 0L, 0L, 0L,
StorageInfo.Type.HDD)
+ assert(internal.askSync[PbRegisterWorkerResponse](registration(worker,
disk)).getSuccess)
+ master.self.send(workerLost(worker))
+ master.self.askSync[Any](CheckWorkersAvailable())
+ assert(!master.statusSystem.workersMap.containsKey(worker.toUniqueId))
+ }
+ }
+
+ test("registered applications retain quota and worker availability queries")
{
+ val app = registeredAppRef("queries-app", "queries-secret")
+ assert(
+ app.askSync[CheckQuotaResponse](CheckQuota(UserIdentifier("tenant",
"user"))).isAvailable)
+ app.askSync[Any](CheckWorkersAvailable())
+ }
}
diff --git
a/master/src/test/scala/org/apache/celeborn/service/deploy/master/MasterRpcAuthorizationSuite.scala
b/master/src/test/scala/org/apache/celeborn/service/deploy/master/MasterRpcAuthorizationSuite.scala
new file mode 100644
index 0000000000..dec34da472
--- /dev/null
+++
b/master/src/test/scala/org/apache/celeborn/service/deploy/master/MasterRpcAuthorizationSuite.scala
@@ -0,0 +1,107 @@
+/*
+ * 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 org.apache.celeborn.service.deploy.master
+
+import java.util
+
+import org.mockito.Mockito.{mock, when}
+import org.scalatest.funsuite.AnyFunSuite
+
+import org.apache.celeborn.common.CelebornConf
+import org.apache.celeborn.common.meta.WorkerStatus
+import org.apache.celeborn.common.network.client.TransportClient
+import org.apache.celeborn.common.protocol._
+import org.apache.celeborn.common.protocol.message.ControlMessages._
+import org.apache.celeborn.common.rpc.{RpcEnv, RpcMessageOrigin}
+import org.apache.celeborn.common.rpc.netty.{NettyRpcEnv,
RemoteNettyRpcCallContext}
+
+class MasterRpcAuthorizationSuite extends AnyFunSuite with
MasterClusterFeature {
+ private val protectedMessages = Seq(
+ PbRegisterWorker.getDefaultInstance,
+ HeartbeatFromWorker(
+ "localhost",
+ 1,
+ 2,
+ 3,
+ 4,
+ Seq.empty,
+ util.Collections.emptyMap(),
+ util.Collections.emptySet(),
+ false,
+ WorkerStatus.normalWorkerStatus()),
+ ReportWorkerUnavailable(util.Collections.emptyList()),
+ ReportWorkerDecommission(util.Collections.emptyList()),
+ PbWorkerExclude.getDefaultInstance,
+ PbWorkerLost.getDefaultInstance,
+ PbWorkerEventRequest.getDefaultInstance,
+ PbRemoveWorkersUnavailableInfo.getDefaultInstance,
+ PbCheckForWorkerTimeout.getDefaultInstance,
+ CheckForWorkerUnavailableInfoTimeout,
+ CheckForApplicationTimeOut,
+ CheckForDFSExpiredDirsTimeout)
+
+ Seq((true, true), (false, true), (false, false)).foreach { case (auth,
internal) =>
+ test(s"Master authorization uses receiver origin: auth=$auth
internal=$internal") {
+ val master = setupMasterWithRandomPort(Map(
+ CelebornConf.AUTH_ENABLED.key -> auth.toString,
+ CelebornConf.INTERNAL_PORT_ENABLED.key -> internal.toString))
+ def remote(env: RpcEnv, clientId: String): RpcMessageOrigin = {
+ val client = mock(classOf[TransportClient])
+ when(client.getClientId).thenReturn(clientId)
+ new RemoteNettyRpcCallContext(
+ env.asInstanceOf[NettyRpcEnv],
+ null,
+ master.rpcEnv.address,
+ client)
+ }
+ try {
+ protectedMessages.foreach { message =>
+ withClue(message.getClass.getSimpleName) {
+ Seq(null, "registered-app").foreach { clientId =>
+ val external = remote(master.rpcEnv, clientId)
+ if (auth) {
+ intercept[SecurityException](master.authorize(external,
message))
+ } else {
+ master.authorize(external, message)
+ }
+ master.authorize(remote(master.internalRpcEnvInUse, clientId),
message)
+ }
+ master.authorize(RpcMessageOrigin.local(), message)
+ if (auth) {
+ intercept[SecurityException](master.authorize(new
RpcMessageOrigin {}, message))
+ }
+ }
+ }
+ if (auth) {
+ intercept[SecurityException] {
+ master.authorize(RpcMessageOrigin.remote(master.rpcEnv), "unknown
request")
+ }
+ }
+ } finally {
+ try {
+ shutdownMaster()
+ } finally {
+ if (internal) {
+ master.internalRpcEnvInUse.shutdown()
+ master.internalRpcEnvInUse.awaitTermination()
+ }
+ }
+ }
+ }
+ }
+}