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
17 changes: 17 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Code owners for laststate-cli.
#
# Ownership is enforced via branch protection ("require review from Code
# Owners") on GitHub; this file alone does not enforce anything.
#
# NOTE: `@laststate` is the repository-owning organization. A human maintainer
# MUST verify this maps to real user/team handles and adjust (e.g.
# `@laststate/maintainers`) before relying on required Code Owner reviews.
# No individual handles are fabricated here.

* @laststate

# Security-sensitive areas - restrict review to maintainers (verify team name).
/.github/ @laststate
/SECURITY.md @laststate
/security.txt @laststate
/.well-known/security.txt @laststate
18 changes: 14 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,33 @@ on:
pull_request:
branches: [master, main]
workflow_dispatch:
permissions:
contents: read

# Least privilege: no token permissions by default; grant per-job below.
permissions: {}

jobs:
build-test:
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- uses: actions/setup-node@v7
with:
persist-credentials: false
- uses: actions/setup-node@8fccf151e3ba8038c300f83b40c8fd1e94f9c5ce # v7
with:
node-version: 20
cache: npm
- name: Install
- name: Install (locked, reproducible; lockfile integrity enforced by npm ci)
run: npm ci
- name: Build
run: npm run build
- name: Test
run: npm test
- name: Audit dependencies (fail on any known vulnerability)
run: npm audit --audit-level=info
- name: Verify registry signatures + attestations
run: npm audit signatures
- name: Smoke test built binary
run: node dist/index.js --help
44 changes: 44 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: CodeQL
# GitHub CodeQL SAST. Actions pinned to immutable SHAs.
on:
push:
branches: [master, main]
pull_request:
branches: [master, main]
schedule:
- cron: '23 4 * * 5' # weekly
workflow_dispatch:

permissions: {}

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
actions: read
contents: read
security-events: write # upload SARIF results
strategy:
fail-fast: false
matrix:
language: [javascript-typescript]
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false

- name: Initialize CodeQL
uses: github/codeql-action/init@915412ff23e8b7659517e607487dbeae018f2934 # v4.39.5
with:
languages: ${{ matrix.language }}
# TypeScript build handled by autobuild; see package.json scripts.
queries: security-extended,security-and-quality

- name: Autobuild
uses: github/codeql-action/autobuild@915412ff23e8b7659517e607487dbeae018f2934 # v4.39.5

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@915412ff23e8b7659517e607487dbeae018f2934 # v4.39.5
25 changes: 25 additions & 0 deletions .github/workflows/gitleaks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Secret scanning (Gitleaks)
# Local + CI secret scan. Action pinned to an immutable SHA.
on:
push:
pull_request:
workflow_dispatch:

permissions: {}

jobs:
gitleaks:
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
fetch-depth: 0
persist-credentials: false
- name: Run Gitleaks
uses: gitleaks/gitleaks-action@e0c47f4f8be36e29cdc102c57e68cb5cbf0e8d1e # v3.0.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53 changes: 33 additions & 20 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,36 @@ name: Release
# Tag a release with: git tag vX.Y.Z && git push origin vX.Y.Z
# The tag MUST equal package.json version (checked below).
#
# npm auth: trusted publishing (OIDC) is preferred — configure it once on
# npm auth: trusted publishing (OIDC) is preferred - configure it once on
# npmjs.com (package settings > Trusted publisher > GitHub Actions, this repo
# + .github/workflows/release.yml). When `NPM_TOKEN` (automation token) is set
# as a repo secret, the workflow falls back to it; otherwise it uses OIDC.
# Without either, the first publish fails with
# `404 'laststate-cli@x.y.z' is not in this registry`.
#
# SCAFFOLDING ONLY in this change: this workflow is NOT executed locally and
# NOTHING is published. `npm publish` is a human-triggered, remote, irreversible
# action. SLSA provenance + SBOM are generated for a real release pipeline;
# see slsa.yml + sbom.yml. We do not claim any published provenance.
on:
push:
tags: ['v*']
permissions:
contents: write
id-token: write

# Least privilege: nothing by default; grant the minimum per job.
permissions: {}

jobs:
publish:
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: write # create GitHub release + upload assets
id-token: write # OIDC for npm provenance + SLSA
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
fetch-depth: 0
persist-credentials: false
- name: Validate tag matches package.json
shell: bash
run: |
Expand All @@ -35,7 +45,7 @@ jobs:
echo "Tag $tag does not match package.json version $pkg" >&2
exit 1
fi
- uses: actions/setup-node@v7
- uses: actions/setup-node@8fccf151e3ba8038c300f83b40c8fd1e94f9c5ce # v7
with:
node-version: 20
cache: npm
Expand All @@ -45,33 +55,36 @@ jobs:
npm ci
npm run build
npm test
- name: Publish to npm
# First publish needs --access public (publishConfig covers it, flag
# kept for explicitness). Provenance requires OIDC; token auth must
# publish without it.
- name: Audit dependencies (fail on any known vulnerability)
run: npm audit --audit-level=info
- name: Verify registry signatures + attestations
run: npm audit signatures
- name: Publish to npm with provenance
# Publishing is remote + irreversible; in this change it is scaffolding.
# Provenance (`--provenance`, OIDC id-token) requires trusted publishing
# or OIDC on a real runner; with NPM_TOKEN auth we still request
# provenance via package.json `publishConfig.provenance`.
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
if [ -n "$NPM_TOKEN" ]; then
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > "$NPM_CONFIG_USERCONFIG"
npm publish --access public
npm publish --provenance --access public
else
npm publish --provenance --access public
fi
- name: Pack tarball for the GitHub release
run: |
npm pack
mkdir -p dist-release && mv laststate-cli-*.tgz dist-release/
- name: Smoke test published package
mkdir -p dist-release
npm pack --pack-destination dist-release
- name: Smoke test packed tarball (no unpinned re-install)
# Extract the packed artifact and run it; avoids `npm install <pkg>` /
# `npx <pkg>` which cannot be pinned by hash. Scaffolding; not run here.
run: |
cd "$(mktemp -d)"
for i in $(seq 1 10); do
npm install laststate-cli@"${GITHUB_REF_NAME#v}" --no-save && break
echo "retry $i: package not yet visible on registry" >&2
sleep 15
done
npx laststate --help
tmp="$(mktemp -d)"
tar -xzf dist-release/laststate-cli-*.tgz -C "$tmp"
node "$tmp/package/dist/index.js" --help
- name: Create GitHub release
uses: softprops/action-gh-release@efb35369e0ad2afab669f228072c1b0d510eae64 # v2
with:
Expand Down
47 changes: 47 additions & 0 deletions .github/workflows/sbom.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: SBOM (syft / anchore)
# Generate a Software Bill of Materials. syft is run locally in this change to
# produce committed artifacts; this workflow is scaffolding for CI/release.
# Action pinned to an immutable SHA.
on:
push:
branches: [master, main]
release:
types: [published]
workflow_dispatch:

