madrob commented on code in PR #857:
URL: https://github.com/apache/solr/pull/857#discussion_r922209673


##########
solr/solrj/src/java/org/apache/solr/common/cloud/DigestZkACLProvider.java:
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.solr.common.cloud;
+
+import static 
org.apache.zookeeper.server.auth.DigestAuthenticationProvider.generateDigest;
+
+import java.lang.invoke.MethodHandles;
+import java.security.NoSuchAlgorithmException;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.StringUtils;
+import org.apache.solr.common.cloud.ZkCredentialsInjector.ZkCredential;
+import org.apache.zookeeper.ZooDefs;
+import org.apache.zookeeper.data.ACL;
+import org.apache.zookeeper.data.Id;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A class that expects a {@link ZkCredentialsInjector} to create Zookeeper 
ACLs using digest scheme
+ */
+public class DigestZkACLProvider extends SecurityAwareZkACLProvider {
+
+  private static final Logger log = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+  /** Called by reflective instantiation */
+  public DigestZkACLProvider() {}
+
+  public DigestZkACLProvider(ZkCredentialsInjector zkCredentialsInjector) {
+    super(zkCredentialsInjector);
+  }
+
+  /**
+   * @return Set of ACLs to return for non-security related znodes
+   */
+  @Override
+  protected List<ACL> createNonSecurityACLsToAdd() {
+    return createACLsToAdd(true);
+  }
+
+  /**
+   * Provider ACL Credential
+   *
+   * @return Set of ACLs to return security-related znodes
+   */
+  @Override
+  protected List<ACL> createSecurityACLsToAdd() {
+    return createACLsToAdd(false);
+  }
+
+  protected List<ACL> createACLsToAdd(boolean includeReadOnly) {
+    List<ACL> result = new ArrayList<>();
+    List<ZkCredential> zkCredentials = 
zkCredentialsInjector.getZkCredentials();
+    log.debug("createACLsToAdd using ZkCredentials: {}", zkCredentials);
+    for (ZkCredential zkCredential : zkCredentials) {
+      if (StringUtils.isEmpty(zkCredential.getUsername())
+          || StringUtils.isEmpty(zkCredential.getPassword())) {
+        continue;
+      }
+      Id id = createACLId(zkCredential.getUsername(), 
zkCredential.getPassword());
+      int perms;
+      if (zkCredential.isAll()) {
+        // Not to have to provide too much credentials and ACL information to 
the process it is
+        // assumed that you want "ALL"-acls
+        // added to the user you are using to connect to ZK
+        perms = ZooDefs.Perms.ALL;
+      } else if (includeReadOnly && zkCredential.isReadonly()) {
+        // Besides, that support for adding additional "READONLY"-acls for 
another user
+        perms = ZooDefs.Perms.READ;
+      } else continue;

Review Comment:
   what is this case for? it looks strange and kind of hard to understand the 
logic at first glance.



##########
solr/solrj/src/java/org/apache/solr/common/cloud/DigestZkACLProvider.java:
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.solr.common.cloud;
+
+import static 
org.apache.zookeeper.server.auth.DigestAuthenticationProvider.generateDigest;
+
+import java.lang.invoke.MethodHandles;
+import java.security.NoSuchAlgorithmException;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.StringUtils;
+import org.apache.solr.common.cloud.ZkCredentialsInjector.ZkCredential;
+import org.apache.zookeeper.ZooDefs;
+import org.apache.zookeeper.data.ACL;
+import org.apache.zookeeper.data.Id;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A class that expects a {@link ZkCredentialsInjector} to create Zookeeper 
ACLs using digest scheme
+ */
+public class DigestZkACLProvider extends SecurityAwareZkACLProvider {
+
+  private static final Logger log = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+  /** Called by reflective instantiation */
+  public DigestZkACLProvider() {}
+
+  public DigestZkACLProvider(ZkCredentialsInjector zkCredentialsInjector) {
+    super(zkCredentialsInjector);
+  }
+
+  /**
+   * @return Set of ACLs to return for non-security related znodes
+   */
+  @Override
+  protected List<ACL> createNonSecurityACLsToAdd() {
+    return createACLsToAdd(true);
+  }
+
+  /**
+   * Provider ACL Credential
+   *
+   * @return Set of ACLs to return security-related znodes
+   */
+  @Override
+  protected List<ACL> createSecurityACLsToAdd() {
+    return createACLsToAdd(false);
+  }
+
+  protected List<ACL> createACLsToAdd(boolean includeReadOnly) {
+    List<ACL> result = new ArrayList<>();

Review Comment:
   this is at most no larger than `zkCredentials.size()`? Which is usually 1 or 
2, right? can probably size the array a little better than default 10



##########
solr/solrj/src/java/org/apache/solr/common/cloud/DigestZkACLProvider.java:
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.solr.common.cloud;
+
+import static 
org.apache.zookeeper.server.auth.DigestAuthenticationProvider.generateDigest;
+
+import java.lang.invoke.MethodHandles;
+import java.security.NoSuchAlgorithmException;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.StringUtils;
+import org.apache.solr.common.cloud.ZkCredentialsInjector.ZkCredential;
+import org.apache.zookeeper.ZooDefs;
+import org.apache.zookeeper.data.ACL;
+import org.apache.zookeeper.data.Id;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A class that expects a {@link ZkCredentialsInjector} to create Zookeeper 
ACLs using digest scheme
+ */
+public class DigestZkACLProvider extends SecurityAwareZkACLProvider {
+
+  private static final Logger log = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+  /** Called by reflective instantiation */
+  public DigestZkACLProvider() {}
+
+  public DigestZkACLProvider(ZkCredentialsInjector zkCredentialsInjector) {
+    super(zkCredentialsInjector);
+  }
+
+  /**
+   * @return Set of ACLs to return for non-security related znodes
+   */
+  @Override
+  protected List<ACL> createNonSecurityACLsToAdd() {
+    return createACLsToAdd(true);
+  }
+
+  /**
+   * Provider ACL Credential
+   *
+   * @return Set of ACLs to return security-related znodes
+   */
+  @Override
+  protected List<ACL> createSecurityACLsToAdd() {
+    return createACLsToAdd(false);
+  }
+
+  protected List<ACL> createACLsToAdd(boolean includeReadOnly) {
+    List<ACL> result = new ArrayList<>();
+    List<ZkCredential> zkCredentials = 
zkCredentialsInjector.getZkCredentials();
+    log.debug("createACLsToAdd using ZkCredentials: {}", zkCredentials);
+    for (ZkCredential zkCredential : zkCredentials) {
+      if (StringUtils.isEmpty(zkCredential.getUsername())
+          || StringUtils.isEmpty(zkCredential.getPassword())) {
+        continue;
+      }
+      Id id = createACLId(zkCredential.getUsername(), 
zkCredential.getPassword());
+      int perms;
+      if (zkCredential.isAll()) {
+        // Not to have to provide too much credentials and ACL information to 
the process it is
+        // assumed that you want "ALL"-acls
+        // added to the user you are using to connect to ZK

Review Comment:
   this line wrapping is strange



##########
solr/solr-ref-guide/modules/deployment-guide/pages/zookeeper-access-control.adoc:
##########
@@ -56,9 +56,37 @@ ACLs describe who is allowed to read, update, delete, 
create, etc.
 Each piece of information (znode/content) in ZooKeeper has its own set of 
ACLs, and inheritance or sharing is not possible.
 The default behavior in Solr is to add one ACL on all the content it creates - 
one ACL that gives anyone the permission to do anything (in ZooKeeper terms 
this is called "the open-unsafe ACL").
 
+
+
+== Solr to Zookeeper ACLs Workflow
+
+* Solr to Zookeeper credentials and ACLs are controlled through 3 interfaces: 
{solr-javadocs}/solrj/org/apache/solr/common/cloud/ZkCredentialsInjector.html[`ZkCredentialsInjector`],
  
{solr-javadocs}/solrj/org/apache/solr/common/cloud/ZkCredentialsProvider.html[`ZkCredentialsProvider`]
 and 
{solr-javadocs}/solrj/org/apache/solr/common/cloud/ZkACLProvider.html[`ZkACLProvider`].
+
+* The classes implementing these 3 interfaces are passed to Solr via System 
Properties using the following properties names:
+`zkCredentialsInjector`, `zkACLProvider` and `zkCredentialsProvider`. See 
below sections for details.

Review Comment:
   I wonder if it makes sense to display this information in a tabular form.
   
   Class | System Property | Description
   ---|---|---
   ZkCredentialsInjector | zkCredentialsInjector | Class which gets credentials 
from some source
   ZkCredentialsProvider | ... | ...
   
   Also, the system properties are defined by the contents of `solr.xml` they 
are not necessarily universal. We should have ref to 
`configuring-solr-xml.adoc` here for that.



##########
solr/solrj/src/java/org/apache/solr/common/cloud/ZkCredentialsInjector.java:
##########
@@ -0,0 +1,94 @@
+/*
+ * 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.solr.common.cloud;
+
+import java.util.List;
+
+/**
+ * A class that retrieves Zookeeper credentials from some source to be 
injected into {@link
+ * DigestZkCredentialsProvider} and {@link DigestZkACLProvider}. The source 
here can be System
+ * Props, a file, a Secret Manager, or any other local or remote source.
+ */
+public interface ZkCredentialsInjector {
+
+  /**
+   * @return List of {@link ZkCredential}s representing Zookeeper credentials 
including the
+   *     username, the password and the permissions (ALL or READ)
+   */
+  List<ZkCredential> getZkCredentials();
+
+  class ZkCredential {
+
+    public enum Perms {
+      ALL,
+      READ
+    }
+
+    private String username;
+    private String password;
+    private String perms;
+
+    public ZkCredential() {}
+
+    public ZkCredential(String username, String password, Perms perms) {
+      this(username, password, String.valueOf(perms));
+    }
+
+    public ZkCredential(String username, String password, String perms) {
+      this.username = username;
+      this.password = password;
+      this.perms = perms;
+    }
+
+    public String getUsername() {
+      return username;
+    }
+
+    public String getPassword() {

Review Comment:
   this is outside of the scope of the PR, but I really hate seeing passwords 
stored as string objects.



-- 
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: issues-unsubscr...@solr.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org
For additional commands, e-mail: issues-h...@solr.apache.org

Reply via email to