Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .Pipelines/CI-AND-RELEASE-PIPELINES.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ by the GitHub Actions workflow
[`.github/workflows/python-package.yml`](../.github/workflows/python-package.yml),
which builds the package and runs `twine check` on every PR.

For the native integration stack targeting `feature/native-primitives`, that
workflow also runs secret-free unit tests on Python 3.9 through 3.14, including
draft PRs. The [native workflow](../.github/workflows/native-primitives.yml)
accepts that stacked base and runs the Windows Debug/Release native matrix,
dependency policy checks, and Python 3.12 native integration tests. Both workflows
publish JUnit artifacts. These checks do not replace OneBranch SDL or live
VBS/MAA/Key Vault validation; the existing ADO branch and draft policies remain
unchanged.

### Stages

```
Expand Down
74 changes: 74 additions & 0 deletions .Pipelines/template-pipeline-stages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -396,3 +396,77 @@ stages:
testResultsFiles: 'test-results/junit-mi-e2e-arc.xml'
failTaskOnFailedTests: true
testRunTitle: 'MI E2E - Azure Arc'

# Explicitly enabled only after a trusted candidate and enrolled fixture are staged.
- stage: MIE2EImdsV2
displayName: 'MI E2E - installed MSI v2 KeyGuard candidate'
dependsOn: UnitTests
condition: and(eq(dependencies.UnitTests.result, 'Succeeded'), ne(variables['System.PullRequest.IsFork'], 'True'), eq(variables['MSAL_RUN_MI_V2'], '1'))
jobs:
- job: PytestV2
pool:
type: windows
isCustom: true
name: MISEManagedIdentity
timeoutInMinutes: 30
variables:
ob_outputDirectory: '$(Build.ArtifactStagingDirectory)'
steps:
- task: PowerShell@2
displayName: 'Verify runner, install selected wheels, run full MSI v2 profile'
inputs:
targetType: inline
script: |
$ErrorActionPreference = 'Stop'
$py = (Get-Command python.exe -ErrorAction Stop).Source
$tpm = Get-Tpm
if (-not $tpm.TpmPresent -or -not $tpm.TpmReady) { throw 'MSI v2 requires a ready TPM.' }
if (-not (Confirm-SecureBootUEFI)) { throw 'MSI v2 requires Secure Boot.' }
$guard = Get-CimInstance -Namespace root\Microsoft\Windows\DeviceGuard -ClassName Win32_DeviceGuard
if ($guard.VirtualizationBasedSecurityStatus -ne 2) { throw 'MSI v2 requires running VBS.' }
$candidate = '$(MSAL_MI_V2_CANDIDATE_DIR)'
if (-not (Test-Path -LiteralPath $candidate -PathType Container)) {
throw 'Stage the reviewed core, native and attestation wheels in MSAL_MI_V2_CANDIDATE_DIR.'
}
$wheels = @()
foreach ($pattern in @('msal-*-py3-none-any.whl', 'msal_native_primitives-*-win_amd64.whl', 'msal_key_attestation-*-win_amd64.whl')) {
$selected = @(Get-ChildItem -LiteralPath $candidate -Filter $pattern -File)
if ($selected.Count -ne 1) { throw "Stage exactly one selected candidate matching $pattern." }
$wheels += $selected[0].FullName
Write-Host "Candidate SHA256: $((Get-FileHash -LiteralPath $selected[0].FullName).Hash)"
}
$env:MSAL_TEST_MI_V2_SOURCE_FINGERPRINT = & $py -c "from tests.test_mi_v2_e2e import _sdk_fingerprint; print(_sdk_fingerprint())"
if ($LASTEXITCODE -ne 0) { throw 'Could not fingerprint the selected SDK source.' }
$env:MSAL_TEST_MI_V2_NATIVE_BUILD_ID = & $py -c "import json,sys,zipfile; z=zipfile.ZipFile(sys.argv[1]); print(json.loads(z.read('msal_native_primitives/lib/native-manifest.json').decode('utf-8-sig'))['build_id'])" $wheels[1]
if ($LASTEXITCODE -ne 0) { throw 'Could not identify the selected native wheel.' }
& $py -m pip install --no-index --no-deps --force-reinstall @wheels
if ($LASTEXITCODE -ne 0) { throw 'Candidate installation failed.' }
$run = Join-Path '$(Agent.TempDirectory)' 'msal-python-mi-v2-candidate'
New-Item -ItemType Directory -Force -Path $run | Out-Null
Copy-Item -LiteralPath tests\test_mi_v2_e2e.py -Destination $run -Force
Push-Location $run
try {
& $py -m pytest -vv -ra test_mi_v2_e2e.py --junitxml='$(Build.ArtifactStagingDirectory)\junit-mi-v2.xml'
if ($LASTEXITCODE -ne 0) { throw 'The installed-candidate MSI v2 profile failed.' }
} finally {
Pop-Location
}
env:
MSAL_TEST_MI_IMDS_V2: '1'
MSAL_TEST_MI_V2_REQUIRE_INSTALLED: '1'
MSAL_NATIVE_PRIMITIVES_DIR: ''
MSAL_KEY_ATTESTATION_DIR: ''
MSAL_TEST_MI_V2_REQUIRE_ATTESTATION: '1'
MSAL_TEST_MI_V2_TOKEN_ONLY: '0'
MSAL_ALLOW_DEVELOPMENT_NATIVE: '1'
MSAL_TEST_MI_V2_UAMI_CLIENT_ID: $(MSAL_TEST_MI_V2_UAMI_CLIENT_ID)
MSAL_TEST_MI_V2_BOUND_SECRET_URL: $(MSAL_TEST_MI_V2_BOUND_SECRET_URL)
MSAL_TEST_MI_V2_BEARER_SECRET_URL: $(MSAL_TEST_MI_V2_BEARER_SECRET_URL)
- task: PublishTestResults@2
condition: succeededOrFailed()
inputs:
testResultsFormat: JUnit
testResultsFiles: '$(Build.ArtifactStagingDirectory)\junit-mi-v2.xml'
failTaskOnFailedTests: true
failTaskOnMissingResultsFile: true
testRunTitle: 'MI E2E - installed MSI v2 KeyGuard full profile'
13 changes: 13 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,16 @@ updates:
interval: "weekly"
cooldown:
default-days: 7
- package-ecosystem: "cargo"
directory: "/native"
schedule:
interval: "weekly"
day: "monday"
open-pull-requests-limit: 10
groups:
rust-development-dependencies:
dependency-type: "development"
patterns: ["*"]

# Native vcpkg/OpenSSL baseline updates are reviewed manually because they
# change the cryptographic/runtime trusted computing base.
124 changes: 124 additions & 0 deletions .github/workflows/native-primitives.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
name: Native Primitives Windows CI

on:
push:
branches: [dev]
paths:
- "native/**"
- "msal/_native*.py"
- "msal/_managed_identity*.py"
- "msal/managed_identity.py"
- "msal/token_cache.py"
- "tests/test_native_mtls.py"
- "tests/test_managed_identity_v2.py"
- "tests/test_token_cache.py"
- "requirements.txt"
- "setup.py"
- "setup.cfg"
- ".github/workflows/native-primitives.yml"
pull_request:
branches: [dev, feature/native-primitives]
paths:
- "native/**"
- "msal/_native*.py"
- "msal/_managed_identity*.py"
- "msal/managed_identity.py"
- "msal/token_cache.py"
- "tests/test_native_mtls.py"
- "tests/test_managed_identity_v2.py"
- "tests/test_token_cache.py"
- "requirements.txt"
- "setup.py"
- "setup.cfg"
- ".github/workflows/native-primitives.yml"
workflow_dispatch:

permissions:
contents: read

defaults:
run:
shell: pwsh
working-directory: native

jobs:
test:
runs-on: windows-2022
timeout-minutes: 60

steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0

- uses: dtolnay/rust-toolchain@6c977a6ca4077a0ceb28ffbe03f59d46e9ac8772
with:
toolchain: 1.97.1-x86_64-pc-windows-msvc
components: clippy, rustfmt

- name: Fetch pinned vcpkg baseline
run: |
$manifest = Get-Content vcpkg.json | ConvertFrom-Json
$baseline = $manifest.'builtin-baseline'
git -C $env:VCPKG_INSTALLATION_ROOT fetch --refetch --depth=1 origin $baseline
if ($LASTEXITCODE -ne 0) { throw "Fetching the native vcpkg baseline failed." }

- name: Configure native test harness
run: |
cmake -S . -B build -G "Visual Studio 17 2022" -A x64 `
-DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_INSTALLATION_ROOT\scripts\buildsystems\vcpkg.cmake" `
-DVCPKG_TARGET_TRIPLET=x64-windows
if ($LASTEXITCODE -ne 0) { throw "Configuring the native test harness failed." }

