Skip to content

[keyvault-certificates] Fix begin_create_certificate validator to accept san_ip_addresses and san_uris#46380

Merged
kashifkhan merged 23 commits into
mainfrom
fix/keyvault-certificates-san-ip-uri-validator
Apr 29, 2026
Merged

[keyvault-certificates] Fix begin_create_certificate validator to accept san_ip_addresses and san_uris#46380
kashifkhan merged 23 commits into
mainfrom
fix/keyvault-certificates-san-ip-uri-validator

Conversation

@rohitsinghal4u

Copy link
Copy Markdown
Contributor

Summary

Fixes a bug where CertificateClient.begin_create_certificate (and its async counterpart create_certificate) incorrectly raised ValueError when a CertificatePolicy was created with only san_ip_addresses or san_uris (with no subject, san_dns_names, san_emails, or san_user_principal_names).

IP addresses and URIs are valid Subject Alternative Name (SAN) types and should be accepted by the client's policy validator.

Root Cause

The validator in both _client.py and aio/_client.py checked:

if not (policy.san_emails or policy.san_user_principal_names or policy.san_dns_names or policy.subject):
    raise ValueError(NO_SAN_OR_SUBJECT)

san_ip_addresses and san_uris were missing from this condition.

Changes

  • azure/keyvault/certificates/_client.py — added san_ip_addresses and san_uris to the validator condition in begin_create_certificate
  • azure/keyvault/certificates/aio/_client.py — same fix for the async client's create_certificate
  • CHANGELOG.md — added 4.11.1 (Unreleased) section documenting the fix
  • tests/test_certificates_client.py — extended test_policy_expected_errors_for_create_cert to assert IP/URI-only policies no longer raise; added test_create_certificate_with_san_ip_and_uris live test (recorded)
  • tests/test_certificates_client_async.py — same test additions for the async client
  • tests/_test_case.py and tests/_async_test_case.py — fixed a secondary issue where empty-string values for AZURE_CLIENT_ID/AZURE_CLIENT_SECRET were set into the environment, causing newer versions of azure-identity's EnvironmentCredential (which checks is not None rather than truthiness) to attempt and fail ClientSecretCredential construction during developer auth. Now empty-string KEYVAULT_* vars cause the corresponding AZURE_* vars to be removed from the env, allowing DefaultAzureCredential to fall through to AzureCliCredential.
  • assets.json — updated tag to python/keyvault/azure-keyvault-certificates_a5c5c34814 (new recordings pushed)

Testing

  • Both new live tests recorded against https://kv-sdk-test-5903.vault.azure.net/
  • Both pass in playback mode
  • test_policy_expected_errors_for_create_cert (sync + async) updated and verified

@rohitsinghal4u rohitsinghal4u marked this pull request as ready for review April 17, 2026 21:04
Copilot AI review requested due to automatic review settings April 17, 2026 21:04
@rohitsinghal4u rohitsinghal4u requested a review from a team as a code owner April 17, 2026 21:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes Key Vault Certificates client-side policy validation so SAN-only policies using IP addresses and/or URIs are accepted, and adds coverage + recordings to prevent regressions.

Changes:

  • Update sync/async certificate creation validators to treat san_ip_addresses and san_uris as satisfying the “SAN or subject required” rule.
  • Add unit assertions and new live tests (sync + async) validating IP/URI-only SAN policies; refresh test recordings/assets tag.
  • Adjust live-test credential environment-variable handling to avoid empty-string AZURE_* values interfering with DefaultAzureCredential.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/_client.py Expands validator to include san_ip_addresses and san_uris.
