TL;DR
- Automated SOC 2 evidence collection starts with a written control, an owner, a population, and a way to verify that the control operated during the examination period. Snapshots show configuration at collection time. Event records, review decisions, and exception handling show activity between snapshots.
- Collect with read-only access to source systems. Store bounded, structured evidence with the source, collection timestamp, scope, policy revision, and digest. Separate collection failure, control failure, and missing scope.
- Start with change management and privileged access. Show the path from a production deployment to its pull request, checks, and exceptions, then test whether a reviewer can reproduce that path after the original engineer has moved on.
What SOC 2 Type II asks engineering to demonstrate
A company preparing for its first SOC 2 Type II examination often has working controls but little historical evidence that they operated. The current GitHub settings page shows that two approvals are required today. It leaves unanswered whether those rules applied across the in-scope repositories through the period, whether emergency changes bypassed them, and whether someone reviewed those exceptions. Gathering screenshots at the end of the period cannot recover missing history.
A Type 2 report addresses the design and operating effectiveness of controls over a specified period. A Type 1 report assesses control design as of a particular date. In a Type 2 examination, the service auditor reports on tests of controls and their results. Management is responsible for the system description and its assertion. Align scope, the examination period, and expected evidence with the service auditor before implementing a collector. AICPA illustrative SOC 2 Type 2 report.
The Trust Services Criteria address security, availability, processing integrity, confidentiality, and privacy. The applicable criteria and how your controls meet them depend on your service commitments and system scope. Multifactor authentication, pull request reviews, and database encryption are reasonable control choices in many SaaS environments. Each needs a population and a test that match your own control language. A cloud console MFA flag, for example, tells you little about federated sign-ins if the identity provider enforces the actual factor policy. AICPA Trust Services Criteria.
Build an evidence map before writing collectors
For each control, identify the authoritative operational source, how frequently the control should operate, and how to reconstruct the eligible records. Write who owns the control, who can approve an exception, and what constitutes a passing test. A single change-management policy can rely on several complementary data sources. A configuration sample shows the active rules. A deployment record supplies the population. A pull request review or an approved emergency change shows how a specific deployment followed the process.
| Control objective | Snapshot or source | Evidence of operation |
|---|---|---|
| Production changes receive review | GitHub rulesets and classic branch protection | Production deployments joined to merge commits, approvals, and exceptions |
| Privileged access stays within policy | Identity provider policy, cloud roles, and scoped access inventory | Access reviews, approved grants and removals, emergency role activity |
| Customer data stored in databases is encrypted | Cloud database and key configuration across in-scope environments | Inventory changes, policy drift alerts, and approved remediation records |
| Vulnerabilities are triaged on schedule | Scanner configuration and scan coverage | Findings linked to triage, resolved versions, or time-limited risk acceptance |
Keep an explicit scope inventory with effective dates. When a repository enters production scope partway through an examination period, collect from the relevant start date and preserve the reason it entered. Pair a complete resource and event list with test results. A directory of passing examples cannot explain which resources were excluded, which data sources were unavailable, or whether the collector omitted a busy account.
Collect an auditable branch rules snapshot
Read effective rules and produce a bounded record
The example targets Python 3.12 and uses the authenticated GitHub CLI. The rules/branches endpoint returns active rules from applicable rulesets. It can return rules for a branch name even if a branch with that name does not exist, so the collector first checks the branch endpoint. GitHub classic branch protection is a separate source. Use this example for a control scoped to a known ruleset and extend your evidence map where classic protection or bypass decisions are in scope. GitHub effective branch rules API · GitHub rule layering.
# collect_branch.py — Python 3.12
import hashlib
import json
import os
import re
import subprocess
from datetime import datetime, timezone
from pathlib import Path
from urllib.parse import quote
def github_api(endpoint: str, *options: str):
raw = subprocess.check_output(
["gh", "api", endpoint, "-H", "X-GitHub-Api-Version: 2022-11-28", *options],
timeout=30, text=True,
)
return json.loads(raw)
repository = os.environ["EVIDENCE_REPOSITORY"]
if not re.fullmatch(r"[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+", repository):
raise ValueError("expected owner/repository")
branch = quote(os.environ["EVIDENCE_BRANCH"], safe="")
prefix = f"repos/{repository}"
branch_state = github_api(f"{prefix}/branches/{branch}")
pages = github_api(f"{prefix}/rules/branches/{branch}", "--paginate", "--slurp")
if not isinstance(pages, list) or not all(isinstance(page, list) for page in pages):
raise ValueError("unexpected GitHub rules response")
review_counts = [
int(rule.get("parameters", {}).get("required_approving_review_count", 0))
for page in pages for rule in page if rule["type"] == "pull_request"
]
record = {
"schema": 1,
"source": "github-rest",
"control_id": "ENG-CHANGE-01",
"policy_revision": os.environ["EVIDENCE_POLICY_REVISION"],
"observed_at": datetime.now(timezone.utc).isoformat(timespec="seconds"),
"repository": repository,
"branch": branch_state["name"],
"tip_commit": branch_state["commit"]["sha"],
"ruleset_approvals_required": max(review_counts, default=0),
"minimum_approvals": 2,
"passed": max(review_counts, default=0) >= 2,
}
data = json.dumps(record, indent=2, sort_keys=True).encode("utf-8") + b"\n"
Path("branch-evidence.json").write_bytes(data)
Path("branch-evidence.sha256").write_text(
hashlib.sha256(data).hexdigest() + " branch-evidence.json\n", encoding="utf-8"
)
The policy revision should point to a reviewed control definition. A result of passed: false is useful evidence and should be archived. A 403, 404, timeout, or malformed response should fail the collector and trigger an investigation into scope or access. Do not interpret any of those responses as successful collection. Check production repositories using a dedicated identity limited to the required branches and repository metadata. Avoid collector access to write repository rules or approve changes.
Schedule collection and transfer evidence out of CI
This GitHub Actions workflow captures the branch rule configured for the same repository and uploads a short-lived transport artifact. A separate collection job or service should copy it into a governed archive and reconcile expected runs. The example uses the built-in repository token with read-only Contents access. For organization-wide collection, use a scoped GitHub App installation or another approved read-only identity. Confirm the permissions on a private target before putting that target into the expected population.
name: Branch evidence
on:
workflow_dispatch:
schedule:
- cron: "17 3 * * *"
permissions:
contents: read
jobs:
evidence:
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ github.token }}
EVIDENCE_REPOSITORY: ${{ github.repository }}
EVIDENCE_BRANCH: main
EVIDENCE_POLICY_REVISION: ENG-CHANGE-01-v1
steps:
- uses: actions/checkout@v4
- run: python3 scripts/collect_branch.py
- uses: actions/upload-artifact@v4
with:
name: branch-evidence-${{ github.run_id }}-${{ github.run_attempt }}
path: |
branch-evidence.json
branch-evidence.sha256
if-no-files-found: error
retention-days: 7
Pin action revisions according to your supply chain policy, and run a watchdog outside the collector so a missed run cannot disappear silently. Monitor last successful observation by source and scope, then reconcile against the expected inventory. Preserve an execution record when collection fails and assign someone to resolve it. GitHub documents that scheduled workflow runs can be delayed under load. Design for an explicit collection cadence and alert tolerances instead of assuming the cron expression proves operation. GitHub Actions scheduling behavior.
Archive only the fields needed for review
Write finalized evidence into durable storage with uploader and reader roles, retention aligned with the evidence policy, and version tracking. A checksum can detect whether a file differs from its recorded digest. If an actor can change the file and the digest, the checksum alone cannot prove who created the evidence. For stronger integrity, retain the original source records, protect the archive from normal writers, and sign or separately protect the manifest if your review model requires it. S3 Object Lock protects specific object versions, so evidence references should include the version and not merely a key that can acquire a newer version. S3 Object Lock and version retention.
Terraform captures the desired infrastructure and the changes reviewed in a plan. It helps tie a declared control to commits. Query runtime APIs or an inventory service to check deployed resources and drift. Build an allowlisted summary if you need a Terraform-derived evidence artifact. terraform show -json can reveal sensitive values from state, and plan files can contain sensitive inputs. Keep raw state and plans in their restricted operational store. Terraform guidance on sensitive data.
Close the gaps a periodic snapshot leaves open
Follow the production change back to its approval
Use the deployment system to enumerate what reached production, including automated releases, emergency changes, and rollbacks. Link the deployed revision or artifact digest to a reviewed pull request and the checks associated with that revision. When a deploy contains a batch of commits, the join must account for each applicable change. Review bypass events and confirm any required post-deployment approvals or follow-up actions. A snapshot proves the configured rule only within the evidence it actually observed.
Track exceptions as evidence
Retain a record when the observed rule differs from the control. Include scope, time discovered, owner, risk assessment, resolution, and validation after remediation. The control owner can then explain what happened during the gap, including whether a production change passed through it. Keep historic evidence and document the correction. Changing the control’s wording after the fact obscures the population and can make review harder.
Test whether a reviewer can rerun the join
Give someone outside the contributing team a sample deployment and the evidence inventory. Ask them to identify its approval and any exception without a private Slack thread. Check that you can see which sources were queried, when, and with which policy revision. Use a mocked missing-source event to verify that gaps show up in the dashboard. Structured operational telemetry can support the investigation with a stable event schema and trace IDs. Correlating structured logs with traces.
Choose collection methods by the source and control
Native audit exports suit identity changes, admin actions, and other event-driven controls where the vendor already records actions. Verify which actions are included for your plan and how long they remain available. Periodic API snapshots suit configuration and inventory controls. Pair them with change events when short-lived drift matters. Manual evidence and sign-off are sensible for controls such as an access review or a disaster recovery exercise where a human decision is the control. Collect the population and timestamps automatically, and preserve the human decision separately.
Frequently asked questions
Does a GitHub branch protection screenshot satisfy a SOC 2 Type II control?
A screenshot can support evidence of a setting at one point in time. If the control governs production changes during the examination period, gather the relevant change population and records showing how approvals, checks, and exceptions operated. Confirm what evidence the service auditor expects for your specific control design and scope.
Can Terraform replace live cloud configuration evidence?
Terraform configuration records intended infrastructure, and reviewed plans can support change evidence. Runtime inventory confirms what was deployed and can reveal drift or unmanaged resources. Use both when the control depends on actual deployed state, and extract a limited evidence summary instead of distributing raw Terraform state or plans.
What if a scheduled SOC 2 evidence collection run fails?
Preserve the failure, identify the affected source and time period, and assign a response owner. Recollect recoverable records from the source and document what remains unknown. A later successful run supplies a new observation, while logs and change records may help reconstruct the missing interval. Record that distinction for the reviewer.
Further reading
- Generating an auditable change trail for database migrations
- Reproducible builds and checksummed file manifests
Review your evidence collection plan
If you are building automated SOC 2 evidence collection, talk to our engineering team about a scope inventory, read-only collectors, and reviewable production change records.
