Skip to content

Commit c67c552

Browse files
committed
[fix](lance) Address review of the OSS storage provider
An independent review of the previous commit found six issues, four of them regressions it had introduced: - safeCause now always rebuilds the cause, but LanceExternalCatalog had no logger, so the original type, stack and suppressed exceptions were lost with nothing recording them. Log the throwable at debug level: its text can carry the very credentials the message just redacted, so it must not reach the log by default. - The connectivity test passed the warehouse as the dataset URI, so a mistyped bucket came back as *** - blanking the string from the operator's own DDL that they most needed to see. - The anonymous test used isBlank while the emitter used isEmpty, so a whitespace-only key pair emitted a credential and allow_anonymous together; OpenDAL then signs with the blank key and cannot fall back. Decide from what was actually emitted instead. - The bucket rewrite also fired on OSS-HDFS roots, whose qualified authority is the required spelling rather than an incidental one. Also state addressing_style for both values as the S3 provider does: lance snapshots the host's OSS_/AWS_ environment into the same config map before storage options are applied, so leaving the default implicit let an exported OSS_ADDRESSING_STYLE outrank an explicit oss.use_path_style=false. Drop a stale @VisibleForTesting and a duplicate Javadoc on the now-public rewrite helper, and correct the base-scoped redaction comment: the pinned lance keys per-base configuration by a nested map, not by a flat dotted option, so suffix matching is defensive rather than a documented contract. Claude-Session: https://claude.ai/code/session_01N7CgMhLYRyy66DYWyxtDy5
1 parent 7205f2a commit c67c552

6 files changed

Lines changed: 83 additions & 23 deletions

File tree

‎fe/fe-core/src/main/java/org/apache/doris/datasource/lance/LanceExternalCatalog.java‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import org.apache.arrow.memory.RootAllocator;
3535
import org.apache.commons.lang3.StringUtils;
3636
import org.apache.commons.lang3.exception.ExceptionUtils;
37+
import org.apache.logging.log4j.LogManager;
38+
import org.apache.logging.log4j.Logger;
3739
import org.lance.namespace.LanceNamespace;
3840
import org.lance.namespace.errors.NamespaceNotFoundException;
3941
import org.lance.namespace.errors.TableNotFoundException;
@@ -60,6 +62,7 @@
6062