sdk/keyvault/azure-keyvault-certificates/azure/keyvault/certificates/aio/_client.py Same validator expansion for async create_certificate.
sdk/keyvault/azure-keyvault-certificates/tests/test_certificates_client.py Adds sync live test + extends validator-behavior assertions.
sdk/keyvault/azure-keyvault-certificates/tests/test_certificates_client_async.py Adds async live test + extends validator-behavior assertions.
sdk/keyvault/azure-keyvault-certificates/tests/_test_case.py Avoids setting empty-string AZURE_* env vars during live tests.
sdk/keyvault/azure-keyvault-certificates/tests/_async_test_case.py Same env-var adjustment for async tests.
sdk/keyvault/azure-keyvault-certificates/CHANGELOG.md Documents the fix in 4.11.1 section.
sdk/keyvault/azure-keyvault-certificates/assets.json Updates assets tag for new recordings.
sdk/keyvault/azure-keyvault-keys/azure/keyvault/keys/_models.py Changes KeyProperties.tags typing to Optional[Dict[str, str]] (appears unrelated to this PR’s stated scope).

Comment thread sdk/keyvault/azure-keyvault-keys/azure/keyvault/keys/_models.py Outdated
… san_uris

- Extended the policy validator in both the sync and async CertificateClient
  to also accept policies that specify only san_ip_addresses or san_uris, which
  are valid SAN types but were previously treated as missing subject information
- Added test_create_certificate_with_san_ip_and_uris (sync + async) with live
  recordings to verify IP-only and URI-only SAN policies succeed end-to-end
- Extended test_policy_expected_errors_for_create_cert to assert that IP-only
  and URI-only policies no longer raise ValueError
- Fixed _test_case.py and _async_test_case.py to avoid setting AZURE_CLIENT_ID/
  AZURE_CLIENT_SECRET to empty strings, which newer azure-identity treats as
  an attempt to use ClientSecretCredential and raises ValueError
@rohitsinghal4u rohitsinghal4u force-pushed the fix/keyvault-certificates-san-ip-uri-validator branch from 8e9343f to db3c5f8 Compare April 18, 2026 00:27
@rohitsinghal4u rohitsinghal4u force-pushed the fix/keyvault-certificates-san-ip-uri-validator branch from c93a4b8 to 8ab52ed Compare April 21, 2026 19:21
singhalrohit4u and others added 2 commits April 21, 2026 12:24
…y_expected_errors_for_create_cert

Use except (HttpResponseError, ServiceRequestError) instead of bare except Exception
to avoid silently swallowing unexpected errors (AttributeError, TypeError, etc.)
that could indicate a regression in the validator or call signature.

Also add HttpResponseError and ServiceRequestError to azure.core.exceptions imports.
@rohitsinghal4u rohitsinghal4u enabled auto-merge (squash) April 23, 2026 01:05
@rohitsinghal4u

Copy link
Copy Markdown
Contributor Author

/check-enforcer override

@Azure Azure deleted a comment from Copilot AI Apr 24, 2026
@rohitsinghal4u rohitsinghal4u disabled auto-merge April 24, 2026 07:13
@rohitsinghal4u

Copy link
Copy Markdown
Contributor Author

/check-enforcer override

@rohitsinghal4u rohitsinghal4u enabled auto-merge (squash) April 24, 2026 07:18
@rohitsinghal4u

Copy link
Copy Markdown
Contributor Author

/check-enforcer override

@kashifkhan

Copy link
Copy Markdown
Member

/check-enforcer override

@kashifkhan kashifkhan disabled auto-merge April 24, 2026 18:08
@kashifkhan kashifkhan enabled auto-merge (squash) April 24, 2026 18:09
@scbedd

scbedd commented Apr 28, 2026

Copy link
Copy Markdown
Member

/azp run python - pullrequest

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@rohitsinghal4u

Copy link
Copy Markdown
Contributor Author

/check-enforcer override

@kashifkhan kashifkhan disabled auto-merge April 29, 2026 17:57
@kashifkhan kashifkhan merged commit 6d0a412 into main Apr 29, 2026
17 of 19 checks passed
@kashifkhan kashifkhan deleted the fix/keyvault-certificates-san-ip-uri-validator branch April 29, 2026 18:02
@rohitsinghal4u

Copy link
Copy Markdown
Contributor Author

Hi @kashifkhan, the code is all merged and the CHANGELOG is set to \4.11.1 (2026-04-29). Could you please trigger the release pipeline to publish this to PyPI? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants