Azure Databricks SQL 执行 API

问题描述 投票:0回答:1

我尝试通过服务主体而不是个人访问令牌创建 Databricks 令牌。下面是我运行的代码:

host = 'host'
client_id = 'clientId'
oauth_secret = 'secretKey' 
endpoint = '/oidc/v1/token'
url = f'{host}{endpoint}'

data = {
  "grant_type": "client_credentials",
  "scope": "all-apis"
}

auth = (client_id, oauth_secret)
oauth_response = requests.post(url, data=data, auth=auth)
oauth_token = oauth_response.json()['access_token']

endpoint = '/api/2.0/token/create'
url = f'{host}{endpoint}'

headers = {
    "Authorization": f"Bearer {oauth_token}"
}
payload = {
    "comment": "TestTokenCreation"
}

response = requests.post(url, headers=headers, json=payload)
response.json()

我得到的输出是:

{'token_value': 'dapixxxxxxxxxxx',
 'token_info': {'token_id': 'xxxxxxxxxxxxxxxxxxx',
  'creation_time': 1715055980619,
  'expiry_time': -1,
  'comment': 'TestTokenCreation'}}

我设法获取了令牌值,如上面的输出所示。我尝试使用令牌值作为授权令牌来查询databricks仓库数据(Databricks SQL执行API)。但是,我收到以下错误:

[INSUFFICIENT_PERMISSIONS] Insufficient privileges:
User does not have permission SELECT on table `brxxxx8`.`0xxxxxxx`.
User does not have permission USAGE on database `brxxxx8`. SQLSTATE: 42501

由于令牌是使用服务主体生成的,我怀疑是服务主体访问问题。但是,我已经向服务主体授予了 Databricks SQL 访问权限,并且还向服务主体授予了仓库的“可以管理”权限,但错误仍然存在。有人知道发生了什么事吗?任何帮助或建议将不胜感激!

api azure-databricks
1个回答
0
投票

该错误是因为您使用的服务主体没有

select
usage
权限。

要启用,请按照以下步骤操作。

enter image description here

转到 > 目录 > 您的架构或数据库 > 权限,然后单击授予

您将获得以下选项。

enter image description here

在这里,搜索您的服务主体并选择。

然后授予必要的权限并单击授予

enter image description here

知道让语句执行post请求,查询就会执行。

© www.soinside.com 2019 - 2024. All rights reserved.