Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set necessary headers when authenticating via Azure CLI #290

Merged
merged 5 commits into from
Aug 17, 2023
Merged

Conversation

mgyucht
Copy link
Contributor

@mgyucht mgyucht commented Aug 17, 2023

Changes

The Python SDK request authentication logic is inconsistent between the Azure login types: for service principal auth, the SDK correctly adds the X-Databricks-Azure-Workspace-Resource-Id when configured, but this is missed for Azure CLI auth.

This PR fixes this by defining the logic to attach this header in a common function that is used by all Azure-specific authentication types.

See databricks/databricks-sdk-go#584 for the same change in Go SDK.

Tests

  • Added a unit test to ensure the header is being set for Azure CLI login

  • make test run locally

  • make fmt applied

  • relevant integration tests applied

@codecov-commenter
Copy link

codecov-commenter commented Aug 17, 2023

Codecov Report

Patch coverage: 86.95% and project coverage change: +0.06% 🎉

Comparison is base (f6e3a1e) 52.60% compared to head (565cc61) 52.66%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #290      +/-   ##
==========================================
+ Coverage   52.60%   52.66%   +0.06%     
==========================================
  Files          33       33              
  Lines       19880    19898      +18     
==========================================
+ Hits        10457    10480      +23     
+ Misses       9423     9418       -5     
Files Changed Coverage Δ
databricks/sdk/core.py 68.21% <80.00%> (+1.07%) ⬆️
databricks/sdk/azure.py 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mgyucht mgyucht changed the title Added X-Databricks-Azure-Workspace-Resource-Id header to Azure CLI-authenticated requests Set necessary headers when authenticating via Azure CLI Aug 17, 2023
@mgyucht mgyucht added this pull request to the merge queue Aug 17, 2023
Merged via the queue into main with commit 02f7d98 Aug 17, 2023
8 checks passed
@mgyucht mgyucht deleted the tf-issue-2590 branch August 17, 2023 12:10
mgyucht added a commit that referenced this pull request Aug 17, 2023
* Added collection of Databricks Runtime versions used together with Python SDK ([#287](#287)).
* Applied attribute transformer when reading in attributes from the environment ([#293](#293)).
* Made notebook-native auth work with more configurations of the Databricks Runtime ([#285](#285)).
* Added retry in `w.clusters.ensure_cluster_is_running(id)` when cluster is simultaneously started by two different processes. ([#283](#283)).
* Set necessary headers when authenticating via Azure CLI ([#290](#290)).
* Updated classifier to `Development Status :: 4 - Beta` ([#291](#291)).
* Introduced Artifact Allowlist, Securable Tags, and Subentity Tags services.
* Introduced DeleteRuns and RestoreRuns methods in the Experiments API.
* Introduced the GetSecret method in the Secrets API.
* Renamed Auto Maintenance to Predictive Optimization.

New Services:

 * Added [w.artifact_allowlists](https://databricks-sdk-py.readthedocs.io/en/latest/workspace/artifact_allowlists.html) workspace-level service.
 * Added [w.securable_tags](https://databricks-sdk-py.readthedocs.io/en/latest/workspace/securable_tags.html) workspace-level service.
 * Added [w.subentity_tags](https://databricks-sdk-py.readthedocs.io/en/latest/workspace/subentity_tags.html) workspace-level service.
 * Added `databricks.sdk.service.catalog.ArtifactAllowlistInfo` dataclass.
 * Added `databricks.sdk.service.catalog.ArtifactMatcher` dataclass.
 * Added `databricks.sdk.service.catalog.ArtifactType` dataclass.
 * Added `databricks.sdk.service.catalog.GetArtifactAllowlistRequest` dataclass.
 * Added `databricks.sdk.service.catalog.ListSecurableTagsRequest` dataclass.
 * Added `databricks.sdk.service.catalog.ListSecurableType` dataclass.
 * Added `databricks.sdk.service.catalog.ListSubentityTagsRequest` dataclass.
 * Added `databricks.sdk.service.catalog.MatchType` dataclass.
 * Added `databricks.sdk.service.catalog.SetArtifactAllowlist` dataclass.
 * Added `databricks.sdk.service.catalog.TagChanges` dataclass.
 * Added `databricks.sdk.service.catalog.TagKeyValuePair` dataclass.
 * Added `databricks.sdk.service.catalog.TagSecurable` dataclass.
 * Added `databricks.sdk.service.catalog.TagSecurableAssignment` dataclass.
 * Added `databricks.sdk.service.catalog.TagSecurableAssignmentsList` dataclass.
 * Added `databricks.sdk.service.catalog.TagSubentity` dataclass.
 * Added `databricks.sdk.service.catalog.TagSubentityAssignmentsList` dataclass.
 * Added `databricks.sdk.service.catalog.TagsSubentityAssignment` dataclass.
 * Added `databricks.sdk.service.catalog.UpdateSecurableType` dataclass.
 * Added `databricks.sdk.service.catalog.UpdateTags` dataclass.

New APIs:

 * Added `delete_runs()` method for [w.experiments](https://databricks-sdk-py.readthedocs.io/en/latest/workspace/experiments.html) workspace-level service.
 * Added `restore_runs()` method for [w.experiments](https://databricks-sdk-py.readthedocs.io/en/latest/workspace/experiments.html) workspace-level service.
 * Added `databricks.sdk.service.ml.DeleteRuns` dataclass.
 * Added `databricks.sdk.service.ml.DeleteRunsResponse` dataclass.
 * Added `databricks.sdk.service.ml.RestoreRuns` dataclass.
 * Added `databricks.sdk.service.ml.RestoreRunsResponse` dataclass.
 * Added `get_secret()` method for [w.secrets](https://databricks-sdk-py.readthedocs.io/en/latest/workspace/secrets.html) workspace-level service.
 * Added `databricks.sdk.service.workspace.GetSecretRequest` dataclass.
 * Added `databricks.sdk.service.workspace.GetSecretResponse` dataclass.

Service Renames:

 * Removed `effective_auto_maintenance_flag` field for `databricks.sdk.service.catalog.CatalogInfo`.
 * Removed `enable_auto_maintenance` field for `databricks.sdk.service.catalog.CatalogInfo`.
 * Added `effective_predictive_optimization_flag` field for `databricks.sdk.service.catalog.CatalogInfo`.
 * Added `enable_predictive_optimization` field for `databricks.sdk.service.catalog.CatalogInfo`.
 * Removed `databricks.sdk.service.catalog.EffectiveAutoMaintenanceFlag` dataclass.
 * Removed `databricks.sdk.service.catalog.EffectiveAutoMaintenanceFlagInheritedFromType` dataclass.
 * Removed `databricks.sdk.service.catalog.EnableAutoMaintenance` dataclass.
 * Removed `effective_auto_maintenance_flag` field for `databricks.sdk.service.catalog.SchemaInfo`.
 * Removed `enable_auto_maintenance` field for `databricks.sdk.service.catalog.SchemaInfo`.
 * Added `effective_predictive_optimization_flag` field for `databricks.sdk.service.catalog.SchemaInfo`.
 * Added `enable_predictive_optimization` field for `databricks.sdk.service.catalog.SchemaInfo`.
 * Removed `effective_auto_maintenance_flag` field for `databricks.sdk.service.catalog.TableInfo`.
 * Removed `enable_auto_maintenance` field for `databricks.sdk.service.catalog.TableInfo`.
 * Added `effective_predictive_optimization_flag` field for `databricks.sdk.service.catalog.TableInfo`.
 * Added `enable_predictive_optimization` field for `databricks.sdk.service.catalog.TableInfo`.
 * Added `databricks.sdk.service.catalog.EffectivePredictiveOptimizationFlag` dataclass.
 * Added `databricks.sdk.service.catalog.EffectivePredictiveOptimizationFlagInheritedFromType` dataclass.
 * Added `databricks.sdk.service.catalog.EnablePredictiveOptimization` dataclass.

OpenAPI SHA: beff621d7b3e1d59244e2e34fc53a496f310e130, Date: 2023-08-17
@mgyucht mgyucht mentioned this pull request Aug 17, 2023
github-merge-queue bot pushed a commit that referenced this pull request Aug 17, 2023
* Added collection of Databricks Runtime versions used together with
Python SDK
([#287](#287)).
* Applied attribute transformer when reading in attributes from the
environment
([#293](#293)).
* Made notebook-native auth work with more configurations of the
Databricks Runtime
([#285](#285)).
* Added retry in `w.clusters.ensure_cluster_is_running(id)` when cluster
is simultaneously started by two different processes.
([#283](#283)).
* Set necessary headers when authenticating via Azure CLI
([#290](#290)).
* Updated classifier to `Development Status :: 4 - Beta`
([#291](#291)).
* Introduced Artifact Allowlist, Securable Tags, and Subentity Tags
services.
* Introduced DeleteRuns and RestoreRuns methods in the Experiments API.
* Introduced the GetSecret method in the Secrets API.
* Renamed Auto Maintenance to Predictive Optimization.

New Services:

* Added
[w.artifact_allowlists](https://databricks-sdk-py.readthedocs.io/en/latest/workspace/artifact_allowlists.html)
workspace-level service.
* Added
[w.securable_tags](https://databricks-sdk-py.readthedocs.io/en/latest/workspace/securable_tags.html)
workspace-level service.
* Added
[w.subentity_tags](https://databricks-sdk-py.readthedocs.io/en/latest/workspace/subentity_tags.html)
workspace-level service.
* Added `databricks.sdk.service.catalog.ArtifactAllowlistInfo`
dataclass.
 * Added `databricks.sdk.service.catalog.ArtifactMatcher` dataclass.
 * Added `databricks.sdk.service.catalog.ArtifactType` dataclass.
* Added `databricks.sdk.service.catalog.GetArtifactAllowlistRequest`
dataclass.
* Added `databricks.sdk.service.catalog.ListSecurableTagsRequest`
dataclass.
 * Added `databricks.sdk.service.catalog.ListSecurableType` dataclass.
* Added `databricks.sdk.service.catalog.ListSubentityTagsRequest`
dataclass.
 * Added `databricks.sdk.service.catalog.MatchType` dataclass.
* Added `databricks.sdk.service.catalog.SetArtifactAllowlist` dataclass.
 * Added `databricks.sdk.service.catalog.TagChanges` dataclass.
 * Added `databricks.sdk.service.catalog.TagKeyValuePair` dataclass.
 * Added `databricks.sdk.service.catalog.TagSecurable` dataclass.
* Added `databricks.sdk.service.catalog.TagSecurableAssignment`
dataclass.
* Added `databricks.sdk.service.catalog.TagSecurableAssignmentsList`
dataclass.
 * Added `databricks.sdk.service.catalog.TagSubentity` dataclass.
* Added `databricks.sdk.service.catalog.TagSubentityAssignmentsList`
dataclass.
* Added `databricks.sdk.service.catalog.TagsSubentityAssignment`
dataclass.
 * Added `databricks.sdk.service.catalog.UpdateSecurableType` dataclass.
 * Added `databricks.sdk.service.catalog.UpdateTags` dataclass.

New APIs:

* Added `delete_runs()` method for
[w.experiments](https://databricks-sdk-py.readthedocs.io/en/latest/workspace/experiments.html)
workspace-level service.
* Added `restore_runs()` method for
[w.experiments](https://databricks-sdk-py.readthedocs.io/en/latest/workspace/experiments.html)
workspace-level service.
 * Added `databricks.sdk.service.ml.DeleteRuns` dataclass.
 * Added `databricks.sdk.service.ml.DeleteRunsResponse` dataclass.
 * Added `databricks.sdk.service.ml.RestoreRuns` dataclass.
 * Added `databricks.sdk.service.ml.RestoreRunsResponse` dataclass.
* Added `get_secret()` method for
[w.secrets](https://databricks-sdk-py.readthedocs.io/en/latest/workspace/secrets.html)
workspace-level service.
 * Added `databricks.sdk.service.workspace.GetSecretRequest` dataclass.
 * Added `databricks.sdk.service.workspace.GetSecretResponse` dataclass.

Service Renames:

* Removed `effective_auto_maintenance_flag` field for
`databricks.sdk.service.catalog.CatalogInfo`.
* Removed `enable_auto_maintenance` field for
`databricks.sdk.service.catalog.CatalogInfo`.
* Added `effective_predictive_optimization_flag` field for
`databricks.sdk.service.catalog.CatalogInfo`.
* Added `enable_predictive_optimization` field for
`databricks.sdk.service.catalog.CatalogInfo`.
* Removed `databricks.sdk.service.catalog.EffectiveAutoMaintenanceFlag`
dataclass.
* Removed
`databricks.sdk.service.catalog.EffectiveAutoMaintenanceFlagInheritedFromType`
dataclass.
* Removed `databricks.sdk.service.catalog.EnableAutoMaintenance`
dataclass.
* Removed `effective_auto_maintenance_flag` field for
`databricks.sdk.service.catalog.SchemaInfo`.
* Removed `enable_auto_maintenance` field for
`databricks.sdk.service.catalog.SchemaInfo`.
* Added `effective_predictive_optimization_flag` field for
`databricks.sdk.service.catalog.SchemaInfo`.
* Added `enable_predictive_optimization` field for
`databricks.sdk.service.catalog.SchemaInfo`.
* Removed `effective_auto_maintenance_flag` field for
`databricks.sdk.service.catalog.TableInfo`.
* Removed `enable_auto_maintenance` field for
`databricks.sdk.service.catalog.TableInfo`.
* Added `effective_predictive_optimization_flag` field for
`databricks.sdk.service.catalog.TableInfo`.
* Added `enable_predictive_optimization` field for
`databricks.sdk.service.catalog.TableInfo`.
* Added
`databricks.sdk.service.catalog.EffectivePredictiveOptimizationFlag`
dataclass.
* Added
`databricks.sdk.service.catalog.EffectivePredictiveOptimizationFlagInheritedFromType`
dataclass.
* Added `databricks.sdk.service.catalog.EnablePredictiveOptimization`
dataclass.

OpenAPI SHA: beff621d7b3e1d59244e2e34fc53a496f310e130, Date: 2023-08-17
github-merge-queue bot pushed a commit to databricks/databricks-sdk-java that referenced this pull request Aug 18, 2023
## Changes
The Java SDK request authentication logic is inconsistent between the
Azure login types: for service principal auth, the SDK correctly adds
the X-Databricks-Azure-Workspace-Resource-Id when configured, but this
is missed for Azure CLI auth. Additionally, when logging in via Azure
CLI using a service principal, the service management token must also be
fetched from the CLI.

This PR fixes this by defining the logic to attach these header in a
common function that is used by all Azure-specific authentication types.

See databricks/databricks-sdk-go#584 for the
same change in the Go SDK.
See databricks/databricks-sdk-py#290 for the
same changes in the Python SDK.
## Tests
- [x] Unit tests to cover the two scenarios for Azure CLI w.r.t.
management endpoint token fetching, and one to verify that
X-Databricks-Azure-Workspace-Resource-Id is included when using Azure
CLI.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants