From d9ab6ec4515ae08f9d360a57ed3f62e03d01be87 Mon Sep 17 00:00:00 2001 From: Sam Erde <20478745+SamErde@users.noreply.github.com> Date: Thu, 5 Nov 2026 16:26:23 -0500 Subject: [PATCH 1/3] ci: add policy-pinned offline OSS Scanner environment --- .github/dependabot.yml | 6 ++ .github/workflows/Build Module.yml | 17 +++- .github/workflows/OSS-Scanner.yml | 74 ++++++++++++++++ .oss-scanner/Dockerfile | 46 ++++++++++ .oss-scanner/Dockerfile.dockerignore | 13 +++ .oss-scanner/NuGet.Config | 10 +++ .oss-scanner/README.md | 85 ++++++++++++++++++ .oss-scanner/setup.ps1 | 43 ++++++++++ .oss-scanner/test.ps1 | 109 ++++++++++++++++++++++++ .oss-scanner/threat_model.md | 82 ++++++++++++++++++ tests/Unit/WorkflowGuardrails.Tests.ps1 | 17 +++- 11 files changed, 498 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/OSS-Scanner.yml create mode 100644 .oss-scanner/Dockerfile create mode 100644 .oss-scanner/Dockerfile.dockerignore create mode 100644 .oss-scanner/NuGet.Config create mode 100644 .oss-scanner/README.md create mode 100644 .oss-scanner/setup.ps1 create mode 100644 .oss-scanner/test.ps1 create mode 100644 .oss-scanner/threat_model.md diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 5a62641a..7d43b078 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -19,6 +19,12 @@ updates: interval: "weekly" day: "sunday" + - package-ecosystem: "docker" + directory: "/.oss-scanner" + schedule: + interval: "weekly" + day: "sunday" + - package-ecosystem: "github-actions" directory: "/" schedule: diff --git a/.github/workflows/Build Module.yml b/.github/workflows/Build Module.yml index 71eb9c63..3a2de617 100644 --- a/.github/workflows/Build Module.yml +++ b/.github/workflows/Build Module.yml @@ -81,9 +81,11 @@ jobs: '^build/' '^tests/' '^tools/' + '^\.oss-scanner/' '^docs/gaps/' '^\.github/ci-scripts/' '^\.github/workflows/Build Module\.yml$' + '^\.github/workflows/OSS-Scanner\.yml$' '^global\.json$' '^build/powershell-test-matrix\.json$' ) @@ -517,6 +519,16 @@ jobs: if-no-files-found: error retention-days: 30 + oss-scanner: + name: Validate offline scanner environment + needs: changes + if: ${{ always() && (inputs.ref != '' || github.event_name == 'workflow_dispatch' || needs.changes.outputs.relevant != 'false') }} + uses: ./.github/workflows/OSS-Scanner.yml + permissions: + contents: read + with: + ref: ${{ inputs.ref || github.ref }} + build-gate: name: Build gate # Aggregate required-check target. GitHub evaluates a matrix job's `if` BEFORE expanding the @@ -525,7 +537,7 @@ jobs: # for status". This single, always-running job is the stable check to require instead: it passes # when the matrix build succeeded OR was skipped (no build-relevant changes) and fails when the # build failed or was cancelled. - needs: [changes, runtime-matrix, build, runtime-tests, dependency-change-report] + needs: [changes, runtime-matrix, build, runtime-tests, dependency-change-report, oss-scanner] if: ${{ always() }} runs-on: ubuntu-latest steps: @@ -542,6 +554,7 @@ jobs: build = '${{ needs.build.result }}' runtimeTests = '${{ needs.runtime-tests.result }}' dependencyChangeReport = '${{ needs.dependency-change-report.result }}' + ossScanner = '${{ needs.oss-scanner.result }}' } $Results.GetEnumerator() | Sort-Object Name | ForEach-Object { Write-Host "$($_.Name) job result: $($_.Value)" @@ -558,7 +571,7 @@ jobs: } } if ($BuildRequired) { - foreach ($RequiredJob in @('runtimeMatrix', 'build', 'runtimeTests')) { + foreach ($RequiredJob in @('runtimeMatrix', 'build', 'runtimeTests', 'ossScanner')) { if ($Results[$RequiredJob] -ne 'success' -and -not $Failures.Contains($RequiredJob)) { $Failures.Add($RequiredJob) } diff --git a/.github/workflows/OSS-Scanner.yml b/.github/workflows/OSS-Scanner.yml new file mode 100644 index 00000000..60196e3b --- /dev/null +++ b/.github/workflows/OSS-Scanner.yml @@ -0,0 +1,74 @@ +name: OSS Scanner environment + +on: + workflow_call: + inputs: + ref: + description: Exact source reference supplied by the calling build workflow + required: true + type: string + workflow_dispatch: + +permissions: + contents: read + +jobs: + offline-tests: + name: Build and test without network + runs-on: ubuntu-24.04 + timeout-minutes: 60 + steps: + - name: Check out source without persisted credentials + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ inputs.ref || github.ref }} + persist-credentials: false + + - name: Build scanner image + shell: bash + run: | + set -euo pipefail + mkdir -p "$RUNNER_TEMP/oss-scanner-evidence" + git rev-parse HEAD > "$RUNNER_TEMP/oss-scanner-evidence/source-commit.txt" + timeout 45m docker build --progress=plain -f .oss-scanner/Dockerfile \ + -t dllpickle-oss-scanner:test . 2>&1 | tee "$RUNNER_TEMP/oss-scanner-evidence/build.log" + docker image inspect dllpickle-oss-scanner:test \ + > "$RUNNER_TEMP/oss-scanner-evidence/image.json" + + - name: Rebuild and test with networking disabled + shell: bash + run: | + set -euo pipefail + evidence="$RUNNER_TEMP/oss-scanner-evidence" + docker create --name dllpickle-offline --network none --cpus 2 --memory 8g \ + dllpickle-oss-scanner:test pwsh -NoLogo -NoProfile -NonInteractive \ + -File .oss-scanner/test.ps1 + docker inspect --format '{{.HostConfig.NetworkMode}}' dllpickle-offline > "$evidence/network-mode.txt" + test "$(cat "$evidence/network-mode.txt")" = none + status=0 + docker start --attach dllpickle-offline 2>&1 | tee "$evidence/offline-tests.log" || status=$? + mkdir -p "$evidence/results" + docker cp dllpickle-offline:/src/artifacts/oss-scanner/. "$evidence/results" || status=1 + test "$status" -eq 0 + jq -e '.status == "passed" and (.profiles | length > 0)' "$evidence/results/summary.json" + { + echo '### OSS Scanner environment' + echo 'Rebuilt and tested in a container with network mode `none`, 2 CPUs and 8 GiB RAM.' + echo 'Unit, synthetic integration, package composition and TFM checks passed for:' + jq -r '.profiles[] | "- PowerShell \(.PowerShellVersion), .NET \(.DotNetVersion), \(.TargetFramework)"' "$evidence/results/summary.json" + echo 'Tenant authentication and Windows/macOS execution are outside this check.' + } >> "$GITHUB_STEP_SUMMARY" + + - name: Upload build and offline evidence + if: always() + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: oss-scanner-evidence + path: ${{ runner.temp }}/oss-scanner-evidence/ + if-no-files-found: error + retention-days: 30 + + - name: Remove test container + if: always() + shell: bash + run: docker rm --force dllpickle-offline 2>/dev/null || true diff --git a/.oss-scanner/Dockerfile b/.oss-scanner/Dockerfile new file mode 100644 index 00000000..035f50ec --- /dev/null +++ b/.oss-scanner/Dockerfile @@ -0,0 +1,46 @@ +# Keep the SDK image aligned with global.json; setup.ps1 checks the exact version. +FROM mcr.microsoft.com/dotnet/sdk:10.0.302-noble@sha256:72dd743782f2ae7e5476fd64f6a460045e3998dc862218b80e6944cba79a01b0 + +SHELL ["/bin/bash", "-o", "pipefail", "-c"] +ENV DOTNET_CLI_TELEMETRY_OPTOUT=1 \ + DOTNET_NOLOGO=1 \ + POWERSHELL_TELEMETRY_OPTOUT=1 \ + NUGET_PACKAGES=/opt/nuget/packages + +RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + ca-certificates curl git jq python3 procps libunwind8 \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /src +# Keep tool provisioning cached when only source, tests or documentation change. +COPY global.json ./ +COPY build/build-tool-versions.json build/powershell-test-matrix.json build/DLLPickle.Tooling.ps1 ./build/ +COPY tools/Install-DLLPickleTestPowerShell.ps1 ./tools/ +COPY .github/ci-scripts/Actions_Bootstrap.ps1 ./.github/ci-scripts/ +COPY .oss-scanner/setup.ps1 ./.oss-scanner/ + +# Bootstrap one PowerShell from the same checksum-pinned matrix used by CI. +# setup.ps1 then uses the existing provisioner to validate/install every profile. +RUN set -eu; \ + read -r url checksum < <(jq -er '[.archiveAssets[] | select(.platform == "linux" and .architecture == "x64")] | sort_by(.powerShellVersion | split(".") | map(tonumber)) | last | [.downloadUrl, .sha256] | @tsv' build/powershell-test-matrix.json); \ + curl --fail --location --proto '=https' --proto-redir '=https' --retry 3 "$url" -o /tmp/powershell.tar.gz; \ + printf '%s /tmp/powershell.tar.gz\n' "$checksum" | sha256sum --check --strict; \ + mkdir -p /opt/powershell-bootstrap; \ + tar -xzf /tmp/powershell.tar.gz -C /opt/powershell-bootstrap; \ + chmod +x /opt/powershell-bootstrap/pwsh; \ + /opt/powershell-bootstrap/pwsh -NoLogo -NoProfile -NonInteractive -File .oss-scanner/setup.ps1; \ + ln -s "$(jq -er 'sort_by(.PowerShellVersion | split(".") | map(tonumber)) | last | .ExecutablePath' /opt/dllpickle/runtimes.json)" /usr/local/bin/pwsh; \ + rm -rf /opt/powershell-bootstrap /tmp/powershell.tar.gz + +# The scanner uses the repository as its build context and expects source at /src. +COPY . /src +# Warm the build AND temporary test-project dependencies for every declared runtime. +RUN pwsh -NoLogo -NoProfile -NonInteractive -File .oss-scanner/test.ps1 + +# Subsequent restores (including test fixtures) use only the retained package cache. +# This is image-local; normal repository builds still use their configured feeds. +RUN mkdir -p /root/.nuget/NuGet \ + && cp .oss-scanner/NuGet.Config /root/.nuget/NuGet/NuGet.Config + +ENTRYPOINT [] +CMD ["bash"] diff --git a/.oss-scanner/Dockerfile.dockerignore b/.oss-scanner/Dockerfile.dockerignore new file mode 100644 index 00000000..0ef1403f --- /dev/null +++ b/.oss-scanner/Dockerfile.dockerignore @@ -0,0 +1,13 @@ +.git +.claude +.vscode +.env +.env.* +artifacts +archive +module +**/bin +**/obj +.nuget +packages +*.nupkg diff --git a/.oss-scanner/NuGet.Config b/.oss-scanner/NuGet.Config new file mode 100644 index 00000000..c0c387e8 --- /dev/null +++ b/.oss-scanner/NuGet.Config @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/.oss-scanner/README.md b/.oss-scanner/README.md new file mode 100644 index 00000000..2e986053 --- /dev/null +++ b/.oss-scanner/README.md @@ -0,0 +1,85 @@ +--- +title: OSS Scanner environment +summary: Build, verify and enroll DLL Pickle's offline security analysis environment. +--- + +## Build and verify + +From the repository root on a Linux x64 Docker host: + +```sh +docker build -f .oss-scanner/Dockerfile -t dllpickle-oss-scanner . +docker run --rm --network none --cpus 2 --memory 8g \ + dllpickle-oss-scanner pwsh -NoLogo -NoProfile -NonInteractive \ + -File .oss-scanner/test.ps1 +``` + +The build downloads dependencies and warms temporary test-project restores. The +second command rebuilds and tests in a new container with no networking and no +host files mounted. A successful image build alone is not offline test evidence. + +The image uses `global.json`, `build/build-tool-versions.json`, and +`build/powershell-test-matrix.json`. Update the SDK image tag and digest together +when `global.json` changes; setup rejects a mismatch. Runtime archives use the +matrix checksums and the existing stock-PowerShell provisioner. Each runtime has +its own fresh processes and explicit module path. + +Source is at `/src`; the built module is at `/src/module/DLLPickle`. Tools and +runtimes live under `/opt/dllpickle`; the NuGet cache is `/opt/nuget/packages`. +The final image's user-level NuGet configuration permits only that local cache. +This does not change normal builds outside the image. Online dependency audits +remain in the existing dependency workflows; offline restores cannot refresh +vulnerability data. + +`test.ps1` runs the existing cross-platform build, then unit tests, synthetic +integration tests, strict package composition and TFM checks for every declared +Linux profile. Live service probes are disabled. JSON/XML results are separated +by runtime under `/src/artifacts/oss-scanner`; a passing summary is written only +after every check succeeds. + +For interactive investigation: + +```sh +docker run --rm -it --network none dllpickle-oss-scanner bash +``` + +The reusable `OSS-Scanner.yml` workflow saves the source commit, image metadata, +network mode, build/test logs and per-runtime results for 30 days. `Build Module` +calls it for build-relevant changes and requires success in the existing Build +gate. Documentation-only changes can still skip the expensive build jobs. +Dependabot tracks the scanner image separately from the development container. + +## Enrollment after merge + +Track preparation in [issue #318](https://github.com/SamErde/DLLPickle/issues/318). +After the implementation PR is merged, create an upstream tracking issue and a +dedicated fork branch in `anthropics/oss-scanner`. Add only +`projects/dllpickle/project.yaml`, pointing to this Dockerfile and threat model. +Confirm the monitored primary security inbox before publishing the registration. + +Run the upstream checks from the oss-scanner checkout: + +```sh +python3 tools/validate.py +python3 tools/check dllpickle +# Inside the resulting offline shell: +pwsh -NoLogo -NoProfile -NonInteractive -File .oss-scanner/test.ps1 +``` + +The helper clones the configured remote ref; it does not test unpublished local +files. Record the actual source revision and results in the enrollment PR. +Anthropic's build-only CI does not replace the offline test run. Its scanner also +adds a tooling layer, so the project image's digest pin does not pin that layer. + +Use the current upstream PR template and provide a factual security-criticality +and adoption rationale. The maintainer must make the contact, service terms and +CLA decisions. Creating these files does not enroll DLL Pickle or accept terms. +See [upstream contribution requirements](https://github.com/anthropics/oss-scanner/blob/main/CONTRIBUTING.md). + +## Coverage + +This environment verifies Linux execution and synthetic authentication-module +interactions. It does not validate live tenant sign-in, Windows broker/WAM, +macOS execution, or the full upstream service-module compatibility matrix. +Existing release and compatibility checks remain necessary. See +[the threat model](threat_model.md) for analysis scope and severity guidance. diff --git a/.oss-scanner/setup.ps1 b/.oss-scanner/setup.ps1 new file mode 100644 index 00000000..190ad248 --- /dev/null +++ b/.oss-scanner/setup.ps1 @@ -0,0 +1,43 @@ +<# +.SYNOPSIS +Installs the repository-pinned tools and Linux runtimes in the scanner image. +.DESCRIPTION +Runs during the network-enabled Docker build. Runtime archives are verified by +the existing provisioner; no tenant credentials or service modules are required. +#> +[CmdletBinding()] +param() + +$ErrorActionPreference = 'Stop' +Set-StrictMode -Version Latest +$RepositoryRoot = Split-Path -Parent $PSScriptRoot +Set-Location -LiteralPath $RepositoryRoot + +$SdkPolicy = Get-Content -LiteralPath 'global.json' -Raw | ConvertFrom-Json +$InstalledSdk = & dotnet --version +if ($LASTEXITCODE -ne 0 -or $InstalledSdk -ne $SdkPolicy.sdk.version) { + throw 'The scanner SDK image must match global.json exactly. Update its tag and digest together.' +} + +$Matrix = Get-Content -LiteralPath 'build/powershell-test-matrix.json' -Raw | ConvertFrom-Json +if (@($Matrix.profiles).Count -eq 0) { + throw 'The PowerShell runtime matrix is empty.' +} +$RuntimeIdentities = @( + foreach ($RuntimeProfile in $Matrix.profiles) { + $InstallParameters = @{ + Provider = 'DirectArchive' + PowerShellVersion = $RuntimeProfile.powerShellVersion + InstallRoot = '/opt/dllpickle/runtimes' + Platform = 'linux' + Architecture = 'x64' + PassThru = $true + } + & ./tools/Install-DLLPickleTestPowerShell.ps1 @InstallParameters + } +) +$RuntimeIdentities | ConvertTo-Json -Depth 10 -AsArray | + Set-Content -LiteralPath '/opt/dllpickle/runtimes.json' -Encoding utf8NoBOM + +# Save-Module avoids a tool dependency on the invoking user's home directory. +& ./.github/ci-scripts/Actions_Bootstrap.ps1 -ModuleInstallPath '/opt/dllpickle/modules' diff --git a/.oss-scanner/test.ps1 b/.oss-scanner/test.ps1 new file mode 100644 index 00000000..6fd1cdfd --- /dev/null +++ b/.oss-scanner/test.ps1 @@ -0,0 +1,109 @@ +<# +.SYNOPSIS +Rebuilds DLL Pickle and tests every declared Linux runtime in fresh processes. +.DESCRIPTION +Run inside the scanner image. During image construction this warms all test +dependencies. For acceptance, run the same command with docker --network none. +The image retains exact tools, runtime archives, reference packs and NuGet caches. +Results are written under artifacts/oss-scanner, separately for each runtime. +#> +[CmdletBinding()] +param() + +$ErrorActionPreference = 'Stop' +Set-StrictMode -Version Latest +$RepositoryRoot = Split-Path -Parent $PSScriptRoot +Set-Location -LiteralPath $RepositoryRoot +$PreviousSummary = Join-Path $RepositoryRoot 'artifacts/oss-scanner/summary.json' +if (Test-Path -LiteralPath $PreviousSummary) { + Remove-Item -LiteralPath $PreviousSummary -Force +} +$Matrix = Get-Content -LiteralPath 'build/powershell-test-matrix.json' -Raw | ConvertFrom-Json +$InstalledRuntimes = @(Get-Content -LiteralPath '/opt/dllpickle/runtimes.json' -Raw | ConvertFrom-Json) +if (@($Matrix.profiles).Count -eq 0) { + throw 'The PowerShell runtime matrix is empty.' +} + +# Exclude real service/tenant probes even if the caller set the opt-in variable. +$env:DLLPICKLE_RUN_LIVE_REPRO = '0' +$OriginalPath = $env:PATH +$DefaultPowerShell = (Get-Process -Id $PID).Path +$env:PSModulePath = '/opt/dllpickle/modules' + [System.IO.Path]::PathSeparator + (Join-Path $PSHOME 'Modules') + +. ./build/DLLPickle.Tooling.ps1 +$ToolPolicy = Get-DLLPickleBuildToolPolicy -Path './build/build-tool-versions.json' +$AnalyzerVersion = Get-DLLPickleBuildToolVersion -Policy $ToolPolicy -Name 'PSScriptAnalyzer' +$null = Import-DLLPickleBuildTool -Name 'PSScriptAnalyzer' -RequiredVersion $AnalyzerVersion +$AnalyzerFindings = @(Invoke-ScriptAnalyzer -Path $PSScriptRoot -Recurse -Settings './build/PSScriptAnalyzerSettings.psd1') +if ($AnalyzerFindings.Count -gt 0) { + $AnalyzerFindings | Format-Table + throw 'Scanner script analysis failed.' +} + +# Reuse the complete build. Its locked restore must also work from the image cache. +& $DefaultPowerShell -NoLogo -NoProfile -NonInteractive -File ./tools/Invoke-DLLPickleBuild.ps1 -Task BuildCrossPlatform +if ($LASTEXITCODE -ne 0) { + throw 'The scanner rebuild failed.' +} + +$ResultsRoot = Join-Path $RepositoryRoot 'artifacts/oss-scanner' +$null = New-Item -ItemType Directory -Path $ResultsRoot -Force +$SummaryPath = Join-Path $ResultsRoot 'summary.json' +@{ status = 'running'; profiles = @() } | ConvertTo-Json | + Set-Content -LiteralPath $SummaryPath -Encoding utf8NoBOM +$VerifiedProfiles = @() + +foreach ($RuntimeProfile in $Matrix.profiles) { + $Runtime = @($InstalledRuntimes | Where-Object PowerShellVersion -EQ $RuntimeProfile.powerShellVersion) + if ($Runtime.Count -ne 1) { + throw "Expected exactly one installed runtime for PowerShell $($RuntimeProfile.powerShellVersion)." + } + $Executable = [string]$Runtime[0].ExecutablePath + $IdentityParameters = @{ + PowerShellExecutable = $Executable + PowerShellVersion = $RuntimeProfile.powerShellVersion + PassThru = $true + } + $Identity = & ./tools/Install-DLLPickleTestPowerShell.ps1 @IdentityParameters + $RuntimeRoot = Split-Path -Parent $Executable + $env:PATH = $RuntimeRoot + [System.IO.Path]::PathSeparator + $OriginalPath + $env:PSModulePath = '/opt/dllpickle/modules' + [System.IO.Path]::PathSeparator + (Join-Path $RuntimeRoot 'Modules') + $env:DLLPICKLE_TEST_PWSH = $Executable + $env:DLLPICKLE_TEST_TFM = $RuntimeProfile.targetFramework + $env:DLLPICKLE_TEST_PSMODULEPATH = $env:PSModulePath + + $RuntimeProfileResults = Join-Path $ResultsRoot $RuntimeProfile.powerShellVersion + $null = New-Item -ItemType Directory -Path $RuntimeProfileResults -Force + $Identity | ConvertTo-Json -Depth 10 | + Set-Content -LiteralPath (Join-Path $RuntimeProfileResults 'runtime.json') -Encoding utf8NoBOM + + foreach ($Task in @('Test', 'IntegrationTest')) { + & $Executable -NoLogo -NoProfile -NonInteractive -File ./tools/Invoke-DLLPickleBuild.ps1 -Task $Task + $TestExitCode = $LASTEXITCODE + $ResultPrefix = if ($Task -eq 'Test') { 'PesterTests' } else { 'PesterIntegrationTests' } + Copy-Item -Path "artifacts/testOutput/$ResultPrefix.*" -Destination $RuntimeProfileResults -Force + if ($TestExitCode -ne 0) { + throw "$Task failed for PowerShell $($RuntimeProfile.powerShellVersion)." + } + [xml]$TestXml = Get-Content -LiteralPath (Join-Path $RuntimeProfileResults "$ResultPrefix.xml") -Raw + if ([int]$TestXml.DocumentElement.GetAttribute('total') -le 0) { + throw "$Task discovered no tests for PowerShell $($RuntimeProfile.powerShellVersion)." + } + } + + & $Executable -NoLogo -NoProfile -NonInteractive -File ./tools/Test-DLLPicklePackageArtifact.ps1 -Strict -OutputPath (Join-Path $RuntimeProfileResults 'artifact-composition.json') + if ($LASTEXITCODE -ne 0) { + throw "Package composition failed for PowerShell $($RuntimeProfile.powerShellVersion)." + } + & $Executable -NoLogo -NoProfile -NonInteractive -File ./tools/Test-DLLPickleTfmAlignment.ps1 -Strict -OutputPath (Join-Path $RuntimeProfileResults 'tfm-alignment.json') + if ($LASTEXITCODE -ne 0) { + throw "TFM alignment failed for PowerShell $($RuntimeProfile.powerShellVersion)." + } + $VerifiedProfiles += $Identity +} + +@{ + status = 'passed' + profiles = $VerifiedProfiles + scope = 'Linux unit, synthetic integration, package composition and TFM alignment; no tenant authentication' +} | ConvertTo-Json -Depth 10 | Set-Content -LiteralPath $SummaryPath -Encoding utf8NoBOM diff --git a/.oss-scanner/threat_model.md b/.oss-scanner/threat_model.md new file mode 100644 index 00000000..d1c8f718 --- /dev/null +++ b/.oss-scanner/threat_model.md @@ -0,0 +1,82 @@ +--- +title: DLL Pickle security analysis scope +summary: Trust boundaries, reproduction guidance and severity expectations. +--- + +## Purpose and security boundary + +DLL Pickle is a PowerShell module that preloads compatible identity assemblies +before service modules import their own dependencies. It runs inside the user's +PowerShell process, often a session used to administer Microsoft tenants. It +coordinates library loading; the consuming modules and Microsoft libraries +perform authentication and token handling. + +Prioritize defects in DLL Pickle that let less-trusted inputs change which code +executes in that process, disclose sensitive data, or undermine the integrity of +the distributed module. Explain the attacker's initial privileges and the new +capability gained. An attacker who already controls the entire installed module +directory can replace executable code; demonstrate an additional trust-boundary +crossing before treating such control as a vulnerability in the loader. + +## Surfaces to examine + +- `src/DLLPickle/Public/Import-DPLibrary.ps1` and its private helpers: runtime + selection, assembly discovery/order, load-context interactions, native runtime + paths, host-provided assembly exclusions and failure handling. +- Module discovery and import helpers: module roots, filenames, versions and + assembly metadata. Determine who controls each input and which process trusts it. +- Configuration and runtime-policy parsing: malformed values, unsafe path + resolution, unintended loading and information exposed through diagnostics. +- Build scripts, NuGet lock enforcement, artifact composition and GitHub release + workflows: attacker-controlled changes or inputs crossing a build/publish + permission boundary. Distinguish a vulnerable workflow from authorized + maintainer changes to trusted source. +- Assembly-resolution callbacks and background execution: process crashes or + unsafe behavior reachable through DLL Pickle's own implementation. + +Dependencies are installed to exercise this project. Attribute bugs in Microsoft +libraries or other service modules to their owning project. Focus reports here +on DLL Pickle's use, selection and packaging of those dependencies. + +## Reproduce and validate + +The full checkout is `/src`. Run: + +```sh +cd /src +pwsh -NoLogo -NoProfile -NonInteractive -File .oss-scanner/test.ps1 +``` + +This rebuilds the module and runs each runtime declared in +`build/powershell-test-matrix.json` in a fresh process. Exact executable paths +are in `/opt/dllpickle/runtimes.json`. The built module is +`/src/module/DLLPickle`; per-runtime results are in +`/src/artifacts/oss-scanner`. Runtime archives, tools and dependency caches remain +available offline. Preserve locked dependency resolution when validating patches. + +Use synthetic modules, assemblies and tokens in reproducers. The image contains +no tenant credentials. A mock authentication success is evidence about that mock +only. Linux execution cannot establish Windows broker/WAM, Windows permissions, +macOS behavior or successful real tenant authentication. Label findings requiring +those platforms as unverified on that platform and describe the missing test. + +## Severity and report expectations + +- Critical: demonstrated broad compromise, such as a viable path to distributing + attacker-controlled authentication code through the trusted release process. + State every prerequisite; proximity to authentication alone is insufficient. +- High: demonstrated code execution, credential/token exposure or privilege + escalation across a real trust boundary under realistic prerequisites. +- Medium: bounded confidentiality/integrity impact or reliably exploitable + availability loss within the affected user's process. +- Low: limited hardening gaps without a demonstrated stronger impact. + +For each report, include the affected source revision, runtime and OS, attacker +control, exact reproduction, expected versus observed behavior, impact and a +focused regression test. Separate verified behavior from inference. Prefer a +small patch that preserves the supported runtime and dependency contracts. +Group findings sharing one root cause; retain distinct exploit prerequisites. + +Report vulnerabilities privately through the configured scanner channel or +`SECURITY.md`. Enrollment configuration and workflow logs are public; keep +credentials and sensitive vulnerability details out of them. diff --git a/tests/Unit/WorkflowGuardrails.Tests.ps1 b/tests/Unit/WorkflowGuardrails.Tests.ps1 index 6108608c..5e3ea8d0 100644 --- a/tests/Unit/WorkflowGuardrails.Tests.ps1 +++ b/tests/Unit/WorkflowGuardrails.Tests.ps1 @@ -320,12 +320,25 @@ Describe 'Exact PowerShell runtime matrix workflow guardrails' -Tag 'Unit' { It 'keeps Build gate stable and aggregates both hosted and exact-runtime jobs' { $BuildWorkflow | Should -Match '(?m)^\s+name: Build gate\s*$' - $BuildWorkflow | Should -Match 'needs: \[changes, runtime-matrix, build, runtime-tests, dependency-change-report\]' - $BuildWorkflow | Should -Match ([regex]::Escape("foreach (`$RequiredJob in @('runtimeMatrix', 'build', 'runtimeTests'))")) + $BuildWorkflow | Should -Match 'needs: \[changes, runtime-matrix, build, runtime-tests, dependency-change-report, oss-scanner\]' + $BuildWorkflow | Should -Match ([regex]::Escape("foreach (`$RequiredJob in @('runtimeMatrix', 'build', 'runtimeTests', 'ossScanner'))")) $BuildWorkflow | Should -Match ([regex]::Escape('needs.runtime-matrix.result')) $BuildWorkflow | Should -Match ([regex]::Escape('runtimeTests =')) $BuildWorkflow | Should -Match ([regex]::Escape('needs.runtime-tests.result')) $BuildWorkflow | Should -Match ([regex]::Escape('needs.dependency-change-report.result')) + $BuildWorkflow | Should -Match ([regex]::Escape('needs.oss-scanner.result')) + } + + It 'requires offline scanner tests without credentials or host-mounted source' { + $ScannerWorkflow = Get-Content -LiteralPath (Join-Path $ProjectRoot '.github/workflows/OSS-Scanner.yml') -Raw + $BuildWorkflow | Should -Match ([regex]::Escape("'^\.oss-scanner/'")) + $BuildWorkflow | Should -Match ([regex]::Escape("'^\.github/workflows/OSS-Scanner\.yml$'")) + $BuildWorkflow | Should -Match 'uses: \./\.github/workflows/OSS-Scanner\.yml' + $ScannerWorkflow | Should -Match 'persist-credentials: false' + $ScannerWorkflow | Should -Match 'docker create --name dllpickle-offline --network none --cpus 2 --memory 8g' + $ScannerWorkflow | Should -Not -Match 'secrets:|secrets\.|--privileged|--mount|--volume' + $ScannerWorkflow | Should -Match ([regex]::Escape('test "$status" -eq 0')) + $ScannerWorkflow | Should -Match ([regex]::Escape('.status == "passed"')) } It 'requires successful profile-matrix generation whenever live upstream evidence is required' { From ea69c8797763d618a268b783685614d74438c8d4 Mon Sep 17 00:00:00 2001 From: Sam Erde <20478745+SamErde@users.noreply.github.com> Date: Thu, 5 Nov 2026 16:36:47 -0500 Subject: [PATCH 2/3] ci: pin scanner OS packages and use an unprivileged default user --- .oss-scanner/Dockerfile | 27 ++++++++++++++++++++++----- .oss-scanner/README.md | 29 ++++++++++++++++++++--------- .oss-scanner/test.ps1 | 4 ++-- .oss-scanner/threat_model.md | 10 +++++----- 4 files changed, 49 insertions(+), 21 deletions(-) diff --git a/.oss-scanner/Dockerfile b/.oss-scanner/Dockerfile index 035f50ec..b7320bbf 100644 --- a/.oss-scanner/Dockerfile +++ b/.oss-scanner/Dockerfile @@ -8,7 +8,13 @@ ENV DOTNET_CLI_TELEMETRY_OPTOUT=1 \ NUGET_PACKAGES=/opt/nuget/packages RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ - ca-certificates curl git jq python3 procps libunwind8 \ + ca-certificates=20260816ubuntu0.24.04.2 \ + curl=8.5.0-2ubuntu10.16 \ + git=1:2.43.0-1ubuntu7.4 \ + jq=1.7.1-3ubuntu0.24.04.2 \ + python3=3.12.3-0ubuntu2.1 \ + procps=2:4.0.4-4ubuntu3.3 \ + libunwind8=1.6.2-3build1.1 \ && rm -rf /var/lib/apt/lists/* WORKDIR /src @@ -34,13 +40,24 @@ RUN set -eu; \ # The scanner uses the repository as its build context and expects source at /src. COPY . /src -# Warm the build AND temporary test-project dependencies for every declared runtime. -RUN pwsh -NoLogo -NoProfile -NonInteractive -File .oss-scanner/test.ps1 +# Restore every TFM's packages/reference packs and warm temporary test projects. +# The complete runtime matrix is exercised by the offline acceptance run. +RUN pwsh -NoLogo -NoProfile -NonInteractive -Command \ + '$env:PSModulePath = "/opt/dllpickle/modules" + [IO.Path]::PathSeparator + (Join-Path $PSHOME "Modules"); & ./tools/Invoke-DLLPickleBuild.ps1 -Task BuildCrossPlatform' # Subsequent restores (including test fixtures) use only the retained package cache. # This is image-local; normal repository builds still use their configured feeds. -RUN mkdir -p /root/.nuget/NuGet \ - && cp .oss-scanner/NuGet.Config /root/.nuget/NuGet/NuGet.Config +RUN useradd --create-home --uid 10001 scanner \ + && mkdir -p /root/.config /home/scanner/.config \ + /root/.nuget/NuGet /home/scanner/.nuget/NuGet \ + && cp .oss-scanner/NuGet.Config /root/.nuget/NuGet/NuGet.Config \ + && cp .oss-scanner/NuGet.Config /home/scanner/.nuget/NuGet/NuGet.Config \ + && chown -R scanner:scanner /src /opt/nuget /home/scanner \ + && chmod -R a+rX /opt/dllpickle +ENV HOME=/home/scanner \ + PSModulePath=/opt/dllpickle/modules +# Anthropic's tooling layer switches to root; its offline NuGet config is ready too. +USER scanner ENTRYPOINT [] CMD ["bash"] diff --git a/.oss-scanner/README.md b/.oss-scanner/README.md index 2e986053..273183c5 100644 --- a/.oss-scanner/README.md +++ b/.oss-scanner/README.md @@ -1,6 +1,6 @@ --- title: OSS Scanner environment -summary: Build, verify and enroll DLL Pickle's offline security analysis environment. +summary: Prepare DLL Pickle for offline security analysis. --- ## Build and verify @@ -14,16 +14,21 @@ docker run --rm --network none --cpus 2 --memory 8g \ -File .oss-scanner/test.ps1 ``` -The build downloads dependencies and warms temporary test-project restores. The -second command rebuilds and tests in a new container with no networking and no +The build downloads framework dependencies and warms test-project restores. +The second command rebuilds and tests in a new container with no networking and no host files mounted. A successful image build alone is not offline test evidence. The image uses `global.json`, `build/build-tool-versions.json`, and -`build/powershell-test-matrix.json`. Update the SDK image tag and digest together +`build/powershell-test-matrix.json`. Update the SDK image tag and digest when `global.json` changes; setup rejects a mismatch. Runtime archives use the matrix checksums and the existing stock-PowerShell provisioner. Each runtime has its own fresh processes and explicit module path. +The Dockerfile also pins its direct OS package versions. Review those pins with +base-image updates; expired package versions fail the build rather than silently +selecting replacements. Dependency feeds and transitive OS packages remain +external inputs, so these pins are not a claim of bit-for-bit reproducibility. + Source is at `/src`; the built module is at `/src/module/DLLPickle`. Tools and runtimes live under `/opt/dllpickle`; the NuGet cache is `/opt/nuget/packages`. The final image's user-level NuGet configuration permits only that local cache. @@ -31,6 +36,11 @@ This does not change normal builds outside the image. Online dependency audits remain in the existing dependency workflows; offline restores cannot refresh vulnerability data. +The project image defaults to the unprivileged `scanner` user. Anthropic's +tooling layer switches to root; both users have the same offline NuGet policy. +The analysis source and NuGet cache are writable, while installed runtimes and +build tools remain root-owned. Shared tools are on the default module path. + `test.ps1` runs the existing cross-platform build, then unit tests, synthetic integration tests, strict package composition and TFM checks for every declared Linux profile. Live service probes are disabled. JSON/XML results are separated @@ -44,14 +54,15 @@ docker run --rm -it --network none dllpickle-oss-scanner bash ``` The reusable `OSS-Scanner.yml` workflow saves the source commit, image metadata, -network mode, build/test logs and per-runtime results for 30 days. `Build Module` -calls it for build-relevant changes and requires success in the existing Build -gate. Documentation-only changes can still skip the expensive build jobs. +network mode, build/test logs and per-runtime results for 30 days. +`Build Module` calls it for build-relevant changes and includes its result in +the existing Build gate. Documentation-only changes can skip expensive jobs. Dependabot tracks the scanner image separately from the development container. ## Enrollment after merge -Track preparation in [issue #318](https://github.com/SamErde/DLLPickle/issues/318). +Track preparation in +[issue #318](https://github.com/SamErde/DLLPickle/issues/318). After the implementation PR is merged, create an upstream tracking issue and a dedicated fork branch in `anthropics/oss-scanner`. Add only `projects/dllpickle/project.yaml`, pointing to this Dockerfile and threat model. @@ -68,7 +79,7 @@ pwsh -NoLogo -NoProfile -NonInteractive -File .oss-scanner/test.ps1 The helper clones the configured remote ref; it does not test unpublished local files. Record the actual source revision and results in the enrollment PR. -Anthropic's build-only CI does not replace the offline test run. Its scanner also +Anthropic's build-only CI does not replace the offline test run. Its scanner adds a tooling layer, so the project image's digest pin does not pin that layer. Use the current upstream PR template and provide a factual security-criticality diff --git a/.oss-scanner/test.ps1 b/.oss-scanner/test.ps1 index 6fd1cdfd..ea719991 100644 --- a/.oss-scanner/test.ps1 +++ b/.oss-scanner/test.ps1 @@ -2,8 +2,8 @@ .SYNOPSIS Rebuilds DLL Pickle and tests every declared Linux runtime in fresh processes. .DESCRIPTION -Run inside the scanner image. During image construction this warms all test -dependencies. For acceptance, run the same command with docker --network none. +Run inside the scanner image after its network-enabled build has cached the +dependencies. For acceptance, run this command with docker --network none. The image retains exact tools, runtime archives, reference packs and NuGet caches. Results are written under artifacts/oss-scanner, separately for each runtime. #> diff --git a/.oss-scanner/threat_model.md b/.oss-scanner/threat_model.md index d1c8f718..ae4a4e86 100644 --- a/.oss-scanner/threat_model.md +++ b/.oss-scanner/threat_model.md @@ -24,7 +24,7 @@ crossing before treating such control as a vulnerability in the loader. selection, assembly discovery/order, load-context interactions, native runtime paths, host-provided assembly exclusions and failure handling. - Module discovery and import helpers: module roots, filenames, versions and - assembly metadata. Determine who controls each input and which process trusts it. + assembly metadata. Identify each input's owner and the process trusting it. - Configuration and runtime-policy parsing: malformed values, unsafe path resolution, unintended loading and information exposed through diagnostics. - Build scripts, NuGet lock enforcement, artifact composition and GitHub release @@ -51,14 +51,14 @@ This rebuilds the module and runs each runtime declared in `build/powershell-test-matrix.json` in a fresh process. Exact executable paths are in `/opt/dllpickle/runtimes.json`. The built module is `/src/module/DLLPickle`; per-runtime results are in -`/src/artifacts/oss-scanner`. Runtime archives, tools and dependency caches remain -available offline. Preserve locked dependency resolution when validating patches. +`/src/artifacts/oss-scanner`. Runtime archives, tools and caches remain +available offline. Preserve locked dependency resolution when testing patches. Use synthetic modules, assemblies and tokens in reproducers. The image contains no tenant credentials. A mock authentication success is evidence about that mock only. Linux execution cannot establish Windows broker/WAM, Windows permissions, -macOS behavior or successful real tenant authentication. Label findings requiring -those platforms as unverified on that platform and describe the missing test. +macOS behavior or real tenant authentication. Label findings requiring those +platforms as unverified on that platform and describe the missing test. ## Severity and report expectations From ce4224960c23a3cbbde82f9bee0d06b5a22c564d Mon Sep 17 00:00:00 2001 From: Sam Erde <20478745+SamErde@users.noreply.github.com> Date: Thu, 5 Nov 2026 17:01:02 -0500 Subject: [PATCH 3/3] fix: support root scanner Git inspection --- .github/workflows/OSS-Scanner.yml | 15 +++++++++++++++ .oss-scanner/Dockerfile | 1 + .oss-scanner/README.md | 9 ++++++--- tests/Unit/WorkflowGuardrails.Tests.ps1 | 2 +- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/.github/workflows/OSS-Scanner.yml b/.github/workflows/OSS-Scanner.yml index 60196e3b..3820b9c2 100644 --- a/.github/workflows/OSS-Scanner.yml +++ b/.github/workflows/OSS-Scanner.yml @@ -35,6 +35,21 @@ jobs: docker image inspect dllpickle-oss-scanner:test \ > "$RUNNER_TEMP/oss-scanner-evidence/image.json" + - name: Verify root tooling can inspect the source worktree + shell: bash + run: | + set -euo pipefail + docker run --rm --network none --user 0 --env HOME=/root \ + dllpickle-oss-scanner:test bash -c ' + set -euo pipefail + test "$(git config --global --get-all safe.directory)" = /src + git init -q /src + git -C /src status --porcelain > /dev/null + git -C /src diff --exit-code + git -C /src diff --cached --exit-code + echo "Root Git inspection passed with trust limited to /src." + ' 2>&1 | tee "$RUNNER_TEMP/oss-scanner-evidence/root-git.log" + - name: Rebuild and test with networking disabled shell: bash run: | diff --git a/.oss-scanner/Dockerfile b/.oss-scanner/Dockerfile index b7320bbf..55f5cc32 100644 --- a/.oss-scanner/Dockerfile +++ b/.oss-scanner/Dockerfile @@ -52,6 +52,7 @@ RUN useradd --create-home --uid 10001 scanner \ /root/.nuget/NuGet /home/scanner/.nuget/NuGet \ && cp .oss-scanner/NuGet.Config /root/.nuget/NuGet/NuGet.Config \ && cp .oss-scanner/NuGet.Config /home/scanner/.nuget/NuGet/NuGet.Config \ + && git config --file /root/.gitconfig --add safe.directory /src \ && chown -R scanner:scanner /src /opt/nuget /home/scanner \ && chmod -R a+rX /opt/dllpickle diff --git a/.oss-scanner/README.md b/.oss-scanner/README.md index 273183c5..197b6ede 100644 --- a/.oss-scanner/README.md +++ b/.oss-scanner/README.md @@ -15,8 +15,9 @@ docker run --rm --network none --cpus 2 --memory 8g \ ``` The build downloads framework dependencies and warms test-project restores. -The second command rebuilds and tests in a new container with no networking and no -host files mounted. A successful image build alone is not offline test evidence. +The second command rebuilds and tests in a new container with no networking +and no host files mounted. A successful image build alone is not offline +test evidence. The image uses `global.json`, `build/build-tool-versions.json`, and `build/powershell-test-matrix.json`. Update the SDK image tag and digest @@ -39,7 +40,9 @@ vulnerability data. The project image defaults to the unprivileged `scanner` user. Anthropic's tooling layer switches to root; both users have the same offline NuGet policy. The analysis source and NuGet cache are writable, while installed runtimes and -build tools remain root-owned. Shared tools are on the default module path. +build tools remain root-owned. Root trusts only `/src` as a Git worktree owned +by another user, so the scanner can inspect patches after restoring `.git`. +Shared tools are on the default module path. `test.ps1` runs the existing cross-platform build, then unit tests, synthetic integration tests, strict package composition and TFM checks for every declared diff --git a/tests/Unit/WorkflowGuardrails.Tests.ps1 b/tests/Unit/WorkflowGuardrails.Tests.ps1 index 5e3ea8d0..a7794641 100644 --- a/tests/Unit/WorkflowGuardrails.Tests.ps1 +++ b/tests/Unit/WorkflowGuardrails.Tests.ps1 @@ -336,7 +336,7 @@ Describe 'Exact PowerShell runtime matrix workflow guardrails' -Tag 'Unit' { $BuildWorkflow | Should -Match 'uses: \./\.github/workflows/OSS-Scanner\.yml' $ScannerWorkflow | Should -Match 'persist-credentials: false' $ScannerWorkflow | Should -Match 'docker create --name dllpickle-offline --network none --cpus 2 --memory 8g' - $ScannerWorkflow | Should -Not -Match 'secrets:|secrets\.|--privileged|--mount|--volume' + $ScannerWorkflow | Should -Not -Match 'secrets:|secrets\.|--privileged|--mount|--volume|(?:^|\s)-v(?:\s|\\|$)' $ScannerWorkflow | Should -Match ([regex]::Escape('test "$status" -eq 0')) $ScannerWorkflow | Should -Match ([regex]::Escape('.status == "passed"')) }