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
14 changes: 14 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Keeps the SHA-pinned GitHub Actions current: each update is a PR that moves
# the commit SHA and its "# vX.Y.Z" comment together, and goes through CI
# and review like any change.
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
groups:
actions:
patterns: ["*"]
commit-message:
prefix: "ci"
105 changes: 105 additions & 0 deletions .github/scripts/check_workflows.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
"""Supply-chain rules for every GitHub Actions workflow in this repository.

Fails (exit 1) when a workflow:

- uses an action by tag or branch instead of a full commit SHA, or without
the version it stands for in a comment (`uses: owner/repo@<40 hex> # v1.2.3`).
Local actions (`./...`) and `docker://image@sha256:...` are fine;
- runs on `pull_request_target` or `workflow_run` (both run with this
repository's secrets on behalf of code or events a stranger controls);
- puts untrusted values (`github.event.*`, `github.head_ref`, `inputs.*`) straight into
a `run:` script, where they become shell code; pass them through `env:`;
- has no top-level or per-job `permissions:` (the token's default can write).

python3 .github/scripts/check_workflows.py [.github/workflows]
"""

import pathlib
import re
import sys

import yaml

SHA_PIN = re.compile(r"^[^@\s]+@[0-9a-f]{40}$")
DOCKER_PIN = re.compile(r"^docker://[^@\s]+@sha256:[0-9a-f]{64}$")
VERSION_COMMENT = re.compile(r"#\s*\S+")
UNTRUSTED = re.compile(r"\$\{\{[^}]*\b(github\.event\.|github\.head_ref|inputs\.)[^}]*\}\}")
FORBIDDEN_TRIGGERS = {"pull_request_target", "workflow_run"}


def _triggers(doc):
# PyYAML reads the key `on` as True.
on = doc.get("on", doc.get(True))
if isinstance(on, str):
return {on}
if isinstance(on, list):
return set(on)
if isinstance(on, dict):
return set(on)
return set()


def check_text(name, text):
"""The problems in one workflow file, as 'file:line: message' strings."""
problems = []
lines = text.split("\n")
for i, line in enumerate(lines, 1):
m = re.match(r"^\s*(?:-\s+)?uses:\s*([^\s#]+)\s*(#.*)?$", line)
if not m:
continue
ref, comment = m.group(1).strip("'\""), m.group(2) or ""
if ref.startswith("./"):
continue
if ref.startswith("docker://"):
if not DOCKER_PIN.match(ref):
problems.append(f"{name}:{i}: {ref} must be pinned by digest (docker://image@sha256:...)")
continue
if not SHA_PIN.match(ref):
problems.append(f"{name}:{i}: {ref} must be pinned by full commit SHA (owner/repo@<40 hex> # vX.Y.Z)")
elif not VERSION_COMMENT.match(comment):
problems.append(f"{name}:{i}: {ref} needs the version it stands for in a comment (# vX.Y.Z)")

try:
doc = yaml.safe_load(text) or {}
except yaml.YAMLError as e:
return problems + [f"{name}: not valid YAML: {e}"]
for t in sorted(_triggers(doc) & FORBIDDEN_TRIGGERS):
problems.append(f"{name}: runs on {t}, which hands this repository's secrets to code or events others control")

jobs = doc.get("jobs") or {}
if "permissions" not in doc:
for job_id, job in jobs.items():
if isinstance(job, dict) and "permissions" not in job:
problems.append(f"{name}: job {job_id} has no permissions (set them at the top or on the job)")

for job_id, job in jobs.items():
for step in (job or {}).get("steps") or []:
run = step.get("run") if isinstance(step, dict) else None
if isinstance(run, str):
for m in UNTRUSTED.finditer(run):
problems.append(f"{name}: job {job_id}: {m.group(0)} is used inside run:; pass it through env: instead")
return problems


def check_dir(path):
problems = []
files = sorted(pathlib.Path(path).glob("*.y*ml"))
for f in files:
problems += check_text(str(f), f.read_text())
return files, problems


def main(argv):
path = argv[1] if len(argv) > 1 else ".github/workflows"
files, problems = check_dir(path)
for p in problems:
print(p)
if problems:
print(f"{len(problems)} problem(s) in {len(files)} workflow(s)")
return 1
print(f"{len(files)} workflows: every action pinned by SHA, no untrusted triggers or inputs in scripts")
return 0


