Github user zsxwing commented on a diff in the pull request:

    https://github.com/apache/spark/pull/16521#discussion_r97176557
  
    --- Diff: 
common/network-common/src/main/java/org/apache/spark/network/crypto/AuthRpcHandler.java
 ---
    @@ -0,0 +1,169 @@
    +/*
    + * 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.spark.network.crypto;
    +
    +import java.io.IOException;
    +import java.nio.ByteBuffer;
    +import javax.security.sasl.Sasl;
    +
    +import com.google.common.annotations.VisibleForTesting;
    +import com.google.common.base.Throwables;
    +import io.netty.buffer.ByteBuf;
    +import io.netty.buffer.Unpooled;
    +import io.netty.channel.Channel;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import org.apache.spark.network.client.RpcResponseCallback;
    +import org.apache.spark.network.client.TransportClient;
    +import org.apache.spark.network.sasl.SecretKeyHolder;
    +import org.apache.spark.network.sasl.SaslRpcHandler;
    +import org.apache.spark.network.server.RpcHandler;
    +import org.apache.spark.network.server.StreamManager;
    +import org.apache.spark.network.util.JavaUtils;
    +import org.apache.spark.network.util.TransportConf;
    +
    +/**
    + * RPC Handler which performs authentication using Spark's auth protocol 
before delegating to a
    + * child RPC handler. If the configuration allows, this handler will 
delegate messages to a SASL
    + * RPC handler for further authentication, to support for clients that do 
not support Spark's
    + * protocol.
    + *
    + * The delegate will only receive messages if the given connection has 
been successfully
    + * authenticated. A connection may be authenticated at most once.
    + */
    +class AuthRpcHandler extends RpcHandler {
    +  private static final Logger LOG = 
LoggerFactory.getLogger(AuthRpcHandler.class);
    +
    +  /** Transport configuration. */
    +  private final TransportConf conf;
    +
    +  /** The client channel. */
    +  private final Channel channel;
    +
    +  /**
    +   * RpcHandler we will delegate to for authenticated connections. When 
falling back to SASL
    +   * this will be replaced with the SASL RPC handler.
    +   */
    +  private RpcHandler delegate;
    +
    +  /** Class which provides secret keys which are shared by server and 
client on a per-app basis. */
    +  private final SecretKeyHolder secretKeyHolder;
    +
    +  /** Whether auth is done and future calls should be delegated. */
    +  @VisibleForTesting
    +  boolean doDelegate;
    +
    +  AuthRpcHandler(
    +      TransportConf conf,
    +      Channel channel,
    +      RpcHandler delegate,
    +      SecretKeyHolder secretKeyHolder) {
    +    this.conf = conf;
    +    this.channel = channel;
    +    this.delegate = delegate;
    +    this.secretKeyHolder = secretKeyHolder;
    +  }
    +
    +  @Override
    +  public void receive(TransportClient client, ByteBuffer message, 
RpcResponseCallback callback) {
    +    if (doDelegate) {
    +      delegate.receive(client, message, callback);
    +      return;
    +    }
    +
    +    int position = message.position();
    +    int limit = message.limit();
    +
    +    ClientChallenge challenge;
    +    try {
    +      challenge = ClientChallenge.decodeMessage(message);
    +      LOG.debug("Received new auth challenge for client {}.", 
channel.remoteAddress());
    +    } catch (RuntimeException e) {
    +      if (conf.saslFallback()) {
    +        LOG.debug("Failed to parse new auth challenge, reverting to SASL 
for client {}.",
    --- End diff --
    
    nit: debug -> warn


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to