Skip to content
Open
35 changes: 25 additions & 10 deletions OneBranchPipelines/conda-build-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# (drop_ConsolidateConda_ConsolidateArtifacts). Publishing is the companion
# conda-release-pipeline.yml. Validated locally that the recipe builds + imports; the
# per-OS legs + SDL settings need an actual ADO run to confirm.
# Successful main wheel builds trigger Official Conda builds using that exact producer run.
# =========================================================================================
name: $(Year:YY)$(DayOfYear)$(Rev:.r)-CondaBuild

Expand Down Expand Up @@ -52,7 +53,7 @@ parameters:

variables:
- name: effectiveOneBranchType
${{ if eq(variables['Build.Reason'], 'Schedule') }}:
${{ if or(eq(variables['Build.Reason'], 'Schedule'), eq(variables['Build.Reason'], 'ResourceTrigger')) }}:
value: 'Official'
Comment thread
jahnvi480 marked this conversation as resolved.
Resolved
${{ else }}:
value: '${{ parameters.oneBranchType }}'
Expand All @@ -68,9 +69,12 @@ resources:
# The wheel build pipeline whose consolidated wheel artifacts this pipeline repackages.
pipelines:
- pipeline: buildPipeline
source: 'Build-Release-Package-Pipeline'
source: '\OneBranch\Build-Release-Package-Pipeline'
branch: main
trigger: none
trigger:
branches:
include:
- refs/heads/main
Comment thread
jahnvi480 marked this conversation as resolved.
Resolved

extends:
template: 'v2/OneBranch.${{ variables.effectiveOneBranchType }}.CrossPlat.yml@templates'
Expand Down Expand Up @@ -356,14 +360,24 @@ extends:
- bash: |
set -euo pipefail
sudo apt-get update
sudo apt-get install -y qemu-user-static binfmt-support libc6-arm64-cross
# qemu-user-static + binfmt-support register the aarch64 binfmt_misc handler
# on install (update-binfmts), so host-level qemu-user emulation works WITHOUT
# a `docker run --privileged multiarch/qemu-user-static` (an unpinned public
# image SDL would flag). Verify the handler is present and fail loudly if not,
# rather than silently emulating nothing.
test -e /proc/sys/fs/binfmt_misc/qemu-aarch64 || { echo "ERROR: aarch64 binfmt handler not registered after apt install" >&2; exit 1; }
sudo apt-get install -y qemu-user qemu-user-binfmt libc6-arm64-cross
# Ubuntu 26.04 provides static emulators in qemu-user; qemu-user-binfmt
# supplies systemd registration files, not update-binfmts entries.
sudo systemctl restart systemd-binfmt.service
qemu-aarch64 --version
test -x /usr/aarch64-linux-gnu/lib/ld-linux-aarch64.so.1 || { echo "ERROR: ARM64 glibc loader is missing after apt install" >&2; exit 1; }
handler="/proc/sys/fs/binfmt_misc/qemu-aarch64"
grep -qx enabled "$handler" || { echo "ERROR: aarch64 binfmt handler is missing or disabled after systemd-binfmt restart" >&2; exit 1; }
interpreter="$(sed -n 's/^interpreter //p' "$handler")"
# Ubuntu 24.04 can register a binfmt-P symlink to the same emulator.
if [[ -z "$interpreter" ]] || ! installed="$(readlink -e "/usr/bin/qemu-aarch64")" \
|| ! registered="$(readlink -e "$interpreter")" || [[ "$registered" != "$installed" ]]; then
echo "ERROR: aarch64 binfmt handler does not resolve to the installed qemu-user emulator" >&2
exit 1
fi
echo "##vso[task.setvariable variable=ready;isOutput=true]true"
displayName: 'Install libc6-arm64-cross + register QEMU binfmt (aarch64)'
name: setupArm64Qemu
# continueOnError so a transient apt/binfmt flake fails ONLY the best-effort
# aarch64 leg (which is itself continueOnError), never the shared Linux job -- a
# blocking setup step here would discard the already-validated linux-64 packages
Expand All @@ -374,6 +388,7 @@ extends:
condaSubdir: 'linux-aarch64'
condaTargetSubdir: 'linux-aarch64'
continueOnError: true
condition: and(succeeded(), eq(variables['setupArm64Qemu.ready'], 'true'))
odbcWheelDir: '$(Pipeline.Workspace)/odbc_wheels'
odbcWheelFilter: 'mssql_python_odbc-*manylinux_2_28_aarch64.whl'
pythonVersions: '${{ parameters.pythonVersions }}'
Expand Down
5 changes: 5 additions & 0 deletions OneBranchPipelines/steps/conda-build-validate-step-posix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ parameters:
- name: continueOnError
type: boolean
default: false
# Emulated callers can require successful provisioning without blocking native artifacts.
- name: condition
type: string
default: succeeded()

