-
Notifications
You must be signed in to change notification settings - Fork 132
Support Azure Managed Identity authentication for Azure Storage model repositories #468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nightflight-dk
wants to merge
5
commits into
triton-inference-server:main
Choose a base branch
from
nightflight-dk:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+72
−6
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4ef4eba
managed-identity-support
nightflight-dk de6bf52
Apply suggestions from code review
whoisj 38b404e
fixup pre-commit complaints
whoisj 6881a86
fixup cmake pre-commit complaints
whoisj eba4837
Merge branch 'main' into main
nightflight-dk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,8 @@ | |
| // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| #pragma once | ||
|
|
||
| #include <azure/identity/default_azure_credential.hpp> | ||
| #include <azure/identity/managed_identity_credential.hpp> | ||
| #include <azure/storage/blobs.hpp> | ||
| #include <azure/storage/common/storage_credential.hpp> | ||
|
|
||
|
|
@@ -39,9 +41,18 @@ namespace as = Azure::Storage; | |
| namespace asb = Azure::Storage::Blobs; | ||
| const std::string AS_URL_PATTERN = "as://([^/]+)/([^/?]+)(?:/([^?]*))?(\\?.*)?"; | ||
|
|
||
| /// Supported authentication modes for Azure Storage access. | ||
| /// - "key": Shared Key (account key) — default, backwards-compatible. | ||
| /// - "managed_identity": Azure Managed Identity (system- or user-assigned). | ||
| /// - "default": Azure DefaultAzureCredential chain | ||
| /// (environment → managed identity → CLI → etc.). | ||
| struct ASCredential { | ||
| std::string account_str_; | ||
| std::string account_key_; | ||
| /// Authentication type: "key" (default), "managed_identity", or "default". | ||
| std::string auth_type_; | ||
whoisj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// Optional client ID for user-assigned Managed Identity. | ||
| std::string client_id_; | ||
|
|
||
| ASCredential(); // from env var | ||
| ASCredential(triton::common::TritonJson::Value& cred_json); | ||
|
|
@@ -54,17 +65,33 @@ ASCredential::ASCredential() | |
| }; | ||
| const char* account_str = std::getenv("AZURE_STORAGE_ACCOUNT"); | ||
| const char* account_key = std::getenv("AZURE_STORAGE_KEY"); | ||
| const char* auth_type = std::getenv("AZURE_STORAGE_AUTH_TYPE"); | ||
| const char* client_id = std::getenv("AZURE_STORAGE_CLIENT_ID"); | ||
| account_str_ = to_str(account_str); | ||
| account_key_ = to_str(account_key); | ||
| auth_type_ = to_str(auth_type); | ||
| client_id_ = to_str(client_id); | ||
whoisj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // When no explicit auth type is set, infer from available credentials: | ||
| // if an account key is present use "key", otherwise remain empty (which | ||
| // the filesystem constructor treats as "key" for backwards compatibility). | ||
| if (auth_type_.empty() && !account_key_.empty()) { | ||
| auth_type_ = "key"; | ||
| } | ||
| } | ||
|
|
||
| ASCredential::ASCredential(triton::common::TritonJson::Value& cred_json) | ||
| { | ||
| triton::common::TritonJson::Value account_str_json, account_key_json; | ||
| triton::common::TritonJson::Value account_str_json, account_key_json, | ||
| auth_type_json, client_id_json; | ||
| if (cred_json.Find("account_str", &account_str_json)) | ||
| account_str_json.AsString(&account_str_); | ||
| if (cred_json.Find("account_key", &account_key_json)) | ||
| account_key_json.AsString(&account_key_); | ||
| if (cred_json.Find("auth_type", &auth_type_json)) | ||
| auth_type_json.AsString(&auth_type_); | ||
whoisj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (cred_json.Find("client_id", &client_id_json)) | ||
| client_id_json.AsString(&client_id_); | ||
| } | ||
|
|
||
| class ASFileSystem : public FileSystem { | ||
|
|
@@ -152,12 +179,45 @@ ASFileSystem::ASFileSystem(const std::string& path, const ASCredential& as_cred) | |
| std::string service_url( | ||
| "https://" + account_name + ".blob.core.windows.net"); | ||
|
|
||
| if (!as_cred.account_key_.empty()) { | ||
| // Shared Key | ||
| if (as_cred.auth_type_ == "managed_identity") { | ||
| // Azure Managed Identity authentication (system- or user-assigned). | ||
| // Token caching and refresh are handled by the Azure Identity SDK. | ||
| LOG_VERBOSE(1) << "Using Azure Managed Identity authentication for " | ||
| << account_name; | ||
| std::shared_ptr<Azure::Core::Credentials::TokenCredential> token_cred; | ||
| if (!as_cred.client_id_.empty()) { | ||
| // User-assigned Managed Identity: specify the client ID. | ||
| Azure::Identity::ManagedIdentityCredentialOptions mi_opts; | ||
| mi_opts.ClientId = as_cred.client_id_; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there does not appear to be a |
||
| token_cred = | ||
| std::make_shared<Azure::Identity::ManagedIdentityCredential>( | ||
| mi_opts); | ||
| LOG_VERBOSE(1) << "Using user-assigned Managed Identity with client ID " | ||
| << as_cred.client_id_; | ||
| } else { | ||
| // System-assigned Managed Identity. | ||
| token_cred = | ||
| std::make_shared<Azure::Identity::ManagedIdentityCredential>(); | ||
| LOG_VERBOSE(1) << "Using system-assigned Managed Identity"; | ||
| } | ||
| client_ = std::make_shared<asb::BlobServiceClient>( | ||
whoisj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| service_url, token_cred); | ||
| } else if (as_cred.auth_type_ == "default") { | ||
| // DefaultAzureCredential chains multiple credential sources: | ||
| // environment variables → managed identity → Azure CLI → etc. | ||
| LOG_VERBOSE(1) << "Using Azure DefaultAzureCredential for " | ||
| << account_name; | ||
| auto token_cred = | ||
| std::make_shared<Azure::Identity::DefaultAzureCredential>(); | ||
| client_ = std::make_shared<asb::BlobServiceClient>( | ||
whoisj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| service_url, token_cred); | ||
| } else if (!as_cred.account_key_.empty()) { | ||
| // Shared Key authentication (backwards-compatible default). | ||
| auto cred = std::make_shared<as::StorageSharedKeyCredential>( | ||
| account_name, as_cred.account_key_); | ||
| client_ = std::make_shared<asb::BlobServiceClient>(service_url, cred); | ||
| } else { | ||
| // Anonymous access (no credential provided). | ||
| client_ = std::make_shared<asb::BlobServiceClient>(service_url); | ||
| } | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.