ci: add basic job to check new key additions and removals

This commit is contained in:
Levente Polyak 2021-04-29 23:58:47 +02:00
parent feab8a68eb
commit 38c96658c2
No known key found for this signature in database
GPG Key ID: FC1B547C8D8172C8
2 changed files with 64 additions and 0 deletions

26
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,26 @@
image: archlinux:latest
stages:
- lint
variables:
PACMAN_CACHE: "${CI_PROJECT_DIR}/.pacman/pkg"
cache:
paths:
- .pacman/pkg
key: ${CI_JOB_NAME}
check-new-key:
stage: lint
needs: []
script:
- install -d "${PACMAN_CACHE}"
- pacman -Syu --needed --noconfirm --cachedir "${PACMAN_CACHE}" git grep hopenpgp-tools sequoia-keyring-linter
- ./.gitlab/check-keyids-change
only:
refs:
- merge_requests
changes:
- master-keyids
- packager-keyids

38
.gitlab/check-keyids-change Executable file
View File

@ -0,0 +1,38 @@
#!/bin/bash
set -eo pipefail
if [[ -z "${CI_MERGE_REQUEST_DIFF_BASE_SHA}" ]]; then
echo "CI_MERGE_REQUEST_DIFF_BASE_SHA is not set"
exit 1
fi
GNUPGHOME="$(mktemp -d --tmpdir archlinux-keyring-XXXXXXXXX)"
export GNUPGHOME
trap 'rm -rf $GNUPGHOME' EXIT INT TERM QUIT
for NEW_KEY in $(git diff --color=never "${CI_MERGE_REQUEST_DIFF_BASE_SHA}" -- master-keyids packager-keyids | grep -oP '^\+(\K[A-Z0-9]{40})'); do
echo "Receive gpg key ${NEW_KEY} ..."
gpg --recv "${NEW_KEY}"
echo "Export gpg key ${NEW_KEY} ..."
gpg --export "${NEW_KEY}" > "${GNUPGHOME}/${NEW_KEY}"
echo "Lint gpg key ${NEW_KEY} via hokey..."
hokey lint < "${GNUPGHOME}/${NEW_KEY}"
echo "Lint gpg key ${NEW_KEY} via sq-keyring-linter..."
sq-keyring-linter "${GNUPGHOME}/${NEW_KEY}"
done
for REMOVED_KEY in $(git diff --color=never "${CI_MERGE_REQUEST_DIFF_BASE_SHA}" -- packager-keyids | grep -oP '^\-(\K[A-Z0-9]{40})'); do
echo "Check if removed packager key ${REMOVED_KEY} is added to revoked keys..."
git diff --color=never "${CI_MERGE_REQUEST_DIFF_BASE_SHA}" -- packager-revoked-keyids | grep -E "^\+${REMOVED_KEY}\s"
echo "Receive gpg key ${REMOVED_KEY} ..."
gpg --recv "${REMOVED_KEY}"
SHORT_KEYID="${REMOVED_KEY:24:16}"
echo "Check if key ${SHORT_KEYID} is still used by a package..."
if pacman -Sii | grep -m1 "${SHORT_KEYID}"; then
exit 1
fi
done