From a9c2b2e93bce1c549832b735d7535aacce105634 Mon Sep 17 00:00:00 2001 From: unkin-agent Date: Thu, 19 Nov 2026 21:55:16 +1100 Subject: [PATCH] Add GitHub Actions CI and GoReleaser release --- .github/CODEOWNERS | 1 + .github/workflows/ci.yml | 52 +++++++++++++++++++ .github/workflows/release.yml | 38 ++++++++++++++ .goreleaser.yml | 56 +++++++++++++++++++++ .woodpecker/release.yml | 66 ------------------------- Makefile | 8 ++- README.md | 2 +- packaging/nfpm.yaml | 35 ------------- packaging/scripts/preinstall-openbao.sh | 3 ++ packaging/scripts/preinstall-vault.sh | 3 ++ packaging/scripts/preinstall.sh.tmpl | 4 -- scripts/build-rpm.sh | 44 ----------------- scripts/sign.sh | 9 ++++ 13 files changed, 166 insertions(+), 155 deletions(-) create mode 100644 .github/CODEOWNERS create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/release.yml create mode 100644 .goreleaser.yml delete mode 100644 .woodpecker/release.yml delete mode 100644 packaging/nfpm.yaml create mode 100644 packaging/scripts/preinstall-openbao.sh create mode 100644 packaging/scripts/preinstall-vault.sh delete mode 100755 packaging/scripts/preinstall.sh.tmpl delete mode 100755 scripts/build-rpm.sh create mode 100755 scripts/sign.sh diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..711107c --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @IUCLabs/maintainers diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..61a15a7 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,52 @@ +name: ci + +on: + pull_request: + push: + branches: [main] + +permissions: + contents: read + +concurrency: + group: ci-${{ github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +jobs: + pre-commit: + runs-on: iuclabs-k8s + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0 + with: + go-version-file: go.mod + - uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3 + - run: uvx pre-commit run --all-files --show-diff-on-failure + + lint: + runs-on: iuclabs-k8s + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0 + with: + go-version-file: go.mod + - run: go vet ./... + + test: + runs-on: iuclabs-k8s + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0 + with: + go-version-file: go.mod + # runner image has no C toolchain, so no -race + - run: go test -count=1 ./... + + build: + runs-on: iuclabs-k8s + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0 + with: + go-version-file: go.mod + - run: go build -trimpath -ldflags="-s -w" ./... diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..3f4f4e4 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,38 @@ +name: release + +on: + push: + tags: ["v*"] + +permissions: + contents: write + id-token: write + +env: + VAULT_ADDR: https://vault.service.consul:8200 + +jobs: + release: + runs-on: iuclabs-release + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 0 + - uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0 + with: + go-version-file: go.mod + - uses: hashicorp/vault-action@892a26828f195e65540a40b4768ae4571f51ebfc # v4.0.0 + with: + url: ${{ env.VAULT_ADDR }} + method: jwt + path: jwt/github/iuclabs + role: release + jwtGithubAudience: ${{ env.VAULT_ADDR }} + exportToken: true + - uses: goreleaser/goreleaser-action@a4f02ab5355a589de60d917a659ce617ed19b3de # v7.3.0 + with: + distribution: goreleaser + version: v2.20.2 + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..46c9289 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,56 @@ +version: 2 +project_name: vault-plugin-secrets-gpg + +builds: + - main: ./cmd/vault-plugin-secrets-gpg + env: + - CGO_ENABLED=0 + mod_timestamp: "{{ .CommitTimestamp }}" + flags: + - -trimpath + ldflags: + - -s -w + goos: [linux] + goarch: [amd64] + +archives: + - formats: [none] + +nfpms: + - &rpm + id: vault + package_name: vault-plugin-secrets-gpg + bindir: /opt/vault-plugins + scripts: + preinstall: packaging/scripts/preinstall-vault.sh + replaces: [vault-plugin-secrets-gpg] + provides: [vault-plugin-secrets-gpg] + formats: [rpm] + file_name_template: "{{ .ConventionalFileName }}" + release: "1" + section: default + priority: extra + description: Vault/OpenBao secrets engine for GPG/OpenPGP keys (sign/verify/encrypt/decrypt) + maintainer: IUCLabs + homepage: https://github.com/IUCLabs/vault-plugin-secrets-gpg + license: MIT + - <<: *rpm + id: openbao + package_name: openbao-plugin-secrets-gpg + bindir: /opt/openbao-plugins + scripts: + preinstall: packaging/scripts/preinstall-openbao.sh + replaces: [openbao-plugin-secrets-gpg] + provides: [openbao-plugin-secrets-gpg] + +checksum: + name_template: "{{ .ProjectName }}_{{ .Version }}_SHA256SUMS" + algorithm: sha256 + +signs: + - artifacts: checksum + cmd: scripts/sign.sh + args: ["${artifact}", "${signature}"] + +changelog: + disable: true diff --git a/.woodpecker/release.yml b/.woodpecker/release.yml deleted file mode 100644 index 80ade25..0000000 --- a/.woodpecker/release.yml +++ /dev/null @@ -1,66 +0,0 @@ -when: - - event: tag - -steps: - - name: build - image: artifactapi.k8s.syd1.au.unkin.net/docker-internal/gobuilder:0.1.2-alma9 - commands: - - make build VERSION=${CI_COMMIT_TAG} - environment: - GOCACHE_S3_BUCKET: gocache - GOCACHE_S3_REGION: us-east-1 - GOCACHE_S3_ENDPOINT_URL: https://s3.ceph.unkin.net - GOCACHE_S3_PATH_STYLE: "true" - GOCACHE_KEY_PREFIX: ci-vault-plugin-secrets-gpg - GOCACHE_METRICS: "true" - GOCACHEPROG: go-cache-plugin --cache-dir=/tmp/gocache - AWS_ACCESS_KEY_ID: - from_secret: GOCACHE_AWS_ACCESS_KEY_ID - AWS_SECRET_ACCESS_KEY: - from_secret: GOCACHE_AWS_SECRET_ACCESS_KEY - backend_options: - kubernetes: - serviceAccountName: default - resources: - requests: {memory: 1Gi, cpu: 1} - limits: {memory: 3Gi, cpu: 2} - - - name: package - image: artifactapi.k8s.syd1.au.unkin.net/docker-internal/rpmbuilder:0.1.0-alma9 - commands: - - ./scripts/build-rpm.sh ${CI_COMMIT_TAG} - depends_on: [build] - backend_options: - kubernetes: - serviceAccountName: default - resources: - requests: {memory: 512Mi, cpu: 1} - limits: {memory: 2Gi, cpu: 2} - - - name: upload - image: git.unkin.net/unkin/almalinux9-base:20260606 - commands: - - | - HOST="https://artifactapi.k8s.syd1.au.unkin.net" - REPO="rpm-internal" - set -o pipefail - VAULT="https://vault.service.consul:8200" - AUTH=$$(mktemp) - VT=$$(jq -n --rawfile jwt /var/run/secrets/kubernetes.io/serviceaccount/token '{role:"woodpecker_artifactapi_writer",jwt:$$jwt}' \ - | curl -sf -d @- "$$VAULT/v1/auth/k8s/au/syd1/login" | jq -er .auth.client_token) || exit 1 - printf 'X-Vault-Token: %s\n' "$$VT" | curl -sf -H @- "$$VAULT/v1/identity/oidc/token/artifactapi-writer" \ - | jq -er '"Authorization: Bearer " + .data.token' > "$$AUTH" || exit 1 - for rpm in dist/*.rpm; do - FILE=$$(basename "$$rpm") - code=$$(curl -s -o /dev/null -w '%{http_code}' "$$HOST/api/v2/remotes/$$REPO/files/Packages/$$FILE" || true) - if [ "$$code" = "200" ]; then echo "$$FILE exists; skipping"; continue; fi - echo "Uploading $$FILE (probe $$code)" - curl -f -X PUT "$$HOST/api/v2/remotes/$$REPO/files/$$FILE" -H "Content-Type: application/x-rpm" -H @"$$AUTH" --data-binary @"$$rpm" - done - depends_on: [package] - backend_options: - kubernetes: - serviceAccountName: default - resources: - requests: {memory: 128Mi, cpu: 100m} - limits: {memory: 512Mi, cpu: 500m} diff --git a/Makefile b/Makefile index d0b10ed..7112d01 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: build install test lint fmt clean tidy rpm rpm-package patch minor major check-go e2e e2e-vault e2e-openbao e2e-up e2e-down +.PHONY: build install test lint fmt clean tidy rpm patch minor major check-go e2e e2e-vault e2e-openbao e2e-up e2e-down BINARY := vault-plugin-secrets-gpg PKG := ./cmd/vault-plugin-secrets-gpg @@ -36,10 +36,8 @@ tidy: clean: rm -rf $(PLUGIN_DIR) -rpm: build rpm-package - -rpm-package: - ./scripts/build-rpm.sh $(VERSION) +rpm: + GOTOOLCHAIN=auto go run github.com/goreleaser/goreleaser/v2@v2.20.2 release --snapshot --clean --skip=sign # End-to-end tests bring up Vault and OpenBao in Docker and drive the full key # lifecycle (generate/sign/verify/encrypt/decrypt/rotate) against each with the diff --git a/README.md b/README.md index 64ea465..430d8dd 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ To manage the engine's mounts and keys from Terraform or OpenTofu, use ## Installation -Download a binary from the +Install the x86_64 RPM (vault or openbao flavour) from the [releases page](https://github.com/IUCLabs/vault-plugin-secrets-gpg/releases), or build one: diff --git a/packaging/nfpm.yaml b/packaging/nfpm.yaml deleted file mode 100644 index 10517b9..0000000 --- a/packaging/nfpm.yaml +++ /dev/null @@ -1,35 +0,0 @@ ---- -# nfpm config for the vault-plugin-secrets-gpg RPM. Rendered through -# envsubst (see scripts/build-rpm.sh) then fed to `nfpm pkg`. Built once per -# target server (Vault, OpenBao); PACKAGE_NAME and PACKAGE_PLUGIN_DIR vary. - -name: ${PACKAGE_NAME} -version: ${PACKAGE_VERSION} -release: ${PACKAGE_RELEASE} -arch: ${PACKAGE_ARCH} -platform: ${PACKAGE_PLATFORM} -section: default -priority: extra -description: "${PACKAGE_DESCRIPTION}" - -maintainer: ${PACKAGE_MAINTAINER} -homepage: ${PACKAGE_HOMEPAGE} -license: ${PACKAGE_LICENSE} - -disable_globbing: false - -replaces: - - ${PACKAGE_NAME} -provides: - - ${PACKAGE_NAME} - -contents: - - src: dist/vault-plugin-secrets-gpg - dst: ${PACKAGE_PLUGIN_DIR}/vault-plugin-secrets-gpg - file_info: - mode: 0755 - owner: root - group: root - -scripts: - preinstall: ${PACKAGE_PREINSTALL} diff --git a/packaging/scripts/preinstall-openbao.sh b/packaging/scripts/preinstall-openbao.sh new file mode 100644 index 0000000..f64c283 --- /dev/null +++ b/packaging/scripts/preinstall-openbao.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +# Ensure the plugin directory exists before the binary is laid down. +mkdir -p /opt/openbao-plugins diff --git a/packaging/scripts/preinstall-vault.sh b/packaging/scripts/preinstall-vault.sh new file mode 100644 index 0000000..9ec17d6 --- /dev/null +++ b/packaging/scripts/preinstall-vault.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +# Ensure the plugin directory exists before the binary is laid down. +mkdir -p /opt/vault-plugins diff --git a/packaging/scripts/preinstall.sh.tmpl b/packaging/scripts/preinstall.sh.tmpl deleted file mode 100755 index e129bf4..0000000 --- a/packaging/scripts/preinstall.sh.tmpl +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -# Ensure the plugin directory exists before the binary is laid down. -# Rendered per flavour via envsubst (see scripts/build-rpm.sh). -mkdir -p ${PACKAGE_PLUGIN_DIR} diff --git a/scripts/build-rpm.sh b/scripts/build-rpm.sh deleted file mode 100755 index d59afd2..0000000 --- a/scripts/build-rpm.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env bash -# -# Package the (already built) plugin binary into RPMs with nfpm. Builds one RPM -# per target server: Vault (/opt/vault-plugins) and OpenBao (/opt/openbao-plugins). -# Usage: scripts/build-rpm.sh [version] (version defaults to $CI_COMMIT_TAG) -# -set -euo pipefail - -ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" -cd "${ROOT_DIR}" - -VERSION="${1:-${CI_COMMIT_TAG:-0.0.0-dev}}" -VERSION="${VERSION#v}" -BINARY="vault-plugin-secrets-gpg" -DIST="dist" - -if [ ! -f "${DIST}/${BINARY}" ]; then - echo "ERROR: ${DIST}/${BINARY} not found; run 'make build' first" >&2 - exit 1 -fi - -export PACKAGE_VERSION="${VERSION}" -export PACKAGE_RELEASE="1" -export PACKAGE_ARCH="amd64" -export PACKAGE_PLATFORM="linux" -export PACKAGE_DESCRIPTION="Vault/OpenBao secrets engine for GPG/OpenPGP keys (sign/verify/encrypt/decrypt)" -export PACKAGE_MAINTAINER="IUCLabs" -export PACKAGE_HOMEPAGE="https://github.com/IUCLabs/vault-plugin-secrets-gpg" -export PACKAGE_LICENSE="MIT" - -build_flavor() { - export PACKAGE_NAME="$1" - export PACKAGE_PLUGIN_DIR="$2" - export PACKAGE_PREINSTALL="${DIST}/preinstall-${PACKAGE_NAME}.sh" - envsubst '${PACKAGE_PLUGIN_DIR}' < packaging/scripts/preinstall.sh.tmpl > "${PACKAGE_PREINSTALL}" - envsubst < packaging/nfpm.yaml > "${DIST}/nfpm-${PACKAGE_NAME}.yaml" - nfpm pkg --config "${DIST}/nfpm-${PACKAGE_NAME}.yaml" --target "${DIST}" --packager rpm -} - -build_flavor "vault-plugin-secrets-gpg" "/opt/vault-plugins" -build_flavor "openbao-plugin-secrets-gpg" "/opt/openbao-plugins" - -echo "Built:" -ls -1 "${DIST}"/*.rpm diff --git a/scripts/sign.sh b/scripts/sign.sh new file mode 100755 index 0000000..e95575d --- /dev/null +++ b/scripts/sign.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +# Detached binary signature of $1 into $2 via the Vault gpg engine. +set -euo pipefail +b=$(base64 -w0 "$1") +jq -n --arg input "$b" '{input: $input, format: "base64"}' \ + | curl -sSf --cacert "${VAULT_CACERT:-/etc/vault-ca/ca.crt}" \ + -H "X-Vault-Token: ${VAULT_TOKEN}" -d @- \ + "${VAULT_ADDR}/v1/gpg/sign/iuclabs-release" \ + | jq -er .data.signature | base64 -d > "$2" -- 2.47.3