ā03-21-2023 07:35 AM
I am trying to generate a Databricks token for a service principal (SP). I have created the SP in Azure AD and have used the Databricks rest api to add it as an admin.
When using the Databricks rest API "/api/2.0/token-management/on-behalf-of/tokens" to create a token for this SP, I get this error, {"error_code":"FEATURE_DISABLED","message":"On-behalf-of token creation for service principals is not enabled for this workspace"}.
I have enabled the personal access tokens in Admin console and I've even gone to the extent to manually add the SP to Admin permissions. I'm not sure what setting I can change in Databricks to enable this feature. Any help would be greatly appreciated.
ā04-03-2023 02:37 AM
Hi all,
I believe I found a temporary fix for this -
Generate an AAD token for the service principle in Azure. Follow this guide if you don't know how to -
https://learn.microsoft.com/en-us/azure/databricks/dev-tools/api/latest/aad/service-prin-aad-token
Then using the Databricks API "token/create" endpoint, create a PAT token but use the Bearer token provided above. With this, you can control the lifespan of that PAT token for the service principle as it's controlled within Databricks, outside of the SCIM.
ā03-21-2023 10:24 AM
The `/on-behalf-of/tokens` API endpoint is not supported in Azure Databricks.
Please generate an AAD token as described in this article: https://docs.microsoft.com/en-us/azure/databricks/dev-tools/api/latest/aad/service-prin-aad-token
ā03-21-2023 10:29 AM
Hi @Sivaprasad C Sā ,
Thanks for your answer, we are following AAD tokens only as a workaround.
The problem with the AAD token with is the lifetime is restricted to 1 hour, that's the sole reason we were looking forward to generating a permanent access token for SP.
Is it possible to increase the lifespan of an AAD token while its generation?
ā03-22-2023 09:28 AM
@Akash Sharmaā best way is go with managed identity instead of service principle
ā03-22-2023 10:05 AM
Have some specific requirements, where we want to hit Databricks Jobs from outside services like PowerRunbook and all, that's where only Access Token can help I believe.
ā03-23-2023 01:26 AM
We had the same issue recently. There isn't any documentation that states that on-behalf of is disabled the only thing to indicate this is the error message. The other issue is that the AAD token requires using it to request a temporary token for access. This doesn't work with apps like Power BI and an alternative solution isn't recommended.
ā04-01-2023 10:15 PM
@Akash Sharmaā :
The error message you are seeing indicates that the on-behalf-of token creation feature for service principals is not enabled for your Databricks workspace. To enable this feature, you will need to contact Databricks support and request that they enable it for your workspace.
Once the feature is enabled, you should be able to use the /api/2.0/token-management/on-behalf-of/tokens endpoint to generate an access token for the service principal.
In the meantime, you can generate a token manually by using the Databricks UI:
This will generate an access token for the service principal, which you can use in your API requests.
ā04-03-2023 07:33 AM
This option doesn't seem to be available in the UI. Maybe it's disabled with the On-Behalf of permission?
ā04-03-2023 07:41 AM
Hi Chris,
The below solution provided by @Callum Whiteā worked for me. If I am not providing any expiry then it's generating a token for a lifetime of 5 years.
Also you can verify the same if it associated with your SPN by using below API:
https://<databricks-instance>/api/2.0/token-management/tokens
ā04-03-2023 02:37 AM
Hi all,
I believe I found a temporary fix for this -
Generate an AAD token for the service principle in Azure. Follow this guide if you don't know how to -
https://learn.microsoft.com/en-us/azure/databricks/dev-tools/api/latest/aad/service-prin-aad-token
Then using the Databricks API "token/create" endpoint, create a PAT token but use the Bearer token provided above. With this, you can control the lifespan of that PAT token for the service principle as it's controlled within Databricks, outside of the SCIM.
ā04-11-2023 11:59 PM
Hi @Callum Whiteā @Akash Sharmaā ,
Could you please explain if we are using Azure AD token of the service principal then why do we need PAT token along with it to Authenticate Databricks Rest API?
And what do we mean by 'create a PAT token but use the Bearer token provided above. With this, you can control the lifespan of that PAT token for the service principle '
ā04-14-2023 09:47 PM
@Sanjoy Senā
Azure AD token of service pricipal can also be used to Authenticate Databricks Rest API but they comes with limited lifespan.
Now it depends upon on your use case, you can integrate it into your script and generate AD tokens whenever you want to do the job. What I wanted to do is that remove the dependency of users personal access token by generating a lifetime/limited-time token based of SPN, this is where the above solution worked for me.
Hope that helps!
ā04-15-2023 11:04 PM
@Akash Sharmaā Thanks..It absolutely make sense.
ā04-17-2023 07:24 AM
Azure AD Token for service principals defaults to 60 minutes - Azure doesn't currently support configuring the token lifetimes for service principals or managed identity service principals, stated in this post - https://learn.microsoft.com/en-us/azure/active-directory/develop/active-directory-configurable-token...
But this is not the case for PAT tokens within Databricks as they can have any lifespan as its controlled by Databricks, not the Azure AD.
Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonāt want to miss the chance to attend and share knowledge.
If there isnāt a group near you, start one and help create a community that brings people together.
Request a New Group