Skip to content

Add Windows Managed Identity v2 mTLS PoP and bearer integration - #985

Closed
Gladwin Johnson VR (gladjohn) wants to merge 8 commits into
AzureAD:devfrom
gladjohn:gladjohn/msi-v2-local
Closed

Gladwin Johnson VR (gladjohn) wants to merge 8 commits into
AzureAD:devfrom
gladjohn:gladjohn/msi-v2-local

Conversation

@gladjohn

@gladjohn Gladwin Johnson VR (gladjohn) commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Implement a Windows Managed Identity v2 development candidate using the Rust foundation in #982:

  • Explicit mtls_proof_of_possession, request_over_mtls, attestation opt-in, minimum strength and force-refresh options on ManagedIdentityClient.
  • IMDS platform metadata and credential issuance, protected-key PKCS#10 signing, independent KeyGuard attestation, and canonical OAuth client-credentials exchange over native mTLS.
  • Separate ordinary bearer, bearer-over-mTLS and full-leaf-bound PoP token caches; exact-generation synchronous and bounded worker-backed asynchronous resource transports.
  • V2-first capability discovery, deadline-isolated concurrent callers, certificate renewal/rejection recovery, and best-effort Windows certificate-store reattachment.
  • Independent optional Windows wheels, public examples, documentation, collected live tests and an opt-in installed-candidate CI stage.

Ordinary managed identity remains independent of the optional native packages. Explicit protected acquisition does not fall back to a software key.

Stacking and immutable references

Depends on #982. This PR targets dev and includes the #982 bridge commits
followed by the Python integration. It is ready for review so the normal
dev OneBranch Python gate can trigger. Until #982 merges, the diff includes
both the native foundation and the integration; once #982 lands in dev, the
diff narrows to the integration. This is not a request to merge before the
dependency or outstanding acceptance requirements are satisfied.

Reference Revision
Python #982 foundation 10b146ad937ad823b2b5cd2da4e66df3b942f5c2
Python dev, already included c53d5ea47f7713d8fbc8e3d9832436fd1028b5c1
MSAL.NET protocol reference 40039615ab4edad6f12e65206f0f7c5e09fa3442
Additional .NET certificate-cache ordering review, #6275 438f351a33a18494bb0938e4209e3413f4716584
Java #1059 / published preview sources ea0148534593acbc58d700bffe8419b076a9dd37
Java recovery/routing reference bc8f196579ed16b79a679849282e43e79d5a001b

Published sources compared: msal4j:1.26.1-preview1 (215 Java files) and msal4j-key-attestation:1.0.0-preview1 (17 Java files); no differences from the pinned Java reference after line-ending normalization.

Review fixes included

The local deep correctness review found six actionable issues, all addressed with focused regressions:

  1. Failed certificate-store deletion could let another client restore a rejected binding. Invalidation is now shared across clients and remains until a replacement is successfully persisted, including after memory-cache eviction.
  2. Token-cache DEBUG logging exposed the new claims pseudo-parameter. It is now redacted without changing partitioning.
  3. Ordinary forced refresh skipped lookup of a challenged token. The refresh request now retains its SHA-256 reference.
  4. A short discovery owner's deadline prematurely failed longer-budget waiters. Eligible waiters now restart within their own remaining budget.
  5. Accepted HTTP retry configuration did not apply to native ESTS requests. Transient status retries now use the adapter's method/status/delay policy, independently bounded to three retries and a total budget, without certificate reminting.
  6. IMDS errors discarded service codes. Trusted, bounded service codes are preserved without including response bodies or descriptions.

Regression mapping

All Python paths below are in this PR. Reference PR numbers in this table refer to MSAL.NET unless identified otherwise.

