08-29-2025 09:50 AM - edited 08-29-2025 09:52 AM
Hi
I am trying to create a service principal federation policy against AKS cluster. But I am struggling to make it work without any examples.
It would be great if you could share examples on how this would work for a service account.
Additionally, what I would like to know is, does databricks inject tokens into the pod, or does it need the Azure workload identity federated token to communicate to databricks? In the latter case, how is it different from oauth m2m flow.
a month ago
Hey sparkplug - Thanks for reaching out!
To enable a service account in AKS to authenticate to Databricks using workload identity federation, you must create a service principal federation policy in Databricks that allows tokens issued by the Kubernetes cluster acting as the OIDC provider.
Federation Policy Example (for Kubernetes Service Account):
Key parameters:
https://kubernetes.default.svc
for in-cluster workloads)https://kubernetes.default.svc
system:serviceaccount:<namespace>:<serviceaccount-name>
Sample Policy (using Databricks CLI):
databricks account service-principal-federation-policy create <SERVICE_PRINCIPAL_NUMERIC_ID> --json \
'{
"oidc_policy": {
"issuer": "https://kubernetes.default.svc",
"audiences": ["https://kubernetes.default.svc"],
"subject": "system:serviceaccount:my-namespace:my-serviceaccount"
}
}'
Corresponding JWT Claims:
{
"iss": "https://kubernetes.default.svc",
"aud": ["https://kubernetes.default.svc"],
"sub": "system:serviceaccount:my-namespace:my-serviceaccount"
}
Terraform Example (resource arguments): https://github.com/databricks/terraform-provider-databricks/blob/main/docs/resources/service_princip...
issuer
(string): OIDC issuer URLaudiences
(list): List of valid audience valuessubject
(string): Required Kubernetes service account identifiersubject_claim
(optional): Defaults to sub
Databricks Integration: Token Handling in AKS Pods
Databricks does not directly inject Databricks tokens into pods in AKS clusters.
How does the authentication work?
YAML Pod Configuration Example (key extracts):
spec:
serviceAccountName: my-serviceaccount
volumes:
- name: azure-projected-service-account-token
projected:
sources:
- serviceAccountToken:
audience: api://AzureADTokenExchange
expirationSeconds: 3600
path: azure-projected-service-account-token
containers:
- name: my-container
volumeMounts:
- mountPath: /databricks/secrets/azure-projected-service-account-token
name: azure-projected-service-account-token
readOnly: true
env:
- name: AZURE_CLIENT_ID
value: <client-id>
- name: AZURE_TENANT_ID
value: <tenant>
- name: AZURE_AUTHORITY_HOST
value: "https://login.microsoftonline.com/"
- name: AZURE_FEDERATED_TOKEN_FILE
value: "/databricks/secrets/azure-projected-service-account-token/azure-projected-service-account-token"
AZURE_FEDERATED_TOKEN_FILE
, perform the token exchange, and obtain a Databricks OAuth token.Databricks Token Federation vs. OAuth m2m Flow
Workload Identity Federation (What you configure here)
OAuth m2m (Machine-to-Machine) Flow
a month ago
Hey sparkplug - Thanks for reaching out!
To enable a service account in AKS to authenticate to Databricks using workload identity federation, you must create a service principal federation policy in Databricks that allows tokens issued by the Kubernetes cluster acting as the OIDC provider.
Federation Policy Example (for Kubernetes Service Account):
Key parameters:
https://kubernetes.default.svc
for in-cluster workloads)https://kubernetes.default.svc
system:serviceaccount:<namespace>:<serviceaccount-name>
Sample Policy (using Databricks CLI):
databricks account service-principal-federation-policy create <SERVICE_PRINCIPAL_NUMERIC_ID> --json \
'{
"oidc_policy": {
"issuer": "https://kubernetes.default.svc",
"audiences": ["https://kubernetes.default.svc"],
"subject": "system:serviceaccount:my-namespace:my-serviceaccount"
}
}'
Corresponding JWT Claims:
{
"iss": "https://kubernetes.default.svc",
"aud": ["https://kubernetes.default.svc"],
"sub": "system:serviceaccount:my-namespace:my-serviceaccount"
}
Terraform Example (resource arguments): https://github.com/databricks/terraform-provider-databricks/blob/main/docs/resources/service_princip...
issuer
(string): OIDC issuer URLaudiences
(list): List of valid audience valuessubject
(string): Required Kubernetes service account identifiersubject_claim
(optional): Defaults to sub
Databricks Integration: Token Handling in AKS Pods
Databricks does not directly inject Databricks tokens into pods in AKS clusters.
How does the authentication work?
YAML Pod Configuration Example (key extracts):
spec:
serviceAccountName: my-serviceaccount
volumes:
- name: azure-projected-service-account-token
projected:
sources:
- serviceAccountToken:
audience: api://AzureADTokenExchange
expirationSeconds: 3600
path: azure-projected-service-account-token
containers:
- name: my-container
volumeMounts:
- mountPath: /databricks/secrets/azure-projected-service-account-token
name: azure-projected-service-account-token
readOnly: true
env:
- name: AZURE_CLIENT_ID
value: <client-id>
- name: AZURE_TENANT_ID
value: <tenant>
- name: AZURE_AUTHORITY_HOST
value: "https://login.microsoftonline.com/"
- name: AZURE_FEDERATED_TOKEN_FILE
value: "/databricks/secrets/azure-projected-service-account-token/azure-projected-service-account-token"
AZURE_FEDERATED_TOKEN_FILE
, perform the token exchange, and obtain a Databricks OAuth token.Databricks Token Federation vs. OAuth m2m Flow
Workload Identity Federation (What you configure here)
OAuth m2m (Machine-to-Machine) Flow
3 weeks ago
Hi @sparkplug, just checking in, did the guidance shared above help address your query? If it did, please consider marking it as the accepted answer.
yesterday - last edited yesterday
@sarahbhord Isn't it the same federation policy that I would configure on Azure as a service principal as well ? Given that I will always use Azure service principal or managed identity.
I am not able to make the databricks-sdk pick up on the environment variables , but it constantly complaints that there is no default auth set
ValueError: default auth: cannot configure default credentials, please check https://docs.databricks.com/en/dev-tools/auth.html#databricks-client-unified-authentication to configure credentials for your preferred authentication method.
yesterday - last edited yesterday
I am currently using a two step process, logging in using azure library and then getting an access token from Azure using the databricks scope. And then using that to authorize towards Databricks. I would like to use `env-oidc` auth type instead, but it doesn't seem to work. Not sure if it's trying to write .databrickscfg . And am not sure how the token refresh is handled in the sdk
from databricks.sdk import WorkspaceClient
from azure.identity import WorkloadIdentityCredential
credential = WorkloadIdentityCredential(client_id=os.environ["APPLICATION_ID"])
token = credential.get_token(DATABRICKS_SCOPE).token
return WorkspaceClient(host=os.environ["DATABRICKS_HOST"], token=token)
I am using
databricks-sdk==0.67.0
azure-identity==1.25.0
Any suggestions are appreciated.
yesterday
Gotcha. Can you describe what is not working? Any specific error or behaviour?
Passionate about hosting events and connecting people? Help us grow a vibrant local community—sign up today to get started!
Sign Up Now