Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
17 changes: 15 additions & 2 deletions .github/workflows/Build Module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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$'
)
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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)"
Expand All @@ -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)
}
Expand Down
89 changes: 89 additions & 0 deletions .github/workflows/OSS-Scanner.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
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: 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: |
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
64 changes: 64 additions & 0 deletions .oss-scanner/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# 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=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
# 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
# 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 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 \
&& git config --file /root/.gitconfig --add safe.directory /src \
&& chown -R scanner:scanner /src /opt/nuget /home/scanner \
Comment thread
Copilot marked this conversation as resolved.
Resolved
&& 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"]
13 changes: 13 additions & 0 deletions .oss-scanner/Dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.git
.claude
.vscode
.env
.env.*
artifacts
archive
module
**/bin
**/obj
.nuget
packages
*.nupkg
10 changes: 10 additions & 0 deletions .oss-scanner/NuGet.Config
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="image-cache" value="/opt/nuget/packages" />
</packageSources>
<auditSources>
<clear />
</auditSources>
</configuration>
99 changes: 99 additions & 0 deletions .oss-scanner/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
---
title: OSS Scanner environment
summary: Prepare DLL Pickle for offline security analysis.
---
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

## 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 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
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.
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. 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
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 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).
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
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.
43 changes: 43 additions & 0 deletions .oss-scanner/setup.ps1
Original file line number Diff line number Diff line change
@@ -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'
Loading
Loading