Fix msgraph/Power BI auth failure from empty allowed_hosts list#69014
Open
davidnzhang wants to merge 2 commits into
Open
Fix msgraph/Power BI auth failure from empty allowed_hosts list#69014davidnzhang wants to merge 2 commits into
davidnzhang wants to merge 2 commits into
Conversation
2fbbc56 to
a738dc2
Compare
| hook = KiotaRequestAdapterHook(conn_id="msgraph_api") | ||
| await hook.get_async_conn() | ||
|
|
||
| assert mock_auth_provider.call_args.kwargs["allowed_hosts"] == [] |
Contributor
There was a problem hiding this comment.
Could we make this test exercise the filtering logic? Right now it only verifies the unconfigured case. Since the implementation now filters out empty entries, it woud be good to include input like "host1,,host2," (or even just ",") and assert that only the non-empty hosts are passed to AzureIdentityAuthenticationProvider.
| verify = config.get("verify", True) | ||
| trust_env = config.get("trust_env", False) | ||
| allowed_hosts = (config.get("allowed_hosts", authority) or "").split(",") | ||
| allowed_hosts = [host for host in (config.get("allowed_hosts", authority) or "").split(",") if host] |
Contributor
There was a problem hiding this comment.
This could be clearer. Please see the below:
allowed_hosts = config.get("allowed_hosts", authority)
if not allowed_hosts:
allowed_hosts = ""
allowed_hosts = [host for host in allowed_hosts.split(",") if host]
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
KiotaRequestAdapterHook._build_request_adapterderivesallowed_hostsfrom the connection'sextrafield and passes it toAzureIdentityAuthenticationProvider. When neitherallowed_hostsnorauthorityis configured,allowed_hostsreturned[""]rather than a true empty list.When this value eventually flows through to kiota's
AllowedHostsValidator.is_url_host_validmethod, it fails to skip validation via the early return:This PR filters out blank strings so an unconfigured connection yields
[]and correctly takes the early exit described above.Why
A recent change in the microsoft-kiota-abstractions package (microsoft/kiota-python@8755f70) fixed the
AllowedHostsValidatorto actually enforce a list of allowed hosts. Previously, it only checked whether a URL was structurally valid and ignored the configuredallowed_hostsset entirely. Theis_url_host_validmethod now correctly extracts the hostname from the URL and checks is against the allow list.This seemed to break existing Power BI connections which did not configure
allowed_hostsorauthority(which is the default for Power BI connections), as the validator receives a list with an empty string instead of a true empty list, causing requests to fail validation.Note that before the Microsoft change this was harmless, as the validator method never actually compared against the configured hosts (
return all([scheme, netloc])->True). This PR restores kiota's "skip validation" pathway for the default case where noallowed_hostsare set.Was generative AI tooling used to co-author this PR?
Generated-by: Claude Sonnet 4.6, following the guidelines
{pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.