|
| 1 | +name: Security release gate |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - 'verification/compose-cli-*' |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + |
| 12 | +concurrency: |
| 13 | + group: compose-cli-security-${{ github.ref }} |
| 14 | + cancel-in-progress: false |
| 15 | + |
| 16 | +jobs: |
| 17 | + build-test-scan: |
| 18 | + runs-on: ubuntu-24.04 |
| 19 | + timeout-minutes: 75 |
| 20 | + env: |
| 21 | + DAPPER_IMAGE: pasturestack/compose-cli-dapper:${{ github.sha }} |
| 22 | + TRIVY_IMAGE: aquasec/trivy:0.73.0@sha256:7cced7cae583819fc7806d4cbc0dbbc7cad18b99f7d3e235192e6da8c091045c |
| 23 | + VERSION_OVERRIDE: v0.14.32 |
| 24 | + PLATFORM_COMPAT_JAR_URL: https://github.com/PastureStack/server/releases/download/v1.6.346/orchestration-engine-0.183.276.jar |
| 25 | + PLATFORM_COMPAT_JAR_SHA256: 64bc18a1654b73116dce89f29ede7b4c629a8c5af236b482ef95f50a78ed6376 |
| 26 | + |
| 27 | + steps: |
| 28 | + - name: Check out candidate |
| 29 | + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 |
| 30 | + with: |
| 31 | + fetch-depth: 0 |
| 32 | + persist-credentials: false |
| 33 | + |
| 34 | + - name: Record candidate identity |
| 35 | + shell: bash |
| 36 | + run: | |
| 37 | + set -euo pipefail |
| 38 | + test -z "$(git status --porcelain)" |
| 39 | + mkdir -p evidence |
| 40 | + git rev-parse HEAD > evidence/source-revision.txt |
| 41 | + sha256sum Dockerfile.dapper ubuntu-apt.lock vendor.conf > evidence/source-locks.sha256 |
| 42 | +
|
| 43 | + - name: Build, test, validate, and package twice |
| 44 | + shell: bash |
| 45 | + run: | |
| 46 | + set -euo pipefail |
| 47 | + docker build \ |
| 48 | + --build-arg DAPPER_HOST_ARCH=amd64 \ |
| 49 | + --tag "$DAPPER_IMAGE" \ |
| 50 | + --file Dockerfile.dapper \ |
| 51 | + . |
| 52 | +
|
| 53 | + source_path="$GITHUB_WORKSPACE" |
| 54 | + run_ci() { |
| 55 | + docker run --rm \ |
| 56 | + --volume "${source_path}:/go/src/github.com/PastureStack/compose-cli" \ |
| 57 | + --volume /var/run/docker.sock:/var/run/docker.sock \ |
| 58 | + --env "DAPPER_UID=$(id -u)" \ |
| 59 | + --env "DAPPER_GID=$(id -g)" \ |
| 60 | + --env "GOCACHE=/tmp/go-build-cache-${GITHUB_RUN_ID}" \ |
| 61 | + --env "XDG_CONFIG_HOME=/tmp/go-config-${GITHUB_RUN_ID}" \ |
| 62 | + --env "GIT_CONFIG_GLOBAL=/tmp/gitconfig-${GITHUB_RUN_ID}" \ |
| 63 | + --env "VERSION_OVERRIDE=$VERSION_OVERRIDE" \ |
| 64 | + --env "SKIP_INTEGRATION=true" \ |
| 65 | + --env "PLATFORM_COMPAT_JAR_URL=$PLATFORM_COMPAT_JAR_URL" \ |
| 66 | + --env "PLATFORM_COMPAT_JAR_SHA256=$PLATFORM_COMPAT_JAR_SHA256" \ |
| 67 | + "$DAPPER_IMAGE" ci |
| 68 | + } |
| 69 | +
|
| 70 | + run_ci |
| 71 | + artifact="dist/artifacts/compose-executor-0.14.32-linux-amd64.gz" |
| 72 | + test -s "$artifact" |
| 73 | + cp "$artifact" /tmp/compose-executor-first.gz |
| 74 | +
|
| 75 | + rm -rf bin build dist |
| 76 | + run_ci |
| 77 | + cmp /tmp/compose-executor-first.gz "$artifact" |
| 78 | + ./scripts/check-pasturestack-source |
| 79 | +
|
| 80 | + mkdir -p evidence/product |
| 81 | + gzip -cd "$artifact" > evidence/product/compose-executor |
| 82 | + chmod +x evidence/product/compose-executor |
| 83 | + evidence/product/compose-executor --version | grep -F '0.14.32' >/dev/null |
| 84 | + sha256sum "$artifact" > evidence/compose-executor.gz.sha256 |
| 85 | + docker run --rm --entrypoint go \ |
| 86 | + --volume "$PWD:/work:ro" \ |
| 87 | + "$DAPPER_IMAGE" \ |
| 88 | + version -m /work/evidence/product/compose-executor \ |
| 89 | + > evidence/product-go-version.txt |
| 90 | +
|
| 91 | + - name: Record resolved build inputs |
| 92 | + shell: bash |
| 93 | + run: | |
| 94 | + set -euo pipefail |
| 95 | + docker inspect "$DAPPER_IMAGE" > evidence/dapper-image-inspect.json |
| 96 | + docker run --rm --entrypoint sh "$DAPPER_IMAGE" -lc \ |
| 97 | + "printf 'package\\tversion\\n'; dpkg-query -W -f='\${binary:Package}\\t\${Version}\\n' | LC_ALL=C sort" \ |
| 98 | + > evidence/dapper-dpkg.tsv |
| 99 | + cp vendor.conf evidence/vendor.conf |
| 100 | +
|
| 101 | + - name: Scan source, product, and build image |
| 102 | + shell: bash |
| 103 | + run: | |
| 104 | + set -euo pipefail |
| 105 | + docker pull "$TRIVY_IMAGE" |
| 106 | + trivy_cache="$RUNNER_TEMP/trivy-cache" |
| 107 | + source_tree="$(mktemp -d)" |
| 108 | + trap 'rm -rf "$source_tree"' EXIT |
| 109 | + mkdir -p "$trivy_cache" |
| 110 | + git archive --format=tar HEAD | tar -xf - -C "$source_tree" |
| 111 | +
|
| 112 | + docker run --rm \ |
| 113 | + -v "$source_tree:/scan:ro" \ |
| 114 | + -v "$PWD/evidence:/evidence" \ |
| 115 | + -v "$trivy_cache:/root/.cache/trivy" \ |
| 116 | + "$TRIVY_IMAGE" fs \ |
| 117 | + --scanners vuln,secret --format json \ |
| 118 | + --output /evidence/source-security.json /scan |
| 119 | + docker run --rm \ |
| 120 | + -v "$PWD/evidence:/evidence" \ |
| 121 | + -v "$trivy_cache:/root/.cache/trivy" \ |
| 122 | + "$TRIVY_IMAGE" rootfs \ |
| 123 | + --scanners vuln,secret --format json \ |
| 124 | + --output /evidence/product-security.json /evidence/product |
| 125 | + docker run --rm \ |
| 126 | + -v /var/run/docker.sock:/var/run/docker.sock \ |
| 127 | + -v "$PWD:/work" -w /work \ |
| 128 | + -v "$trivy_cache:/root/.cache/trivy" \ |
| 129 | + "$TRIVY_IMAGE" image \ |
| 130 | + --scanners vuln,secret --format json \ |
| 131 | + --output /work/evidence/dapper-image-raw.json "$DAPPER_IMAGE" |
| 132 | +
|
| 133 | + jq -r ' |
| 134 | + .Results[]?.Vulnerabilities[]? |
| 135 | + | select(.Severity == "CRITICAL" or .Severity == "HIGH") |
| 136 | + | [.VulnerabilityID, .PkgIdentifier.PURL] |
| 137 | + | @tsv |
| 138 | + ' evidence/dapper-image-raw.json | LC_ALL=C sort -u \ |
| 139 | + > /tmp/dapper-critical-high.tsv |
| 140 | + jq -r ' |
| 141 | + .statements[]? |
| 142 | + | select( |
| 143 | + .status == "not_affected" |
| 144 | + and .justification == "vulnerable_code_not_present" |
| 145 | + ) |
| 146 | + | .vulnerability.name as $id |
| 147 | + | .products[]? |
| 148 | + | [$id, .["@id"]] |
| 149 | + | @tsv |
| 150 | + ' security/dapper.openvex.json | LC_ALL=C sort -u \ |
| 151 | + > /tmp/dapper-vex.tsv |
| 152 | + test -s /tmp/dapper-critical-high.tsv |
| 153 | + diff -u /tmp/dapper-critical-high.tsv /tmp/dapper-vex.tsv |
| 154 | + test "$(jq '.statements | length' security/dapper.openvex.json)" \ |
| 155 | + -eq "$(wc -l < /tmp/dapper-vex.tsv)" |
| 156 | + jq -e ' |
| 157 | + all( |
| 158 | + .statements[]; |
| 159 | + .status == "not_affected" |
| 160 | + and .justification == "vulnerable_code_not_present" |
| 161 | + and ((.impact_statement | type) == "string") |
| 162 | + and ((.impact_statement | length) > 0) |
| 163 | + ) |
| 164 | + ' security/dapper.openvex.json >/dev/null |
| 165 | + grep -F $'build\tCGO_ENABLED=0' evidence/product-go-version.txt >/dev/null |
| 166 | + if grep -Eq '^linux-(image|modules)([-:]|[[:space:]])' evidence/dapper-dpkg.tsv; then |
| 167 | + printf 'Unexpected Linux kernel runtime package in Dapper image\n' >&2 |
| 168 | + exit 1 |
| 169 | + fi |
| 170 | + docker run --rm \ |
| 171 | + -v /var/run/docker.sock:/var/run/docker.sock \ |
| 172 | + -v "$PWD:/work" -w /work \ |
| 173 | + -v "$trivy_cache:/root/.cache/trivy" \ |
| 174 | + "$TRIVY_IMAGE" image \ |
| 175 | + --scanners vuln,secret \ |
| 176 | + --vex /work/security/dapper.openvex.json --show-suppressed \ |
| 177 | + --format json \ |
| 178 | + --output /work/evidence/dapper-image-applicable.json "$DAPPER_IMAGE" |
| 179 | + docker run --rm \ |
| 180 | + -v "$source_tree:/scan:ro" \ |
| 181 | + -v "$PWD/evidence:/evidence" \ |
| 182 | + -v "$trivy_cache:/root/.cache/trivy" \ |
| 183 | + "$TRIVY_IMAGE" fs \ |
| 184 | + --format cyclonedx --output /evidence/source.cdx.json /scan |
| 185 | + docker run --rm \ |
| 186 | + -v "$PWD/evidence:/evidence" \ |
| 187 | + -v "$trivy_cache:/root/.cache/trivy" \ |
| 188 | + "$TRIVY_IMAGE" rootfs \ |
| 189 | + --format cyclonedx --output /evidence/product.cdx.json /evidence/product |
| 190 | +
|
| 191 | + - name: Summarize and enforce candidate security |
| 192 | + shell: bash |
| 193 | + run: | |
| 194 | + set -euo pipefail |
| 195 | + count() { |
| 196 | + jq "$2" "$1" |
| 197 | + } |
| 198 | + source_secrets=$(count evidence/source-security.json '[.Results[]?.Secrets[]?] | length') |
| 199 | + source_critical=$(count evidence/source-security.json '[.Results[]?.Vulnerabilities[]? | select(.Severity == "CRITICAL")] | length') |
| 200 | + source_high=$(count evidence/source-security.json '[.Results[]?.Vulnerabilities[]? | select(.Severity == "HIGH")] | length') |
| 201 | + product_secrets=$(count evidence/product-security.json '[.Results[]?.Secrets[]?] | length') |
| 202 | + product_critical=$(count evidence/product-security.json '[.Results[]?.Vulnerabilities[]? | select(.Severity == "CRITICAL")] | length') |
| 203 | + product_high=$(count evidence/product-security.json '[.Results[]?.Vulnerabilities[]? | select(.Severity == "HIGH")] | length') |
| 204 | + dapper_raw_critical=$(count evidence/dapper-image-raw.json '[.Results[]?.Vulnerabilities[]? | select(.Severity == "CRITICAL")] | length') |
| 205 | + dapper_raw_high=$(count evidence/dapper-image-raw.json '[.Results[]?.Vulnerabilities[]? | select(.Severity == "HIGH")] | length') |
| 206 | + dapper_applicable_critical=$(count evidence/dapper-image-applicable.json '[.Results[]?.Vulnerabilities[]? | select(.Severity == "CRITICAL" and .Status != "not_affected")] | length') |
| 207 | + dapper_applicable_high=$(count evidence/dapper-image-applicable.json '[.Results[]?.Vulnerabilities[]? | select(.Severity == "HIGH" and .Status != "not_affected")] | length') |
| 208 | + dapper_secrets=$(count evidence/dapper-image-applicable.json '[.Results[]?.Secrets[]?] | length') |
| 209 | + { |
| 210 | + printf 'source_secrets=%s\n' "$source_secrets" |
| 211 | + printf 'source_critical=%s\n' "$source_critical" |
| 212 | + printf 'source_high=%s\n' "$source_high" |
| 213 | + printf 'product_secrets=%s\n' "$product_secrets" |
| 214 | + printf 'product_critical=%s\n' "$product_critical" |
| 215 | + printf 'product_high=%s\n' "$product_high" |
| 216 | + printf 'dapper_raw_critical=%s\n' "$dapper_raw_critical" |
| 217 | + printf 'dapper_raw_high=%s\n' "$dapper_raw_high" |
| 218 | + printf 'dapper_applicable_critical=%s\n' "$dapper_applicable_critical" |
| 219 | + printf 'dapper_applicable_high=%s\n' "$dapper_applicable_high" |
| 220 | + printf 'dapper_secrets=%s\n' "$dapper_secrets" |
| 221 | + } | tee evidence/security-summary.txt |
| 222 | +
|
| 223 | + test "$source_secrets" -eq 0 |
| 224 | + test "$product_secrets" -eq 0 |
| 225 | + test "$product_critical" -eq 0 |
| 226 | + test "$product_high" -eq 0 |
| 227 | + test "$dapper_applicable_critical" -eq 0 |
| 228 | + test "$dapper_applicable_high" -eq 0 |
| 229 | + test "$dapper_secrets" -eq 0 |
| 230 | +
|
| 231 | + - name: Upload review evidence |
| 232 | + if: always() |
| 233 | + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a |
| 234 | + with: |
| 235 | + name: compose-cli-security-${{ github.sha }} |
| 236 | + path: evidence/ |
| 237 | + if-no-files-found: error |
| 238 | + retention-days: 30 |
| 239 | + |
| 240 | + - name: Clean runner resources |
| 241 | + if: always() |
| 242 | + shell: bash |
| 243 | + run: | |
| 244 | + set +e |
| 245 | + docker rm -f $(docker ps -aq --filter ancestor="$DAPPER_IMAGE") 2>/dev/null |
| 246 | + docker image rm -f "$DAPPER_IMAGE" "$TRIVY_IMAGE" 2>/dev/null |
| 247 | + docker builder prune --all --force >/dev/null 2>&1 |
| 248 | + rm -rf bin build dist evidence/product |
0 commit comments