eBPF-based security platform
ci: add a DCO checker and run it as the DCO workflow
Daniel Borkmann8588ac0523c4
diff --git a/.github/scripts/check-dco.sh b/.github/scripts/check-dco.shnew file mode 100755index 00000000..ff8292a9--- /dev/null+++ b/.github/scripts/check-dco.sh@@ -0,0 +1,118 @@+#!/bin/sh+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo+#+# .github/scripts/check-dco.sh -- verify that every commit in a range has the+# message Documentation/contributing.rst asks for: a one-line subject, a+# body that says more than its tags, and the Signed-off-by of its author,+# the Developer's Certificate of Origin. Merge commits are not signed in+# the kernel's process and are skipped.+#+# .github/scripts/check-dco.sh [<rev-list arguments>]+#+# The arguments go to git rev-list: a range such as origin/main..HEAD,+# or -3 HEAD. Without any, the commit at HEAD alone is checked.++set -eu++if [ $# -eq 0 ]; then+ set -- -1 HEAD+fi++bad=0+checked=0++report() {+ failed=1+ if [ -n "${GITHUB_ACTIONS:-}" ]; then+ printf '::error::%s\n' "$*"+ fi+ printf 'error: %s\n' "$*" >&2+}++lower() {+ printf '%s' "$1" | tr '[:upper:]' '[:lower:]'+}++commits=$(git rev-list --no-merges "$@")++for commit in $commits; do+ checked=$((checked + 1))+ failed=0+ id=$(git log -1 --format='%h ("%s")' "$commit")+ author=$(git log -1 --format='%an <%ae>' "$commit")+ message=$(git log -1 --format=%B "$commit")+ signoffs=$(printf '%s\n' "$message" | grep -i '^signed-off-by:' || :)++ # The subject is the first paragraph and one line; the body follows+ # the blank line after it, and tag lines alone do not make one.+ nsubject=$(printf '%s\n' "$message" | sed '/^[[:space:]]*$/q' | grep -c . || :)+ body=$(printf '%s\n' "$message" | sed '1,/^[[:space:]]*$/d' |+ grep -Ev '^[[:space:]]*$|^[A-Za-z][A-Za-z0-9-]*:[[:space:]]' || :)+ if [ "$nsubject" -eq 0 ]; then+ report "$id: empty commit message"+ bad=$((bad + 1))+ continue+ fi+ if [ "$nsubject" -gt 1 ]; then+ report "$id: the subject runs on for $nsubject lines; one line, a blank line, then the body"+ bad=$((bad + 1))+ continue+ fi+ if [ -z "$body" ]; then+ report "$id: no body text; a subject and tags alone do not say why the change is made"+ bad=$((bad + 1))+ continue+ fi+ if [ -z "$signoffs" ]; then+ report "$id: no Signed-off-by: line; sign the commit with git commit -s"+ bad=$((bad + 1))+ continue+ fi++ # One finding per commit: the first ill-formed sign-off line, else+ # the absence of the author's.+ problem=''+ by_author=0+ while IFS= read -r line; do+ value=$(printf '%s' "$line" |+ sed 's/^[Ss][Ii][Gg][Nn][Ee][Dd]-[Oo][Ff][Ff]-[Bb][Yy]:[[:space:]]*//; s/[[:space:]]*$//')+ if [ "$(lower "$value")" = "$(lower "$author")" ]; then+ by_author=1+ fi+ [ -z "$problem" ] || continue+ case "$line" in+ 'Signed-off-by: '*)+ ;;+ *)+ problem="the tag is spelled 'Signed-off-by: ', found: $line"+ continue+ ;;+ esac+ # A name and an address in angle brackets, as git commit -s+ # writes them; an address alone or a name alone is no identity.+ if ! printf '%s\n' "$value" |+ grep -Eq '^[^<>]*[^<>[:space:]][^<>]* <[^<>@[:space:]]+@[^<>@[:space:]]+>$'; then+ problem="malformed sign-off, expected 'Name <email>', found: $line"+ fi+ done <<EOT+$signoffs+EOT++ if [ -n "$problem" ]; then+ report "$id: $problem"+ elif [ "$by_author" -eq 0 ]; then+ found=$(printf '%s\n' "$signoffs" | sed 's/^[Ss]igned-off-by:[[:space:]]*//' |+ tr '\n' ',' | sed 's/,$//; s/,/, /g')+ report "$id: no sign-off by the author, expected 'Signed-off-by: $author', found: $found"+ fi+ if [ "$failed" -ne 0 ]; then+ bad=$((bad + 1))+ fi+done++if [ "$bad" -gt 0 ]; then+ printf '%d of %d commits fail the DCO check\n' "$bad" "$checked" >&2+ exit 1+fi+printf 'DCO: %d commits checked\n' "$checked"diff --git a/.github/workflows/dco.yml b/.github/workflows/dco.ymlnew file mode 100644index 00000000..b6177ec7--- /dev/null+++ b/.github/workflows/dco.yml@@ -0,0 +1,43 @@+name: DCO++on:+ push:+ branches:+ - main+ pull_request:++permissions:+ contents: read++jobs:+ dco:+ name: Signed-off-by+ runs-on: ubuntu-latest++ steps:+ - name: Check out repository+ uses: actions/checkout@v4+ with:+ fetch-depth: 0++ # Every commit a pull request adds, or a push brings to main, needs+ # a subject, a body and its author's sign-off. A push whose previous+ # tip is unknown, after a force push, is checked at the pushed tip+ # alone.+ - name: Check the sign-off of every commit+ env:+ EVENT_NAME: ${{ github.event_name }}+ BASE_SHA: ${{ github.event.pull_request.base.sha }}+ HEAD_SHA: ${{ github.event.pull_request.head.sha }}+ BEFORE_SHA: ${{ github.event.before }}+ SHA: ${{ github.sha }}+ run: |+ if [ "$EVENT_NAME" = pull_request ]; then+ set -- "$BASE_SHA..$HEAD_SHA"+ elif git cat-file -e "$BEFORE_SHA^{commit}" 2>/dev/null; then+ set -- "$BEFORE_SHA..$SHA"+ else+ echo "::notice::previous tip $BEFORE_SHA is unknown; checking the pushed tip alone"+ set -- -1 "$SHA"+ fi+ .github/scripts/check-dco.sh "$@"diff --git a/AGENTS.md b/AGENTS.mdindex b231ea84..d68faa18 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -299,8 +299,10 @@ one usually still compiles and passes tests.- `.github/scripts/check-spdx.sh` checks the SPDX tag of every trackedsource against the licensing rules above: the form for the file type,the expression, the dual licence for everything a BPF object compiles- and a Beefile ships. CI runs it on every pull request; run it before- handing work over.+ and a Beefile ships. `.github/scripts/check-dco.sh <range>` checks+ that every commit has a one-line subject, a body beyond its tags and+ the author's sign-off. CI runs both on every pull request; run them+ before handing work over.- `make -C packaging bindeb-pkg`, `make -C packaging binrpm-pkg` and `make -C packaging bintar-pkg` build thedistribution packages. The target package is static apart from glibcand portable; the operator package links the host's shared librariesdiff --git a/Documentation/contributing.rst b/Documentation/contributing.rstindex bc5dca0f..b54a6c39 100644--- a/Documentation/contributing.rst+++ b/Documentation/contributing.rst@@ -126,7 +126,10 @@ A commit without a valid sign-off is not merged, and a maintainer whoapplies a commit adds their own sign-off after the author's, so thechain of ``Signed-off-by:`` lines records the real route the changetook. The first sign-off is the author's; the last is the person who-submits the commit.+submits the commit. ``.github/scripts/check-dco.sh`` verifies that+every commit in a range has a one-line subject, a body that says more+than its tags and its author's sign-off, and CI runs it on every pull+request as the ``DCO`` check.Only a person can certify the DCO. Coding agents and other automatedtools must never add a ``Signed-off-by:`` line; the human who reviews@@ -203,7 +206,9 @@ Before sendingevery source carries an SPDX tag in the kernel's form for its type,``BSD-2-Clause`` for userspace and ``GPL-2.0 OR BSD-2-Clause`` foreverything compiled into a BPF object, the headers it includes and- the decoders a package ships. CI runs it.+ the decoders a package ships. Run+ ``.github/scripts/check-dco.sh origin/main..HEAD`` on the commits. CI+ runs both.* Keep each commit to one logical change that builds and passes on itsown, so the history bisects.* Read `threat-model <threat-model.rst>`__ before changing anything on adiff --git a/testing/t0041-check-dco.sh b/testing/t0041-check-dco.shnew file mode 100755index 00000000..88a5face--- /dev/null+++ b/testing/t0041-check-dco.sh@@ -0,0 +1,163 @@+#!/bin/sh+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo+#+# t0041 -- .github/scripts/check-dco.sh: the subject, body and sign-off every+# commit needs, the forms it rejects, the author the sign-off must come+# from and the merge commits it skips, on a throwaway repository.++cd "$(dirname "$0")"+. ./test-lib.sh+command -v git >/dev/null 2>&1 || test_skip_all "git not installed"+S=$(cd .. && pwd)/.github/scripts/check-dco.sh+W=$(mktemp -d)+trap 'rm -rf "$W"' EXIT+R=$W/repo+export GIT_AUTHOR_NAME='Random J Developer' GIT_AUTHOR_EMAIL='[email protected]'+export GIT_COMMITTER_NAME='Random J Developer' GIT_COMMITTER_EMAIL='[email protected]'+git init -q "$R"+git -C "$R" config commit.gpgsign false++commit() {+ msg=$1+ shift+ git -C "$R" commit -q --allow-empty -m "$msg" "$@"+}++check() {+ (cd "$R" && sh "$S" "$@") >"$W/out" 2>"$W/err"+}++test_expect_success 'a commit with a subject, a body and the author sign-off passes' '+ commit "a: first++Why the change is made." -s &&+ check &&+ grep -q "DCO: 1 commits checked" "$W/out"+'++test_expect_success 'a commit without a sign-off fails' '+ commit "a: unsigned++Why the change is made." &&+ ! check &&+ grep -q "no Signed-off-by: line" "$W/err" &&+ grep -q "1 of 1 commits fail" "$W/err"+'++test_expect_success 'a sign-off by someone else is not the author'"'"'s' '+ commit "a: someone else++Why the change is made.++Signed-off-by: Other Person <[email protected]>" &&+ ! check &&+ grep -q "no sign-off by the author, expected .Signed-off-by: Random J Developer <[email protected]>., found: Other Person <[email protected]>" "$W/err"+'++test_expect_success 'a sign-off without an address is malformed' '+ commit "a: no address++Why the change is made.++Signed-off-by: Random J Developer" &&+ ! check &&+ grep -q "malformed sign-off" "$W/err"+'++test_expect_success 'a sign-off with an address alone is malformed' '+ commit "a: no name++Why the change is made.++Signed-off-by: <[email protected]>" &&+ ! check &&+ grep -q "malformed sign-off" "$W/err"+'++test_expect_success 'the tag keeps its spelling' '+ commit "a: spelling++Why the change is made.++signed-off-by: Random J Developer <[email protected]>" &&+ ! check &&+ grep -q "spelled .Signed-off-by: ." "$W/err"+'++test_expect_success 'the identity compares without case' '+ commit "a: case++Why the change is made.++Signed-off-by: RANDOM J DEVELOPER <[email protected]>" &&+ check+'++test_expect_success 'the author sign-off counts among several' '+ commit "a: chain++Why the change is made.++Co-developed-by: Other Person <[email protected]>+Signed-off-by: Other Person <[email protected]>+Signed-off-by: Random J Developer <[email protected]>" &&+ check+'++test_expect_success 'an empty message fails' '+ commit "" --allow-empty-message &&+ ! check &&+ grep -q "empty commit message" "$W/err"+'++test_expect_success 'a subject with the sign-off alone has no body' '+ commit "a: bare" -s &&+ ! check &&+ grep -q "no body text" "$W/err"+'++test_expect_success 'tags alone do not make a body' '+ commit "a: tags only++Fixes: 1234567890ab (\"a: earlier\")+Link: https://example.org/report+Signed-off-by: Random J Developer <[email protected]>" &&+ ! check &&+ grep -q "no body text" "$W/err"+'++test_expect_success 'a subject running into the body is not a subject' '+ commit "a: glued+Why the change is made.+Signed-off-by: Random J Developer <[email protected]>" &&+ ! check &&+ grep -q "the subject runs on for 3 lines" "$W/err"+'++test_expect_success 'a range reports every failing commit once' '+ ! check -12 HEAD &&+ [ "$(grep -c "^error:" "$W/err")" -eq 9 ] &&+ grep -q "9 of 12 commits fail" "$W/err"+'++test_expect_success 'merge commits are skipped' '+ base=$(git -C "$R" rev-parse HEAD) &&+ git -C "$R" checkout -q -b side &&+ commit "b: side++Why the change is made." -s &&+ git -C "$R" checkout -q - &&+ commit "a: mainline++Why the change is made." -s &&+ git -C "$R" merge -q --no-ff -m "Merge branch side" side &&+ check "$base..HEAD" &&+ grep -q "DCO: 2 commits checked" "$W/out"+'++test_expect_success 'an unknown range fails' '+ ! check nonexistent..HEAD+'++test_done