Reference / regression Python implementation Python regression coverage
#6178/#6181: GetManagedIdentityCapabilities_TimedOutWaiter_DoesNotCancelLockOwnerAsync; kill-switch/minimum-strength behavior _managed_identity_v2._CapabilityDiscovery; ManagedIdentityClient tests/test_managed_identity_v2.py::CapabilityDiscoveryTests; PublicProtectedFlowTests::test_disabled_or_invalid_modes_do_no_http_or_native_work; test_keyguard_failure_preserves_required_strength_and_native_category
#6200/#6238/#5741/#5887: regional/cloud routing, tenant metadata and fresh endpoint/key-generation attestation cache _ImdsClient, _MaaTokenCache, _NativeAttestation ImdsV2ProtocolTests; MaaCacheTests; NativeAttestationOwnershipTests; PublicProtectedFlowTests::test_attestation_denial_prevents_credential_issuance in tests/test_managed_identity_v2.py
#6215/#6173/#5761: mTLSPop_ForceRefresh_RemintsCachedCert_PostsCanonicalClientId_AndReusesCachedAttestation; rejected-binding recovery _V2Client, _is_binding_rejection PublicProtectedFlowTests::test_force_refresh_remints_leaf_but_reuses_fresh_attestation_generation; test_wrapped_binding_reset_retries_once_but_unrelated_oauth_failure_does_not; test_native_certificate_alerts_recover_once_and_nested_trust_failure_never_retries
#5566/#6123: Read_Boundary_Exactly24h_IsRejected; persistent-cache binding restoration _CertificateStore, _V2Client WindowsCertificateStoreTests; PublicProtectedFlowTests::test_restart_reattaches_persisted_leaf_before_returning_serialized_pop_token; test_failed_invalidation_is_shared_with_another_client
#6275: dynamic-certificate rotation/retry cache-ordering invariant; not itself an MI implementation change _V2Client.acquire: resolve binding before lookup; update partition after recovery PublicProtectedFlowTests::test_invalid_client_remints_once_but_wrong_token_types_never_enter_cache; force-refresh and restart tests
.NET ImdsV2Tests.TestCsrGeneration_VmIdAndVmssId / OnlyVmId; Java Pkcs10BuilderTest subject, CUID and DER tests _create_csr tests/test_native_mtls.py::NativeKeyOwnershipTests::test_csr_preserves_platform_identity_cuid_der_and_pss_parameters; test_csr_omits_absent_cuid_fields
Python #982: request/response allocation contract and external C mTLS fixture _NativeRuntime, additive native protected-key exports tests/test_native_mtls.py::NativeOwnershipTests; WindowsRustOAuthTests::test_real_oauth_form_posts_present_the_opaque_cng_key_in_both_modes; native Debug/Release matrix

Platform differences: Python uses OpenSSL alert categories / Windows reset 10054, not Schannel exceptions; PoP partitioning uses SHA-256 of the entire leaf DER, not a certificate serial number. The async adapter is bounded worker-backed, not an aiohttp SSL-context integration. The audience is not a wildcard for arbitrary resource origins.

CI and PR targeting

The original draft targeted feature/native-primitives and initially ran only
the package build: native Actions filtered for dev, and OneBranch targets
dev and excludes drafts. Credential-free checks were added for that stacked
base and have now passed remotely at
e339f16aca840a4c048ca8445374482c1124df7a:

  • The existing Build workflow runs unit tests on Python 3.9 through 3.14 for
    PRs targeting feature/native-primitives, including drafts.
  • Native Windows CI accepts that stacked base and relevant Python integration
    paths. Its existing complete Debug/Release native matrix and dependency checks
    are retained, followed by Python 3.12 native integration tests.
  • Both workflows upload JUnit artifacts. Existing OneBranch branch/draft rules,
    SDL checks and live-test restrictions are unchanged.

All six Python matrix jobs, Windows native/Python integration and dependency
policy checks passed. The PR now targets dev and is ready for review, retaining
the bridge in its head history so the normal OneBranch gate can run as well.

The workflow changes passed pinned actionlint validation. The exact Windows
Python test command passed locally: 117 tests and 121 subtests. Remote CI results
are reported in the PR checks; the local results below are not remote-CI claims.

