diff --git a/CMakeLists.txt b/CMakeLists.txt index ab55276b8..57d96654a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -286,6 +286,7 @@ if(NOT TRITON_CORE_HEADERS_ONLY) -Dazure-storage-blobs-cpp_DIR:PATH=${TRITON_THIRD_PARTY_INSTALL_PREFIX}/azure-sdk/share/azure-storage-blobs-cpp -Dazure-storage-common-cpp_DIR:PATH=${TRITON_THIRD_PARTY_INSTALL_PREFIX}/azure-sdk/share/azure-storage-common-cpp -Dazure-core-cpp_DIR:PATH=${TRITON_THIRD_PARTY_INSTALL_PREFIX}/azure-sdk/share/azure-core-cpp + -Dazure-identity-cpp_DIR:PATH=${TRITON_THIRD_PARTY_INSTALL_PREFIX}/azure-sdk/share/azure-identity-cpp ) endif() # TRITON_ENABLE_AZURE_STORAGE if(${TRITON_ENABLE_METRICS}) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6a0967036..5eea9c072 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -104,6 +104,8 @@ endif() if(${TRITON_ENABLE_AZURE_STORAGE}) find_package(azure-storage-blobs-cpp CONFIG REQUIRED) message(STATUS "Using Azure storage blobs ${azure-storage-blobs-cpp_VERSION}") + find_package(azure-identity-cpp CONFIG REQUIRED) + message(STATUS "Using Azure identity ${azure-identity-cpp_VERSION}") endif() configure_file(libtritonserver.ldscript libtritonserver.ldscript COPYONLY) @@ -327,6 +329,7 @@ if(${TRITON_ENABLE_AZURE_STORAGE}) target_include_directories( triton-core PRIVATE $ + PRIVATE $ ) endif() # TRITON_ENABLE_AZURE_STORAGE @@ -501,6 +504,11 @@ if(${TRITON_ENABLE_AZURE_STORAGE}) PRIVATE Azure::azure-storage-blobs ) + target_link_libraries( + triton-core + PRIVATE + Azure::azure-identity + ) endif() # TRITON_ENABLE_AZURE_STORAGE if(${TRITON_ENABLE_GPU}) diff --git a/src/filesystem/implementations/as.h b/src/filesystem/implementations/as.h index fc449475a..fe19ed0ec 100644 --- a/src/filesystem/implementations/as.h +++ b/src/filesystem/implementations/as.h @@ -25,6 +25,7 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #pragma once +#include #include #include @@ -37,6 +38,7 @@ namespace triton { namespace core { namespace as = Azure::Storage; namespace asb = Azure::Storage::Blobs; +namespace ai = Azure::Identity; const std::string AS_URL_PATTERN = "as://([^/]+)/([^/?]+)(?:/([^?]*))?(\\?.*)?"; struct ASCredential { @@ -152,11 +154,18 @@ ASFileSystem::ASFileSystem(const std::string& path, const ASCredential& as_cred) std::string service_url( "https://" + account_name + ".blob.core.windows.net"); + auto use_default_env = + GetEnvironmentVariableOrDefault("AZURE_USE_DEFAULT_CREDENTIAL", "0"); + if (!as_cred.account_key_.empty()) { // Shared Key auto cred = std::make_shared( account_name, as_cred.account_key_); client_ = std::make_shared(service_url, cred); + } else if (use_default_env == "1" || use_default_env == "true") { + // Default Azure Credential (Managed Identity, Environment, VS, CLI, etc) + auto cred = std::make_shared(); + client_ = std::make_shared(service_url, cred); } else { client_ = std::make_shared(service_url); }