Skip to content

Commit 9e96bac

Browse files
Add support for Env and File OIDC. (#977)
## What changes are proposed in this pull request? This PR adds two new OIDC auth types, `env-oidc` and `file-oidc`, respectively extracting ID token from an environment variable or a file. This PR also opportunistically improves formatting and some imports. ## How is this tested? Unit tests. --------- Signed-off-by: Renaud Hartert <[email protected]>
1 parent 1baca79 commit 9e96bac

File tree

8 files changed

+445
-74
lines changed

8 files changed

+445
-74
lines changed

NEXT_CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
### New Features and Improvements
66

7+
- Add support for OIDC ID token authentication from an environment variable
8+
([PR #977](https://github.com/databricks/databricks-sdk-py/pull/977)).
9+
- Add support for OIDC ID token authentication from a file
10+
([PR #977](https://github.com/databricks/databricks-sdk-py/pull/977)).
11+
712
### Bug Fixes
813

914
### Documentation

databricks/sdk/config.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,21 @@ def with_user_agent_extra(key: str, value: str):
6060
class Config:
6161
host: str = ConfigAttribute(env="DATABRICKS_HOST")
6262
account_id: str = ConfigAttribute(env="DATABRICKS_ACCOUNT_ID")
63+
64+
# PAT token.
6365
token: str = ConfigAttribute(env="DATABRICKS_TOKEN", auth="pat", sensitive=True)
66+
67+
# Audience for OIDC ID token source accepting an audience as a parameter.
68+
# For example, the GitHub action ID token source.
6469
token_audience: str = ConfigAttribute(env="DATABRICKS_TOKEN_AUDIENCE", auth="github-oidc")
70+
71+
# Environment variable for OIDC token.
72+
oidc_token_env: str = ConfigAttribute(env="DATABRICKS_OIDC_TOKEN_ENV", auth="env-oidc")
73+
oidc_token_filepath: str = ConfigAttribute(env="DATABRICKS_OIDC_TOKEN_FILE", auth="file-oidc")
74+
6575
username: str = ConfigAttribute(env="DATABRICKS_USERNAME", auth="basic")
6676
password: str = ConfigAttribute(env="DATABRICKS_PASSWORD", auth="basic", sensitive=True)
77+
6778
client_id: str = ConfigAttribute(env="DATABRICKS_CLIENT_ID", auth="oauth")
6879
client_secret: str = ConfigAttribute(env="DATABRICKS_CLIENT_SECRET", auth="oauth", sensitive=True)
6980
profile: str = ConfigAttribute(env="DATABRICKS_CONFIG_PROFILE")
@@ -194,7 +205,7 @@ def oauth_token(self) -> Token:
194205
def wrap_debug_info(self, message: str) -> str:
195206
debug_string = self.debug_string()
196207
if debug_string:
197-
message = f'{message.rstrip(".")}. {debug_string}'
208+
message = f"{message.rstrip('.')}. {debug_string}"
198209
return message
199210

200211
@staticmethod
@@ -337,9 +348,9 @@ def debug_string(self) -> str:
337348
safe = "***" if attr.sensitive else f"{value}"
338349
attrs_used.append(f"{attr.name}={safe}")
339350
if attrs_used:
340-
buf.append(f'Config: {", ".join(attrs_used)}')
351+
buf.append(f"Config: {', '.join(attrs_used)}")
341352
if envs_used:
342-
buf.append(f'Env: {", ".join(envs_used)}')
353+
buf.append(f"Env: {', '.join(envs_used)}")
343354
return ". ".join(buf)
344355

345356
def to_dict(self) -> Dict[str, any]:
@@ -481,7 +492,7 @@ def _known_file_config_loader(self):
481492
if profile not in profiles:
482493
raise ValueError(f"resolve: {config_path} has no {profile} profile configured")
483494
raw_config = profiles[profile]
484-
logger.info(f'loading {profile} profile from {config_file}: {", ".join(raw_config.keys())}')
495+
logger.info(f"loading {profile} profile from {config_file}: {', '.join(raw_config.keys())}")
485496
for k, v in raw_config.items():
486497
if k in self._inner:
487498
# don't overwrite a value previously set

0 commit comments

Comments
 (0)