yifan-c commented on code in PR #165: URL: https://github.com/apache/cassandra-sidecar/pull/165#discussion_r1902265517
########## server/src/main/java/org/apache/cassandra/sidecar/routes/KeyspaceSchemaHandler.java: ########## @@ -0,0 +1,157 @@ +/* + * 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.sidecar.routes; + +import java.util.Set; + +import com.google.common.collect.ImmutableSet; + +import com.datastax.driver.core.KeyspaceMetadata; +import com.datastax.driver.core.Metadata; +import com.google.inject.Inject; +import com.google.inject.Singleton; +import io.netty.handler.codec.http.HttpResponseStatus; +import io.vertx.core.Future; +import io.vertx.core.http.HttpServerRequest; +import io.vertx.core.net.SocketAddress; +import io.vertx.ext.auth.authorization.Authorization; +import io.vertx.ext.auth.authorization.OrAuthorization; +import io.vertx.ext.web.RoutingContext; +import org.apache.cassandra.sidecar.acl.authorization.CassandraPermissions; +import org.apache.cassandra.sidecar.acl.authorization.SidecarPermissions; +import org.apache.cassandra.sidecar.acl.authorization.VariableAwareResource; +import org.apache.cassandra.sidecar.cluster.CassandraAdapterDelegate; +import org.apache.cassandra.sidecar.common.response.SchemaResponse; +import org.apache.cassandra.sidecar.common.server.data.Name; +import org.apache.cassandra.sidecar.concurrent.ExecutorPools; +import org.apache.cassandra.sidecar.utils.CassandraInputValidator; +import org.apache.cassandra.sidecar.utils.InstanceMetadataFetcher; +import org.apache.cassandra.sidecar.utils.MetadataUtils; + +import static org.apache.cassandra.sidecar.utils.HttpExceptions.cassandraServiceUnavailable; +import static org.apache.cassandra.sidecar.utils.HttpExceptions.wrapHttpException; + +/** + * The {@link KeyspaceSchemaHandler} class handles schema request for a keyspace + */ +@Singleton +public class KeyspaceSchemaHandler extends AbstractHandler<Name> implements AccessProtected Review Comment: Same, please drop this class or extend from `SchemaHandler`. ########## server/src/test/java/org/apache/cassandra/sidecar/server/ServerTest.java: ########## @@ -308,6 +308,16 @@ void unrecognizedAuthenticationHandlerSet() "UnrecognizedAuthenticationHandler has not been registered"); } + @Test + @DisplayName("Invalid access control config, unrecognized authorization provider set") + void unrecognizedAuthorizationProviderSet() + { + assertThatThrownBy(() -> configureServer("config/sidecar_unrecognized_authorizer.yaml")) + .hasCauseInstanceOf(RuntimeException.class) Review Comment: can it throw a dedicated exception instead of `RuntimeException`? ########## server/src/main/java/org/apache/cassandra/sidecar/routes/KeyspaceRingHandler.java: ########## @@ -0,0 +1,105 @@ +package org.apache.cassandra.sidecar.routes; + +import java.util.Set; + +import com.google.common.collect.ImmutableSet; + +import org.apache.commons.lang3.StringUtils; + +import com.google.inject.Inject; +import com.google.inject.Singleton; +import io.netty.handler.codec.http.HttpResponseStatus; +import io.vertx.core.http.HttpServerRequest; +import io.vertx.core.net.SocketAddress; +import io.vertx.ext.auth.authorization.Authorization; +import io.vertx.ext.web.RoutingContext; +import org.apache.cassandra.sidecar.acl.authorization.SidecarPermissions; +import org.apache.cassandra.sidecar.acl.authorization.VariableAwareResource; +import org.apache.cassandra.sidecar.cluster.CassandraAdapterDelegate; +import org.apache.cassandra.sidecar.common.server.StorageOperations; +import org.apache.cassandra.sidecar.common.server.data.Name; +import org.apache.cassandra.sidecar.concurrent.ExecutorPools; +import org.apache.cassandra.sidecar.utils.CassandraInputValidator; +import org.apache.cassandra.sidecar.utils.InstanceMetadataFetcher; + +import static org.apache.cassandra.sidecar.utils.HttpExceptions.cassandraServiceUnavailable; +import static org.apache.cassandra.sidecar.utils.HttpExceptions.wrapHttpException; + +/** + * A handler that provides ring information for a specific keyspace for the Cassandra cluster + */ +@Singleton +public class KeyspaceRingHandler extends AbstractHandler<Name> implements AccessProtected Review Comment: Can you either drop this class and only have `RingHandler`? or extend from `RingHandler` to remove code duplication? ########## server/src/main/java/org/apache/cassandra/sidecar/routes/restore/RestoreJobSummaryHandler.java: ########## @@ -50,6 +59,17 @@ public RestoreJobSummaryHandler(ExecutorPools executorPools, super(instanceMetadataFetcher, executorPools, validator); } + @Override + public Set<Authorization> requiredAuthorizations() + { + String resource = VariableAwareResource.DATA_WITH_KEYSPACE_TABLE.resource(); + Authorization createRestore = SidecarPermissions.CREATE_RESTORE_JOB.toAuthorization(resource); + Authorization viewRestore = SidecarPermissions.VIEW_RESTORE_JOB.toAuthorization(resource); + OrAuthorization createOrView + = new OrAuthorizationImpl().addAuthorization(createRestore).addAuthorization(viewRestore); + return ImmutableSet.of(createOrView); Review Comment: Same, why allow `create`? ########## server/src/main/java/org/apache/cassandra/sidecar/routes/restore/RestoreJobProgressHandler.java: ########## @@ -64,6 +73,17 @@ public RestoreJobProgressHandler(InstanceMetadataFetcher metadataFetcher, this.consistencyLevelChecker = consistencyLevelChecker; } + @Override + public Set<Authorization> requiredAuthorizations() + { + String resource = VariableAwareResource.DATA_WITH_KEYSPACE_TABLE.resource(); + Authorization createRestore = SidecarActions.CREATE_RESTORE.toAuthorization(resource); + Authorization viewRestore = SidecarActions.VIEW_RESTORE.toAuthorization(resource); + OrAuthorization createOrView Review Comment: Is there any overlap between `CREATE` and `VIEW`? For this endpoint, I think only view is required. What is the reasoning of allowing a user with `CREATE` only permission to view the progress? ########## server/src/main/java/org/apache/cassandra/sidecar/routes/KeyspaceRingHandler.java: ########## @@ -0,0 +1,105 @@ +package org.apache.cassandra.sidecar.routes; + +import java.util.Set; + +import com.google.common.collect.ImmutableSet; + +import org.apache.commons.lang3.StringUtils; + +import com.google.inject.Inject; +import com.google.inject.Singleton; +import io.netty.handler.codec.http.HttpResponseStatus; +import io.vertx.core.http.HttpServerRequest; +import io.vertx.core.net.SocketAddress; +import io.vertx.ext.auth.authorization.Authorization; +import io.vertx.ext.web.RoutingContext; +import org.apache.cassandra.sidecar.acl.authorization.SidecarPermissions; +import org.apache.cassandra.sidecar.acl.authorization.VariableAwareResource; +import org.apache.cassandra.sidecar.cluster.CassandraAdapterDelegate; +import org.apache.cassandra.sidecar.common.server.StorageOperations; +import org.apache.cassandra.sidecar.common.server.data.Name; +import org.apache.cassandra.sidecar.concurrent.ExecutorPools; +import org.apache.cassandra.sidecar.utils.CassandraInputValidator; +import org.apache.cassandra.sidecar.utils.InstanceMetadataFetcher; + +import static org.apache.cassandra.sidecar.utils.HttpExceptions.cassandraServiceUnavailable; +import static org.apache.cassandra.sidecar.utils.HttpExceptions.wrapHttpException; + +/** + * A handler that provides ring information for a specific keyspace for the Cassandra cluster + */ +@Singleton +public class KeyspaceRingHandler extends AbstractHandler<Name> implements AccessProtected +{ + @Inject + public KeyspaceRingHandler(InstanceMetadataFetcher metadataFetcher, + CassandraInputValidator validator, + ExecutorPools executorPools) + { + super(metadataFetcher, executorPools, validator); + } + + @Override + public Set<Authorization> requiredAuthorizations() + { + String resource = VariableAwareResource.DATA_WITH_KEYSPACE.resource(); + return ImmutableSet.of(SidecarPermissions.VIEW_CLUSTER.toAuthorization(resource)); + } Review Comment: The method seems to be the only reason that this class exists. Since the `requiredAuthorizations` is configured statically, maybe extending from `RingHandler` and only overriding `requiredAuthorizations` is a more viable option. -- 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: pr-unsubscr...@cassandra.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org For additional commands, e-mail: pr-h...@cassandra.apache.org