steps:
- bash: |
Expand Down Expand Up @@ -102,4 +106,5 @@ steps:
MSSQL_CONDA_PYTHON_VERSIONS: ${{ parameters.pythonVersions }}
CONDA_TARGET_SUBDIR: ${{ parameters.condaTargetSubdir }}
displayName: 'Conda build + validate (${{ parameters.condaSubdir }})'
condition: ${{ parameters.condition }}
continueOnError: ${{ parameters.continueOnError }}
31 changes: 31 additions & 0 deletions conda/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@ version before rendering/building. The shared orchestrator derives and supplies
automatically; omitted input fails recipe rendering instead of choosing a release.
Both native installation and cross extraction require the bulk-copy initializer and
a compatible extension filename. The separate native audits still validate binary headers.
Linux ARM64 builds on the x64 Ubuntu agent require working QEMU emulation. The pipeline
installs `qemu-user`, `qemu-user-binfmt` and `libc6-arm64-cross`, reloads the systemd binfmt
registrations, and checks the enabled aarch64 handler, its emulator and the ARM64 loader.
The handler's interpreter must resolve to the installed emulator; valid Ubuntu 24.04
`binfmt-P` symlinks are accepted, but missing, dangling or different interpreters are not.
On Ubuntu 26.04, `qemu-user-static` is only a virtual package, not an install candidate.
The recipe sets `QEMU_LD_PREFIX` to the cross libc directory when available; failed
Linux interpreter execution stops with an emulation diagnostic, not a missing-wheel
error. Interpreter-free wheel extraction remains restricted to `osx-*` targets.
The ARM64 build runs only after every setup check passes; failed setup skips that leg
without blocking native Linux artifact publication. ARM64 failures still preserve native
Linux artifacts, but a missing ARM64 matrix blocks release.

For RS-dependent bindings, the orchestrator also supplies the derived `MSSQL_RS_VERSION`
and a validated `rs-wheel-cp<minor>.txt` selection in `WHEELS_DIR`. Recipes install or
extract that entire wheel, including private libraries and distribution metadata, before
Expand Down Expand Up @@ -259,6 +272,24 @@ path is passed to the publishing task through a read-only task output. Dependenc
use the publisher's target-specific hash lock and explicit package-feed-proxy `--index-url`
with pip's `--isolated` mode. Both production and rehearsal use this same code.

On `refs/heads/main`, successful completion of `Build-Release-Package-Pipeline`
automatically starts an Official `Conda-Build-Pipeline` run. This resource trigger
waits for the entire upstream pipeline, not just an individual stage, and retains
the exact triggering wheel producer run through `buildPipeline.runID`.
An Official Conda build does not by itself make its input wheels production-eligible.
The release provenance gate checks the recorded wheel run's effective Official mode
(including scheduled Official runs), enabled SDL and Windows signing settings, and
completed/succeeded timeline evidence for every recorded platform build job: wheel
ESRP malware scans and Component Governance, plus Windows native malware scanning,
signing, Authenticode verification and signed-wheel verification. The ODBC wheel scan
is also required. Missing, skipped, failed or mismatched evidence blocks production;
non-publishing validation reports the ineligibility without granting publication.
Automation stops after the Conda build: `Conda-Release-Pipeline` remains manually
queued, with no build-completion trigger for release, rehearsal or publication.
Direct CI and PR triggers remain disabled on both Conda pipelines. The build-trigger YAML
must be present in the ADO repository's configured default branch, with the existing
pipeline-resource authorizations in place, before automatic Conda builds can run.

With `publishToConda=false` (the default), the release pipeline now rehearses the
publisher instead of only printing an upload plan. Both modes use the Official
template, Windows 2022 managed container, network isolation, independent producer
Expand Down
6 changes: 5 additions & 1 deletion conda/mssql-python/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ if "$PYTHON" -c "import sys" >/dev/null 2>&1; then
"$PYTHON" -m pip install --no-deps --no-index "$WHEELS_DIR/$rs_whl" -vv
fi
core_suffix="$("$PYTHON" -c 'import sysconfig; print(sysconfig.get_config_var("EXT_SUFFIX"))')"
else
elif [[ "${target_platform:-${CONDA_SUBDIR:-}}" == osx-* ]]; then
core_suffix=".cpython-${CONDA_PY}-darwin.so"
echo "Host Python '$PYTHON' is not executable on this agent (non-emulated cross-build);"
echo "extracting both wheels into \$SP_DIR without running Python."
Expand Down Expand Up @@ -67,6 +67,10 @@ else
if [ -n "$rs_ver" ]; then
unzip -oq "$WHEELS_DIR/$rs_whl" -d "$SP_DIR"
fi
else
echo "ERROR: target Python '$PYTHON' cannot execute for '${target_platform:-${CONDA_SUBDIR:-unknown}}'; only osx-* targets support wheel extraction without Python." >&2
echo "For linux-aarch64, check QEMU binfmt registration and the ARM64 glibc loader/QEMU_LD_PREFIX before rebuilding." >&2
exit 1
fi

if [ -n "$rs_ver" ]; then
Expand Down
99 changes: 93 additions & 6 deletions eng/conda_tools/provenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,96 @@ def _verify_run(build: dict, run: dict, pipeline_id: int, run_id: int) -> dict:
return {"pipeline": pipeline_id, "run": run_id, "branch": branch, "commit": commit}