if __name__ == "__main__":
sys.exit(main(sys.argv))
71 changes: 71 additions & 0 deletions .github/scripts/test_check_workflows.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
"""Tests for check_workflows.py, and the repository's own workflows against it.

Run: python3 -m unittest discover -s .github/scripts
"""

import pathlib
import sys
import unittest

sys.path.insert(0, str(pathlib.Path(__file__).parent))
import check_workflows as cw # noqa: E402

SHA = "11d5960a326750d5838078e36cf38b85af677262"


def wf(steps, on="push:\n branches: [main]", top_permissions=True):
perms = "permissions:\n contents: read\n" if top_permissions else ""
body = "\n".join(f" {s}" for s in steps)
return f"name: t\non:\n {on.replace(chr(10), chr(10) + ' ')}\n{perms}jobs:\n a:\n runs-on: ubuntu-latest\n steps:\n{body}\n"


class Pins(unittest.TestCase):
def test_sha_with_version_comment_passes(self):
self.assertEqual(cw.check_text("w", wf([f"- uses: actions/checkout@{SHA} # v4.4.0"])), [])

def test_tags_branches_and_short_shas_fail(self):
for ref in ("actions/checkout@v4", "dtolnay/rust-toolchain@stable", "actions/checkout@11d5960", "actions/checkout@main"):
p = cw.check_text("w", wf([f"- uses: {ref}"]))
self.assertTrue(any("full commit SHA" in x for x in p), ref)

def test_a_sha_needs_its_version_in_a_comment(self):
p = cw.check_text("w", wf([f"- uses: actions/checkout@{SHA}"]))
self.assertTrue(any("version it stands for" in x for x in p))

def test_local_and_digest_pinned_docker_pass(self):
self.assertEqual(cw.check_text("w", wf(["- uses: ./.github/actions/x", "- uses: docker://alpine@sha256:" + "a" * 64])), [])
self.assertTrue(cw.check_text("w", wf(["- uses: docker://alpine:3"])))


class Triggers(unittest.TestCase):
def test_pull_request_target_and_workflow_run_fail(self):
for on in ("pull_request_target:\n branches: [main]", "workflow_run:\n workflows: [CI]"):
p = cw.check_text("w", wf([f"- uses: actions/checkout@{SHA} # v4.4.0"], on=on))
self.assertTrue(any("hands this repository's secrets" in x for x in p), on)


class Scripts(unittest.TestCase):
def test_untrusted_values_in_run_fail(self):
for expr in ("${{ github.event.pull_request.title }}", "${{ github.head_ref }}", "${{ inputs.tag }}", "${{ github.event.inputs.tag || github.ref_name }}"):
p = cw.check_text("w", wf([f'- run: echo "{expr}"']))
self.assertTrue(any("pass it through env" in x for x in p), expr)

def test_env_is_fine(self):
steps = ["- env:", " T: ${{ github.event.pull_request.title }}", ' run: echo "$T"']
self.assertEqual(cw.check_text("w", wf(steps)), [])

def test_permissions_are_required(self):
p = cw.check_text("w", wf([f"- uses: actions/checkout@{SHA} # v4.4.0"], top_permissions=False))
self.assertTrue(any("has no permissions" in x for x in p))


class ThisRepository(unittest.TestCase):
def test_every_workflow_here_passes(self):
root = pathlib.Path(__file__).resolve().parents[1] / "workflows"
files, problems = cw.check_dir(root)
self.assertGreater(len(files), 0)
self.assertEqual(problems, [])


if __name__ == "__main__":
unittest.main()
64 changes: 47 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,52 @@ concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

# Pull requests (including from forks) get a read-only token and no secrets.
permissions:
contents: read

env:
CARGO_TERM_COLOR: always

