@@ -6,7 +6,8 @@ The [brickster](https://github.com/databrickslabs/brickster) package
66connects to a Databricks workspace in three ways:
77
881 . [ OAuth user-to-machine (U2M)
9- authentication] ( https://docs.databricks.com/en/dev-tools/auth/oauth-u2m.html#oauth-user-to-machine-u2m-authentication )
9+ authentication] ( https://docs.databricks.com/en/dev-tools/auth/oauth-u2m.html#oauth-user-to-machine-u2m-authentication ) ,
10+ either directly or through credentials managed by the Databricks CLI
10112 . [ OAuth machine-to-machine (M2M)
1112 authentication] ( https://docs.databricks.com/en/dev-tools/auth/oauth-m2m.html )
12133 . [ Personal Access Tokens
@@ -56,9 +57,6 @@ To get started add the following to your `.Renviron`:
5657- ` ARM_TENANT_ID ` : Azure AD tenant id (* only required for Azure service
5758 principal OAuth M2M* )
5859
59- - ` DATABRICKS_AUTH_TYPE ` : Optional auth mode override (` oauth-m2m ` ,
60- ` azure-client-secret ` , ` oauth-u2m ` )
61-
6260- ` DATABRICKS_WSID ` : The workspace ID
6361 ([ docs] ( https://docs.databricks.com/workspace/workspace-details.html#workspace-instance-names-urls-and-ids ) )
6462
@@ -85,12 +83,12 @@ For Azure service principal OAuth M2M:
8583 ARM_CLIENT_SECRET=abcdefg1234567890
8684 ARM_TENANT_ID=aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee
8785
88- With no explicit auth override ,
86+ With no ` auth_type ` in a selected ` .databrickscfg ` profile ,
8987[ brickster] ( https://github.com/databrickslabs/brickster ) attempts
9088Databricks OAuth M2M (` DATABRICKS_CLIENT_* ` ), then Azure service
91- principal OAuth M2M (` ARM_* ` ), then OAuth U2M. Set
92- ` DATABRICKS_AUTH_TYPE= azure-client-secret` to force Azure service
93- principal authentication.
89+ principal OAuth M2M (` ARM_* ` ), then OAuth U2M. When using
90+ ` .databrickscfg ` , set ` auth_type = azure-client-secret` in the profile
91+ to force Azure service principal authentication.
9492
9593** Note** : Recommend creating an ` .Renviron ` for each project. You can
9694create ` .Renviron ` within your user home directory if required.
@@ -145,29 +143,47 @@ simplify switching of credentials within an R project/session:
1451432 . Using a ` .databrickscfg ` file (primary method in [ Databricks
146144 CLI] ( https://docs.databricks.com/dev-tools/cli/index.html#set-up-authentication ) )
147145
148- To differentiate between (1) and (2) the option ` use_databrickscfg ` is
149- used, the following example shows how to switch the session to use
150- ` .databrickscfg ` .
146+ The ` use_databrickscfg ` option selects which configuration source
147+ [ brickster] ( https://github.com/databrickslabs/brickster ) reads. It does
148+ not sign in to the Databricks CLI or select a named profile. The
149+ following example switches the session from ` .Renviron ` to
150+ ` .databrickscfg ` :
151151
152152``` r
153153
154- # will use the `DEFAULT` profile in `.databrickscfg`
154+ # uses the CLI-selected default profile, or `DEFAULT` when none is selected
155155options(use_databrickscfg = TRUE )
156156
157- # values returned should be those in profile of `.databrickscfg`
157+ # values are read from `.databrickscfg`
158158db_host()
159159db_token()
160160```
161161
162- The default behaviour is to read credentials from ` .Renviron ` . If you
163- wish to change this it’s recommended to set the option within
164- ` .Rprofile ` so that it’s set during initialization of the R session.
162+ With its default value of ` FALSE ` ,
163+ [ brickster] ( https://github.com/databrickslabs/brickster ) does not
164+ discover profiles created by ` databricks auth login ` and does not enable
165+ the ` databricks-cli ` authentication provider. Set the option in
166+ ` .Rprofile ` when ` .databrickscfg ` should be the normal configuration
167+ source. Posit Workbench managed OAuth sessions enable ` .databrickscfg `
168+ automatically.
165169
166170### Switching Between Credentials
167171
168- The ` db_profile ` option controls which profiles credentials are returned
169- by
170- [ ` db_host() ` ] ( https://databrickslabs.github.io/brickster/dev/reference/db_host.md ) /[ ` db_token() ` ] ( https://databrickslabs.github.io/brickster/dev/reference/db_token.md ) /[ ` db_wsid() ` ] ( https://databrickslabs.github.io/brickster/dev/reference/db_wsid.md ) .
172+ When ` .databrickscfg ` is enabled, the selected profile controls the
173+ host, credentials, authentication type, and the profile passed to
174+ ` databricks auth token ` .
175+ [ brickster] ( https://github.com/databrickslabs/brickster ) resolves the
176+ profile in this order:
177+
178+ 1 . ` DATABRICKS_CONFIG_PROFILE `
179+ 2 . The ` db_profile ` option
180+ 3 . The CLI default selected by ` databricks auth switch `
181+ 4 . The ` DEFAULT ` profile
182+
183+ ` DATABRICKS_CONFIG_PROFILE ` is the standard Databricks unified
184+ authentication setting. ` db_profile ` is the
185+ [ brickster] ( https://github.com/databrickslabs/brickster ) session-level
186+ equivalent.
171187
172188Profiles enable you to switch contexts between:
173189
@@ -181,20 +197,20 @@ This behaviour works when using credentials specified in either
181197``` r
182198
183199# using .Renviron
184- db_host() # returns `DB_HOST ` (.Renviron)
200+ db_host() # returns `DATABRICKS_HOST ` (.Renviron)
185201
186202# switch profile to 'prod'
187203options(db_profile = " prod" )
188- db_host() # returns `DB_HOST_PROD ` (.Renviron)
204+ db_host() # returns `DATABRICKS_HOST_PROD ` (.Renviron)
189205
190- # set back to default (NULL)
206+ # clear the session-specific profile selection
191207options(db_profile = NULL )
192- # use .databrickcfg
208+ # use .databrickscfg
193209options(use_databrickscfg = TRUE )
194- db_host() # returns host from `DEFAULT` profile (.databrickscfg)
210+ db_host() # returns the CLI-selected default, otherwise `DEFAULT` (.databrickscfg)
195211
196212options(db_profile = " prod" )
197- db_host() # returns host from `prod` profile in (.datarickscfg )
213+ db_host() # returns host from `prod` profile (.databrickscfg )
198214```
199215
200216It is expected that profiles in ` .Renviron ` will adhere to the same
@@ -226,16 +242,71 @@ There is only one
226242[ brickster] ( https://github.com/databrickslabs/brickster ) specific
227243feature and it is the inclusion of ` wsid ` alongside ` host ` /` token ` .
228244
229- When using OAuth M2M with a ` .databrickscfg ` profile:
245+ Supported OAuth fields in a ` .databrickscfg ` profile include :
230246
231247- Databricks service principal fields: ` client_id ` , ` client_secret `
232248- Azure service principal fields: ` azure_client_id ` ,
233249 ` azure_client_secret ` , ` azure_tenant_id `
234250- Optional auth mode override: ` auth_type ` (` oauth-m2m ` ,
235- ` azure-client-secret ` , ` oauth-u2m ` )
251+ ` azure-client-secret ` , ` oauth-u2m ` , ` databricks-cli ` )
252+
253+ #### Databricks CLI OAuth profiles
254+
255+ Profiles created by ` databricks auth login ` use
256+ ` auth_type = databricks-cli ` . The login can be performed from any
257+ terminal; the credentials are not scoped to that terminal session.
258+ [ brickster] ( https://github.com/databrickslabs/brickster ) must run as the
259+ same operating-system user and use the same ` .databrickscfg ` and CLI
260+ credential storage.
261+
262+ The ` databricks-cli ` provider is intentionally available only when the
263+ selected ` .databrickscfg ` profile contains ` auth_type = databricks-cli ` .
264+ Environment configuration cannot activate this provider independently.
265+
266+ Enable ` .databrickscfg ` and select the profile before making requests:
267+
268+ ``` r
269+
270+ options(
271+ use_databrickscfg = TRUE ,
272+ db_profile = " e2-demo"
273+ )
274+
275+ # The host and CLI token are resolved from the same profile.
276+ db_sql_warehouse_list()
277+ ```
278+
279+ Instead of ` db_profile ` , set ` DATABRICKS_CONFIG_PROFILE ` , or select the
280+ CLI default outside R:
281+
282+ ``` sh
283+ databricks auth switch --profile e2-demo
284+ ```
236285
237- If both ` DATABRICKS_AUTH_TYPE ` (environment variable) and ` auth_type `
238- (` .databrickscfg ` ) are set, ` DATABRICKS_AUTH_TYPE ` takes precedence.
286+ When a profile is selected,
287+ [ brickster] ( https://github.com/databrickslabs/brickster ) calls
288+ ` databricks auth token --profile <profile> ` . Without a selected profile,
289+ [ brickster] ( https://github.com/databrickslabs/brickster ) follows the
290+ Databricks SDK behavior and asks the CLI for the resolved host. If
291+ multiple profiles contain the same host, the CLI refuses to guess;
292+ select a profile rather than signing in again. Avoid supplying a
293+ different ` host ` argument while a profile is selected, because the
294+ request host and CLI credential would no longer describe the same
295+ configuration.
296+
297+ Token acquisition is deferred until an API request is performed.
298+ [ brickster] ( https://github.com/databrickslabs/brickster ) keeps only the
299+ short-lived access token in memory until it expires, then calls the CLI
300+ again. The Databricks CLI remains responsible for durable credential
301+ storage and refresh. The CLI must be available on ` PATH ` , or its
302+ executable can be provided with ` DATABRICKS_CLI_PATH ` .
303+ ` DATABRICKS_CONFIG_FILE ` is inherited by the CLI when using a
304+ non-default config location.
305+
306+ The ` oauth-u2m ` mode remains
307+ [ brickster] ( https://github.com/databrickslabs/brickster ) ’s direct
308+ browser-based OAuth flow; it does not reuse credentials created by
309+ ` databricks auth login ` .
239310
240311` wsid ` is used by the connections pane integration in RStudio as the
241312underlying API’s require it.
0 commit comments