Automation

Azure DevOps: verify artifact provenance before redeploying after an agent compromise

A production runbook for tracing an Azure DevOps artifact from source commit to build, package and container digest before promotion, clean rebuild or rollback.

11 Nov 2026 azure-devopspipelinesartifactssupply-chainself-hosted-agentsecurityacrprovenanceautomationobservabilityrunbookrollbackproduction

A self-hosted Azure DevOps agent is quarantined after an endpoint alert. The affected run is green, its web-api package is available, and the container tag has already reached the staging registry. Production has not been changed yet. Rerunning the deployment from the same artifact would be fast, but nobody can prove that the package still represents the reviewed commit.

The incident is no longer limited to the runner. Every artifact produced, transformed or uploaded during the exposure window is a candidate for quarantine. This runbook follows one release from Azure DevOps run to source commit, published package, Azure Container Registry manifest and deployment input. It ends with one of four decisions: release the original candidate with evidence, rebuild from trusted inputs, keep the candidate quarantined, or restore the last known-good digest.

Freeze the artifact path before rebuilding

Pause production stages and any automated promotion that can consume the suspect run. Keep the compromised agent offline, preserve its diagnostics, and stop retention from deleting the build record or artifacts. Do not delete the image tag: losing the candidate also loses the object that must be compared.

Create one incident ledger. Human-readable build numbers and mutable tags help operators, but they are not stable identities. The useful anchors are the Azure DevOps build ID, source version, definition and revision, repository, artifact name, package digest, container manifest digest and deployment reference.

yaml 01-artifact-provenance-incident.yml
incident: INC-CICD-20261111-04
exposure_window_utc:
start: 2026-11-11T05:40:00Z
end: 2026-11-11T07:10:00Z

build:
organization: contoso
project: platform
definition_id: 42
definition_revision: 18
build_id: 8912
source_version: <full-git-commit>
source_branch: refs/heads/main
agent_pool: linux-production
agent_name: runner-07

outputs:
pipeline_artifact: web-api
package_sha256: <pending>
image: platform/web-api
image_tag: 20261111.42
manifest_digest: <pending>

promotion:
staging_deployment: <deployment-id>
production_started: false
last_known_good_digest: sha256:<trusted-digest>

decision_owner: release-on-call
status: quarantined

Record whether the run checked out one repository or several, pulled submodules, downloaded pipeline resources or generated code. Build.SourceVersion identifies the triggering repository version; it does not by itself describe every external input. For PR builds, it may identify a merge commit. Preserve the evaluated pipeline YAML and resource versions, not only the current files on the branch.

Reconstruct the Azure DevOps build record

Read the immutable build ID first. Capture the definition, source version, queue time, start and finish time, result, requested identity, agent pool, repository and links to logs. Then list every published artifact and retain its artifact source. Azure DevOps exposes build artifacts by build ID through its Build REST API.

bash 02-freeze-build-and-artifacts.sh
set -euo pipefail

ORG="https://dev.azure.com/contoso"
PROJECT="platform"
BUILD_ID="8912"
OUT="evidence/build-$BUILD_ID"
mkdir -p "$OUT"

curl --fail --silent --show-error -H "Authorization: Bearer $AZDO_OAUTH_TOKEN" "$ORG/$PROJECT/_apis/build/builds/$BUILD_ID?api-version=7.1" > "$OUT/build.json"

curl --fail --silent --show-error -H "Authorization: Bearer $AZDO_OAUTH_TOKEN" "$ORG/$PROJECT/_apis/build/builds/$BUILD_ID/artifacts?api-version=7.1" > "$OUT/artifacts.json"

jq '{
id,
buildNumber,
definition: {id: .definition.id, name: .definition.name, revision: .definition.revision},
repository: {id: .repository.id, type: .repository.type},
sourceBranch,
sourceVersion,
queueTime,
startTime,
finishTime,
result,
reason,
requestedFor: .requestedFor.id
}' "$OUT/build.json" > "$OUT/build-summary.json"

jq '[.value[] | {
id,
name,
source,
resourceType: .resource.type,
resourceUrl: .resource.url,
downloadUrl: .resource.downloadUrl
}]' "$OUT/artifacts.json" > "$OUT/artifact-index.json"

Use a scoped incident credential and never print it. Retain the response and hash it in the evidence store. Fetch logs before retention expires, especially checkout, dependency restore, build, signing, packaging, publication and registry push. A successful task only proves that the task reported success; compare the command, inputs and output identity.

Check the definition revision and task versions that actually ran. A current pipeline review can miss a template, variable group, service connection or extension version that differed during the suspect run. Map each privileged boundary: source read, package feed, signing service, artifact publication, registry push and deployment environment.

Identify the exact bytes, not the artifact name

Download the artifact from its frozen build record into an isolated analysis environment. Do not execute scripts from it. Inventory paths, file types, permissions, archives and hashes. If the package contains nested archives, inspect them without running post-install hooks.

bash 03-inventory-candidate-artifact.sh
set -euo pipefail

CANDIDATE="evidence/web-api.zip"
OUT="evidence/web-api-inventory"
mkdir -p "$OUT/unpacked"

sha256sum "$CANDIDATE" | tee "$OUT/package.sha256"
unzip -Z -1 "$CANDIDATE" | LC_ALL=C sort > "$OUT/paths.txt"
unzip -q "$CANDIDATE" -d "$OUT/unpacked"

