github-actions[bot] commented on code in PR #68540:
URL: https://github.com/apache/doris/pull/68540#discussion_r4208967423
##########
cloud/src/meta-service/meta_service_resource.cpp:
##########
@@ -495,7 +504,13 @@ static int update_instance_ak_sk(InstanceInfoPB& instance,
const UpdateAkSkReque
proto_to_json(*request);
return -1;
}
- if (it.ak() == ak && it.sk() == sk) {
+ if (has_obj_credential(it) && (ak.empty() || sk.empty())) {
+ code = MetaServiceCode::INVALID_ARGUMENT;
+ msg = "nonempty access key and secret key are required to
replace native "
+ "credentials";
+ return -1;
+ }
+ if (it.ak() == ak && it.sk() == sk && !has_obj_credential(it))
{
Review Comment:
[P1] Let an idempotent key update finish the derived-instance cascade. After
this branch clears a root instance's native GCP credential and commits it, any
derived-instance transaction can fail. Retrying the identical request now hits
the equal-key return here before `find_cascade_instances`, leaving a derived
instance on the old OAuth identity indefinitely. The legacy ALTER path has the
same early-return pattern. Continue cascading on an equal root update, and test
failure after root commit followed by retry.
##########
fe/fe-filesystem/fe-filesystem-gcs/src/main/java/org/apache/doris/filesystem/gcs/GcpAuth.java:
##########
@@ -0,0 +1,148 @@
+// 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.doris.filesystem.gcs;
+
+import org.apache.doris.filesystem.auth.GcpCredential;
+
+import com.google.auth.oauth2.ComputeEngineCredentials;
+import com.google.auth.oauth2.GoogleCredentials;
+import com.google.auth.oauth2.ImpersonatedCredentials;
+import software.amazon.awssdk.auth.credentials.AnonymousCredentialsProvider;
+import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
+import software.amazon.awssdk.core.client.config.SdkAdvancedClientOption;
+import software.amazon.awssdk.core.interceptor.Context;
+import software.amazon.awssdk.core.interceptor.ExecutionAttributes;
+import software.amazon.awssdk.core.interceptor.ExecutionInterceptor;
+import software.amazon.awssdk.core.retry.RetryPolicy;
+import software.amazon.awssdk.core.retry.backoff.EqualJitterBackoffStrategy;
+import software.amazon.awssdk.core.signer.NoOpSigner;
+import software.amazon.awssdk.http.SdkHttpRequest;
+import software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient;
+import software.amazon.awssdk.regions.Region;
+import software.amazon.awssdk.services.s3.S3AsyncClient;
+import software.amazon.awssdk.services.s3.S3Client;
+import software.amazon.awssdk.services.s3.S3Configuration;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.net.URI;
+import java.time.Duration;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+/** Creates GCP OAuth2 credentials and adapts them to the S3-compatible
client. */
+public final class GcpAuth {
+ public static final String DEVSTORAGE_SCOPE =
+ "https://www.googleapis.com/auth/devstorage.read_write";
+ private static final String CLOUD_PLATFORM_SCOPE =
"https://www.googleapis.com/auth/cloud-platform";
+ private static final int IMPERSONATION_LIFETIME_SECONDS = 3600;
+
+ private GcpAuth() {
+ }
+
+ public static S3Client createS3Client(GcsFileSystemProperties properties)
throws IOException {
+ return S3Client.builder()
+
.httpClient(UrlConnectionHttpClient.builder().socketTimeout(Duration.ofSeconds(30))
+ .connectionTimeout(Duration.ofSeconds(30)).build())
+ .endpointOverride(endpoint(properties))
Review Comment:
[P1] Keep native GCP tokens off caller-selected endpoints. A user can run
`SELECT * FROM s3(...)` with `provider=GCP`,
`gs.credential_provider_type=DEFAULT`, `gs.use_path_style=true`, and
`gs.endpoint=https://their-host`; FE file discovery creates this client and
sends its ADC bearer token to that host. The default endpoint whitelist is
empty, and the BE scan client also attaches its own token to the same endpoint.
Reject untrusted or plaintext endpoints for native OAuth in both FE and BE
before sending either request.
##########
cloud/src/meta-service/meta_service_resource.cpp:
##########
@@ -1259,7 +1342,7 @@ static int extract_object_storage_info(const
AlterObjStoreInfoRequest* request,
external_id] = obj_desc;
bool use_credential_provider_for_add_vault =
- request->op() == AlterObjStoreInfoRequest::ADD_S3_VAULT &&
obj.has_cred_provider_type();
+ request->op() == AlterObjStoreInfoRequest::ADD_S3_VAULT &&
use_credential_provider(obj);
Review Comment:
[P2] Admit native GCP credentials when adding legacy instance object
storage. `ADD_OBJ_INFO` with `provider=GCP` and `credential.gcp_credential` but
no AK/SK reaches this static-key requirement and fails; the later
`ADD_OBJ_INFO` check also requires keys or role ARN. This prevents a running
legacy instance from adding a GCP OAuth object-store entry even though
create-instance and vault creation accept it. Validate the native envelope in
both gates and cover add/readback.
##########
be/src/util/s3_util.cpp:
##########
@@ -389,17 +434,53 @@ Result<std::shared_ptr<io::ObjStorageClient>>
S3ClientFactory::_create_s3_client
return ResultError(Status::InvalidArgument("failed to create AWS
credential provider: {}",
credentials.error));
}
- std::shared_ptr<Aws::S3::S3Client> new_client =
std::make_shared<Aws::S3::S3Client>(
- std::move(credentials.provider), std::move(aws_config),
- Aws::Client::AWSAuthV4Signer::PayloadSigningPolicy::Never,
- s3_conf.use_virtual_addressing);
+ auto new_client = make_s3_client(
+ s3_conf.credential,
+ S3ClientBuildContext {
+ .fallback_provider = std::move(credentials.provider),
+ .config = std::move(aws_config),
+ .payload_signing_policy =
+
Aws::Client::AWSAuthV4Signer::PayloadSigningPolicy::Never,
+ .use_virtual_addressing = s3_conf.use_virtual_addressing,
+ .ca_cert_path = _ca_cert_file_path,
Review Comment:
[P2] Use the locked local CA path here. Parallel cache misses can enter
`_create_s3_client`; when no configured CA file is found,
`_get_ca_cert_file_path()` keeps assigning `_ca_cert_file_path` under its lock.
This new read, and the read passed to `GcpTokenProvider` below, occur outside
that lock and can race with another constructor's assignment. Pass the
`ca_cert_file_path` local copied above to both consumers.
##########
cloud/src/meta-service/meta_service_resource.cpp:
##########
@@ -1496,7 +1582,11 @@ void
MetaServiceImpl::alter_storage_vault(google::protobuf::RpcController* contr
}
if (use_credential_provider(obj)) {
- if (!obj.has_provider() || obj.provider() !=
ObjectStoreInfoPB::S3) {
+ bool valid_aws = obj.has_cred_provider_type() &&
!has_obj_credential(obj) &&
Review Comment:
[P2] Preserve role-only vault ADD requests. An S3 `ADD_S3_VAULT` request
with a nonempty `role_arn` but no `cred_provider_type` reaches this branch and
now fails `valid_aws`, although this RPC previously accepted it and
`object_info_pb_factory` defaults the omitted field to `INSTANCE_PROFILE`.
Older or direct Meta Service clients therefore cannot add a role-based vault.
Accept the role ARN case here and cover an omitted provider-type request.
##########
be/src/io/fs/gcs_signed_url_provider.cpp:
##########
@@ -0,0 +1,211 @@
+// 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.
+
+#include "io/fs/gcs_signed_url_provider.h"
+
+#include <fmt/format.h>
+#include <rapidjson/document.h>
+
+#include <algorithm>
+#include <cstdlib>
+#include <exception>
+#include <string_view>
+#include <utility>
+
+#include "cpp/obj-client/auth/gcp/gcp_token_provider.h"
+#include "cpp/obj-client/auth/gcp/gcs_signed_url.h"
+#include "service/http/http_client.h"
+#include "util/string_util.h"
+#include "util/url_coding.h"
+
+namespace doris::io {
+namespace {
+
+constexpr std::string_view IAM_CREDENTIALS_ENDPOINT =
+ "https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/";
+constexpr std::string_view DEFAULT_METADATA_HOST = "metadata.google.internal";
+constexpr std::string_view METADATA_SERVICE_ACCOUNT_EMAIL_PATH =
+ "/computeMetadata/v1/instance/service-accounts/default/email";
+constexpr int64_t METADATA_REQUEST_TIMEOUT_MS = 1000;
+
+std::string iam_error_message(const rapidjson::Document& document) {
+ if (!document.IsObject() || !document.HasMember("error") ||
!document["error"].IsObject()) {
+ return "unparseable error response";
+ }
+ const auto& error = document["error"];
+ std::string message;
+ if (error.HasMember("status") && error["status"].IsString()) {
+ message = error["status"].GetString();
+ }
+ if (error.HasMember("message") && error["message"].IsString()) {
+ if (!message.empty()) {
+ message.append(": ");
+ }
+ message.append(error["message"].GetString());
+ }
+ if (message.empty()) {
+ return "error response did not contain status or message";
+ }
+ constexpr size_t MAX_ERROR_MESSAGE_SIZE = 1024;
+ if (message.size() > MAX_ERROR_MESSAGE_SIZE) {
+ message.resize(MAX_ERROR_MESSAGE_SIZE);
+ message.append("...");
+ }
+ return message;
+}
+
+bool is_unreserved(unsigned char c) {
+ return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c
<= '9') || c == '-' ||
+ c == '_' || c == '.' || c == '~';
+}
+
+std::string percent_encode(std::string_view value) {
+ constexpr char HEX[] = "0123456789ABCDEF";
+ std::string encoded;
+ encoded.reserve(value.size());
+ for (unsigned char c : value) {
+ if (is_unreserved(c)) {
+ encoded.push_back(static_cast<char>(c));
+ continue;
+ }
+ encoded.push_back('%');
+ encoded.push_back(HEX[c >> 4]);
+ encoded.push_back(HEX[c & 0x0F]);
+ }
+ return encoded;
+}
+
+Status call_iam_sign_blob(std::string_view access_token, std::string_view
service_account,
+ std::string_view string_to_sign, int64_t
request_timeout_ms,
+ std::string* signature) {
+ std::string encoded_payload;
+ base64_encode(std::string(string_to_sign), &encoded_payload);
+ std::string request_body = fmt::format(R"({{"payload":"{}"}})",
encoded_payload);
+ std::string endpoint =
+ std::string(IAM_CREDENTIALS_ENDPOINT) +
percent_encode(service_account) + ":signBlob";
+
+ HttpClient client;
+ // Keep the response body for non-2xx replies so IAM permission and
+ // service-account errors are actionable to operators.
+ RETURN_IF_ERROR(client.init(endpoint, false));
Review Comment:
[P2] Omit the Doris cluster token from GCP HTTP requests. `HttpClient::init`
automatically adds `Auth-Token: <curr_auth_token>` in production, so this IAM
`signBlob` request sends the cluster credential alongside the intended Google
bearer token; the metadata email request does too. Use an HTTP client mode
without the Doris cluster header for the IAM and metadata requests.
--
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]