github-actions[bot] commented on code in PR #70725:
URL: https://github.com/apache/doris/pull/70725#discussion_r4626670414
##########
fe/fe-connector/fe-connector-lance/src/main/java/org/apache/doris/connector/lance/LanceCatalogProperties.java:
##########
@@ -160,36 +212,163 @@ private static void validateWarehouse(String warehouse) {
return;
}
String scheme = uri.getScheme().toLowerCase(Locale.ROOT);
- if (!"file".equals(scheme) && !"s3".equals(scheme)) {
+ if (!"file".equals(scheme) && !"s3".equals(scheme) &&
!"oss".equals(scheme)) {
throw new IllegalArgumentException("Unsupported Lance filesystem
warehouse scheme '" + scheme
- + "'; supported schemes are local/file and s3");
+ + "'; supported schemes are local/file, s3, and oss");
}
// An object-store root names its bucket in the authority. Lance reads
that authority as the
// bucket and fails deep inside the store when it is absent, so reject
the no-authority form
// here where the message can still name the property.
- if ("s3".equals(scheme) && StringUtils.isBlank(uri.getAuthority())) {
+ if (("s3".equals(scheme) || "oss".equals(scheme)) &&
StringUtils.isBlank(uri.getAuthority())) {
throw new IllegalArgumentException(
"Lance " + scheme + " warehouse must name a bucket, as in
" + scheme
+ "://bucket/path, but was: " + warehouse);
}
}
+ private void validateRestProperties() {
+ if (raw.containsKey(WAREHOUSE)) {
+ throw new IllegalArgumentException("Property 'warehouse' is not
valid for Lance REST catalog");
+ }
+ if (StringUtils.isBlank(restUri)) {
+ throw new IllegalArgumentException(
+ "Missing required property '" + REST_URI + "' for Lance
REST catalog");
+ }
+ validateRestUri(restUri);
+
+ // ALTER merges property maps and cannot remove keys; an empty
inactive credential clears it.
+ boolean bearerTokenConfigured = StringUtils.isNotEmpty(bearerToken);
+ boolean apiKeyConfigured = StringUtils.isNotEmpty(apiKey);
+ switch (securityType) {
+ case SECURITY_NONE:
+ if (bearerTokenConfigured || apiKeyConfigured) {
+ throw new IllegalArgumentException("Lance REST security
type 'none' cannot configure '"
+ + REST_BEARER_TOKEN + "' or '" + REST_API_KEY +
"'");
+ }
+ break;
+ case SECURITY_BEARER:
+ if (StringUtils.isBlank(bearerToken) || apiKeyConfigured) {
+ throw new IllegalArgumentException("Lance REST security
type 'bearer' requires only '"
+ + REST_BEARER_TOKEN + "'");
+ }
+ validateCredentialHeaderValue(REST_BEARER_TOKEN, bearerToken);
+ break;
+ case SECURITY_API_KEY:
+ if (StringUtils.isBlank(apiKey) || bearerTokenConfigured) {
+ throw new IllegalArgumentException("Lance REST security
type 'api_key' requires only '"
+ + REST_API_KEY + "'");
+ }
+ validateCredentialHeaderValue(REST_API_KEY, apiKey);
+ break;
+ default:
+ throw new IllegalArgumentException("Property '" +
REST_SECURITY_TYPE
+ + "' must be 'none', 'bearer', or 'api_key'");
+ }
+
+ for (Map.Entry<String, String> entry : raw.entrySet()) {
+ String key = entry.getKey();
+ if (!key.startsWith(REST_PREFIX) || REST_KEYS.contains(key)) {
+ continue;
+ }
+ if (!key.startsWith(REST_HEADER_PREFIX)) {
+ throw new IllegalArgumentException("Unsupported Lance REST
property '" + key + "'");
+ }
+ String headerName = key.substring(REST_HEADER_PREFIX.length());
+ String headerValue = entry.getValue();
+ validateRestHeader(headerName, headerValue);
+ // ALTER preserves case-sensitive property keys, but HTTP header
names are case-insensitive.
+ headerName = headerName.toLowerCase(Locale.ROOT);
+ String previous = restHeaders.putIfAbsent(headerName, headerValue);
+ if (previous != null && !previous.equals(headerValue)) {
+ throw new IllegalArgumentException("Conflicting values for
HTTP header '" + headerName
+ + "' in Lance REST properties");
+ }
+ }
+ }
+
+ private static void validateRestUri(String value) {
+ final URI uri;
+ try {
+ uri = URI.create(value.trim());
+ } catch (IllegalArgumentException e) {
+ throw new IllegalArgumentException("Invalid Lance REST URI in
property '" + REST_URI + "'", e);
+ }
+ String scheme = uri.getScheme();
+ if (scheme == null || (!"http".equalsIgnoreCase(scheme) &&
!"https".equalsIgnoreCase(scheme))) {
+ throw new IllegalArgumentException("Property '" + REST_URI + "'
must use http or https");
+ }
+ if (StringUtils.isBlank(uri.getRawAuthority()) || uri.getRawUserInfo()
!= null
+ || uri.getRawQuery() != null || uri.getRawFragment() != null) {
+ throw new IllegalArgumentException("Property '" + REST_URI
+ + "' must contain an authority and cannot contain
user-info, query, or fragment");
+ }
+ }
+
+ private static void validateRestHeader(String headerName, String
headerValue) {
+ if (StringUtils.isBlank(headerName) ||
!HTTP_HEADER_NAME.matcher(headerName).matches()) {
+ throw new IllegalArgumentException("Invalid HTTP header name in
property '"
+ + REST_HEADER_PREFIX + headerName + "'");
+ }
+ if ("authorization".equalsIgnoreCase(headerName) ||
"x-api-key".equalsIgnoreCase(headerName)) {
+ throw new IllegalArgumentException("Authentication header '" +
headerName
+ + "' must be configured through '" + REST_SECURITY_TYPE +
"'");
+ }
+ if (headerValue == null || headerValue.indexOf('\r') >= 0 ||
headerValue.indexOf('\n') >= 0) {
Review Comment:
[P2] Reject HTTP control bytes before Lance silently drops the header
With default SQL escaping, `lance.rest.header.X-Tenant = "tenant\b"`
contains a backspace and passes this check. The pinned Lance 12.0.0
[`RestClient::apply_headers`](https://github.com/lance-format/lance/blob/v12.0.0/rust/lance-namespace-impls/src/rest.rs#L94-L103)
inserts a header only when `HeaderValue::from_str` succeeds and silently skips
it otherwise. That parser rejects backspace, NUL, SUB and DEL as well as CR/LF,
so every request loses the entire configured tenant header. A namespace service
with a default tenant can then successfully list/read that default instead of
reporting the invalid configuration. The bearer/API-key guard below has the
same gap. Validate the full native header-value byte domain for extra headers
and both credentials, retaining legal HTAB, and cover these control-byte values
in negative tests.
--
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]