Merge pull request #65962 from ClickHouse/backport/24.6/65848

Backport #65848 to 24.6: Add missing workload identity changes
This commit is contained in:
robot-ch-test-poll1 2024-07-02 10:48:04 +04:00 committed by GitHub
commit e96e1cea8b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -12,6 +12,7 @@
#include <azure/storage/blobs.hpp>
#include <Interpreters/evaluateConstantExpression.h>
#include <azure/identity/managed_identity_credential.hpp>
#include <azure/identity/workload_identity_credential.hpp>
#include <Parsers/ASTIdentifier.h>
#include <Parsers/ASTFunction.h>
@ -179,19 +180,28 @@ AzureClientPtr StorageAzureConfiguration::createClient(bool is_read_only, bool a
}
std::unique_ptr<BlobServiceClient> blob_service_client;
size_t pos = connection_url.find('?');
std::shared_ptr<Azure::Identity::ManagedIdentityCredential> managed_identity_credential;
if (storage_shared_key_credential)
{
blob_service_client = std::make_unique<BlobServiceClient>(connection_url, storage_shared_key_credential);
}
else
{
/// If conneciton_url does not have '?', then its not SAS
if (pos == std::string::npos)
{
auto workload_identity_credential = std::make_shared<Azure::Identity::WorkloadIdentityCredential>();
blob_service_client = std::make_unique<BlobServiceClient>(connection_url, workload_identity_credential);
}
else
{
managed_identity_credential = std::make_shared<Azure::Identity::ManagedIdentityCredential>();
blob_service_client = std::make_unique<BlobServiceClient>(connection_url, managed_identity_credential);
}
}
std::string final_url;
size_t pos = connection_url.find('?');
if (pos != std::string::npos)
{
auto url_without_sas = connection_url.substr(0, pos);
@ -215,9 +225,18 @@ AzureClientPtr StorageAzureConfiguration::createClient(bool is_read_only, bool a
{
if (storage_shared_key_credential)
result = std::make_unique<BlobContainerClient>(final_url, storage_shared_key_credential);
else
{
/// If conneciton_url does not have '?', then its not SAS
if (pos == std::string::npos)
{
auto workload_identity_credential = std::make_shared<Azure::Identity::WorkloadIdentityCredential>();
result = std::make_unique<BlobContainerClient>(final_url, workload_identity_credential);
}
else
result = std::make_unique<BlobContainerClient>(final_url, managed_identity_credential);
}
}
else
{
if (is_read_only)
@ -235,9 +254,18 @@ AzureClientPtr StorageAzureConfiguration::createClient(bool is_read_only, bool a
{
if (storage_shared_key_credential)
result = std::make_unique<BlobContainerClient>(final_url, storage_shared_key_credential);
else
{
/// If conneciton_url does not have '?', then its not SAS
if (pos == std::string::npos)
{
auto workload_identity_credential = std::make_shared<Azure::Identity::WorkloadIdentityCredential>();
result = std::make_unique<BlobContainerClient>(final_url, workload_identity_credential);
}
else
result = std::make_unique<BlobContainerClient>(final_url, managed_identity_credential);
}
}
else
{
throw;