- name: Run complete matrix
run: .\scripts\test.ps1

- name: Set up Python
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
with:
python-version: '3.12'
cache: 'pip'

- name: Install Python test dependencies
working-directory: ${{ github.workspace }}
run: |
python -m pip install -r requirements.txt pytest-timeout
if ($LASTEXITCODE -ne 0) { throw "Installing Python test dependencies failed." }

- name: Test Python and native integration
working-directory: ${{ github.workspace }}
run: |
$env:MSAL_TEST_NATIVE_MTLS_DIR = (Resolve-Path .\native\artifacts\Release).Path
python -m pytest -q --timeout=120 `
tests\test_managed_identity_v2.py tests\test_native_mtls.py tests\test_token_cache.py `
--junitxml=test-results\junit-native-python.xml
if ($LASTEXITCODE -ne 0) { throw "Python native integration tests failed." }

- name: Upload Python native test results
if: always()
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: native-python-tests
path: test-results/
if-no-files-found: warn
retention-days: 7

dependency-policy:
runs-on: windows-2025
timeout-minutes: 30

steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0

- uses: dtolnay/rust-toolchain@6c977a6ca4077a0ceb28ffbe03f59d46e9ac8772
with:
toolchain: 1.97.1-x86_64-pc-windows-msvc

- uses: taiki-e/install-action@a2a5f6e99e1a31540baa0468acfa302cff0f359f # v2
with:
tool: cargo-audit@0.22.2,cargo-deny@0.20.2
fallback: none

