Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Harden GitHub command file data boundaries
pulse-triage[bot]c55db584c1fe
diff --git a/.github/workflows/README.md b/.github/workflows/README.mdindex 553d69f7de..279c2c245e 100644--- a/.github/workflows/README.md+++ b/.github/workflows/README.md@@ -42,6 +42,13 @@ be interpolated into the generated shell program. Outputs remain data evenwhen an intermediate step parsed or validated them, because later substitutionwould turn their value back into shell source.+Passing data through `env` does not make it safe to append to the runner's+`GITHUB_OUTPUT`, `GITHUB_ENV`, `GITHUB_PATH`, or `GITHUB_STATE` command files.+The audit rejects direct writes of workflow data and values read from the event+payload; a step must first constrain the value to its exact one-line grammar or+encode it with the command-file multiline protocol. This prevents embedded+newlines from creating additional outputs or environment entries.+Workflows triggered by `pull_request` cannot reference confidential repositorysecrets. Canonical governance therefore keeps its pull-request checks local tothe public checkout. `canonical-private-governance.yml` performs cross-repodiff --git a/.github/workflows/build-release-candidate.yml b/.github/workflows/build-release-candidate.ymlindex df84795226..91a8223ae2 100644--- a/.github/workflows/build-release-candidate.yml+++ b/.github/workflows/build-release-candidate.yml@@ -104,6 +104,10 @@ jobs:run: |set -euo pipefail[[ "${GITHUB_REF}" == refs/heads/* ]]+ if [[ ! "${VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-((rc|alpha|beta)\.[0-9]+))?$ ]]; then+ echo "::error::Release candidate version is not an exact supported version."+ exit 1+ fidispatch_payload="$(jq -nc \--arg ref "${SOURCE_REF}" \--arg version "${VERSION}" \@@ -621,7 +625,9 @@ jobs:files = $files}$evidence | ConvertTo-Json -Depth 6 | Set-Content windows-signing-evidence.json -Encoding utf8NoBOM- "signing_backend=$env:WINDOWS_SIGNING_BACKEND" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8+ if ($env:WINDOWS_SIGNING_BACKEND -notin @('signpath', 'legacy-pfx')) { throw "Invalid Windows signing backend." }+ $validatedBackend = $env:WINDOWS_SIGNING_BACKEND+ "signing_backend=$validatedBackend" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8- name: Upload signed Windows binariesuses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1@@ -662,9 +668,14 @@ jobs:VERSION: ${{ inputs.version }}run: |set -euo pipefail- echo "artifact_name=release-candidate-${GITHUB_SHA}-${VERSION}" >> "$GITHUB_OUTPUT"- echo "manifest_artifact_name=release-candidate-manifest-${GITHUB_SHA}-${VERSION}" >> "$GITHUB_OUTPUT"- echo "container_artifact_name=release-container-payload-${GITHUB_SHA}-${VERSION}" >> "$GITHUB_OUTPUT"+ if [[ ! "${VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-((rc|alpha|beta)\.[0-9]+))?$ ]]; then+ echo "::error::Release candidate version is not an exact supported version."+ exit 1+ fi+ validated_version="${VERSION}"+ echo "artifact_name=release-candidate-${GITHUB_SHA}-${validated_version}" >> "$GITHUB_OUTPUT"+ echo "manifest_artifact_name=release-candidate-manifest-${GITHUB_SHA}-${validated_version}" >> "$GITHUB_OUTPUT"+ echo "container_artifact_name=release-container-payload-${GITHUB_SHA}-${validated_version}" >> "$GITHUB_OUTPUT"- name: Checkout repositoryuses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1diff --git a/.github/workflows/compile-release-payload.yml b/.github/workflows/compile-release-payload.ymlindex c7f4ce6d07..e8900f00a9 100644--- a/.github/workflows/compile-release-payload.yml+++ b/.github/workflows/compile-release-payload.yml@@ -33,10 +33,12 @@ jobs:env:EXPECTED_SOURCE_SHA: ${{ inputs.source_sha }}REQUEST_ID: ${{ inputs.request_id }}+ VERSION: ${{ inputs.version }}run: |set -euo pipefail[[ "${EXPECTED_SOURCE_SHA}" =~ ^[0-9a-f]{40}$ ]][[ "${REQUEST_ID}" =~ ^[0-9]+-[0-9]+$ ]]+ [[ "${VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-((rc|alpha|beta)\.[0-9]+))?$ ]]test "${GITHUB_SHA}" = "${EXPECTED_SOURCE_SHA}"test "${GITHUB_WORKFLOW_SHA}" = "${EXPECTED_SOURCE_SHA}"diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.ymlindex 8793ad85ef..18bbf4b78d 100644--- a/.github/workflows/create-release.yml+++ b/.github/workflows/create-release.yml@@ -110,12 +110,21 @@ jobs:steps:- name: Extract versionid: extract+ env:+ VERSION_INPUT: ${{ inputs.version }}+ HISTORICAL_ASSET_BACKFILL_INPUT: ${{ inputs.historical_asset_backfill_only }}run: |- VERSION=$(jq -r '.inputs.version // ""' "$GITHUB_EVENT_PATH" 2>/dev/null || echo "")- if [ -z "$VERSION" ]; then- echo "::error::workflow_dispatch must include a version input"+ set -euo pipefail+ if [[ ! "${VERSION_INPUT}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-((rc|alpha|beta)\.[0-9]+))?$ ]]; then+ echo "::error::workflow_dispatch must include an exact supported version"+ exit 1+ fi+ if [[ "${HISTORICAL_ASSET_BACKFILL_INPUT}" != "true" && \+ "${HISTORICAL_ASSET_BACKFILL_INPUT}" != "false" ]]; then+ echo "::error::historical_asset_backfill_only must be true or false"exit 1fi+ VERSION="${VERSION_INPUT}"TAG="v${VERSION}"IS_PRERELEASE="false"@@ -130,7 +139,7 @@ jobs:fiSOURCE_BRANCH="${GITHUB_REF_NAME}"- HISTORICAL_ASSET_BACKFILL_ONLY=$(jq -r '.inputs.historical_asset_backfill_only // "false"' "$GITHUB_EVENT_PATH" 2>/dev/null || echo "false")+ HISTORICAL_ASSET_BACKFILL_ONLY="${HISTORICAL_ASSET_BACKFILL_INPUT}"echo "tag=${TAG}" >> $GITHUB_OUTPUTecho "version=${VERSION}" >> $GITHUB_OUTPUTecho "is_prerelease=${IS_PRERELEASE}" >> $GITHUB_OUTPUTdiff --git a/.github/workflows/helm-pages.yml b/.github/workflows/helm-pages.ymlindex db1278bd81..d91493c562 100644--- a/.github/workflows/helm-pages.yml+++ b/.github/workflows/helm-pages.yml@@ -50,7 +50,7 @@ jobs:CHART_DIGEST: ${{ inputs.chart_digest }}run: |set -euo pipefail- if [[ -z "${VERSION}" ]] || \+ if [[ ! "${VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-((rc|alpha|beta)\.[0-9]+))?$ ]] || \[[ ! "${SOURCE_RELEASE_RUN_ID}" =~ ^[0-9]+$ ]] || \[[ ! "${TARGET_COMMITISH}" =~ ^[0-9a-f]{40}$ ]] || \[[ ! "${CHART_DIGEST}" =~ ^sha256:[0-9a-f]{64}$ ]]; then@@ -102,7 +102,8 @@ jobs:exit 1fi- echo "version=${VERSION}" >> "$GITHUB_OUTPUT"+ validated_version="${VERSION}"+ echo "version=${validated_version}" >> "$GITHUB_OUTPUT"echo "release_tag=${release_tag}" >> "$GITHUB_OUTPUT"- name: Download immutable qualified chartdiff --git a/.github/workflows/publish-helm-chart.yml b/.github/workflows/publish-helm-chart.ymlindex 87a638bcc5..1337cf545b 100644--- a/.github/workflows/publish-helm-chart.yml+++ b/.github/workflows/publish-helm-chart.yml@@ -212,9 +212,14 @@ jobs:run: |set -euo pipefailhelm registry logout ghcr.io || true- ./scripts/verify-release-helm-chart.sh \+ proof_output="$(./scripts/verify-release-helm-chart.sh \"${RELEASE_TAG}" "${GITHUB_SHA}" \- "${GITHUB_REPOSITORY}" "${EXPECTED_DIGEST}" >> "$GITHUB_OUTPUT"+ "${GITHUB_REPOSITORY}" "${EXPECTED_DIGEST}")"+ if [[ ! "${proof_output}" =~ ^chart_digest=sha256:[0-9a-f]{64}$ ]]; then+ echo "::error::Helm verification did not return one exact chart digest."+ exit 1+ fi+ printf '%s\n' "${proof_output}" >> "$GITHUB_OUTPUT"- name: Attach chart to releaseif: github.event_name == 'release'diff --git a/.github/workflows/validate-release-assets.yml b/.github/workflows/validate-release-assets.ymlindex 1359548cdd..8df1a1423d 100644--- a/.github/workflows/validate-release-assets.yml+++ b/.github/workflows/validate-release-assets.yml@@ -87,7 +87,7 @@ jobs:INPUT_COMMIT: ${{ inputs.target_commitish }}run: |python3 <<'EOF' > context.env- import json, os, sys+ import json, os, re, sysevent_name = os.environ.get("EVENT_NAME", "")result = {}@@ -110,8 +110,20 @@ jobs:draft_value = os.environ.get("INPUT_DRAFT", "false")result["draft"] = str(draft_value).lower()- if not result["tag"] or not result["release_id"]:- sys.stderr.write("::error::Release metadata is missing. Provide tag, version, release_id, and target_commitish.\n")+ version_pattern = r"[0-9]+\.[0-9]+\.[0-9]+(?:-(?:rc|alpha|beta)\.[0-9]+)?"+ valid = (+ isinstance(result["tag"], str)+ and isinstance(result["version"], str)+ and isinstance(result["target_commitish"], str)+ and re.fullmatch(f"v{version_pattern}", result["tag"])+ and re.fullmatch(version_pattern, result["version"])+ and result["tag"] == f"v{result['version']}"+ and re.fullmatch(r"[0-9]+", result["release_id"])+ and re.fullmatch(r"[0-9a-f]{40}", result["target_commitish"])+ and result["draft"] in {"true", "false"}+ )+ if not valid:+ sys.stderr.write("::error::Release metadata must contain one exact tag, version, release ID, source commit, and draft state.\n")sys.exit(1)result["should_run"] = "true"diff --git a/scripts/check_workflow_trust.py b/scripts/check_workflow_trust.pyindex 2087697661..818bc840e9 100644--- a/scripts/check_workflow_trust.py+++ b/scripts/check_workflow_trust.py@@ -23,7 +23,13 @@ USES_RE = re.compile(rf"^\s*(?:-\s*)?{_yaml_key('uses')}\s*:\s*([^\s#]+)")RUN_RE = re.compile(rf"^(\s*)(?:-\s*)?{_yaml_key('run')}\s*:\s*(.*)$")+ENV_RE = re.compile(rf"^(\s*)(?:-\s*)?{_yaml_key('env')}\s*:\s*$")+ENV_ENTRY_RE = re.compile(r"^\s*([A-Za-z_][A-Za-z0-9_]*)\s*:\s*(.*?)\s*$")EXPRESSION_RE = re.compile(r"\$\{\{(.*?)\}\}")+GITHUB_COMMAND_FILE_RE = re.compile(r"\bGITHUB_(?:ENV|OUTPUT|PATH|STATE)\b")+SHELL_ASSIGNMENT_RE = re.compile(+ r"^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*="+)# Workflow-call and dispatch inputs are data, not shell source. The legacy# github.event.inputs alias is identical data, and repository_dispatch callers# fully control client_payload. Step and job outputs are data too: they can@@ -153,6 +159,151 @@ def _run_script_lines(lines: list[str], run_index: int) -> list[tuple[int, str]]return script+def _step_env_bindings(lines: list[str], run_index: int) -> dict[str, str]:+ """Return literal step env names and values for a run declaration."""+ run_match = RUN_RE.match(lines[run_index])+ if not run_match:+ return {}+ field_indent = len(run_match.group(1))++ step_start = run_index+ for index in range(run_index - 1, -1, -1):+ line = lines[index]+ if (+ line.strip()+ and _indent(line) == field_indent - 2+ and line.lstrip().startswith("- ")+ ):+ step_start = index+ break++ step_end = len(lines)+ for index in range(run_index + 1, len(lines)):+ line = lines[index]+ if (+ line.strip()+ and _indent(line) == field_indent - 2+ and line.lstrip().startswith("- ")+ ):+ step_end = index+ break++ bindings: dict[str, str] = {}++ # Job-level env is inherited by every run step. Locate the enclosing job+ # from normal Actions indentation before applying step-level overrides.+ job_key_indent = field_indent - 6+ job_start: int | None = None+ for index in range(step_start - 1, -1, -1):+ code = lines[index].split("#", 1)[0]+ if _indent(code) == job_key_indent and JOB_RE.match(code):+ job_start = index+ break+ if job_start is not None:+ job_end = len(lines)+ for index in range(job_start + 1, len(lines)):+ code = lines[index].split("#", 1)[0]+ if code.strip() and _indent(code) == job_key_indent and JOB_RE.match(code):+ job_end = index+ break+ job_field_indent = field_indent - 4+ for index in range(job_start + 1, job_end):+ code = lines[index].split("#", 1)[0]+ match = ENV_RE.match(code)+ if not match or len(match.group(1)) != job_field_indent:+ continue+ for env_line in lines[index + 1 : job_end]:+ env_code = env_line.split("#", 1)[0]+ if not env_code.strip():+ continue+ if _indent(env_code) <= job_field_indent:+ break+ entry = ENV_ENTRY_RE.match(env_code)+ if entry and _indent(env_code) == job_field_indent + 2:+ bindings[entry.group(1)] = entry.group(2).strip("'\"")+ break++ for index in range(step_start, step_end):+ code = lines[index].split("#", 1)[0]+ match = ENV_RE.match(code)+ mapping_indent = len(match.group(1)) if match else -1+ inline_step_field = bool(match and code.lstrip().startswith("- "))+ if not match or not (+ mapping_indent == field_indent+ or (inline_step_field and mapping_indent + 2 == field_indent)+ ):+ continue+ for env_line in lines[index + 1 : step_end]:+ code = env_line.split("#", 1)[0]+ if not code.strip():+ continue+ if _indent(code) <= field_indent:+ break+ entry = ENV_ENTRY_RE.match(code)+ if entry and _indent(code) == field_indent + 2:+ bindings[entry.group(1)] = entry.group(2).strip("'\"")+ break+ return bindings+++def _shell_variable_reference(line: str, name: str) -> bool:+ escaped = re.escape(name)+ return bool(+ re.search(+ rf"(?:\$\{{{escaped}(?::?[-+?=][^}}]*)?\}}|\${escaped}\b|\$env:{escaped}\b)",+ line,+ re.IGNORECASE,+ )+ )+++def _is_untrusted_expression(value: str) -> bool:+ return any(+ SHELL_DATA_CONTEXT_RE.search(expression)+ or UNTRUSTED_GITHUB_CONTEXT_RE.search(expression)+ for expression in EXPRESSION_RE.findall(value)+ )+++def _audit_command_file_data(+ path: Path,+ lines: list[str],+ run_index: int,+) -> list[Finding]:+ """Keep raw workflow/event values out of GitHub runner command files."""+ findings: list[Finding] = []+ bindings = {+ name: value+ for name, value in _step_env_bindings(lines, run_index).items()+ if _is_untrusted_expression(value)+ }+ event_payload_variables: set[str] = set()++ for script_index, script_line in _run_script_lines(lines, run_index):+ assignment = SHELL_ASSIGNMENT_RE.match(script_line)+ if assignment and "GITHUB_EVENT_PATH" in script_line:+ event_payload_variables.add(assignment.group(1))++ if not GITHUB_COMMAND_FILE_RE.search(script_line):+ continue+ unsafe_names = sorted(+ name+ for name in (*bindings, *event_payload_variables)+ if _shell_variable_reference(script_line, name)+ )+ if unsafe_names:+ findings.append(+ Finding(+ path,+ script_index + 1,+ "untrusted workflow data must be validated or encoded "+ "before writing to GitHub command files "+ f"({', '.join(unsafe_names)})",+ )+ )+ return findings++def _has_trigger(lines: list[str], event: str) -> bool:"""Return whether the top-level Actions trigger includes *event*."""event_re = re.compile(rf"(?<![\w-]){re.escape(event)}(?![\w-])")@@ -425,6 +576,7 @@ def audit_workflow(path: Path) -> list[Finding]:)if RUN_RE.match(code):+ findings.extend(_audit_command_file_data(path, lines, index))for script_index, script_line in _run_script_lines(lines, index):if has_workflow_run_trigger and WORKFLOW_RUN_INGRESS_COMMAND_RE.search(script_linediff --git a/scripts/tests/test_workflow_trust.py b/scripts/tests/test_workflow_trust.pyindex 23b5985c31..26bac7fa4e 100644--- a/scripts/tests/test_workflow_trust.py+++ b/scripts/tests/test_workflow_trust.py@@ -412,6 +412,51 @@ jobs:3,)+ def test_rejects_raw_workflow_data_in_github_command_files(self) -> None:+ findings = self.audit(+ """permissions: {}+jobs:+ unsafe:+ runs-on: ubuntu-24.04+ timeout-minutes: 10+ env:+ JOB_RELEASE: ${{ needs.prepare.outputs.release }}+ steps:+ - env:+ RELEASE_NAME: ${{ inputs.release_name }}+ DERIVED_DIGEST: ${{ steps.build.outputs.digest }}+ run: |+ echo "release=$RELEASE_NAME" >> "$GITHUB_OUTPUT"+ printf 'digest=%s\\n' "$DERIVED_DIGEST" >> "$GITHUB_ENV"+ echo "job_release=$JOB_RELEASE" >> "$GITHUB_STATE"+ - run: |+ EVENT_TAG=$(jq -r '.release.tag_name' "$GITHUB_EVENT_PATH")+ echo "tag=$EVENT_TAG" >> "$GITHUB_OUTPUT"+"""+ )+ self.assertEqual(+ sum("validated or encoded" in finding for finding in findings),+ 4,+ )++ def test_accepts_validated_command_file_values(self) -> None:+ findings = self.audit(+ """permissions: {}+jobs:+ safe:+ runs-on: ubuntu-24.04+ timeout-minutes: 10+ steps:+ - env:+ RELEASE_INPUT: ${{ inputs.release }}+ run: |+ [[ "$RELEASE_INPUT" =~ ^v[0-9]+\\.[0-9]+\\.[0-9]+$ ]]+ validated_release="$RELEASE_INPUT"+ printf 'release=%s\\n' "$validated_release" >> "$GITHUB_OUTPUT"+"""+ )+ self.assertEqual(findings, [])+def test_rejects_dispatch_data_and_whole_github_contexts_in_shell(self) -> None:findings = self.audit("""permissions: {}