You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@zookeeper.apache.org by GitBox <gi...@apache.org> on 2020/10/14 03:53:42 UTC

[GitHub] [zookeeper] hanm commented on a change in pull request #1500: ZOOKEEPER-3561: Generalize target authentication scheme for ZooKeeper authentication enforcement.

hanm commented on a change in pull request #1500:
URL: https://github.com/apache/zookeeper/pull/1500#discussion_r504363384



##########
File path: zookeeper-server/src/main/java/org/apache/zookeeper/server/ZooKeeperServer.java
##########
@@ -1623,11 +1625,9 @@ public void processPacket(ServerCnxn cnxn, ByteBuffer incomingBuffer) throws IOE
         } else if (h.getType() == OpCode.sasl) {
             processSasl(incomingBuffer, cnxn, h);
         } else {
-            if (shouldRequireClientSaslAuth() && !hasCnxSASLAuthenticated(cnxn)) {
-                ReplyHeader replyHeader = new ReplyHeader(h.getXid(), 0, Code.SESSIONCLOSEDREQUIRESASLAUTH.intValue());
-                cnxn.sendResponse(replyHeader, null, "response");
-                cnxn.sendCloseSession();
-                cnxn.disableRecv();
+            if (!authHelper.enforceAuthentication(cnxn, h.getXid())) {
+                // Authentication enforcement is not successful, close is already closed. lets return.

Review comment:
       >> close is already closed
   
   connection is already closed?

##########
File path: zookeeper-server/src/test/java/org/apache/zookeeper/EnforceAuthenticationTest.java
##########
@@ -0,0 +1,274 @@
+/*
+ * 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.zookeeper;
+
+import org.apache.zookeeper.ZooDefs.Ids;
+import org.apache.zookeeper.client.ZKClientConfig;
+import org.apache.zookeeper.server.AuthenticationHelper;
+import org.apache.zookeeper.server.ServerConfig;
+import org.apache.zookeeper.server.ZooKeeperServerMain;
+import org.apache.zookeeper.server.admin.AdminServer;
+import org.apache.zookeeper.server.quorum.QuorumPeerConfig;
+import org.apache.zookeeper.server.quorum.QuorumPeerTestBase;
+import org.apache.zookeeper.test.ClientBase;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.CountDownLatch;
+
+import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+public class EnforceAuthenticationTest extends QuorumPeerTestBase {
+  protected static final Logger LOG = LoggerFactory.getLogger(EnforceAuthenticationTest.class);
+  private MainThread mt;
+  private int clientPort;
+
+  @Before
+  public void setUp() {
+    System.setProperty("zookeeper.admin.enableServer", "false");
+    System.setProperty("zookeeper.4lw.commands.whitelist", "*");
+    System.clearProperty(AuthenticationHelper.ENFORCE_AUTH_ENABLED);
+    System.clearProperty(AuthenticationHelper.ENFORCE_AUTH_SCHEME);
+  }
+
+  /**
+   * When ZooKeeperServer.ENFORCE_AUTH_ENABLED is not set or set to false, behaviour should be same
+   * as the old ie. clients without authentication are allowed to operations
+   */
+  @Test
+  public void testEnforceAuthenticationOldBehaviour() throws Exception {
+    Map<String, String> prop = new HashMap<>();
+    startServer(prop);
+    testEnforceAuthOldBehaviour(false);
+  }
+
+  @Test
+  public void testEnforceAuthenticationOldBehaviourWithNett() throws Exception {

Review comment:
       should be `testEnforceAuthenticationOldBehaviourWithNetty` 




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org