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
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,13 @@ updates:
time: "09:30"
timezone: Etc/UTC
open-pull-requests-limit: 5

# Keeps the digest-pinned base images in the Dockerfile current.
- package-ecosystem: docker
directory: /
schedule:
interval: weekly
day: monday
time: "10:00"
timezone: Etc/UTC
open-pull-requests-limit: 5
5 changes: 4 additions & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ on:
permissions:
actions: read
contents: read
security-events: write

jobs:
analyze:
name: Analyze (${{ matrix.language }})
runs-on: blacksmith-2vcpu-ubuntu-2404
timeout-minutes: 30
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
Expand Down
18 changes: 10 additions & 8 deletions .github/workflows/image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ on:

permissions:
contents: read
packages: write

concurrency:
group: image-${{ github.ref }}
Expand All @@ -24,16 +23,19 @@ concurrency:
jobs:
image:
runs-on: blacksmith-2vcpu-ubuntu-2404
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0

- uses: docker/setup-buildx-action@v3
- uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0

# Push only on branch/dispatch builds; PRs build-only to validate the Dockerfile.
# The gascity-registry package is connected to this repo (org.opencontainers.image.source
# below), so the per-repo GITHUB_TOKEN (packages: write) publishes it — no PAT.
- if: github.event_name != 'pull_request'
uses: docker/login-action@v3
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
with:
registry: ghcr.io
username: ${{ github.actor }}
Expand All @@ -45,7 +47,7 @@ jobs:
if: github.event_name != 'pull_request'
run: echo "epoch=$(date +%s)" >> "$GITHUB_OUTPUT"
- id: meta
uses: docker/metadata-action@v5
uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0
with:
images: ghcr.io/gascity/gascity-registry
tags: |
Expand All @@ -55,7 +57,7 @@ jobs:
type=raw,value=main-${{ steps.epoch.outputs.epoch }},enable={{is_default_branch}}

- id: build
uses: docker/build-push-action@v6
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
Expand Down Expand Up @@ -86,7 +88,7 @@ jobs:
# works.gascity.com/registry/. The Dockerfile's grep guard fails the build if the apex
# assets weren't actually prefixed (catches a dropped build-arg = the asset-escape bug).
- id: apex-meta
uses: docker/metadata-action@v5
uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0
with:
images: ghcr.io/gascity/gascity-registry
tags: |
Expand All @@ -96,7 +98,7 @@ jobs:
type=raw,value=apex-main-${{ steps.epoch.outputs.epoch }},enable={{is_default_branch}}

- id: apex-build
uses: docker/build-push-action@v6
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/promote.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ on:
permissions:
contents: read
actions: read
packages: write

concurrency:
group: promote
Expand All @@ -28,6 +27,10 @@ env:
jobs:
promote:
runs-on: ubuntu-latest
permissions:
contents: read
actions: read
packages: write
# workflow_run's branches filter matches head_branch, which a fork PR can spoof (a fork branch
# named "main"). Trust only a push, from THIS repo, on main, that succeeded — never a PR/fork.
if: >-
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/update-registry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ on:
- cron: "17 * * * *"

permissions:
contents: write
packages: read # the @gascity/* deps live on GitHub Packages (org-internal)
pull-requests: write # the refresh lands via a PR, not a direct push to main
actions: write # only for the built-in-token fallback, which must dispatch CI itself
contents: read

jobs:
update:
runs-on: blacksmith-2vcpu-ubuntu-2404
permissions:
contents: write
packages: read # the @gascity/* deps live on GitHub Packages (org-internal)
pull-requests: write # the refresh lands via a PR, not a direct push to main
actions: write # only for the built-in-token fallback, which must dispatch CI itself
env:
AGGREGATE_APP_ID: ${{ secrets.AGGREGATE_APP_ID }}
steps:
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# syntax=docker/dockerfile:1
# Stage 1: build the gc binary used for publish request validation.
FROM golang:1.26.10-alpine AS gc-build
FROM golang:1.26.10-alpine@sha256:27f2d3b83cfc5803c8078f8e730af0f7c431bf067afaec8f60a36fb763187cba AS gc-build
WORKDIR /src/gascity
# gascity v1.3.3 — includes `gc … --dev-auth` (#3343), which the CLI e2e + manual-testing
# doc rely on. The previous pin predated that flag. Bump in lockstep with the CLI contract.
Expand All @@ -13,7 +13,7 @@ RUN set -eux; \
/out/gc pack release hash --help >/dev/null

# Stage 2: build the website and typecheck the server.
FROM oven/bun:1 AS build
FROM oven/bun:1.4.4@sha256:1d22548f177f4ff38e0c15baa3c2c46c6c2060ba2d1bc573bb4720b407548f1d AS build
WORKDIR /app
# .npmrc maps @gascity/* to GitHub Packages + reads ${NODE_AUTH_TOKEN}; pass the
# token as a BuildKit secret (never baked into a layer).
Expand All @@ -36,7 +36,7 @@ RUN if [ "$REGISTRY_WEB_BASE" != "/" ]; then \
fi

