-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
GH-39320: [C++][FS][Azure] Add managed identity auth configuration #39321
Changes from 4 commits
4bfacdd
f6e40aa
d4af840
3a9b89f
414f582
de0a869
8cdcf4b
bfa2cc5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,27 +117,42 @@ Status AzureOptions::ConfigureClientSecretCredential(const std::string& account_ | |
const std::string& tenant_id, | ||
const std::string& client_id, | ||
const std::string& client_secret) { | ||
account_name_ = account_name; | ||
credential_kind_ = CredentialKind::kTokenCredential; | ||
token_credential_ = std::make_shared<Azure::Identity::ClientSecretCredential>( | ||
tenant_id, client_id, client_secret); | ||
return Status::OK(); | ||
} | ||
|
||
Status AzureOptions::ConfigureDefaultCredential(const std::string& account_name) { | ||
account_name_ = account_name; | ||
credential_kind_ = CredentialKind::kTokenCredential; | ||
token_credential_ = std::make_shared<Azure::Identity::DefaultAzureCredential>(); | ||
return Status::OK(); | ||
} | ||
|
||
Status AzureOptions::ConfigureManagedIdentityCredential(const std::string& account_name, | ||
const std::string& client_id) { | ||
account_name_ = account_name; | ||
credential_kind_ = CredentialKind::kTokenCredential; | ||
token_credential_ = | ||
std::make_shared<Azure::Identity::ManagedIdentityCredential>(client_id); | ||
return Status::OK(); | ||
} | ||
|
||
Status AzureOptions::ConfigureWorkloadIdentityCredential( | ||
const std::string& account_name) { | ||
account_name_ = 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 { | ||
if (account_name_.empty()) { | ||
return Status::Invalid("AzureOptions doesn't contain a valid account name"); | ||
} | ||
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. Another simplification we can make:
In the What you think? 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. I think its useful to support both anonymous and default credential as distinct things. Admittedly, its a niche use-case but storage accounts can be public, which is when anonymous is useful https://learn.microsoft.com/en-us/azure/storage/blobs/anonymous-read-access-configure?tabs=portal. Its a good question though which should be the default. I know 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. Ok. Makes sense to keep 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. I looked and there is a constructor that doesn't take any credentials. I guess that's what we should call :-) 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. 👍 Do you mind if we do that in a separate PR to fix up anonymous and change the default to default credential. This was supposed to be a super simple PR until kou realised all the auths were broken 😅 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. No problem. |
||
switch (credential_kind_) { | ||
case CredentialKind::kAnonymous: | ||
break; | ||
|
@@ -153,6 +168,9 @@ Result<std::unique_ptr<Blobs::BlobServiceClient>> AzureOptions::MakeBlobServiceC | |
|
||
Result<std::unique_ptr<DataLake::DataLakeServiceClient>> | ||
AzureOptions::MakeDataLakeServiceClient() const { | ||
if (account_name_.empty()) { | ||
return Status::Invalid("AzureOptions doesn't contain a valid account name"); | ||
} | ||
switch (credential_kind_) { | ||
case CredentialKind::kAnonymous: | ||
break; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that
account_name
isn't used. Is it needed?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Sorry, I have not been paying enough attention 🤦♂️ . I think @felipecrv refactored this slightly. I need to check how the account name is configured now. I'll do it tomorrow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
It seems that both of
ConfigureWorkloadIdentityCredential()
andConfigureDefaultCredential()
are the same situation too. Could you check them too?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed now. I have added a check so that filesystem initialisation fails if
account_name_.empty()
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry. I messed up and forgot to set
account_name_
on theConfigure...
functions.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should undo something I did and move
account_name_
back to a publicaccount_name
field (the first inAzureOptions
, but remove theaccount_name
parameter from all theConfigure...
functions. That allows us to avoid the repetition of theaccount_name
parameter and is more in line to how every credential constructor doesn't really need anaccount_name
.@Tom-Newton what you think and can you do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds good to me 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we actually need to make
account_name_
public though? Personally I would just makeaccount_name
a required argument of the AzureOptions constructor.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be a good idea in normal classes, but these
*Options
classes tend to be designed like simple C structs that can be constructed from any language and easily serialized. The only exception being the secret stuff that we don't want to leak and lazily initialized fields.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. I think its as you recommended now.