def _wheel_security_reasons(get_json: Callable[[str], dict], build: dict, run: dict) -> list[str]:
parameters = run.get("templateParameters")
if not isinstance(parameters, dict):
return ["wheel producer security parameters are missing"]
reasons = []
# Scheduled producers select Official even when the parameter defaults to NonOfficial.
if build.get("reason") != "schedule" and parameters.get("oneBranchType") != "Official":
reasons.append("wheel producer did not use Official mode")
for name in ("runSdlTasks", "signWindowsBinaries"):
if parameters.get(name) is not True:
reasons.append(f"wheel producer {name} was not enabled")
if reasons:
return reasons

expected_jobs = {"ODBC_BuildAll.BuildWheel.__default"}
for parameter, prefix, fields, job in (
("windowsConfigs", "Win_py", ("pyVer", "arch"), "BuildWheel"),
("macosConfigs", "MacOS_py", ("pyVer",), "BuildWheel"),
("linuxConfigs", "Linux_", ("tag", "arch"), "BuildWheels"),
):
configs = parameters.get(parameter)
if not isinstance(configs, list) or not configs:
return [f"wheel producer {parameter} evidence is missing"]
for config in configs:
if not isinstance(config, dict) or any(
not isinstance(config.get(field), str)
or not re.fullmatch(r"[a-zA-Z0-9_]+", config[field])
for field in fields
):
return [f"wheel producer {parameter} evidence is invalid"]
identifier = prefix + "_".join(config[field] for field in fields) + f".{job}.__default"
if identifier in expected_jobs:
return [f"wheel producer {parameter} contains duplicate jobs"]
expected_jobs.add(identifier)

timeline = get_json(f"build/builds/{build['id']}/timeline?api-version=7.1").get("records")
if not isinstance(timeline, list) or not all(isinstance(record, dict) for record in timeline):
return ["wheel producer security timeline is missing or invalid"]
for identifier in sorted(expected_jobs):
jobs = [
record
for record in timeline
if record.get("type") == "Job" and record.get("identifier") == identifier
]
if (
len(jobs) != 1
or not isinstance(jobs[0].get("id"), str)
or not jobs[0]["id"]
or jobs[0].get("state") != "completed"
or jobs[0].get("result") != "succeeded"
or type(jobs[0].get("attempt")) is not int
or jobs[0]["attempt"] < 1
):
reasons.append(f"wheel producer job {identifier} is missing or did not succeed")
continue
job_record = jobs[0]
wheel_kind = "ODBC" if identifier.startswith("ODBC_") else "Python"
required_tasks = [
(f"ESRP MalwareScanning - {wheel_kind} Wheels (Official)", "EsrpMalwareScanning"),
("Component Governance Detection", "ComponentGovernanceComponentDetection"),
]
if identifier.startswith("Win_"):
required_tasks.extend(
[
("ESRP MalwareScanning - Native extension", "EsrpMalwareScanning"),
("ESRP CodeSigning - Native extension (.pyd)", "EsrpCodeSigning"),
("Verify Authenticode signature (native extension)", "PowerShell"),
("Verify signed .pyd inside built wheel", "PowerShell"),
]
)
for name, task_type in required_tasks:
tasks = [
record
for record in timeline
if record.get("type") == "Task"
and record.get("parentId") == job_record["id"]
and record.get("name") == name
and record.get("attempt") == job_record["attempt"]
]
if (
len(tasks) != 1
or tasks[0].get("state") != "completed"
or tasks[0].get("result") != "succeeded"
or not isinstance(tasks[0].get("task"), dict)
or tasks[0]["task"].get("name") != task_type
):
reasons.append(f"wheel producer {identifier} lacks completed/succeeded {name}")
return reasons


def verify_provenance(
get_json: Callable[[str], dict],
*,
Expand Down Expand Up @@ -122,12 +212,8 @@ def verify_provenance(
"buildNumber"
):
raise ValueError("Recorded upstream wheel version differs from its Build API build number.")
wheel = _verify_run(
wheel_build,
get_json(f"pipelines/{_WHEEL_PIPELINE_ID}/runs/{wheel_run_id}?api-version=7.1"),
_WHEEL_PIPELINE_ID,
wheel_run_id,
)
wheel_run = get_json(f"pipelines/{_WHEEL_PIPELINE_ID}/runs/{wheel_run_id}?api-version=7.1")
wheel = _verify_run(wheel_build, wheel_run, _WHEEL_PIPELINE_ID, wheel_run_id)
reasons = [
f"{name} source is {branch}, not {_MAIN}"
for name, branch in (
Expand All @@ -137,6 +223,7 @@ def verify_provenance(
)
if branch != _MAIN
]
reasons.extend(_wheel_security_reasons(get_json, wheel_build, wheel_run))
if publish and reasons:
raise ValueError("Production publication is ineligible: " + "; ".join(reasons))
return {
Expand Down
Loading
Loading