xiangfu0 commented on code in PR #20121:
URL: https://github.com/apache/pinot/pull/20121#discussion_r4442194429


##########
pinot-connectors/pinot-flink-connector/src/main/java/org/apache/pinot/connector/flink/sink/PinotSink.java:
##########
@@ -137,6 +140,21 @@ static TableConfig prepareTableConfigForSink(TableConfig 
tableConfig, String con
     return tableConfig;
   }
 
+  /// Builds an [AuthProvider] from the `authToken` in the table's batch 
config, or returns null if none is set.

Review Comment:
   (minor, docs) The "set the token only on the in-memory `TableConfig`, never 
on the controller-stored config" guidance is only in the PR description, and 
the connector README doesn't mention auth. Could you add a sentence here and a 
short auth section to `pinot-connectors/pinot-flink-connector/README.md` so the 
guidance ships with the code?



##########
pinot-connectors/pinot-flink-connector/src/test/java/org/apache/pinot/connector/flink/sink/PinotSinkAuthIntegrationTest.java:
##########
@@ -0,0 +1,152 @@
+/**
+ * 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.pinot.connector.flink.sink;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.apache.commons.io.FileUtils;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.common.typeinfo.Types;
+import org.apache.flink.api.java.typeutils.RowTypeInfo;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.types.Row;
+import org.apache.pinot.connector.flink.common.FlinkRowGenericRowConverter;
+import org.apache.pinot.integration.tests.BaseClusterIntegrationTest;
+import org.apache.pinot.integration.tests.BasicAuthTestUtils;
+import org.apache.pinot.spi.config.table.TableConfig;
+import org.apache.pinot.spi.config.table.TableType;
+import org.apache.pinot.spi.config.table.ingestion.BatchIngestionConfig;
+import org.apache.pinot.spi.config.table.ingestion.IngestionConfig;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.apache.pinot.spi.data.Schema;
+import org.apache.pinot.spi.env.PinotConfiguration;
+import org.apache.pinot.spi.ingestion.batch.BatchConfigProperties;
+import org.apache.pinot.spi.utils.builder.TableConfigBuilder;
+import org.apache.pinot.spi.utils.builder.TableNameBuilder;
+import org.apache.pinot.util.TestUtils;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertEquals;
+
+
+/// Runs [PinotSink] against a cluster with Basic Auth enabled on the 
controller.
+public class PinotSinkAuthIntegrationTest extends BaseClusterIntegrationTest {
+  private static final String RAW_TABLE_NAME = "authTable";
+  private static final String OFFLINE_TABLE_NAME = 
TableNameBuilder.OFFLINE.tableNameWithType(RAW_TABLE_NAME);
+
+  private List<Row> _data;
+  private RowTypeInfo _typeInfo;
+  private Schema _schema;
+
+  @Override
+  protected void overrideControllerConf(Map<String, Object> properties) {
+    BasicAuthTestUtils.addControllerConfiguration(properties);
+  }
+
+  @Override
+  protected void overrideBrokerConf(PinotConfiguration brokerConf) {
+    BasicAuthTestUtils.addBrokerConfiguration(brokerConf);
+  }
+
+  @Override
+  protected void overrideServerConf(PinotConfiguration serverConf) {
+    BasicAuthTestUtils.addServerConfiguration(serverConf);
+  }
+
+  @Override
+  protected Map<String, String> getAdminClientHeaders() {
+    return BasicAuthTestUtils.AUTH_HEADER;
+  }
+
+  @BeforeClass
+  public void setUp()
+      throws Exception {
+    TestUtils.ensureDirectoriesExistAndEmpty(_tempDir, _segmentDir, _tarDir);
+
+    startZk();
+    startController();
+    startBroker();
+    startServer();
+
+    _data = Arrays.asList(Row.of(1, 1L, "Hi"), Row.of(2, 2L, "Hello"), 
Row.of(3, 3L, "Hello world"));
+    _typeInfo =
+        new RowTypeInfo(new TypeInformation[]{Types.INT, Types.LONG, 
Types.STRING}, new String[]{"a", "b", "c"});
+    _schema =
+        new 
Schema.SchemaBuilder().setSchemaName(RAW_TABLE_NAME).addSingleValueDimension("a",
 FieldSpec.DataType.INT)
+            .addSingleValueDimension("b", FieldSpec.DataType.LONG)
+            .addSingleValueDimension("c", FieldSpec.DataType.STRING).build();
+
+    addSchema(_schema);
+    // The table config stored in the controller never contains the token
+    addTableConfig(createSinkTableConfig(null));
+  }
+
+  @AfterClass
+  public void tearDown()
+      throws Exception {
+    dropOfflineTable(OFFLINE_TABLE_NAME);
+    deleteSchema(RAW_TABLE_NAME);
+
+    stopServer();
+    stopBroker();
+    stopController();
+    stopZk();
+
+    FileUtils.deleteDirectory(_tempDir);
+  }
+
+  @Test
+  public void testUploadSucceedsWithAuthToken()
+      throws Exception {
+    // The token is only set on the in-memory table config passed to the sink
+    runSink(createSinkTableConfig(BasicAuthTestUtils.AUTH_TOKEN));
+
+    List<String> segments = getOrCreateAdminClient().getSegmentClient()
+        .listSegments(OFFLINE_TABLE_NAME, TableType.OFFLINE.toString(), false);
+    assertEquals(segments.size(), 1);

Review Comment:
   (minor, testing) This catches a propagation regression (I checked by 
mutation), but nothing shows the cluster actually enforces auth. If 
`BasicAuthTestUtils` ever stopped enabling it, the test would pass without 
testing anything. A quick check that avoids the #20133 `close()` issue: assert 
that an unauthenticated controller request (e.g. listing segments without 
headers) gets 401.



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