# Stage 3: serve static assets and /api through the Bun BFF.
FROM oven/bun:1-alpine
FROM oven/bun:1.4.4-alpine@sha256:4cf82f5686b196504fe119db3fcd9185b191f82ece82c40680e597228ec6070a
WORKDIR /app
ENV NODE_ENV=production
ENV PORT=8080
Expand Down
134 changes: 134 additions & 0 deletions scripts/supply-chain-pins.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import { describe, expect, test } from "bun:test";
import { readdirSync, readFileSync } from "node:fs";

// Guards the OpenSSF Scorecard TokenPermissions and PinnedDependencies checks:
// write scopes are granted per job, never at the workflow top level, and every
// third-party action, reusable workflow and base image is pinned to an
// immutable digest.

const workflowDir = new URL("../.github/workflows/", import.meta.url);
const workflowFiles = readdirSync(workflowDir).filter((name) => /\.ya?ml$/.test(name));

type Permissions = string | Record<string, string> | undefined;

type Workflow = {
permissions?: Permissions;
jobs?: Record<string, { uses?: string; steps?: Array<{ uses?: string }> }>;
};

function loadWorkflow(name: string): Workflow {
return Bun.YAML.parse(readFileSync(new URL(name, workflowDir), "utf8")) as Workflow;
}

function writeScopes(permissions: Permissions): string[] {
if (permissions === undefined) return ["<unset: defaults to the repo token policy>"];
if (typeof permissions === "string") return permissions === "read-all" ? [] : [permissions];
return Object.entries(permissions)
.filter(([, level]) => level === "write")
.map(([scope]) => scope);
}

// A full commit SHA for actions and reusable workflows; a content digest for
// docker:// actions.
function isPinned(uses: string): boolean {
return uses.startsWith("docker://")
? /@sha256:[0-9a-f]{64}$/.test(uses)
: /@[0-9a-f]{40}$/.test(uses);
}

function unpinnedActions(workflow: Workflow): string[] {
return Object.values(workflow.jobs ?? {})
.flatMap((job) => [job.uses, ...(job.steps ?? []).map((step) => step.uses)])
.filter((uses): uses is string => typeof uses === "string" && !uses.startsWith("./"))
.filter((uses) => !isPinned(uses));
}

// `scratch` and earlier stage names (both case-insensitive) pull nothing, so
// they need no digest.
function unpinnedBaseImages(dockerfile: string): string[] {
const local = new Set(["scratch"]);
const unpinned: string[] = [];
for (const match of dockerfile.matchAll(/^FROM\s+(?:--\S+\s+)*(\S+)(?:\s+AS\s+(\S+))?/gim)) {
const image = match[1]!;
if (!local.has(image.toLowerCase()) && !/@sha256:[0-9a-f]{64}$/.test(image)) {
unpinned.push(image);
}
if (match[2]) local.add(match[2].toLowerCase());
}
return unpinned;
}

describe("workflow token permissions", () => {
test("finds the workflows", () => {
expect(workflowFiles.length).toBeGreaterThan(0);
});

for (const name of workflowFiles) {
test(`${name} grants no write scope at the top level`, () => {
expect(writeScopes(loadWorkflow(name).permissions)).toEqual([]);
});
}
});

describe("workflow action pins", () => {
for (const name of workflowFiles) {
test(`${name} pins every action and reusable workflow`, () => {
expect(unpinnedActions(loadWorkflow(name))).toEqual([]);
});
}
});

describe("Dockerfile base images", () => {
test("pins every external base image by digest", () => {
const dockerfile = readFileSync(new URL("../Dockerfile", import.meta.url), "utf8");
expect(unpinnedBaseImages(dockerfile)).toEqual([]);
});
});

describe("pin detection", () => {
const sha = "a".repeat(40);
const digest = `sha256:${"b".repeat(64)}`;

test("counts only write levels as top-level write scopes", () => {
expect(writeScopes("read-all")).toEqual([]);
expect(writeScopes({})).toEqual([]);
expect(writeScopes({ contents: "read", "id-token": "write" })).toEqual(["id-token"]);
expect(writeScopes("write-all")).toEqual(["write-all"]);
expect(writeScopes(undefined)).toHaveLength(1);
});

test("flags tag-pinned actions and reusable workflows, not SHA-pinned or local ones", () => {
const workflow: Workflow = {
jobs: {
build: {
steps: [
{ uses: "actions/checkout@v4" },
{ uses: `actions/checkout@${sha}` },
{ uses: "./.github/actions/local" },
{ uses: "docker://alpine:3.20" },
{ uses: `docker://alpine@${digest}` },
],
},
shared: { uses: "example/workflows/.github/workflows/ci.yml@main" },
pinned: { uses: `example/workflows/.github/workflows/ci.yml@${sha}` },
local: { uses: "./.github/workflows/local.yml" },
},
};
expect(unpinnedActions(workflow)).toEqual([
"actions/checkout@v4",
"docker://alpine:3.20",
"example/workflows/.github/workflows/ci.yml@main",
]);
});

test("flags undigested base images, not stage references or scratch", () => {
const dockerfile = [
`FROM golang:1.26-alpine@${digest} AS Builder`,
"FROM --platform=$BUILDPLATFORM oven/bun:1 AS web",
"from builder",
"FROM scratch",
"FROM web",
].join("\n");
expect(unpinnedBaseImages(dockerfile)).toEqual(["oven/bun:1"]);
});
});
Loading