|
34 | 34 | import org.apache.arrow.memory.RootAllocator; |
35 | 35 | import org.apache.commons.lang3.StringUtils; |
36 | 36 | import org.apache.commons.lang3.exception.ExceptionUtils; |
| 37 | +import org.apache.logging.log4j.LogManager; |
| 38 | +import org.apache.logging.log4j.Logger; |
37 | 39 | import org.lance.namespace.LanceNamespace; |
38 | 40 | import org.lance.namespace.errors.NamespaceNotFoundException; |
39 | 41 | import org.lance.namespace.errors.TableNotFoundException; |
|
60 | 62 |
|
61 | 63 | /** Read-only Lance Directory or REST Namespace catalog. */ |
62 | 64 | public class LanceExternalCatalog extends ExternalCatalog { |
| 65 | + private static final Logger LOG = LogManager.getLogger(LanceExternalCatalog.class); |
63 | 66 | public static final String LANCE_CATALOG_TYPE = AbstractLanceProperties.LANCE_CATALOG_TYPE; |
64 | 67 | public static final String LANCE_FILESYSTEM = AbstractLanceProperties.LANCE_FILESYSTEM; |
65 | 68 | public static final String LANCE_REST = AbstractLanceProperties.LANCE_REST; |
@@ -145,9 +148,10 @@ public void checkWhenCreating() throws DdlException { |
145 | 148 | } |
146 | 149 | } catch (Exception e) { |
147 | 150 | // 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); |
151 | 155 | throw new DdlException("Lance " + type + " catalog connectivity test failed: " |
152 | 156 | + sanitizedMessage, sanitizedCause(e, sanitizedMessage)); |
153 | 157 | } |
@@ -489,8 +493,9 @@ String sanitizedRootCauseMessage(Throwable throwable, String datasetUri, |
489 | 493 | List<String> sensitiveValues = new ArrayList<>(); |
490 | 494 | sensitiveValues.add(catalogProperty.getOrDefault(REST_BEARER_TOKEN, "")); |
491 | 495 | 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. |
494 | 499 | nonNullStorageOptions.forEach((key, value) -> { |
495 | 500 | if (key == null) { |
496 | 501 | return; |
@@ -521,6 +526,13 @@ private Throwable safeCause(Throwable throwable) { |
521 | 526 | } |
522 | 527 |
|
523 | 528 | 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 | + } |
524 | 536 | return throwable instanceof IllegalArgumentException |
525 | 537 | ? new IllegalArgumentException(sanitizedMessage) |
526 | 538 | : new RuntimeException(sanitizedMessage); |
|
0 commit comments