You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2022/04/05 20:59:21 UTC

[GitHub] [druid] clintropolis commented on a diff in pull request #12396: Add support for authorizing query context params

clintropolis commented on code in PR #12396:
URL: https://github.com/apache/druid/pull/12396#discussion_r843244684


##########
server/src/main/java/org/apache/druid/server/QueryLifecycle.java:
##########
@@ -82,13 +91,43 @@
   private final RequestLogger requestLogger;
   private final AuthorizerMapper authorizerMapper;
   private final DefaultQueryConfig defaultQueryConfig;
+  private final AuthConfig authConfig;
   private final long startMs;
   private final long startNs;
 
   private State state = State.NEW;
   private AuthenticationResult authenticationResult;
   private QueryToolChest toolChest;
-  private Query baseQuery;
+
+  /**
+   * A holder for the user query to run.
+   *
+   * The holder has a state for query context.
+   * The query context in {@link QueryHolder#delegate#context} is not valid until they are authorized.
+   * {@link #context} should be used instead to get query context until authorized.
+   *
+   * Variable state change flow:
+   *
+   * - Initialized to null.
+   * - Set in {@link #initialize}.
+   * - Updated with context after authorization in {@link #doAuthorize}.
+   */
+  @MonotonicNonNull
+  private QueryHolder<?> baseQuery;

Review Comment:
   this seems error prone to have two contexts like this with one hidden in the wrapper, I think it might be easier to follow what is going on here to keep this as a `Query` and have a `baseContext` separate from the `context`.



##########
server/src/main/java/org/apache/druid/server/QueryHolder.java:
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.druid.server;
+
+import com.google.common.base.Preconditions;
+import org.apache.druid.query.DataSource;
+import org.apache.druid.query.Query;
+
+/**
+ * Holder of a native Druid query.
+ *
+ * The native Druid query object has query context parameters in it (see {@link Query#getContext()}).
+ * During query processing, Druid can add extra parameters as it needs. However, when authorizing context params,
+ * only the params that the user sets should be authorized. To separate user params from others,
+ * the Druid native query entry uses {@link QueryContext}. After user context params are authorized
+ * in {@link QueryLifecycle#authorize}, QueryLifecycle sets the query context back to this query holder
+ * using {@link #withContext(QueryContext)}. When callers use query context, they should check first
+ * if the query holder has a valid query context using {@link #isValidContext()}.
+ */
+public class QueryHolder<T>

Review Comment:
   this feels somewhat sad given the existence of `QueryPlus`, the other wrapper, though i guess it is used for processing queries instead of the lead up to it... still, seems like we have too many wrappers...



##########
server/src/main/java/org/apache/druid/server/QueryResource.java:
##########
@@ -184,28 +180,19 @@ public Response doPost(
   ) throws IOException
   {
     final QueryLifecycle queryLifecycle = queryLifecycleFactory.factorize();
-    Query<?> query = null;
 
     final ResourceIOReaderWriter ioReaderWriter = createResourceIOReaderWriter(req, pretty != null);
 
     final String currThreadName = Thread.currentThread().getName();
     try {
-      queryLifecycle.initialize(readQuery(req, in, ioReaderWriter));
-      query = queryLifecycle.getQuery();
-      final String queryId = query.getId();
-
-      final String queryThreadName = StringUtils.format(
-          "%s[%s_%s_%s]",
-          currThreadName,
-          query.getType(),
-          query.getDataSource().getTableNames(),
-          queryId
-      );
-
+      final NonnullPair<QueryHolder<?>, QueryContext> pair = readQuery(req, in, ioReaderWriter);

Review Comment:
   again this feels confusing to have two query contexts, one of which is wrapped, i'd personally probably rather just see them all separately to make it easier to follow what is what



-- 
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: commits-unsubscribe@druid.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org