beobal commented on a change in pull request #1208:
URL: https://github.com/apache/cassandra/pull/1208#discussion_r729586250



##########
File path: 
test/unit/org/apache/cassandra/auth/CassandraNetworkAuthorizerTest.java
##########
@@ -63,13 +62,12 @@ public static void setupSuperUser()
     public static void defineSchema() throws ConfigurationException
     {
         SchemaLoader.prepareServer();
-        SchemaLoader.setupAuth(new LocalCassandraRoleManager(),
-                               new PasswordAuthenticator(),
-                               new AuthTestUtils.LocalCassandraAuthorizer(),
-                               new 
AuthTestUtils.LocalCassandraNetworkAuthorizer());
+        SchemaLoader.setupAuth(new AuthTestUtils.LocalCassandraRoleManager(),

Review comment:
       nit: this is highly subjective, but I find the original alignment more 
readable. It wouldn't stop me +1'ing a patch, but I just wanted to mention in 
case it was done by an IDE unintentionally. (nb. applies in multiple locations 
in the PR)

##########
File path: 
test/unit/org/apache/cassandra/db/virtual/CredentialsCacheKeysTableTest.java
##########
@@ -0,0 +1,180 @@
+/*
+ * 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.cassandra.db.virtual;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.datastax.driver.core.EndPoint;
+import com.datastax.driver.core.PlainTextAuthProvider;
+import org.apache.cassandra.SchemaLoader;
+import org.apache.cassandra.auth.AuthTestUtils;
+import org.apache.cassandra.auth.AuthenticatedUser;
+import org.apache.cassandra.auth.IAuthenticator;
+import org.apache.cassandra.auth.RoleResource;
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.cql3.CQLTester;
+import org.apache.cassandra.cql3.UntypedResultSet;
+
+import static org.apache.cassandra.auth.AuthTestUtils.ROLE_A;
+import static org.apache.cassandra.auth.AuthTestUtils.ROLE_B;
+
+public class CredentialsCacheKeysTableTest extends CQLTester
+{
+    private static final String KS_NAME = "vts";
+    private static AuthTestUtils.LocalPasswordAuthenticator 
passwordAuthenticator;
+
+    @SuppressWarnings("FieldCanBeLocal")
+    private CredentialsCacheKeysTable table;
+
+    @BeforeClass
+    public static void setUpClass()
+    {
+        // high value is used for convenient debugging
+        DatabaseDescriptor.setPermissionsValidity(20_000);
+
+        CQLTester.setUpClass();
+        AuthTestUtils.LocalCassandraRoleManager roleManager = new 
AuthTestUtils.LocalCassandraRoleManager();
+        passwordAuthenticator = new AuthTestUtils.LocalPasswordAuthenticator();
+        SchemaLoader.setupAuth(roleManager,
+                passwordAuthenticator,
+                new AuthTestUtils.LocalCassandraAuthorizer(),
+                new AuthTestUtils.LocalCassandraNetworkAuthorizer());
+
+        roleManager.createRole(AuthenticatedUser.SYSTEM_USER, ROLE_A, 
AuthTestUtils.getLoginRoleOprions());

Review comment:
       typo here, which is common to all the new `*CacheKeysTableTest` and 
causes compilation failures. 

##########
File path: src/java/org/apache/cassandra/auth/PasswordAuthenticator.java
##########
@@ -69,14 +69,18 @@
     static final byte NUL = 0;
     private SelectStatement authenticateStatement;
 
-    private CredentialsCache cache;
+    private static CredentialsCache cache;
 
     // No anonymous access.
     public boolean requireAuthentication()
     {
         return true;
     }
 
+    public static CredentialsCache getCredentialsCache() {

Review comment:
       I don't see a problem with making the caches public and breaking 
encapsulation/making them all first class citizens. In fact, they are intended 
to be independent of the underlying auth implementations as far as is possible, 
it's just that the nature of SASL authentication doesn't lend itself to a 
generic caching approach in the same way as simple user/pass credentials do.

##########
File path: src/java/org/apache/cassandra/db/virtual/PermissionsCacheTable.java
##########
@@ -0,0 +1,90 @@
+/*
+ * 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.cassandra.db.virtual;
+
+import java.util.Optional;
+import java.util.Set;
+
+import org.apache.cassandra.auth.AuthenticatedUser;
+import org.apache.cassandra.auth.IResource;
+import org.apache.cassandra.auth.Permission;
+import org.apache.cassandra.auth.Resources;
+import org.apache.cassandra.db.marshal.UTF8Type;
+import org.apache.cassandra.dht.LocalPartitioner;
+import org.apache.cassandra.schema.TableMetadata;
+import org.apache.cassandra.utils.Pair;
+
+final class PermissionsCacheTable extends AbstractMutableVirtualTable
+{
+    private static final String ROLE = "role";
+    private static final String RESOURCE = "resource";
+    private static final String PERMISSION = "permission";
+
+    PermissionsCacheTable(String keyspace)
+    {
+        super(TableMetadata.builder(keyspace, "permissions_cache")
+                .comment("Permissions cache")
+                .kind(TableMetadata.Kind.VIRTUAL)
+                .partitioner(new LocalPartitioner(UTF8Type.instance))
+                .addPartitionKeyColumn(ROLE, UTF8Type.instance)
+                .addPartitionKeyColumn(RESOURCE, UTF8Type.instance)
+                .addClusteringColumn(PERMISSION, UTF8Type.instance)

Review comment:
       This still has the individual permission as a clustering column. As 
mentioned on the JIRA, this mismatches the underlying auth cache, which _only_ 
maps role/resource pairs to a set of permissions.  IMO introducing a mismatch 
like this between the public API of the cache and the VT supposed to represent 
it is confusing and unnecessary.

##########
File path: 
src/java/org/apache/cassandra/db/virtual/JmxPermissionsCacheTable.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.cassandra.db.virtual;
+
+import java.util.Optional;
+import java.util.Set;
+
+import org.apache.cassandra.auth.IResource;
+import org.apache.cassandra.auth.Permission;
+import org.apache.cassandra.auth.PermissionDetails;
+import org.apache.cassandra.auth.Resources;
+import org.apache.cassandra.auth.RoleResource;
+import org.apache.cassandra.auth.jmx.AuthorizationProxy;
+import org.apache.cassandra.db.marshal.UTF8Type;
+import org.apache.cassandra.dht.LocalPartitioner;
+import org.apache.cassandra.schema.TableMetadata;
+
+final class JmxPermissionsCacheTable extends AbstractMutableVirtualTable
+{
+    private static final String ROLE = "role";
+    private static final String GRANTEE = "grantee";
+    private static final String RESOURCE = "resource";
+    private static final String PERMISSION = "permission";
+
+    JmxPermissionsCacheTable(String keyspace)
+    {
+        super(TableMetadata.builder(keyspace, "jmx_permissions_cache")
+                .comment("JMX permissions cache")
+                .kind(TableMetadata.Kind.VIRTUAL)
+                .partitioner(new LocalPartitioner(UTF8Type.instance))
+                .addPartitionKeyColumn(ROLE, UTF8Type.instance)
+                .addClusteringColumn(GRANTEE, UTF8Type.instance)
+                .addClusteringColumn(RESOURCE, UTF8Type.instance)
+                .addClusteringColumn(PERMISSION, UTF8Type.instance)

Review comment:
       Same comment applies here as to the main (non-jmx) permissions cache wrt 
to granularity & clustering columns

##########
File path: src/java/org/apache/cassandra/auth/Roles.java
##########
@@ -38,26 +35,8 @@
 
     private static final Role NO_ROLE = new Role("", false, false, 
Collections.emptyMap(), Collections.emptySet());
 
-    private static RolesCache cache;
-    static
-    {
-        initRolesCache(DatabaseDescriptor.getRoleManager(),
-                       () -> 
DatabaseDescriptor.getAuthenticator().requireAuthentication());
-    }
-
-    @VisibleForTesting
-    public static void initRolesCache(IRoleManager roleManager, 
BooleanSupplier enableCache)
-    {
-        if (cache != null)
-            cache.unregisterMBean();
-        cache = new RolesCache(roleManager, enableCache);
-    }
-
-    @VisibleForTesting
-    public static void clearCache()
-    {
-        cache.invalidate();
-    }
+    public static final RolesCache cache = new 
RolesCache(DatabaseDescriptor.getRoleManager(),

Review comment:
       This seems to have overlapped with CASSANDRA-17016 being committed and 
which makes use of `initRolesCache`.

##########
File path: src/java/org/apache/cassandra/db/virtual/PermissionsCacheTable.java
##########
@@ -0,0 +1,90 @@
+/*
+ * 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.cassandra.db.virtual;
+
+import java.util.Optional;
+import java.util.Set;
+
+import org.apache.cassandra.auth.AuthenticatedUser;
+import org.apache.cassandra.auth.IResource;
+import org.apache.cassandra.auth.Permission;
+import org.apache.cassandra.auth.Resources;
+import org.apache.cassandra.db.marshal.UTF8Type;
+import org.apache.cassandra.dht.LocalPartitioner;
+import org.apache.cassandra.schema.TableMetadata;
+import org.apache.cassandra.utils.Pair;
+
+final class PermissionsCacheTable extends AbstractMutableVirtualTable
+{
+    private static final String ROLE = "role";
+    private static final String RESOURCE = "resource";
+    private static final String PERMISSION = "permission";
+
+    PermissionsCacheTable(String keyspace)
+    {
+        super(TableMetadata.builder(keyspace, "permissions_cache")
+                .comment("Permissions cache")
+                .kind(TableMetadata.Kind.VIRTUAL)
+                .partitioner(new LocalPartitioner(UTF8Type.instance))
+                .addPartitionKeyColumn(ROLE, UTF8Type.instance)
+                .addPartitionKeyColumn(RESOURCE, UTF8Type.instance)
+                .addClusteringColumn(PERMISSION, UTF8Type.instance)

Review comment:
       This still has the individual permission as a clustering column. As 
mentioned on the JIRA, this mismatches the underlying auth cache, which _only_ 
maps role/resource pairs to a set of permissions.  IMO introducing a mismatch 
like this between the public API of the cache and the VT supposed to represent 
it is confusing and unnecessary.




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



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

Reply via email to