jobs:
# Every action pinned by commit SHA, no pull_request_target, no untrusted
# values in scripts (.github/scripts/check_workflows.py), and actionlint.
workflows:
name: Workflow security
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
persist-credentials: false
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
with:
python-version: "3.12"
- name: Pinned actions and safe triggers
run: |
pip install --quiet pyyaml==6.0.2
python3 .github/scripts/check_workflows.py
- name: actionlint
env:
ACTIONLINT_VERSION: 1.7.12
ACTIONLINT_SHA256: 8aca8db96f1b94770f1b0d72b6dddcb1ebb8123cb3712530b08cc387b349a3d8
run: |
curl --proto =https -fsSL -o "$RUNNER_TEMP/al.tgz" "https://github.com/rhysd/actionlint/releases/download/v${ACTIONLINT_VERSION}/actionlint_${ACTIONLINT_VERSION}_linux_amd64.tar.gz"
echo "${ACTIONLINT_SHA256} $RUNNER_TEMP/al.tgz" | sha256sum -c -
tar -xzf "$RUNNER_TEMP/al.tgz" -C "$RUNNER_TEMP" actionlint
"$RUNNER_TEMP/actionlint" -color

rust:
name: Rust (workspace)
runs-on: ubuntu-latest
defaults:
run:
working-directory: services
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
- uses: dtolnay/rust-toolchain@b725eda525362e7cf34af9a7243cac1e3f01a7ec # stable
with:
components: rustfmt, clippy
- uses: Swatinem/rust-cache@v2
- uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3
with:
workspaces: services
cache-on-failure: true
Expand All @@ -37,8 +67,8 @@ jobs:
name: Lambda (Python)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
with:
python-version: "3.12"
- run: python3 -m unittest discover -s lambda/tests
Expand All @@ -50,8 +80,8 @@ jobs:
run:
working-directory: lambda/mcp-proxy
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: lts/*
- run: npm ci
Expand All @@ -64,14 +94,14 @@ jobs:
run:
working-directory: coderhelm-jira
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: lts/*
# Pure rules only (no Forge runtime); `forge lint` needs a login and
# runs in the release workflow (jira-app-release.yml).
- run: npm test
- uses: actions/setup-python@v5
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
with:
python-version: "3.12"
# The release workflow's permission check (scopes, egress, web triggers).
Expand All @@ -88,8 +118,8 @@ jobs:
run:
working-directory: infra
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: lts/*
cache: npm
Expand Down Expand Up @@ -118,8 +148,8 @@ jobs:
run:
working-directory: installer
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: lts/*
- run: npm test
Expand All @@ -129,13 +159,13 @@ jobs:
name: Launch Stack (template and installer)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: lts/*
# The installer the stack runs, and the release's template stamping.
- run: node --test selfhost/launch/*.test.mjs
- uses: actions/setup-python@v5
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
with:
python-version: "3.12"
- name: cfn-lint the CloudFormation templates
Expand Down
24 changes: 13 additions & 11 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,19 @@ jobs:
needs: [gate]
if: needs.gate.outputs.changed == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
- uses: dtolnay/rust-toolchain@b725eda525362e7cf34af9a7243cac1e3f01a7ec # stable
with:
targets: aarch64-unknown-linux-musl
# Cache ~/.cargo/registry + services/target in one hit for both crates
- uses: Swatinem/rust-cache@v2
- uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3
with:
workspaces: services
cache-on-failure: true
- uses: mlugg/setup-zig@v2
- uses: mlugg/setup-zig@d1434d08867e3ee9daa34448df10607b98908d29 # v2.2.1
- name: Install cargo-zigbuild
run: pip3 install --retries 3 --timeout 60 cargo-zigbuild
# Build both gateway + worker in one invocation — shared deps compiled once
Expand All @@ -83,11 +85,11 @@ jobs:
rm bootstrap
cp services/target/aarch64-unknown-linux-musl/release/worker bootstrap
zip worker.zip bootstrap
- uses: actions/upload-artifact@v4
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: gateway
path: gateway.zip
- uses: actions/upload-artifact@v4
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: worker
path: worker.zip
Expand All @@ -101,24 +103,24 @@ jobs:
id-token: write
contents: read
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: lts/*
cache: npm
cache-dependency-path: |
infra/package-lock.json

- uses: actions/download-artifact@v4
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
name: gateway
path: artifacts/
- uses: actions/download-artifact@v4
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
name: worker
path: artifacts/

- uses: aws-actions/configure-aws-credentials@v4
- uses: aws-actions/configure-aws-credentials@7474bc4690e29a8392af63c5b98e7449536d5c3a # v4.3.1
with:
role-to-assume: ${{ secrets.AWS_DEPLOY_ROLE_ARN }}
aws-region: ${{ env.AWS_REGION }}
Expand Down
Loading
Loading