[英]Snowflake: Configure Microsoft Azure AD for External OAuth - admin consent
我正在使用本指南為 Snowflake 中的外部 OAuth 配置 Microsoft Azure AD。 我很確定我遵循了所有步驟,因為在三個 Azure 訂閱上仔細嘗試並得到了相同的結果。
每次我被困在測試程序部分時,我應該向 Azure AD 發送請求以獲取訪問令牌:
curl -X POST -H "Content-Type: application/x-www-form-urlencoded;charset=UTF-8" \
--data-urlencode "client_id=<OAUTH_CLIENT_ID>" \
--data-urlencode "client_secret=<OAUTH_CLIENT_SECRET>" \
--data-urlencode "username=<AZURE_AD_USER>" \
--data-urlencode "password=<AZURE_AD_USER_PASSWORD>" \
--data-urlencode "grant_type=password" \
--data-urlencode "scope=session:role:analyst" \
'<AZURE_AD_OAUTH_TOKEN_ENDPOINT>'
我是訂閱所有者,並且明確授予了對session:role:analyst
scope 的管理員訪問權限:
但是,我得到的不是訪問令牌,而是以下響應:
{
"error": "invalid_grant",
"error_description": "AADSTS65001: The user or administrator has not consented to use the application with ID '...' named 'Snowflake OAuth Client'. Send an interactive authorization request for this user and resource.\r\nTrace ID: ...\r\nCorrelation ID: ...\r\nTimestamp: ...",
"error_codes": [
65001
],
"timestamp": "...",
"trace_id": "...",
"correlation_id": "...",
"suberror": "consent_required"
}
試圖通過到達https://login.microsoftonline.com/{{tenant_id}}/adminconsent?client_id={{client_id}}來授予同意,並在授予同意后出現錯誤: AADSTS500113: No reply address is registered for the application.
找到這個並添加了 return URL http://localhost/ (不清楚為什么)。 再次同意並被重定向到 http://localhost/?admin_consent=True&tenant={{tenant_id}}# 我想這很好。
但我仍然收到AADSTS65001: The user or administrator has not consented to use the application
。
訪問了 Microsoft 文檔並發現不推薦使用grant_type=password
- 有道理。
嘗試過grant_type=client
credentials:
curl --location --request GET 'https://login.microsoftonline.com/{{tenant_id}}/oauth2/v2.0/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode 'client_id={{client_id}}' \
--data-urlencode 'scope=https://graph.microsoft.com/.default' \
--data-urlencode 'client_secret={{client_secret}}'
獲得了訪問令牌,但嘗試使用如下連接字符串連接到 Snowflake:
connection.ConnectionString = $"account={account};host={host};authenticator=oauth;user={oauthUser};token={token};";
拋出Snowflake.Data.Client.SnowflakeDbException: 'Invalid OAuth access token.
.
我懷疑這是因為scope=https://graph.microsoft.com/.default
,但是用session:scope:analyst
替換它會帶來這個:
{
"error": "invalid_scope",
"error_description": "AADSTS1002012: The provided value for scope session:scope:analyst is not valid. Client credential flows must have a scope value with /.default suffixed to the resource identifier (application ID URI).\r\nTrace ID: ...\r\nCorrelation ID: ...\r\nTimestamp: ...",
"error_codes": [
1002012
],
"timestamp": "...",
"trace_id": "...",
"correlation_id": "..."
}
由於我已經偏離了官方 Snowflake 指南,因此我向社區尋求有關此問題的幫助。 提前謝謝你!
當使用資源所有者密碼憑據授予流程獲取訪問令牌時(不推薦,您確實不應該這樣做),生成的訪問令牌用於代表登錄用戶訪問資源 (API)。 在 Microsoft 標識平台中,代表用戶進行訪問要求客戶端應用程序至少被授予對所請求資源的一種委派權限。
在您的屏幕截圖中,我們看到您授予“Snowflake OAuth Resource”的權限是應用程序權限(又名“應用程序角色”)。
你需要做兩件事:
然后,當您 go 測試獲取令牌時,請確保“范圍”參數是完整的 scope 值,包括資源的標識符 URI(您在子步驟 9 中定義)。 例如,如果您的標識符 URI 是https://my.snowflake.example.com
,則“范圍”值將為https://my.snowflake.example.com/session:role:analyst
並且您的 cURL 請求將是:
curl -X POST -H "Content-Type: application/x-www-form-urlencoded;charset=UTF-8" \
--data-urlencode "client_id=<OAUTH_CLIENT_ID>" \
--data-urlencode "client_secret=<OAUTH_CLIENT_SECRET>" \
--data-urlencode "username=<AZURE_AD_USER>" \
--data-urlencode "password=<AZURE_AD_USER_PASSWORD>" \
--data-urlencode "grant_type=password" \
--data-urlencode "scope=https://my.snowflake.example.com/session:role:analyst" \
'<AZURE_AD_OAUTH_TOKEN_ENDPOINT>'
警告:不建議使用資源所有者密碼憑據授予流程。 我建議聯系建議您使用此流程的應用發行商。 以下是微軟對這個問題的警告:
Microsoft 建議您不要使用 ROPC 流程。 在大多數情況下,可以使用並推薦更安全的替代方案。 此流程需要對應用程序有非常高的信任度,並且會帶來其他流程中不存在的風險。 您應該僅在無法使用其他更安全的流程時才使用此流程。
如果設置仍配置為“密碼”類型的授權憑證,則 scope 存在問題,應在 AAD 上設置並按如下方式傳遞:
**session:role-<name>**
請注意,角色和名稱之間的連字符不是冒號。
在您的設置中,它似乎被設置並傳遞為:
session:role:<name>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.