morningman commented on code in PR #70903:
URL: https://github.com/apache/doris/pull/70903#discussion_r4677086789
##########
fe/fe-core/src/main/java/org/apache/doris/tablefunction/ExternalFileTableValuedFunction.java:
##########
@@ -214,6 +223,84 @@ protected void parseFile(List<TBrokerFileStatus> files)
throws AnalysisException
}
+ /**
+ * The endpoint white list and SSRF check of an object-storage location,
which the FE reaches before any BE
+ * does: listing its files, or a plugin reading the data set there.
+ */
+ private static void validateEndpoint(BrokerDesc brokerDesc) throws
UserException {
+ // "Object storage" here means an S3-compatible binding
(S3/OSS/OBS/COS/GCS/MinIO/
+ // Ozone) — the exact implementor set of the legacy object-storage
marker interface;
+ // Azure deliberately stays excluded, matching the legacy instanceof
check.
+ StorageAdapter storageAdapter = brokerDesc.getStorageAdapter();
+ if (storageAdapter != null
+ && storageAdapter.getSpiProperties() instanceof
S3CompatibleFileSystemProperties) {
+ S3Util.validateAndTestEndpoint(
+ ((S3CompatibleFileSystemProperties)
storageAdapter.getSpiProperties()).getEndpoint());
+ }
+ }
+
+ /** Whether a connector plugin reads this table function's format; see
{@link #readPluginFormat}. */
+ public boolean isPluginFormat() {
+ return pluginFormat != null;
+ }
+
+ /**
+ * Hands the location to the plugin that reads this table function's
format, after the endpoint check a listing
+ * gets, and takes the columns from what the plugin resolved. The plugin
interprets the data set as a whole, so
+ * nothing is listed, and it pins what the statement reads.
+ */
+ protected void readPluginFormat() throws AnalysisException {
+ // s3() reports FILE_S3 whatever it binds, Azure included, and
rewrites an Azure location to
+ // s3://container/path, which a plugin would read with no S3 storage
at all.
+ if (!(storageAdapter.getSpiProperties() instanceof
S3CompatibleFileSystemProperties)) {
+ throw pluginFormatOutsideS3(pluginFormat.getFormat());
+ }
+ long startAt = System.currentTimeMillis();
+ try {
+ validateEndpoint(getBrokerDesc());
+ ConnectorFileSource source = new
ConnectorFileSource(pluginFormat.getFormat(), filePath,
+
Collections.singletonList(storageAdapter.getSpiProperties()),
backendConnectProperties);
+ ConnectorSession session = pluginFormat.buildSession();
+ ConnectorMetadata metadata = PluginDrivenMetadata.get(session,
pluginFormat.getConnector());
+ pluginTableHandle = ((ConnectorFileSourceOps)
metadata).getFileTableHandle(session, source);
+ List<Column> pluginColumns =
ConnectorColumnConverter.convertColumns(
+ metadata.getTableSchema(session,
pluginTableHandle).getColumns());
+ // Kept in the plugin's spelling; names that differ only in case
are refused, as a file's are.
+ Set<String> columnLowerNames = new HashSet<>();
+ for (Column column : pluginColumns) {
+ addColumnLowerName(columnLowerNames, column.getName());
+ }
+ columns = pluginColumns;
+ } catch (UserException e) {
+ throw new AnalysisException("parse file failed, err: " +
e.getMessage(), e);
+ } catch (DorisConnectorException e) {
+ throw new AnalysisException(e.getMessage(), e);
+ } finally {
+ SummaryProfile profile =
SummaryProfile.getSummaryProfile(ConnectContext.get());
+ if (profile != null) {
+ profile.addExternalTvfInitTime(System.currentTimeMillis() -
startAt);
+ }
+ }
+ }
+
+ /** A plugin reads its data set from object storage by the S3 vocabulary,
which only s3() hands over. */
+ private static AnalysisException pluginFormatOutsideS3(String format) {
+ return new AnalysisException("Format " + format + " is read only by
the s3() table function,"
+ + " or by file() over S3-compatible storage");
+ }
+
+ /**
+ * Records a column's name in lower case and returns it, refusing a name
another column already took: Doris
+ * resolves column names regardless of case, so two columns whose names
differ only in case cannot be told apart.
+ */
+ private static String addColumnLowerName(Set<String> columnLowerNames,
String columnName) {
+ String colLowerName = columnName.toLowerCase();
Review Comment:
Fix this in another PR
--
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]