Local test evidence

Tests were run on Windows x64 with Python 3.12.10:

Run Result
Automated repository baseline before review fixes 513 passed, 26 skipped, 2 deselected, 780 subtests passed
Initial six review fixes: protected flows, native Release interop, legacy MI and token cache 225 passed, 770 subtests passed
Final persistence hardening: protected flows, Windows store, native Release interop and token cache 117 passed, 121 subtests passed
Final wheel installed in a separate environment, executed outside the checkout: native tests, IMDS protocol, public protected flows and discovery 54 unittest tests passed, including all seven new review regressions
Native Debug and Release matrices, formatting, Clippy, dependency audit and policy checks Passed
Sphinx HTML, pipeline YAML parse and diff whitespace Passed

Focused source commands:

$env:MSAL_TEST_NATIVE_MTLS_DIR = (Resolve-Path .\native\artifacts\Release).Path
python -m pytest -q tests\test_managed_identity_v2.py tests\test_native_mtls.py tests\test_mi.py tests\test_token_cache.py
python -m pytest -q tests\test_managed_identity_v2.py tests\test_native_mtls.py tests\test_token_cache.py

Clean-installed command, using copied test modules outside the checkout:

python -m unittest -q test_native_mtls test_managed_identity_v2.ImdsV2ProtocolTests test_managed_identity_v2.PublicProtectedFlowTests test_managed_identity_v2.CapabilityDiscoveryTests

The automated baseline excluded existing live integration files and the interactive Windows broker sign-in test (which timed out waiting for user interaction). Two existing latest-cryptography policy tests were deselected. The 513-test result is a baseline, not a post-fix full-suite claim. The installed unittest run reports implicit temporary-directory cleanup ResourceWarnings from fixtures.

All seven relevant installed Python modules, including token_cache, matched checkout hashes. The live-profile SDK fingerprint is 668df0f7f2e8d6eafeb04f7d8b7098e5ad40bec78cbfbbca7543d50daf8b3aac.

Outstanding acceptance evidence

This is not a release-ready or positively attested implementation claim.

  • Ten live cases are collected but were not executed. Actual VBS/KeyGuard creation/liveness/recreation, MAA, IMDSv2, ESTS and strict Key Vault binding/negative controls remain outstanding.
  • Actual supported-host representation of the CNG Virtual Iso property remains to be verified; software-CNG fixtures are not VBS evidence.
  • Cross-process/live rotation and remaining historical parity mapping require follow-through.
  • Maintainer/security release review and production signing are still required. Development integrity manifests do not authenticate a publisher.
  • Optional wheels remain development versions. No compiled native libraries, downloaded packages, credentials or private keys are included in this PR.

See docs/managed-identity-v2.rst for build/install instructions, supported transport constraints, samples and the full installed live-validation profile.

Host the native workspace separately from Python runtime and packaging.
Clarify compatible dependency ranges without changing the lockfile.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 6fe4a5cf-79f6-48f9-aa71-bd8af58c504b
Duplicate selected public material when no private material exists.
Add an external OpenSSL regression and correct the example DLL path.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 6fe4a5cf-79f6-48f9-aa71-bd8af58c504b
Reject retained explicit MGF1 mismatches before signature state updates.
Account for IPv6 brackets before reserving the plaintext request buffer.
Add sequential-update and exact wire-limit regressions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 6fe4a5cf-79f6-48f9-aa71-bd8af58c504b
Move CMake/vcpkg setup ahead of the first quick-start build and reuse
the quick-start configuration steps from the build/test section.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 6fe4a5cf-79f6-48f9-aa71-bd8af58c504b
Guard sensitive copies before validation can fail. Accept HTTP token field names and surrounding Content-Length whitespace while preserving strict framing. Add allocation-observer and protocol regressions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 6fe4a5cf-79f6-48f9-aa71-bd8af58c504b
Permit secure delayed TLS client authentication under the existing I/O deadline. Preserve key and signing configuration during null-key context reuse. Bound RSA encodings before conversion and zeroize transient URI/name copies. Add Windows/CNG regressions, with 67 Rust tests per Debug/Release configuration and the complete native matrix passing.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 6fe4a5cf-79f6-48f9-aa71-bd8af58c504b
Connect the Rust native foundation to explicit PoP and bearer-over-mTLS managed identity acquisition, attestation, generation-bound transports, persistence, packaging and regression coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 6fe4a5cf-79f6-48f9-aa71-bd8af58c504b
Keep the feature/native-primitives stack and existing OneBranch policies. Add credential-free Python matrix checks for stacked drafts and enable Windows native/Python integration coverage on the stacked base.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 6fe4a5cf-79f6-48f9-aa71-bd8af58c504b
@gladjohn
Gladwin Johnson VR (gladjohn) changed the base branch from feature/native-primitives to dev November 13, 2026 12:45
@gladjohn
Gladwin Johnson VR (gladjohn) marked this pull request as ready for review November 13, 2026 12:45
Copilot AI balanced review requested due to automatic review settings November 13, 2026 12:45

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.

