mirror of
https://github.com/safedep/pmg.git
synced 2026-08-03 07:24:09 +02:00
* refactor: remove guard mode execution paths and guard-only packages Guard (non-proxy) mode is removed; all package-manager commands now always run the proxy flow. Removes the guard engine, the common flow, the extractor package, the npm/pypi dependency resolvers and the PackageResolver plumbing that only guard mode consumed. The guard package retains only PackageManagerGuardInteraction, which the proxy flow and confirmation interceptors reuse for user prompts. Proxy behavior is unchanged. * refactor: remove proxy opt-out surfaces, guard references in config, action and docs Removes Config.ProxyMode, ProxyConfig.Enabled, IsProxyModeEnabled, the proxy_mode legacy fallback, PMG_PROXY_ENABLED handling and the --proxy-mode / --include-dev-dependencies flags. Proxy interception can no longer be disabled. Also removes the proxy-mode input from the GitHub Action, the proxy-mode doctor check and setup info row, updates the E2E workflow to stop passing --proxy-mode=false, and sweeps guard-mode wording from docs and the config template. The legacy proxy_install_only flat key and PMG_PROXY_INSTALL_ONLY env var remain supported. audit.FlowTypeGuard is kept so previously recorded audit events still translate for cloud sync. * feat: fail loudly when a removed proxy opt-out is still configured A leftover proxy.enabled: false / proxy_mode: false config key or PMG_PROXY_ENABLED=false / PMG_PROXY_MODE=false env var previously meant guard mode; silently ignoring it would switch those users to proxy interception without notice. PMG now exits with an actionable error naming the exact source. Precedence mirrors the old resolution order: env (ignored under lockdown) > proxy.enabled > legacy proxy_mode. The pmg config subtree is exempt so the config file can still be fixed with pmg config edit/set. The GitHub Action's proxy-mode input is kept as a tombstone that fails the action when set to false and warns otherwise. * refactor: extract flows.RunProxy and address review findings Collapses the identical parse-then-run body duplicated across the 12 package manager commands into flows.RunProxy. Documents the cache-hit / offline analysis trade-off versus the removed guard manifest path, fixes a stale non-proxy label in the E2E workflow and a stale guard reference in the uvx parser comment. * fix(config): mirror old proxy opt-out precedence exactly PMG_PROXY_MODE only ever took effect through the legacy fallback, which was gated on the presence of a proxy: key in the config file (even a null one). Promoting it to the top env tier caused two inversions: a stale PMG_PROXY_MODE=false hard-failed configs that resolved to proxy mode, and PMG_PROXY_MODE=true silently overrode an explicit proxy.enabled: false file opt-out. The check now resolves in the old order: PMG_PROXY_ENABLED > proxy: section (presence gates the legacy tier) > PMG_PROXY_MODE > flat proxy_mode. parseOptOutBool also accepts numeric values (0 = false) to match viper's WeaklyTypedInput/cast.ToBool coercion, so proxy.enabled: 0 and proxy_mode: 0 are detected as opt-outs. * refactor: move package manager interaction out of guard * refactor: trim package manager interaction * fix(config): normalize config keys viper-style in proxy opt-out check Viper resolved config file keys case-insensitively and expanded dotted keys, so spellings like Proxy:, Enabled:, a literal proxy.enabled key or Proxy_Mode selected guard mode before the removal. The opt-out check now lowercases keys recursively and nests dotted keys before matching, so those existing opt-outs fail loudly instead of being silently ignored. * refactor: remove inert transitive controls, dead parser state and guard audit variant transitive / transitive_depth lost their only consumers with the dependency resolvers; remove the config fields, flags, template and doc entries, and the report/audit plumbing that misreported transitive analysis as enabled. Remove write-only parser state (PackageInstallTarget.Extras, ParsedCommand.ManifestFiles, ShouldExtractFromManifest); IsManifestInstall stays as it feeds sandbox gating via IsInstallationCommand. Remove audit.FlowTypeGuard and its cloud mapping; guard events recorded by pre-removal versions in an unsynced WAL translate to UNSPECIFIED. * fix: address review findings on the opt-out wiring and cleanups Move the removed-opt-out rejection from the CLI PersistentPreRun into proxyFlow.Run: the check now fires exactly for package-manager runs, so non-install commands (pmg setup remove, doctor, config, version) stay usable to fix or remove an opted-out installation, and future commands inherit or avoid the check by construction instead of by exemption list. Also: make the e2e malicious-package assertion actually fail the job when an install is not blocked, route pmg go through flows.RunProxy, and drop the dead extras return from pypiParsePackageInfo (extras are still stripped from package names). * fix(config): make the removed opt-out check faithful to the old resolution The gate that silenced the legacy proxy_mode surfaces matched the raw proxy key case-sensitively in the old code, while values resolved viper-style (case-insensitive, dotted keys); applying each semantic where the old code did fixes both divergences: a case-variant Proxy: section no longer hides a flat proxy_mode: false opt-out, and a dotted proxy.enabled: false overridden by proxy_mode: true no longer errors. Replace the generic key-tree normalization with two targeted lookups (the check only ever resolves proxy.enabled and proxy_mode), which also makes colliding spellings resolve deterministically. Coerce legacy-tier values cast.ToBool-style so PMG_PROXY_MODE=off style opt-outs are detected, log the config read error instead of swallowing it, and shorten the error to a one-line statement with the specific remedy in the help text. Add lockdown coverage (env inert both directions) and a repeated-run determinism test. * fix(config): fall back to defaults for unrecognized proxy opt-out values The old loader swallowed viper errors and ran on defaults, so values like proxy.enabled: yes or PMG_PROXY_ENABLED=banana silently discarded the whole config and defaulted to proxy. Treat them the same way now: unrecognized values mean the default (proxy on) instead of a hard error, and the doc comment no longer claims the old loader failed loudly. Only values that actually meant guard mode fail. Also check the removed opt-out before the CA trust check in pmg go, restoring the old error precedence: a config problem must not steer the user into an unnecessary OS trust store change. * fix(e2e): PMG_PROXY_MODE assertion must match the legacy gate semantics The runner's setup step writes the template config, which has a proxy: section — and with one present the legacy PMG_PROXY_MODE was always inert, so expecting a loud failure there asserts pre-fidelity-fix behavior. Assert both sides instead: inert (command succeeds) with the standard config, loud failure against an empty config dir where the legacy fallback actually applied. * refactor(config): collapse parseOptOutBool to ParseBool over the string form YAML hands us typed values (bool, int), so route them through fmt.Sprintf %v and strconv.ParseBool instead of a per-type switch. Identical behavior for every recognized value; numbers other than 0/1 now read as no opinion instead of cast.ToBool's nonzero-true, which no real config relies on.
353 lines
14 KiB
YAML
353 lines
14 KiB
YAML
name: Setup PMG
|
|
description: Install Package Manager Guard (PMG) and wrap npm/pip/etc. in this Linux GitHub Actions runner.
|
|
author: SafeDep
|
|
branding:
|
|
icon: shield
|
|
color: green
|
|
|
|
inputs:
|
|
version:
|
|
description: PMG release tag to install (e.g. v0.42.0) or "latest".
|
|
required: false
|
|
default: latest
|
|
|
|
api-key:
|
|
description: SafeDep Cloud API key. When set together with tenant-id, cloud sync is enabled and credentials are passed via env (no keychain needed in CI).
|
|
required: false
|
|
default: ""
|
|
tenant-id:
|
|
description: SafeDep Cloud tenant ID. Required when api-key is set.
|
|
required: false
|
|
default: ""
|
|
endpoint-id:
|
|
description: Identifier reported to SafeDep Cloud for this runner. When empty and cloud is enabled, defaults to "github-actions/<owner>/<repo>" so events aggregate per repository instead of per ephemeral runner hostname.
|
|
required: false
|
|
default: ""
|
|
|
|
paranoid:
|
|
description: Treat suspicious packages as malicious (PMG_PARANOID). Empty = use PMG default (false).
|
|
required: false
|
|
default: ""
|
|
cooldown-enabled:
|
|
description: Block recently-published package versions (PMG_DEPENDENCY_COOLDOWN_ENABLED). Empty = use PMG default (true).
|
|
required: false
|
|
default: ""
|
|
cooldown-days:
|
|
description: Cooldown window in days (PMG_DEPENDENCY_COOLDOWN_DAYS). Empty = use PMG default (5).
|
|
required: false
|
|
default: ""
|
|
proxy-mode:
|
|
description: REMOVED. PMG always uses proxy-based interception. Setting "false" fails the action; any other value is ignored with a warning.
|
|
required: false
|
|
default: ""
|
|
|
|
sandbox:
|
|
description: Run package managers inside an OS sandbox (PMG_SANDBOX_ENABLED). Empty = use PMG default (false). Enabling will also relax AppArmor user-namespace restrictions on the runner so unprivileged user namespaces work.
|
|
required: false
|
|
default: ""
|
|
sandbox-driver:
|
|
description: Sandbox backend on Linux (PMG_SANDBOX_DRIVER). One of "landlock" or "bubblewrap". Defaults to "landlock" when sandbox is enabled and this is empty.
|
|
required: false
|
|
default: ""
|
|
|
|
verbosity:
|
|
description: PMG output verbosity (PMG_VERBOSITY). One of "silent", "normal", "verbose". Empty = use PMG default.
|
|
required: false
|
|
default: ""
|
|
disable-telemetry:
|
|
description: Disable anonymous PMG telemetry (PMG_DISABLE_TELEMETRY). Empty = use PMG default.
|
|
required: false
|
|
default: ""
|
|
skip-event-logging:
|
|
description: Skip writing audit events to the local event log (PMG_SKIP_EVENT_LOGGING). Empty = use PMG default.
|
|
required: false
|
|
default: ""
|
|
|
|
config-file:
|
|
description: Path (relative to the workspace) to a user-supplied PMG config.yml. Copied into the PMG config directory before "pmg setup install" runs, so PMG merges any missing template keys into it.
|
|
required: false
|
|
default: ""
|
|
|
|
cache:
|
|
description: Reuse a previously-installed PMG binary from $RUNNER_TOOL_CACHE/pmg/<version>/<arch>. Off by default; fresh download per run keeps the binary current and reduces the blast radius of any cached artifact tampering. Checksum verification still runs on every install path.
|
|
required: false
|
|
default: "false"
|
|
|
|
server-mode:
|
|
description: Run PMG as a persistent proxy server instead of shims. The proxy is started as a daemon and HTTP_PROXY/cert env vars are exported to the job. Requires a job-end "pmg proxy stop --fail-on-violation" step.
|
|
required: false
|
|
default: "false"
|
|
|
|
runs:
|
|
using: composite
|
|
steps:
|
|
- name: Verify runner OS
|
|
shell: bash
|
|
run: |
|
|
if [ "${{ runner.os }}" != "Linux" ]; then
|
|
echo "::error::safedep/pmg action currently supports Linux runners only. See https://github.com/safedep/pmg/issues/248 for cross-platform tracking."
|
|
exit 1
|
|
fi
|
|
|
|
- name: Install PMG
|
|
id: install
|
|
shell: bash
|
|
env:
|
|
INPUT_VERSION: ${{ inputs.version }}
|
|
INPUT_CACHE: ${{ inputs.cache }}
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
repo="safedep/pmg"
|
|
|
|
# Resolve version tag.
|
|
if [ "$INPUT_VERSION" = "latest" ] || [ -z "$INPUT_VERSION" ]; then
|
|
echo "Resolving latest PMG release..."
|
|
tag=$(curl -fsSI -o /dev/null -w '%{redirect_url}' \
|
|
"https://github.com/${repo}/releases/latest" | sed 's|.*/||' | tr -d '\r\n')
|
|
if [ -z "$tag" ]; then
|
|
echo "::error::Could not resolve latest PMG release tag." >&2
|
|
exit 1
|
|
fi
|
|
else
|
|
tag="$INPUT_VERSION"
|
|
fi
|
|
echo "PMG version: $tag"
|
|
|
|
# Map architecture.
|
|
case "$(uname -m)" in
|
|
x86_64|amd64) arch="x86_64" ;;
|
|
aarch64|arm64) arch="arm64" ;;
|
|
*)
|
|
echo "::error::Unsupported architecture: $(uname -m)" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
asset="pmg_Linux_${arch}.tar.gz"
|
|
cache_dir="${RUNNER_TOOL_CACHE:-/opt/hostedtoolcache}/pmg/${tag}/${arch}"
|
|
install_dir="$cache_dir"
|
|
|
|
if [ "$INPUT_CACHE" != "true" ]; then
|
|
install_dir="${RUNNER_TEMP:-/tmp}/pmg-${tag}-${arch}"
|
|
fi
|
|
|
|
mkdir -p "$install_dir"
|
|
bin_path="${install_dir}/pmg"
|
|
tar_path="${install_dir}/${asset}"
|
|
|
|
# Always fetch upstream checksums.txt — even on a cache hit — so a
|
|
# tampered cache entry is caught before we run the binary.
|
|
tmpdir=$(mktemp -d)
|
|
trap 'rm -rf "$tmpdir"' EXIT
|
|
curl -fsSL -o "${tmpdir}/checksums.txt" \
|
|
"https://github.com/${repo}/releases/download/${tag}/checksums.txt"
|
|
expected=$(grep " ${asset}\$" "${tmpdir}/checksums.txt" | cut -d' ' -f1 || true)
|
|
if [ -z "$expected" ]; then
|
|
echo "::error::No checksum entry for ${asset} in ${tag}/checksums.txt" >&2
|
|
exit 1
|
|
fi
|
|
|
|
need_download=true
|
|
if [ "$INPUT_CACHE" = "true" ] && [ -f "$tar_path" ] && [ -x "$bin_path" ]; then
|
|
cached=$(sha256sum "$tar_path" | cut -d' ' -f1)
|
|
if [ "$cached" = "$expected" ]; then
|
|
echo "Cached PMG ${tag} verified against upstream checksum"
|
|
need_download=false
|
|
else
|
|
echo "Cached PMG ${tag} checksum drift (want ${expected}, got ${cached}); refreshing"
|
|
rm -f "$tar_path" "$bin_path"
|
|
fi
|
|
fi
|
|
|
|
if [ "$need_download" = "true" ]; then
|
|
curl -fsSL -o "$tar_path" \
|
|
"https://github.com/${repo}/releases/download/${tag}/${asset}"
|
|
actual=$(sha256sum "$tar_path" | cut -d' ' -f1)
|
|
if [ "$actual" != "$expected" ]; then
|
|
echo "::error::Checksum mismatch for ${asset}: want ${expected}, got ${actual}" >&2
|
|
exit 1
|
|
fi
|
|
echo "Checksum verified for ${asset}"
|
|
tar -xzf "$tar_path" -C "$install_dir" pmg
|
|
chmod +x "$bin_path"
|
|
fi
|
|
|
|
echo "$install_dir" >> "$GITHUB_PATH"
|
|
echo "pmg-bin-dir=$install_dir" >> "$GITHUB_OUTPUT"
|
|
echo "pmg-version=$tag" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Prepare sandbox (apt + AppArmor)
|
|
if: inputs.sandbox == 'true'
|
|
shell: bash
|
|
env:
|
|
INPUT_DRIVER: ${{ inputs.sandbox-driver }}
|
|
run: |
|
|
set -euo pipefail
|
|
if [ "$INPUT_DRIVER" = "bubblewrap" ]; then
|
|
if command -v sudo >/dev/null 2>&1; then
|
|
sudo apt-get update
|
|
sudo apt-get install -y bubblewrap
|
|
else
|
|
apt-get update
|
|
apt-get install -y bubblewrap
|
|
fi
|
|
fi
|
|
|
|
# Relax AppArmor restriction on unprivileged user namespaces so
|
|
# Landlock helper and Bubblewrap can clone with CLONE_NEWUSER.
|
|
# Tolerate failure on locked-down runners; the sandbox driver will
|
|
# report a clear error at runtime if it cannot start.
|
|
if command -v sudo >/dev/null 2>&1; then
|
|
sudo systemctl stop apparmor 2>/dev/null || true
|
|
sudo systemctl disable apparmor 2>/dev/null || true
|
|
sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0 2>/dev/null || true
|
|
else
|
|
systemctl stop apparmor 2>/dev/null || true
|
|
systemctl disable apparmor 2>/dev/null || true
|
|
sysctl -w kernel.apparmor_restrict_unprivileged_userns=0 2>/dev/null || true
|
|
fi
|
|
|
|
- name: Stage user config file
|
|
if: inputs.config-file != ''
|
|
shell: bash
|
|
env:
|
|
INPUT_CONFIG_FILE: ${{ inputs.config-file }}
|
|
run: |
|
|
set -euo pipefail
|
|
src="${GITHUB_WORKSPACE}/${INPUT_CONFIG_FILE}"
|
|
if [ ! -f "$src" ]; then
|
|
echo "::error::config-file not found: $src" >&2
|
|
exit 1
|
|
fi
|
|
dest_dir="${XDG_CONFIG_HOME:-$HOME/.config}/safedep/pmg"
|
|
mkdir -p "$dest_dir"
|
|
cp "$src" "$dest_dir/config.yml"
|
|
echo "Staged $src -> $dest_dir/config.yml"
|
|
|
|
- name: Export PMG configuration
|
|
shell: bash
|
|
env:
|
|
IN_API_KEY: ${{ inputs.api-key }}
|
|
IN_TENANT_ID: ${{ inputs.tenant-id }}
|
|
IN_ENDPOINT_ID: ${{ inputs.endpoint-id }}
|
|
IN_PARANOID: ${{ inputs.paranoid }}
|
|
IN_COOLDOWN_ENABLED: ${{ inputs.cooldown-enabled }}
|
|
IN_COOLDOWN_DAYS: ${{ inputs.cooldown-days }}
|
|
IN_PROXY_MODE: ${{ inputs.proxy-mode }}
|
|
IN_SANDBOX: ${{ inputs.sandbox }}
|
|
IN_SANDBOX_DRIVER: ${{ inputs.sandbox-driver }}
|
|
IN_VERBOSITY: ${{ inputs.verbosity }}
|
|
IN_DISABLE_TELEMETRY: ${{ inputs.disable-telemetry }}
|
|
IN_SKIP_EVENT_LOGGING: ${{ inputs.skip-event-logging }}
|
|
IN_SERVER_MODE: ${{ inputs.server-mode }}
|
|
GH_REPOSITORY: ${{ github.repository }}
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
export_var() {
|
|
local name="$1" value="$2"
|
|
if [ -n "$value" ]; then
|
|
printf '%s=%s\n' "$name" "$value" >> "$GITHUB_ENV"
|
|
fi
|
|
}
|
|
|
|
# Guard mode is removed: fail loudly when a workflow still opts out of
|
|
# proxy interception instead of silently switching it to proxy mode.
|
|
case "$(echo "$IN_PROXY_MODE" | tr '[:upper:]' '[:lower:]')" in
|
|
false|0|f)
|
|
echo "::error::PMG guard mode has been removed and proxy interception can no longer be disabled. Remove the 'proxy-mode' input." >&2
|
|
exit 1
|
|
;;
|
|
"") ;;
|
|
*)
|
|
echo "::warning::The 'proxy-mode' input is removed and has no effect. Remove it from your workflow." >&2
|
|
;;
|
|
esac
|
|
|
|
# Cloud credentials. PMG sync reads these directly when no keychain
|
|
# credential is found, so we skip "pmg cloud login" entirely.
|
|
if [ -n "$IN_API_KEY" ] || [ -n "$IN_TENANT_ID" ]; then
|
|
if [ -z "$IN_API_KEY" ] || [ -z "$IN_TENANT_ID" ]; then
|
|
echo "::error::api-key and tenant-id must be set together." >&2
|
|
exit 1
|
|
fi
|
|
echo "::add-mask::$IN_API_KEY"
|
|
export_var SAFEDEP_API_KEY "$IN_API_KEY"
|
|
export_var SAFEDEP_TENANT_ID "$IN_TENANT_ID"
|
|
export_var PMG_CLOUD_ENABLED "true"
|
|
|
|
if [ "$IN_SERVER_MODE" = "true" ]; then
|
|
# In server mode the proxy daemon owns delivery and uses auto_sync
|
|
# to gate both periodic sync and the shutdown flush.
|
|
export_var PMG_CLOUD_AUTO_SYNC_ENABLED "true"
|
|
else
|
|
# PMG's opportunistic background auto-sync is designed for
|
|
# long-lived workstations. On an ephemeral runner the detached child
|
|
# can be torn down before it drains the WAL, and the WAL goes with
|
|
# it. Turn it off and rely on an explicit `pmg cloud sync` at
|
|
# job-end if the user wants events delivered.
|
|
export_var PMG_CLOUD_AUTO_SYNC_ENABLED "false"
|
|
fi
|
|
|
|
if [ -n "$IN_ENDPOINT_ID" ]; then
|
|
export_var PMG_CLOUD_ENDPOINT_ID "$IN_ENDPOINT_ID"
|
|
else
|
|
# Stable per-repo identifier; the runner hostname is ephemeral
|
|
# so PMG's hostname fallback would create a new "machine" entry
|
|
# in SafeDep Cloud for every job.
|
|
export_var PMG_CLOUD_ENDPOINT_ID "gha/${GH_REPOSITORY}"
|
|
fi
|
|
fi
|
|
|
|
# Only emit PMG_* vars when the user explicitly set the input. This
|
|
# preserves the "config-file overrides PMG defaults" guarantee — env
|
|
# vars take precedence over config.yml in Viper, so empty pass-through
|
|
# means we don't shadow file-based tuning.
|
|
export_var PMG_PARANOID "$IN_PARANOID"
|
|
export_var PMG_DEPENDENCY_COOLDOWN_ENABLED "$IN_COOLDOWN_ENABLED"
|
|
export_var PMG_DEPENDENCY_COOLDOWN_DAYS "$IN_COOLDOWN_DAYS"
|
|
export_var PMG_SANDBOX_ENABLED "$IN_SANDBOX"
|
|
if [ "$IN_SANDBOX" = "true" ]; then
|
|
driver="${IN_SANDBOX_DRIVER:-landlock}"
|
|
export_var PMG_SANDBOX_DRIVER "$driver"
|
|
fi
|
|
export_var PMG_VERBOSITY "$IN_VERBOSITY"
|
|
export_var PMG_DISABLE_TELEMETRY "$IN_DISABLE_TELEMETRY"
|
|
export_var PMG_SKIP_EVENT_LOGGING "$IN_SKIP_EVENT_LOGGING"
|
|
|
|
- name: Run pmg setup install (shim mode)
|
|
if: inputs.server-mode != 'true'
|
|
shell: bash
|
|
run: pmg setup install
|
|
|
|
- name: Add PMG shims to PATH (shim mode)
|
|
if: inputs.server-mode != 'true'
|
|
shell: bash
|
|
run: echo "$HOME/.pmg/bin" >> "$GITHUB_PATH"
|
|
|
|
- name: Start PMG proxy server (server mode)
|
|
if: inputs.server-mode == 'true'
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
# No cert install needed: `pmg proxy env` exports the CA path via
|
|
# NODE_EXTRA_CA_CERTS/SSL_CERT_FILE/PIP_CERT, so package managers trust
|
|
# the proxy without touching the OS trust store.
|
|
pmg proxy start --daemon
|
|
pmg proxy env >> "$GITHUB_ENV"
|
|
|
|
- name: Verify PMG
|
|
shell: bash
|
|
run: |
|
|
pmg version
|
|
echo "npm resolves to: $(command -v npm || echo '<not installed>')"
|
|
|
|
outputs:
|
|
version:
|
|
description: The resolved PMG version that was installed.
|
|
value: ${{ steps.install.outputs.pmg-version }}
|
|
bin-dir:
|
|
description: Directory containing the pmg binary on this runner.
|
|
value: ${{ steps.install.outputs.pmg-bin-dir }}
|