Commit 1020902
Fix Azure CLI authentication for federated token service principals (#1274)
## What changes are proposed in this pull request?
**WHAT**: This PR enhances the Azure CLI authentication logic in the
Databricks Go SDK to properly handle federated token service principals
used in AKS workload identity scenarios.
The specific changes include:
- Enhanced MSI detection logic in `config/auth_azure_cli.go` to
recognize service principals with GUID-like names as federated token
authentication
- Added `isGuidLike()` helper function to detect GUID patterns
(8-4-4-4-12 character format)
- Updated the authentication flow to skip tenant ID parameters for
federated token service principals (treating them like MSI)
- Added comprehensive test coverage in
`config/auth_azure_cli_federated_token_test.go`
**WHY**: The existing MSI detection logic only recognized system/user
assigned identities by their specific names (`systemAssignedIdentity` or
`userAssignedIdentity`). However, when using AKS with workload identity,
service principals authenticate using federated tokens and show their
client ID as the name (e.g., `5817e630-86b3-4f67-a38e-a63e6a1a401c`).
This caused the SDK to incorrectly treat federated token service
principals as regular service principals, leading to:
1. SDK passing `--tenant <tenant_id>` to `az account get-access-token`
2. Azure CLI rejecting the request because federated tokens don't work
with explicit tenant parameters
3. Complete authentication failure in AKS environments
The decision to use GUID pattern detection was made because:
- Federated token service principals consistently show client IDs
(GUIDs) as their names
- This approach is more efficient than a fallback mechanism (no retry
needed)
- It matches the authentication flow observed in working environments
where no tenant parameter is used from the start
- It preserves backward compatibility for all existing authentication
methods
## How is this tested?
**Unit Tests:**
- Added `TestAzureCliCredentials_FederatedTokenServicePrincipal` which
simulates the exact federated token scenario using the client ID pattern
from the reported issue
- Test uses `FAIL_IF_TENANT_ID_SET=true` environment variable to ensure
the fix correctly skips tenant ID usage (test would fail if `--tenant`
parameter was passed)
- All existing Azure CLI authentication tests continue to pass, ensuring
no regressions
**Test Coverage Validation:**
- Federated token service principals: Correctly detected and skip tenant
ID ✅
- Traditional MSI (system/user assigned identities): Behavior unchanged
✅
- Regular service principals: Continue to use tenant ID as before ✅
- Edge cases: GUID detection handles malformed strings appropriately ✅
The test uses the existing mock infrastructure (`testdata/az`) rather
than custom mocks, ensuring consistency with other authentication tests.
---------
Co-authored-by: Omer Lachish <rauchy@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>1 parent 797d5ef commit 1020902
3 files changed
Lines changed: 56 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
9 | 14 | | |
10 | 15 | | |
11 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
165 | | - | |
| 165 | + | |
166 | 166 | | |
167 | 167 | | |
168 | 168 | | |
| |||
176 | 176 | | |
177 | 177 | | |
178 | 178 | | |
| 179 | + | |
179 | 180 | | |
180 | 181 | | |
181 | | - | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
182 | 191 | | |
183 | 192 | | |
184 | 193 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
0 commit comments