【问题标题】:How can I authenticate against ADXProxy using app key authentication?如何使用应用密钥身份验证针对 ADXProxy 进行身份验证?
【发布时间】:2021-08-23 05:44:47
【问题描述】:

我正在尝试使用(预览版)ADXProxy 功能通过 Redash 访问 Azure Application Insights 资源。

我已经在 Azure 中创建了一个应用注册,并且我有一些概念验证 python 代码可以成功访问我的 Application Insights 资源并使用应用程序令牌执行 Kusto 查询 (traces | take 1):

import azure.kusto
import azure.kusto.data.request
import msal

cluster = 'https://ade.applicationinsights.io/subscriptions/<MY_SUBSCRIPTION>/resourcegroups/<MY_RESOURCE_GROUP>/providers/microsoft.insights/components/<MY_APP_INSIGHTS_RESOURCE>'
app_id = '<MY_APP_ID>'
app_key = '<MY_SECRET>'
authority_id = '<MY_AAD_SUBSCRIPTION_ID>'

def run():

    app = msal.ConfidentialClientApplication(
        client_id=app_id, 
        client_credential=app_key, 
        authority='https://login.microsoftonline.com/<MY_AAD_SUBSCRIPTION_ID>')

    token = app.acquire_token_for_client(['https://help.kusto.windows.net/.default'])

    kcsb = azure.kusto.data.request.KustoConnectionStringBuilder.with_aad_application_token_authentication(
        connection_string=cluster,
        application_token=token['access_token']
    )

    client = azure.kusto.data.request.KustoClient(kcsb)

    result = client.execute('<MY_APP_INSIGHTS_RESOURCE>', 'traces | take 1')

    for res in result.primary_results:
        print(res)

    return 1

if __name__ == "__main__":
    run()

但是,Redash 不支持应用程序令牌认证:它使用应用程序密钥认证,调用如下:

    kcsb = azure.kusto.data.request.KustoConnectionStringBuilder.with_aad_application_key_authentication(
        connection_string = cluster,
        aad_app_id = app_id,
        app_key = app_key,
        authority_id = '<MY_AAD_SUBSCRIPTION_ID>'
    )

我无法使用这种类型的流程成功连接到我的 App Insights 资源。如果我将此 KustoConnectionStringBuilder 替换到我上面的程序中,我会收到一个异常告诉我:

在名为 的租户中找不到名为 https://ade.applicationinsights.io 的资源主体。如果租户管理员未安装应用程序或未获得租户中任何用户的同意,则可能会发生这种情况。您可能将身份验证请求发送给了错误的租户。

我可以在代码或 Azure 门户配置中做些什么来将我的“租户”连接到 ade.applicationinsights.io 资源主体并使此连接正常工作吗?

【问题讨论】:

    标签: msal azure-data-explorer redash


    【解决方案1】:

    Adxproxy 仅支持由 Azure Active Directory (AAD) 生成的令牌。必须为你拥有的 Azure 数据资源管理器群集 (ADX) 创建令牌。如果您没有自己的 ADX 集群,并且出于任何原因想要通过 Adxproxy 访问 Application Insights 资源,您始终可以向“https://help.kusto.windows.net”进行身份验证并使用该令牌。

    【讨论】:

    • 酷,如果这是它接受的唯一身份验证类型,我只需要使用它。我可以构建一个处理令牌而不是应用程序密钥身份验证的 Redash 数据源。
    猜你喜欢
    • 2017-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-11
    • 2019-02-17
    • 1970-01-01
    • 2021-01-22
    • 2017-11-24
    相关资源
    最近更新 更多