🟡 Changes recommended

Malformed SDK-tagged store entries with non-string fields can trigger an uncaught AttributeError and abort token acquisition; string validation and regression tests are needed.

1 open issue
What changed in this PR

Adds a Windows Managed Identity v2 development candidate on top of the Rust foundation in #982. Explicit protected acquisition uses optional native packages, while ordinary managed identity remains independent of them. Live platform validation and release/security review remain outstanding.

Changes:

  • Adds protected mTLS PoP and bearer acquisition, certificate persistence, and generation-bound synchronous and asynchronous resource transports.
  • Includes the Rust CNG/OpenSSL foundation, protected-key ABI, and independent Windows wheel packaging.
  • Adds samples, documentation, native CI, and an opt-in installed-candidate live validation stage.
File Description
tools/​prepare_mi_attestation.ps1 Downloads and verifies the pinned attestation DLL.
tools/​build_mi_native_wheels.ps1 Stages verified artifacts and builds optional wheels.
tests/​test_mi_v2_e2e.py Adds opt-in installed-candidate live tests.
sample/​managed_identity_v2.py Demonstrates PoP, async PoP, and bearer requests.
README.md Introduces the native project.
packages/​msal-native-primitives/​setup.py Defines the Windows native wheel.
packages/​msal-native-primitives/​msal_native_primitives/​__init__.py Declares optional native package metadata.
packages/​msal-key-attestation/​setup.py Defines the independent attestation wheel.
packages/​msal-key-attestation/​msal_key_attestation/​__init__.py Declares attestation package metadata.
native/​vcpkg.json Pins the native OpenSSL dependency baseline.
native/​THIRD-PARTY-NOTICES.md Documents dependency notice obligations.
native/​tests/​native/​support/​cng_key.h Declares CNG test-support interfaces.
native/​SUPPORT.md Defines pre-release support scope.
native/​SECURITY.md Documents vulnerability reporting and sensitive areas.
native/​scripts/​test.ps1 Runs Debug/Release validation and key cleanup checks.
native/​scripts/​loc.ps1 Reports a production Rust line count.
native/​scripts/​build.ps1 Builds native artifacts and integrity manifests.
native/​rustfmt.toml Configures Rust formatting.
native/​README.md Describes native architecture, setup, and usage.
native/​LICENSE Supplies the native project's MIT license.
native/​include/​microsoft_identity_native_primitives.h Declares transport and protected-key C APIs.
native/​include/​cng_provider_params.h Defines provider parameters and URI limits.
native/​examples/​c/​mtls_request.c Demonstrates a native certificate-bound request.
native/​docs/​versioning.md Defines product, ABI, and dependency versioning.
native/​docs/​security-review.md Specifies security review requirements.
native/​docs/​security-model.md Documents trust boundaries and enforced properties.
native/​docs/​releasing.md Defines native release gates.
native/​docs/​development.md Documents native development practices.
native/​docs/​building-and-testing.md Explains build, test, and OpenSSL servicing plans.
native/​docs/​architecture.md Describes crate responsibilities and request flow.
native/​docs/​abi.md Documents ABI ownership and protected-key contracts.
native/​deny.toml Configures dependency and license policy checks.
native/​crates/​rust-tests/​tests/​key_creation_race.rs Tests cross-process key creation convergence.
native/​crates/​rust-tests/​src/​lib.rs Adds an ABI smoke test.
native/​crates/​rust-tests/​src/​bin/​key-race-helper.rs Supports concurrent key creation tests.
native/​crates/​rust-tests/​src/​bin/​key-audit.rs Detects leftover project test keys.
native/​crates/​rust-tests/​Cargo.toml Configures cross-crate test dependencies.
native/​crates/​openssl-provider-sys/​Cargo.toml Configures the OpenSSL FFI crate.
native/​crates/​mtls-bridge/​src/​lib.rs Implements request execution and response ownership.
native/​crates/​mtls-bridge/​src/​abi.rs Defines ABI layouts, bounds, and structured errors.
native/​crates/​mtls-bridge/​Cargo.toml Configures the transport library and dependencies.
native/​crates/​cng-provider/​src/​uri.rs Parses bounded CNG key URIs.
native/​crates/​cng-provider/​src/​store.rs Implements OpenSSL STORE loading and ownership.
native/​crates/​cng-provider/​src/​params.rs Handles typed OpenSSL parameters.
native/​crates/​cng-provider/​src/​lib.rs Registers provider algorithms and callbacks.
native/​crates/​cng-provider/​src/​error.rs Produces bounded provider diagnostics.
native/​crates/​cng-provider/​src/​allocation.rs Adds fallible allocation and cleanup test helpers.
native/​crates/​cng-provider/​Cargo.toml Configures the CNG provider library.
native/​crates/​cng-core/​Cargo.toml Configures Windows key primitive dependencies.
native/​CONTRIBUTING.md Defines native contribution and validation requirements.
native/​CMakeLists.txt Builds external C tests and the example.
native/​CHANGELOG.md Records native additions and hardening changes.
native/​Cargo.toml Defines workspace dependencies and lint settings.
native/​Cargo.lock Records resolved Rust dependencies.
native/​AGENTS.md Documents native-specific development guidance.
native/​.gitignore Excludes generated native artifacts.
native/​.gitattributes Defines line endings and binary handling.
native/​.editorconfig Defines native file formatting conventions.
msal/​token_cache.py Redacts the v2 claims cache parameter.
msal/​managed_identity.py Adds discovery, protected modes, and refresh options.
msal/​_native_attestation.py Wraps optional native attestation with explicit ownership.
msal/​_managed_identity_store.py Persists and restores public certificate bindings.
msal/​_managed_identity_binding.py Adds generation-bound sync and async transports.
docs/​managed-identity-v2.rst Documents installation, contracts, and validation profiles.
docs/​index.rst Links the Managed Identity v2 guide.
.Pipelines/​template-pipeline-stages.yml Adds the opt-in installed-candidate live stage.
.Pipelines/​CI-AND-RELEASE-PIPELINES.md Documents stacked integration CI coverage.
.gitignore Excludes optional wheel staging outputs.
.github/​workflows/​python-package.yml Adds stacked-branch Python unit test coverage.
.github/​workflows/​native-primitives.yml Adds Windows native and Python integration CI.
.github/​dependabot.yml Adds native Cargo dependency monitoring.

Review effort: Balanced

Comment on lines +151 to +153
client = metadata["client_id"]
uuid.UUID(client)
endpoint = _endpoint(metadata["token_endpoint"], stage="binding")
@gladjohn

Copy link
Copy Markdown
Contributor Author

Superseded by #987, using the repository-owned feature/managed-identity-v2 branch rather than a fork. The implementation is unchanged at e339f16 and still includes the #982 bridge dependency.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants