Skip to content

Commit

Permalink
GH-39318: [C++][FS][Azure] Add workload identity auth configuration (#…
Browse files Browse the repository at this point in the history
…39319)

### Rationale for this change
Workload identity is a useful Azure authentication method.

### What changes are included in this PR?
Implement `AzureOptions::ConfigureWorkloadIdentityCredential`

### Are these changes tested?
Added a simple test initialising a fileystem using `ConfigureWorkloadIdentityCredential`. This is not the most comprehensive test but its the same as what we agreed on for #39263. 

### Are there any user-facing changes?
Workload identity authentication is now supported. 

* Closes: #39318

Authored-by: Thomas Newton <thomas.w.newton@gmail.com>
Signed-off-by: Sutou Kouhei <kou@clear-code.com>
  • Loading branch information
Tom-Newton authored Dec 21, 2023
1 parent 37616a8 commit 3c66491
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
7 changes: 7 additions & 0 deletions cpp/src/arrow/filesystem/azurefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ Status AzureOptions::ConfigureDefaultCredential(const std::string& account_name)
return Status::OK();
}

Status AzureOptions::ConfigureWorkloadIdentityCredential(
const std::string& account_name) {
credential_kind_ = CredentialKind::kTokenCredential;
token_credential_ = std::make_shared<Azure::Identity::WorkloadIdentityCredential>();
return Status::OK();
}

Result<std::unique_ptr<Blobs::BlobServiceClient>> AzureOptions::MakeBlobServiceClient()
const {
switch (credential_kind_) {
Expand Down
2 changes: 2 additions & 0 deletions cpp/src/arrow/filesystem/azurefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ struct ARROW_EXPORT AzureOptions {

Status ConfigureDefaultCredential(const std::string& account_name);

Status ConfigureWorkloadIdentityCredential(const std::string& account_name);

Status ConfigureAccountKeyCredential(const std::string& account_name,
const std::string& account_key);

Expand Down
8 changes: 7 additions & 1 deletion cpp/src/arrow/filesystem/azurefs_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,13 @@ class AzureHierarchicalNSEnv : public AzureEnvImpl<AzureHierarchicalNSEnv> {
TEST(AzureFileSystem, InitializeFilesystemWithDefaultCredential) {
AzureOptions options;
ARROW_EXPECT_OK(options.ConfigureDefaultCredential("dummy-account-name"));
EXPECT_OK_AND_ASSIGN(auto default_credential_fs, AzureFileSystem::Make(options));
EXPECT_OK_AND_ASSIGN(auto fs, AzureFileSystem::Make(options));
}

TEST(AzureFileSystem, InitializeFilesystemWithWorkloadIdentityCredential) {
AzureOptions options;
ARROW_EXPECT_OK(options.ConfigureWorkloadIdentityCredential("dummy-account-name"));
EXPECT_OK_AND_ASSIGN(auto fs, AzureFileSystem::Make(options));
}

TEST(AzureFileSystem, OptionsCompare) {
Expand Down

0 comments on commit 3c66491

Please sign in to comment.