permissions: {}

jobs:
sbom:
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false

- name: Build (so SBOM includes shipped output)
uses: actions/setup-node@8fccf151e3ba8038c300f83b40c8fd1e94f9c5ce # v7
with:
node-version: 20
cache: npm
- run: npm ci && npm run build

- name: Generate SPDX SBOM with anchore/sbom-action (syft)
uses: anchore/sbom-action@dfcb83b97731532d72be422cbc51ee64adb6fd56 # v0.24.4
with:
format: spdx-json
output-file: sbom.spdx.json
artifact-name: sbom-spdx-json
upload-artifact: true

- name: Generate CycloneDX SBOM with anchore/sbom-action (syft)
uses: anchore/sbom-action@dfcb83b97731532d72be422cbc51ee64adb6fd56 # v0.24.4
with:
format: cyclonedx-json
output-file: sbom.cdx.json
artifact-name: sbom-cyclonedx-json
upload-artifact: true
49 changes: 49 additions & 0 deletions .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: OpenSSF Scorecard
# https://github.com/ossf/scorecard-action - pinned to an immutable SHA.
on:
branch_protection_rule:
schedule:
- cron: '36 22 * * 2' # weekly
push:
branches: [master, main]
workflow_dispatch:

# Least privilege default; the analysis job grants only what it needs.
permissions: {}

jobs:
analysis:
name: Scorecard analysis
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: read # check out repo
actions: read # read workflow runs for CI checks
security-events: write # upload SARIF to code scanning
id-token: write # OIDC for publishing results
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false

- name: Run OpenSSF Scorecard
uses: ossf/scorecard-action@23f22cd43608bae7a1f1fa2603d7314dee9538a5 # v2.6.0
with:
results_file: results.sarif
results_format: sarif
# Publish to GitHub code scanning + the public OpenSSF API.
# Requires the repo to be public + id-token: write; no local effect.
publish_results: true

- name: Upload SARIF artifact
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: SARIF file
path: results.sarif
retention-days: 5

- name: Upload SARIF to code scanning
uses: github/codeql-action/upload-sarif@915412ff23e8b7659517e607487dbeae018f2934 # v4.39.5
with:
sarif_file: results.sarif
66 changes: 66 additions & 0 deletions .github/workflows/slsa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: SLSA provenance (slsa-github-generator)
# SCAFFOLDING ONLY. This workflow is NOT executed locally; no provenance is
# generated or claimed in this change. It requires a real runner + remote
# release to emit SLSA Build L3 attestations. NOTHING is published.
#
# Reusable workflow pinned to an immutable SHA. NOTE: the upstream
# slsa-github-generator project itself documents that its reusable workflow
# must be referenced for provenance verification; this scaffolding pins a SHA
# for scorecard pinning, and a human MUST verify the intended ref before use.
#
# Separately, npm provenance (`npm publish --provenance`, OIDC id-token) is
# scaffolded in release.yml. We do not claim either has run.
on:
release:
types: [published]
workflow_dispatch:

permissions: {}

jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: read
outputs:
hashes: ${{ steps.hash.outputs.hashes }}
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- name: Setup Node
uses: actions/setup-node@8fccf151e3ba8038c300f83b40c8fd1e94f9c5ce # v7
with:
node-version: 20
cache: npm
- name: Build
run: npm ci && npm run build
- name: Pack npm tarball
run: npm pack --pack-destination .
- name: Generate base64 subject hashes
id: hash
shell: bash
run: |
set -euo pipefail
{
echo "hashes<<__HASHES_EOF__"
sha256sum laststate-cli-*.tgz | base64 -w 0
echo
echo "__HASHES_EOF__"
} >> "$GITHUB_OUTPUT"

provenance:
name: Generate SLSA provenance
needs: build
if: startsWith(github.ref, 'refs/tags/')
permissions:
actions: read
id-token: write
contents: write
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@f7dd8c54c2067bafc12ca7a55595d5ee9b75204a # v2.1.0
with:
base64-subjects: "${{ needs.build.outputs.hashes }}"
upload-assets: true
# SLSA generator emits a .intoto.jsonl attestation alongside artifacts.
Loading
Loading