- name: Audit Rust dependencies
run: cargo audit

- name: Enforce dependency policy
run: cargo deny check
43 changes: 41 additions & 2 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
# fast feedback that the package still builds and that the distribution metadata
# passes `twine check`.
#
# Unit tests, E2E tests, benchmarks, SDL scans, and PyPI publishing are NOT run
# here. Those run in the IDDP/ADO pipelines:
# Stacked PRs targeting feature/native-primitives also run secret-free unit tests
# here because the IDDP/ADO gate targets dev and skips drafts.
# E2E tests, benchmarks, SDL scans, and PyPI publishing remain in IDDP/ADO:
# - azure-pipelines.yml (PRs + pushes: unit + E2E + benchmarks + SDL)
# - .Pipelines/pipeline-publish.yml (manual release to TestPyPI / PyPI)

Expand All @@ -16,6 +17,44 @@ on:
# No `branches` filter — run on PRs against any target branch.

jobs:
unit-tests:
name: Stacked unit tests (Python ${{ matrix.python-version }})
if: github.base_ref == 'feature/native-primitives'
permissions:
contents: read
runs-on: ubuntu-22.04
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13', '3.14']
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install test dependencies
run: python -m pip install -r requirements.txt pytest-timeout
- name: Run unit tests without live credentials
run: |
python -m pytest -q --benchmark-skip --timeout=120 \
--junitxml=test-results/junit-unit.xml \
--ignore=tests/test_e2e.py \
--ignore=tests/test_e2e_manual.py \
--ignore=tests/test_fmi_e2e.py \
--ignore=tests/test_mi_e2e.py \
--deselect tests/test_cryptography.py::CryptographyTestCase::test_ceiling_should_be_latest_cryptography_version_plus_three \
--deselect tests/test_cryptography.py::CryptographyTestCase::test_should_be_run_with_latest_version_of_cryptography
- name: Upload unit test results
if: always()
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: stacked-unit-tests-${{ matrix.python-version }}
path: test-results/
if-no-files-found: warn
retention-days: 7

build:
name: Build package (sdist + wheel)
permissions:
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,10 @@ msal_cache.bin
.env
.perf-baseline/

# Optional Windows integration candidate staging
/packages/*/build/
/packages/*/*.egg-info/
/packages/*/*/lib/

*.pfx
.vscode/settings.json
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ You can follow the latest updates and plans for MSAL Python in the [Roadmap](htt

## Samples and Documentation

The repository also hosts the pre-release
[Microsoft.Identity.Native.Primitives](https://github.com/AzureAD/microsoft-authentication-library-for-python/tree/dev/native)
project under `native/`. It provides Windows CNG/OpenSSL and bounded mTLS
transport primitives through a C ABI. It builds and tests independently and
is not integrated into the `msal` Python package or its PyPI distributions.

MSAL Python supports multiple [application types and authentication scenarios](https://docs.microsoft.com/azure/active-directory/develop/authentication-flows-app-scenarios).
The generic documents on
[Auth Scenarios](https://docs.microsoft.com/azure/active-directory/develop/authentication-scenarios)
Expand Down
2 changes: 2 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ MSAL Python Documentation
:caption: Contents:
:hidden:

managed-identity-v2

..
Comment: Perhaps because of the theme, only the first level sections will show in TOC,
regardless of maxdepth setting.
Expand Down
Loading
Loading