6163
/** Read-only Lance Directory or REST Namespace catalog. */
6264
public class LanceExternalCatalog extends ExternalCatalog {
65+
private static final Logger LOG = LogManager.getLogger(LanceExternalCatalog.class);
6366
public static final String LANCE_CATALOG_TYPE = AbstractLanceProperties.LANCE_CATALOG_TYPE;
6467
public static final String LANCE_FILESYSTEM = AbstractLanceProperties.LANCE_FILESYSTEM;
6568
public static final String LANCE_REST = AbstractLanceProperties.LANCE_REST;
@@ -145,9 +148,10 @@ public void checkWhenCreating() throws DdlException {
145148
}
146149
} catch (Exception e) {
147150
// The catalog is not initialized yet, so the namespace options this test just built are
148-
// the only ones the sanitizer can see.
149-
String sanitizedMessage = sanitizedRootCauseMessage(
150-
e, properties.getNamespaceStorageUri(), storageOptions);
151+
// the only ones the sanitizer can see. The warehouse is deliberately not passed as the
152+
// dataset URI: it came from this very DDL, and blanking it would hide the mistyped
153+
// bucket the operator needs to see.
154+
String sanitizedMessage = sanitizedRootCauseMessage(e, null, storageOptions);
151155
throw new DdlException("Lance " + type + " catalog connectivity test failed: "
152156
+ sanitizedMessage, sanitizedCause(e, sanitizedMessage));
153157
}
@@ -489,8 +493,9 @@ String sanitizedRootCauseMessage(Throwable throwable, String datasetUri,
489493
List<String> sensitiveValues = new ArrayList<>();
490494
sensitiveValues.add(catalogProperty.getOrDefault(REST_BEARER_TOKEN, ""));
491495
sensitiveValues.add(catalogProperty.getOrDefault(REST_API_KEY, ""));
492-
// Lance also accepts these options scoped to one base, as base_<id>.oss_secret_access_key,
493-
// so match on the suffix rather than looking each bare key up exactly.
496+
// Match on a trailing dotted segment as well as the bare key, so any namespace that scopes
497+
// an option to one store still has its secret redacted. Over-redaction costs nothing here,
498+
// while an exact-key lookup would print a secret it did not recognize.
494499
nonNullStorageOptions.forEach((key, value) -> {
495500
if (key == null) {
496501
return;
@@ -521,6 +526,13 @@ private Throwable safeCause(Throwable throwable) {
521526
}
522527

523528
private static Throwable sanitizedCause(Throwable throwable, String sanitizedMessage) {
529+
// The rebuilt cause keeps the provider's credentials out of the user-visible error, but it
530+
// also drops the original type, stack and suppressed exceptions. Keep them at debug level:
531+
// the untouched text can hold those same credentials, so it must not reach the log by
532+
// default, and an operator debugging a provider failure can turn it on deliberately.
533+
if (LOG.isDebugEnabled()) {
534+
LOG.debug("Lance provider failure, replaced by a redacted cause", throwable);
535+
}
524536
return throwable instanceof IllegalArgumentException
525537
? new IllegalArgumentException(sanitizedMessage)
526538
: new RuntimeException(sanitizedMessage);

‎fe/fe-core/src/main/java/org/apache/doris/datasource/lance/LanceOssStorageProvider.java‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,20 @@ public Map<String, String> fromDorisProperties(List<StorageProperties> storagePr
7777
// Doris reads a blank key pair as a request for anonymous access. Lance forwards options it
7878
// does not recognize straight to OpenDAL, whose OSS service only skips request signing when
7979
// allow_anonymous is set; without it the open fails in credential loading instead of
80-
// issuing the unsigned request Doris asked for.
81-
if (StringUtils.isBlank(properties.getAccessKey())
82-
&& StringUtils.isBlank(properties.getSecretKey())) {
80+
// issuing the unsigned request Doris asked for. Decide from what was actually emitted above
81+
// rather than re-testing the properties, so a credential this class considers present can
82+
// never be paired with a claim that there is none.
83+
if (!result.containsKey(ACCESS_KEY_ID) && !result.containsKey(SECRET_ACCESS_KEY)) {
8384
result.put(ALLOW_ANONYMOUS, "true");
8485
}
8586

86-
// OpenDAL's OSS service addresses buckets virtual-host style by default, which is also
87-
// Doris's default, so only an explicit path-style request needs translating.
88-
if (Boolean.parseBoolean(properties.getUsePathStyle())) {
89-
result.put(ADDRESSING_STYLE, "path");
87+
// Lance snapshots the host's OSS_*/AWS_*/ALIBABA_CLOUD_* environment into the same config
88+
// map before storage options are applied, so state both addressing styles explicitly the
89+
// way the S3 provider does. Leaving the default implicit would let an exported
90+
// OSS_ADDRESSING_STYLE outrank an explicit oss.use_path_style=false.
91+
String usePathStyle = properties.getUsePathStyle();
92+
if (StringUtils.isNotEmpty(usePathStyle)) {
93+
result.put(ADDRESSING_STYLE, Boolean.parseBoolean(usePathStyle) ? "path" : "virtual");
9094
}
9195
return result;
9296
}

‎fe/fe-core/src/main/java/org/apache/doris/datasource/property/metastore/LanceFileSystemMetastoreProperties.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
/** Properties for a Lance directory namespace backed by a filesystem warehouse. */
3535
public class LanceFileSystemMetastoreProperties extends AbstractLanceProperties {
3636
public static final String WAREHOUSE = "warehouse";
37+
private static final String OSS_HDFS_MARKER = ".oss-dls.aliyuncs.com";
3738

3839
@ConnectorProperty(
3940
names = {WAREHOUSE},
@@ -137,6 +138,12 @@ private static String normalizeWarehouse(String warehouse) {
137138
if (uri.getScheme() == null || !"oss".equals(uri.getScheme().toLowerCase(Locale.ROOT))) {
138139
return warehouse;
139140
}
141+
// OSS-HDFS is the one oss:// form whose qualified authority is the required spelling -
142+
// OSSHdfsProperties validates such a URL without ever rewriting it - so leave it alone.
143+
String authority = uri.getAuthority();
144+
if (authority != null && authority.toLowerCase(Locale.ROOT).contains(OSS_HDFS_MARKER)) {
145+
return warehouse;
146+
}
140147
return OSSProperties.rewriteOssBucketIfNecessary(warehouse);
141148
}
142149
}

‎fe/fe-core/src/main/java/org/apache/doris/datasource/property/storage/OSSProperties.java‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.apache.doris.foundation.property.ConnectorPropertiesUtils;
2222
import org.apache.doris.foundation.property.ConnectorProperty;
2323

24-
import com.google.common.annotations.VisibleForTesting;
2524
import com.google.common.collect.ImmutableSet;
2625
import lombok.Getter;
2726
import lombok.Setter;
@@ -345,13 +344,6 @@ public void initializeHadoopStorageConfig() {
345344
* @param uri the original URI string
346345
* @return the rewritten URI string, or the original URI if no rewrite is needed
347346
*/
348-
@VisibleForTesting
349-
/**
350-
* Collapses the qualified {@code oss://bucket.oss-<region>.aliyuncs.com/path} form Doris
351-
* accepts down to {@code oss://bucket/path}. Public so that callers outside this package
352-
* which take an OSS URL before any {@link OSSProperties} instance exists - the Lance
353-
* directory namespace root, for one - can apply the same contract.
354-
*/
355347
public static String rewriteOssBucketIfNecessary(String uri) {
356348
if (uri == null || uri.isEmpty()) {
357349
return uri;

‎fe/fe-core/src/test/java/org/apache/doris/datasource/lance/LanceStorageOptionsTest.java‎

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,13 @@ public void testOssCatalogPropertiesMapToThePublicSpelling() {
125125
Assertions.assertEquals("oss-sk", options.get("oss_secret_access_key"));
126126
Assertions.assertEquals("cn-hangzhou", options.get("oss_region"));
127127
Assertions.assertEquals("oss-token", options.get("oss_security_token"));
128+
// Stated rather than implied, so the host environment cannot decide it; see
129+
// testOssVirtualHostAddressingIsStatedExplicitly.
130+
Assertions.assertEquals("virtual", options.get("addressing_style"));
128131
Assertions.assertEquals(
129132
new TreeSet<>(Arrays.asList("oss_endpoint", "oss_access_key_id",
130-
"oss_secret_access_key", "oss_region", "oss_security_token")),
133+
"oss_secret_access_key", "oss_region", "oss_security_token",
134+
"addressing_style")),
131135
new TreeSet<>(options.keySet()));
132136
}
133137

@@ -470,10 +474,33 @@ public void testOssPathStyleAddressingIsForwarded() {
470474
Assertions.assertEquals("path", options.get("addressing_style"));
471475
}
472476

477+
/**
478+
* Lance snapshots the host's {@code OSS_} and {@code AWS_} environment variables into the same
479+
* config map before storage options are applied, so the default has to be stated rather than
480+
* left implicit - otherwise an exported OSS_ADDRESSING_STYLE would outrank the catalog.
481+
*/
473482
@Test
474-
public void testOssVirtualHostAddressingStaysImplicit() {
483+
public void testOssVirtualHostAddressingIsStatedExplicitly() {
475484
Map<String, String> options = LanceStorageOptions.forUri(OSS_URI, createAll(ossProperties()));
476485

477-
Assertions.assertNull(options.get("addressing_style"));
486+
Assertions.assertEquals("virtual", options.get("addressing_style"));
487+
}
488+
489+
/**
490+
* Doris accepts a whitespace-only key pair as "both set", so the emitted credentials and the
491+
* anonymous claim have to agree: whatever this provider treats as a usable credential must
492+
* suppress allow_anonymous, or OpenDAL signs with the blank key and cannot fall back.
493+
*/
494+
@Test
495+
public void testWhitespaceOssCredentialsAreNotAlsoCalledAnonymous() {
496+
Map<String, String> properties = ossProperties();
497+
properties.put("oss.access_key", " ");
498+
properties.put("oss.secret_key", " ");
499+
500+
Map<String, String> options = LanceStorageOptions.forUri(OSS_URI, createAll(properties));
501+
502+
Assertions.assertNotEquals(
503+
options.containsKey("oss_access_key_id"), options.containsKey("allow_anonymous"),
504+
"a credential and a claim of anonymity must never both be emitted");
478505
}
479506
}

‎fe/fe-core/src/test/java/org/apache/doris/datasource/property/metastore/LancePropertiesTest.java‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,22 @@ public void testObjectStoreWarehouseMustNameABucket() {
108108
"unexpected message: " + thrown.getMessage());
109109
}
110110
}
111+
112+
/**
113+
* OSS-HDFS is the one oss:// form whose qualified authority is required rather than incidental,
114+
* so the bucket rewrite must not touch it.
115+
*/
116+
@Test
117+
public void testOssHdfsWarehouseKeepsItsQualifiedAuthority() throws Exception {
118+
String warehouse = "oss://bkt.cn-hangzhou.oss-dls.aliyuncs.com/lance";
119+
Map<String, String> properties = new HashMap<>();
120+
properties.put("type", "lance");
121+
properties.put(LanceFileSystemMetastoreProperties.WAREHOUSE, warehouse);
122+
123+
AbstractLanceProperties lanceProperties =
124+
(AbstractLanceProperties) MetastoreProperties.create(properties);
125+
126+
Assertions.assertEquals(warehouse,
127+
((LanceFileSystemMetastoreProperties) lanceProperties).getWarehouse());
128+
}
111129
}

0 commit comments

Comments
 (0)