Skip to content

Commit b32dc8d

Browse files
Accept both v1 and v2 Entra ID issuer formats for WIF (#2281)
1 parent 3b64495 commit b32dc8d

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/snowflake/connector/wif_util.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,10 @@ def create_azure_attestation(
234234
issuer, subject = extract_iss_and_sub_without_signature_verification(jwt_str)
235235
if not issuer or not subject:
236236
return None
237-
if not issuer.startswith("https://sts.windows.net/"):
237+
if not (
238+
issuer.startswith("https://sts.windows.net/")
239+
or issuer.startswith("https://login.microsoftonline.com/")
240+
):
238241
# This might happen if we're running on a different platform that responds to the same metadata request signature as Azure.
239242
logger.debug("Unexpected Azure token issuer '%s'", issuer)
240243
return None

test/unit/test_auth_workload_identity.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,32 @@ def test_explicit_azure_metadata_server_error_raises_auth_error(exception):
236236

237237

238238
def test_explicit_azure_wrong_issuer_raises_error(fake_azure_metadata_service):
239-
fake_azure_metadata_service.iss = "not-azure"
239+
fake_azure_metadata_service.iss = "https://notazure.com"
240240

241241
auth_class = AuthByWorkloadIdentity(provider=AttestationProvider.AZURE)
242242
with pytest.raises(ProgrammingError) as excinfo:
243243
auth_class.prepare()
244244
assert "No workload identity credential was found for 'AZURE'" in str(excinfo.value)
245245

246246

247+
@pytest.mark.parametrize(
248+
"issuer",
249+
[
250+
"https://sts.windows.net/067802cd-8f92-4c7c-bceb-ea8f15d31cc5",
251+
"https://login.microsoftonline.com/067802cd-8f92-4c7c-bceb-ea8f15d31cc5",
252+
"https://login.microsoftonline.com/067802cd-8f92-4c7c-bceb-ea8f15d31cc5/v2.0",
253+
],
254+
ids=["v1", "v2_without_suffix", "v2_with_suffix"],
255+
)
256+
def test_explicit_azure_v1_and_v2_issuers_accepted(fake_azure_metadata_service, issuer):
257+
fake_azure_metadata_service.iss = issuer
258+
259+
auth_class = AuthByWorkloadIdentity(provider=AttestationProvider.AZURE)
260+
auth_class.prepare()
261+
262+
assert issuer == json.loads(auth_class.assertion_content)["iss"]
263+
264+
247265
def test_explicit_azure_plumbs_token_to_api(fake_azure_metadata_service):
248266
auth_class = AuthByWorkloadIdentity(provider=AttestationProvider.AZURE)
249267
auth_class.prepare()

0 commit comments

Comments
 (0)