Add multi-tenant Databricks token support via cross-namespace K8s secrets#3394
Open
rohitrsh wants to merge 1 commit intoflyteorg:masterfrom
Open
Add multi-tenant Databricks token support via cross-namespace K8s secrets#3394rohitrsh wants to merge 1 commit intoflyteorg:masterfrom
rohitrsh wants to merge 1 commit intoflyteorg:masterfrom
Conversation
…space K8s secrets Enable per-project Databricks authentication by reading tokens from Kubernetes secrets in workflow namespaces, with backward-compatible fallback to the FLYTE_DATABRICKS_ACCESS_TOKEN environment variable. Changes: - Add get_secret_from_k8s() for cross-namespace K8s secret reading - Add get_databricks_token() with tiered resolution (K8s -> env var) - Update DatabricksJobMetadata to persist auth_token across lifecycle - Update DatabricksConnector.create/get/delete to use per-project tokens - Add DatabricksV2.databricks_token_secret for custom secret names - Add 31 comprehensive tests covering all token resolution paths Tracking: flyteorg/flyte#6911 Signed-off-by: Rohit Sharma <rohitrsh@gmail.com>
|
Thank you for opening this pull request! 🙌 These tips will help get your PR across the finish line:
|
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tracking issue
Related to flyteorg/flyte#6911
Why are the changes needed?
The Databricks Spark connector currently uses a single global
FLYTE_DATABRICKS_ACCESS_TOKENenvironment variable for authenticating all Databricks API calls. This creates significant limitations for multi-tenant Flyte deployments:This PR adds per-project Databricks token support by enabling the connector to read tokens from Kubernetes secrets in the workflow's project namespace, with backwards-compatible fallback to the existing environment variable.
What changes were proposed in this pull request?
Token Resolution Strategy
The connector now resolves Databricks tokens using a tiered strategy:
databricks-token, key:token) from the workflow's Kubernetes namespace using cross-namespace lookup.FLYTE_DATABRICKS_ACCESS_TOKENif no namespace secret is found.Changes
connector.py:get_secret_from_k8s(secret_name, secret_key, namespace)Cross-namespace K8s secret reader using the Kubernetes Python client. Tries in-cluster config first, falls back to kubeconfig for local development.get_databricks_token(namespace, task_template, secret_name). Implements the token resolution strategy with structured logging and error handling.get_header()Now accepts an optionalauth_tokenparameter.DatabricksJobMetadataAddedauth_tokenfield to persist the resolved token across create/get/delete operations.DatabricksConnector.create(). Now acceptstask_execution_metadataparameter, extracts the namespace, and resolves the project-specific token.DatabricksConnector.get()/delete()Use storedauth_tokenfrom metadata.task.py:databricks_token_secretfield toDatabricksV2Allows users to specify a custom K8S secret name per task.get_custom()SerialisesdatabricksTokenSecretinto the task template custom dict.User Experience
No changes needed for existing users Existing workflows continue to work with the global
FLYTE_DATABRICKS_ACCESS_TOKEN.New capability for multi-tenant setups:
How was this patch tested?
Unit Tests (
test_databricks_token.py)30+ test cases covering:
get_secret_from_k8s:get_databricks_token:get_header:DatabricksJobMetadata:DatabricksConnector:DatabricksV2task config:Setup process
getpermission on secrets across namespaces:kubectl create secret generic databricks-token \ --from-literal=token='your-token' \ --namespace=your-project-namespaceScreenshots
N/A (backend-only change)
Check all the applicable boxes
Related PRs
Docs link
N/A