find "$OUT/unpacked" -type f -print0 | LC_ALL=C sort -z | xargs -0 sha256sum > "$OUT/files.sha256"

find "$OUT/unpacked" -type f -exec file --brief --mime-type {} + > "$OUT/mime-types.txt"

A hash created by the suspect runner is useful for identification, but it is not independent proof of integrity. Recompute it outside that runner and compare it with any manifest stored in a separate control plane. If the only digest exists inside the artifact, treat it as a claim made by the candidate.

Compare the candidate with the release contract: expected entry points, dependency lockfile, SBOM when one is produced, compiler and runtime versions, signing identity, generated configuration and excluded files. Look for unexpected executables, startup scripts, credentials, debugging endpoints and timestamps that fall outside the build window.

Trace container tags to immutable digests

If the pipeline pushed a container, record the registry, repository, tag and manifest digest. A tag can move; the manifest digest identifies the object currently referenced. Azure Container Registry exposes manifest metadata, and a deployment can pin an image with repository@sha256:digest.

bash 04-freeze-acr-manifest.sh
set -euo pipefail

ACR="acrplatformprod"
REPOSITORY="platform/web-api"
TAG="20261111.42"

az acr manifest list-metadata --registry "$ACR" --name "$REPOSITORY" --query "[?contains(tags, '$TAG')].{digest:digest,tags:tags,timestamp:timestamp}" --output json > evidence/acr-manifest.json

DIGEST="$(jq -r '.[0].digest // empty' evidence/acr-manifest.json)"
test -n "$DIGEST"
printf '%s@%s
' "$REPOSITORY" "$DIGEST" | tee evidence/deployment-image-reference.txt

Confirm that one tag resolves to the expected single candidate in the incident snapshot. Then read staging or production configuration to learn whether it references the tag or digest. A green staging deployment does not prove provenance; it proves only that the deployed object can run in that environment.

Do not retag the suspect manifest as trusted. Quarantine promotion permissions, preserve the digest, and ensure no policy or automation can select it through a floating tag such as latest or stable.

Rebuild on a clean boundary and compare

A trustworthy rebuild must not reuse the suspect agent workspace, pipeline cache, mutable base-image tag or credentials exposed during the incident. Start from the pinned commit and the evaluated pipeline definition. Resolve every additional repository, base image, package lock and build tool to a recorded version.

Build on a newly provisioned or separately trusted agent with a clean workspace and isolated credentials. Disable optional network access where the build allows it. Publish the clean candidate under a new build ID and tag; never overwrite the suspect object.

Exact byte equality is strong evidence only when the build is designed to be reproducible. Timestamps, archive ordering, generated IDs and compiler metadata can make two legitimate packages differ. When equality is not expected, compare a normalized file inventory, dependency graph, SBOM, signatures, configuration and executable sections. Any unexplained executable difference blocks promotion.

yaml 05-provenance-decision-gates.yml
gates:
source:
  build_id_frozen: true
  full_commit_matches_review: true
  pipeline_definition_revision_frozen: true
  external_inputs_pinned: true

candidate:
  package_hash_recomputed_off_agent: true
  registry_manifest_digest_frozen: true
  unexpected_files: 0
  secrets_found: 0

clean_rebuild:
  trusted_ephemeral_agent: true
  clean_workspace_and_cache: true
  isolated_credentials: true
  normalized_inventory_matches: true
  executable_differences_explained: true
  tests_pass: true

deployment:
  image_referenced_by_digest: true
  canary_healthy: true
  last_known_good_digest_available: true

decision:
promote_original: false
promote_clean_rebuild: pending
keep_quarantined: true
rollback_digest: sha256:<trusted-digest>

Promoting the original candidate should be rare after agent compromise. It requires an independent signature or attestation bound to the exact digest, a trusted signing boundary outside the agent, complete input provenance and no exposure of the signing identity. A matching clean rebuild alone does not erase the incident, but it can support the decision when the build is reproducible and every privileged boundary is understood.

Canary, decide and keep rollback explicit

Deploy the clean digest to a bounded canary with production-equivalent policy but no broad write path. Verify startup, dependency calls, identity, telemetry, vulnerability policy and the critical user journey. Correlate the canary with its new build ID and digest in deployment records.

Promote the clean rebuild only when source, build definition, external inputs, package inventory and registry digest form one explainable chain. Keep both candidates blocked when an input is mutable, a privileged step is missing from logs, the signing identity may have been exposed or the clean output contains an unexplained difference.

Rollback means restoring the last known-good immutable digest and its compatible configuration, then verifying service health and telemetry. It does not mean moving stable back without recording which manifest now sits behind the tag. If production consumed the suspect artifact, rotate exposed credentials, inspect its runtime effects and treat rollback as containment rather than proof that no compromise occurred.

Conclusion

After an Azure DevOps agent incident, a green run and a familiar tag are not release evidence. The operable unit is a chain: reviewed source, evaluated pipeline, known inputs, identified bytes, immutable registry digest and a deployment record that names the same object.

The final decision is deliberately narrow: promote a clean, explainable digest; keep the candidate quarantined; or restore the last known-good digest while the supply-chain investigation continues. Rebuilding is useful only when it creates a new trust boundary, not when it repeats the same pipeline on the same uncertain machine.