Skip to content
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

Support Microsoft Entra ID authentication to Azure. #4126

Merged
merged 14 commits into from
Mar 22, 2024

Conversation

teo-tsirpanis
Copy link
Member

@teo-tsirpanis teo-tsirpanis commented Jun 12, 2023

SC-25944

To authenticate to Azure, we currently support shared keys and SAS tokens. The former have the disadvantage of being discouraged by Microsoft and the latter have the disadvantage of having a usually short expiry time (edit: and being impossible to individually revoke).

This PR adds support for Microsoft Entra ID authentication (formerly known as Azure Active Directory), which is what Microsoft recommends. It will be used for HTTPS endpoints if neither a shared key or SAS token are specified in the config. We use the ChainedTokenCredential class from the azure-identity-cpp package, and try to get credentials from the following sources in order:

At initialization time we try to fetch an Active Directory token. If all three credential sources fail, we fall back to anonymous authentication.

TODO

  • Verify that it works locally.
  • Verify that accessing a publicly available blob with Entra ID credentials that do not grant access to it works.
    • If it doesn't, we have to remove the anonymous access fallback and add a config option (whether it will be opt-in or out is TBD).

TYPE: FEATURE
DESC: Support Microsoft Entra ID authentication to Azure.

@shortcut-integration
Copy link

This pull request has been linked to Shortcut Story #25944: Support Active Directory authentication to Azure..

@teo-tsirpanis teo-tsirpanis force-pushed the azure-ad branch 2 times, most recently from 41f112b to c80b8bd Compare June 16, 2023 14:33
@teo-tsirpanis teo-tsirpanis force-pushed the azure-ad branch 2 times, most recently from 6c4b189 to 91ae487 Compare October 23, 2023 20:48
@teo-tsirpanis teo-tsirpanis changed the title Support Active Directory authentication to Azure. Support Microsoft Entra ID authentication to Azure. Nov 16, 2023
@KiterLuc
Copy link
Contributor

Closing for now. We don't have time to test the authentication properly at the moment. It's still a good change and we can re-open this PR when we prioritize the shortcut story.

@KiterLuc KiterLuc closed this Feb 28, 2024
@teo-tsirpanis teo-tsirpanis reopened this Mar 12, 2024
@KiterLuc KiterLuc requested a review from robertbindar March 12, 2024 21:04
@teo-tsirpanis
Copy link
Member Author

teo-tsirpanis commented Mar 12, 2024

Validated successfully on the real Azure. I followed these steps:

  • Create an Azure Blob Storage account.
  • Add a role assignment of the "Storage Blob Data Contributor" role on the account to your user.
  • Log in to Azure by running az login and select your subscription.
  • Configure the tests to use your account name here, here and here1. Remove the custom endpoint and storage key options.
  • Run tiledb_unit [vfs][uri][file_io].

Please don't review yet; I will do some additional changes tomorrow.

Footnotes

  1. Why is the VFS configuration split in three places? --vfs azure is also broken; I had to change this line to run only Azure tests.

Copy link
Contributor

@KiterLuc KiterLuc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to see the same concerns addressed as in the GCS PR here.

In addition, I see that this is changing a lot on the build, probably because we now need more components and it's easier to get those from VCPKG. I need confirmation that this will not end up breaking dependencies like SOMA, mariaBD before we merge this change.

try {
::Azure::Core::Credentials::TokenCredentialOptions cred_options;
cred_options.Retry = options.Retry;
cred_options.Transport = options.Transport;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line will protect us from bugs similar to the AssumeRole bugs that were fixed by #4616 and #4641. options.Transport is created some lines earlier with the user-provided SSL config.

Comment on lines 224 to 226
// If a token is not available we wouldn't know it until we make a
// request and it would be too late. Try getting a token, and if it
// fails fall back to anonymous authentication.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For simplicity, instead of trying to fetch a token during initialization, I am thinking of enabling Entra ID authentication by default unless:

  • A storage key or SAS token is specified.
  • A custom endpoint is specified with the http protocol.
  • A new config option vfs.azure.disable_token_auth is enabled.

What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most existing use cases would not be broken since they already specify a shared key.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@robertbindar @KiterLuc thoughts on this? And if we don't add the config option to disable it now, can we do it in a subsequent PR/release?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@teo-tsirpanis I think it's better if we move this work in incremental steps. The current implementation you have here keeps the behavior we currently have intact. I'd go with this, then try to do config+no token in a PR past this release.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on Robert's comment. @teo-tsirpanis, we can file a follow up story.

Comment on lines -550 to -567
find_package(AzureCore_EP REQUIRED)
find_package(AzureStorageCommon_EP REQUIRED)
find_package(AzureStorageBlobs_EP REQUIRED)
if (NOT WIN32)
if (NOT TARGET LibXml2::LibXml2)
find_package(LibXml2 REQUIRED)
endif()
endif()
target_link_libraries(TILEDB_CORE_OBJECTS_ILIB
INTERFACE
Azure::azure-storage-blobs
Azure::azure-storage-common
Azure::azure-core)
# Link xml after Azure to allow symbol resolution on all platforms
if (NOT WIN32)
target_link_libraries(TILEDB_CORE_OBJECTS_ILIB INTERFACE LibXml2::LibXml2)
endif()
endif()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is used only if vcpkg is disabled, which no longer happens in first-party code.

Regarding the new dependency, Conda will need to be updated to add azure-identity-cpp in the requirements, and an empty vcpkg port overlay.

@teo-tsirpanis teo-tsirpanis marked this pull request as ready for review March 13, 2024 13:38
Copy link
Contributor

@robertbindar robertbindar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR looks good to me, minor code structure suggestions.
I would be more comfortable with all the build changes here (removal of non-vcpkg cmake code) if #4570 would already be in and things would scream if we'd still have any builds with -DTILEDB_VCPKG=OFF.
I'll reproduce asap Theo's steps for manually testing this, in the meantime it'd be lovely to get a confirmation on this statement, @ihnorton can you help out?

Regarding the new dependency, Conda will need to be updated to add azure-identity-cpp in the requirements, and an empty vcpkg port overlay.

@@ -79,9 +80,12 @@ std::string get_config_with_env_fallback(
}

std::string get_blob_endpoint(
const Config& config, const std::string& account_name) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

definitely a new function for checking if there is a sas token.

@@ -192,15 +196,57 @@ Azure::AzureClientSingleton::get(const AzureParameters& params) {
make_shared<::Azure::Storage::StorageSharedKeyCredential>(
HERE(), params.account_name_, params.account_key_),
options));
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should return early here the client if not nullptr, it'll help us get rid of the some if levels.

Copy link
Contributor

@KiterLuc KiterLuc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll let that one go through for now as we need to validate the build changes early. Testing will still be required to ship this.

@KiterLuc
Copy link
Contributor

Merging so that we can test the build changes early. @robertbindar will validate further and make fixes if required before we ship.

@KiterLuc KiterLuc merged commit ceee95e into TileDB-Inc:dev Mar 22, 2024
54 checks passed
@teo-tsirpanis teo-tsirpanis deleted the azure-ad branch March 22, 2024 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants